new file mode 100644
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * log_api.cpp - log API test
+ */
+
+#include <algorithm>
+#include <fcntl.h>
+#include <iostream>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <libcamera/logging.h>
+
+#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)
new file mode 100644
@@ -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
@@ -4,6 +4,7 @@ subdir('camera')
subdir('controls')
subdir('ipa')
subdir('ipc')
+subdir('log')
subdir('media_device')
subdir('pipeline')
subdir('stream')
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 <paul.elder@ideasonboard.com> --- 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