From patchwork Thu Jul 11 09:36:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 1652 Return-Path: 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 4AF0261574 for ; Thu, 11 Jul 2019 11:36:42 +0200 (CEST) Received: from neptunite.amanokami.net (softbank126163157105.bbtec.net [126.163.157.105]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EC07031C; Thu, 11 Jul 2019 11:36:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562837802; bh=MEe5LOrSjSEUgloFHFiVyg1HAL8LDkX77lUmON/smz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mjkT46jQQMWxETAzVSvDxW+O6V9mCiI2lw+JlhPrB6LZJ6/ZgZatmoRhiV7ZoL6Xn hEB8iPN1AD5EewHuE6ngKdfBOjr+K4kv88nEeYQVWdynVC2UP8ZvstYhG3vvpH9xLx VRJjfANjifH1niJK2xPSX7xL4z/Opx6Dhf1Rg9hE= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Thu, 11 Jul 2019 18:36:32 +0900 Message-Id: <20190711093632.22133-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190711093632.22133-1-paul.elder@ideasonboard.com> References: <20190711093632.22133-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] test: add logging API test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jul 2019 09:36:42 -0000 Test that setting the log file and log levels works from an application point of view. The test uses the internal logging mechanism as well, just to write to the log file. Signed-off-by: Paul Elder --- test/log/log_api.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++ test/log/meson.build | 12 ++++++++ test/meson.build | 1 + 3 files changed, 79 insertions(+) create mode 100644 test/log/log_api.cpp create mode 100644 test/log/meson.build diff --git a/test/log/log_api.cpp b/test/log/log_api.cpp new file mode 100644 index 0000000..e294d1e --- /dev/null +++ b/test/log/log_api.cpp @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * log_api.cpp - log API test + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "log.h" +#include "test.h" + +using namespace std; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(LogAPITest) + +class LogAPITest : public Test +{ +protected: + int run() override + { + int fd = open("/tmp", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR); + if (fd < 0) { + cerr << "Failed to open tmp log file" << endl; + return TestFail; + } + + char path[PATH_MAX]; + snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd); + + logSetFile(path); + + logSetLevel("LogAPITest", "WARN"); + LOG(LogAPITest, Info) << "asdf"; + + logSetLevel("LogAPITest", "INFO"); + LOG(LogAPITest, Warning) << "asdf"; + + logSetLevel("LogAPITest", "ERROR"); + LOG(LogAPITest, Error) << "asdf"; + + char buf[200]; + lseek(fd, 0, SEEK_SET); + read(fd, buf, 1000); + close(fd); + + std::string s(buf); + int n = count(s.begin(), s.end(), '\n'); + if (n == 2) + return TestPass; + + return TestFail; + } +}; + +TEST_REGISTER(LogAPITest) diff --git a/test/log/meson.build b/test/log/meson.build new file mode 100644 index 0000000..35ea553 --- /dev/null +++ b/test/log/meson.build @@ -0,0 +1,12 @@ +log_api_test = [ + ['log_api', 'log_api.cpp'], +] + +foreach t : log_api_test + exe = executable(t[0], t[1], + dependencies : libcamera_dep, + link_with : test_libraries, + include_directories : test_includes_internal) + + test(t[0], exe, suite : 'log') +endforeach diff --git a/test/meson.build b/test/meson.build index 60ce960..44d8495 100644 --- a/test/meson.build +++ b/test/meson.build @@ -4,6 +4,7 @@ subdir('camera') subdir('controls') subdir('ipa') subdir('ipc') +subdir('log') subdir('media_device') subdir('pipeline') subdir('stream')