From patchwork Thu Jun 12 13:56:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23625 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5D3A7BDE6B for ; Mon, 23 Jun 2025 14:12:20 +0000 (UTC) Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A885915BF for ; Mon, 23 Jun 2025 16:12:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1750687923; bh=oXWnWY8eXvX5cVuwOlFhkQrR5v4i4wBsledl1Kd06hc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Resent-From:Resent-To:From; b=djwTKfh/yFI4BgQbGput1OyeMr3Q+ofZDNXgSlkLhk+01pUoItDxsIfR9GhCsXPya 1aaf4/ZOdTjtLym1PZx24JRt2hoJGisb3dHlq5rXN0RagaizQ8ObNbR9TXjTiftzep RqtElud7iJp2Tw+2ldPaa1xv/su6Y/O09Erf4Mto= Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id 0B0kKlfdSmgaMi0A4E0KoQ (envelope-from ) for ; Thu, 12 Jun 2025 15:59:51 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id 88BDA169; Thu, 12 Jun 2025 15:59:51 +0200 (CEST) Authentication-Results: perceval.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=jJr01cUY; dkim-atps=neutral Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E4B468DC2; Thu, 12 Jun 2025 15:59:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jJr01cUY"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B7C6D61551 for ; Thu, 12 Jun 2025 15:59:53 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:3176:2bf8:8f04:4c4]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id C4DE0169; Thu, 12 Jun 2025 15:59:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749736784; bh=ZKg3lMlyX7gLA7uXXVKXCtfM8PCrRdeKQUgLQtc5cRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jJr01cUYtWLk9nupb1IKkQ9Bo22pQLFkY+8J0AqWtq3h4uhGIMF4C/+eki5EMTWlA YowPDcdmXtbK3Q75NVwuP3A0buI8jBvFVopXCod5sBkXSUOtqhY5JuemBUuP9h0ed+ xhxa4DONh5hJaYnah3EdSM5Lm9G93aNcxCpAgJPw= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , =?utf-8?q?Barnab=C3=A1s_P?= =?utf-8?b?xZFjemU=?= Subject: [PATCH v2 1/2] libcamera: test: Add a failing test for the log level parser Date: Thu, 12 Jun 2025 15:56:44 +0200 Message-ID: <20250612135943.522819-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250612135943.522819-1-stefan.klug@ideasonboard.com> References: <20250612135943.522819-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: EZK/VqjjYHAd Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org Log level parsing doesn't always work as expected. Add a failing test for that. Co-authored-by: Barnabás Pőcze Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- test/log/log_api.cpp | 39 ++++++++++++++++++++++++++++++++++++++- test/log/meson.build | 5 +++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/test/log/log_api.cpp b/test/log/log_api.cpp index 0b999738d891..8d19cf0ceb67 100644 --- a/test/log/log_api.cpp +++ b/test/log/log_api.cpp @@ -26,6 +26,11 @@ using namespace std; using namespace libcamera; LOG_DEFINE_CATEGORY(LogAPITest) +LOG_DEFINE_CATEGORY(Cat0) +LOG_DEFINE_CATEGORY(Cat1) +LOG_DEFINE_CATEGORY(Cat2) +LOG_DEFINE_CATEGORY(Cat3) +LOG_DEFINE_CATEGORY(Cat4) class LogAPITest : public Test { @@ -74,6 +79,34 @@ protected: return TestPass; } + int testEnvLevels() + { + setenv("LIBCAMERA_LOG_LEVELS", + "Cat0:0,Cat0:9999,Cat1:INFO,Cat1:INVALID,Cat2:2,Cat2:-1," + "Cat3:ERROR,Cat3:{[]},Cat4:4,Cat4:rubbish", + true); + logSetTarget(libcamera::LoggingTargetNone); + + const std::pair expected[] = { + { _LOG_CATEGORY(Cat0)(), libcamera::LogDebug }, + { _LOG_CATEGORY(Cat1)(), libcamera::LogInfo }, + { _LOG_CATEGORY(Cat2)(), libcamera::LogWarning }, + { _LOG_CATEGORY(Cat3)(), libcamera::LogError }, + { _LOG_CATEGORY(Cat4)(), libcamera::LogFatal }, + }; + bool ok = true; + + for (const auto &[c, s] : expected) { + if (c.severity() != s) { + ok = false; + cerr << "Severity of " << c.name() << " (" << c.severity() << ") " + << "does not equal " << s << endl; + } + } + + return ok ? TestPass : TestFail; + } + int testFile() { int fd = open("/tmp", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR); @@ -135,7 +168,11 @@ protected: int run() override { - int ret = testFile(); + int ret = testEnvLevels(); + if (ret != TestPass) + return TestFail; + + ret = testFile(); if (ret != TestPass) return TestFail; diff --git a/test/log/meson.build b/test/log/meson.build index 2298ff84ee62..d91f62b9ea5b 100644 --- a/test/log/meson.build +++ b/test/log/meson.build @@ -1,7 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 log_test = [ - {'name': 'log_api', 'sources': ['log_api.cpp']}, + {'name': 'log_api', 'sources': ['log_api.cpp'], 'should_fail':true}, {'name': 'log_process', 'sources': ['log_process.cpp']}, ] @@ -11,5 +11,6 @@ foreach test : log_test link_with : test_libraries, include_directories : test_includes_internal) - test(test['name'], exe, suite : 'log') + test(test['name'], exe, suite : 'log', + should_fail : test.get('should_fail', false)) endforeach