{"id":1654,"url":"https://patchwork.libcamera.org/api/1.1/patches/1654/?format=json","web_url":"https://patchwork.libcamera.org/patch/1654/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190711102418.29661-2-paul.elder@ideasonboard.com>","date":"2019-07-11T10:24:18","name":"[libcamera-devel,v2,2/2] test: add logging API test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"94c9479285fa2eff874a3ad9f926afad7706ba45","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1654/mbox/","series":[{"id":417,"url":"https://patchwork.libcamera.org/api/1.1/series/417/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=417","date":"2019-07-11T10:24:17","name":"[libcamera-devel,v2,1/2] libcamera: logging: add logging API for applications","version":2,"mbox":"https://patchwork.libcamera.org/series/417/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1654/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1654/checks/","tags":{},"headers":{"Return-Path":"<paul.elder@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 00C6B61574\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Jul 2019 12:24:31 +0200 (CEST)","from neptunite.amanokami.net (softbank126163157105.bbtec.net\n\t[126.163.157.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 98FF3CC;\n\tThu, 11 Jul 2019 12:24:29 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562840670;\n\tbh=WMuIkKCL1z6hOX3eK3QIAspUay7E/fz69zaUpbaBWp8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Gm28taQ5akzr6RGnnoFkiBt/rkLHMYBSnKt7oHjMD5UMV57z475HDcVNUEnSJXg7d\n\taQ5KLmf8Y7g6VOJCVSwao38CbdN3yAhjk4FS+GBvfBqWUOgfyUKqGB5oZ8ujUSt+/R\n\tOkPz8gDoVXot4kMEgmCpmaCuOPwkm1q7fn+S/iaU=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 11 Jul 2019 19:24:18 +0900","Message-Id":"<20190711102418.29661-2-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190711102418.29661-1-paul.elder@ideasonboard.com>","References":"<20190711102418.29661-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel]  [PATCH v2 2/2] test: add logging API test","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 11 Jul 2019 10:24:31 -0000"},"content":"Test that setting the log file and log levels works from an application\npoint of view. The test uses the internal logging mechanism as well,\njust to write to the log file.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nChanges in v2:\n- added more test cases to catch if log level changes fail\n\n test/log/log_api.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++\n test/log/meson.build | 12 +++++++\n test/meson.build     |  1 +\n 3 files changed, 88 insertions(+)\n create mode 100644 test/log/log_api.cpp\n create mode 100644 test/log/meson.build","diff":"diff --git a/test/log/log_api.cpp b/test/log/log_api.cpp\nnew file mode 100644\nindex 0000000..395b857\n--- /dev/null\n+++ b/test/log/log_api.cpp\n@@ -0,0 +1,75 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * log_api.cpp - log API test\n+ */\n+\n+#include <algorithm>\n+#include <fcntl.h>\n+#include <iostream>\n+#include <stdio.h>\n+#include <string.h>\n+#include <sys/stat.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n+\n+#include <libcamera/logging.h>\n+\n+#include \"log.h\"\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+LOG_DEFINE_CATEGORY(LogAPITest)\n+\n+class LogAPITest : public Test\n+{\n+protected:\n+\tint run() override\n+\t{\n+\t\tint fd = open(\"/tmp\", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);\n+\t\tif (fd < 0) {\n+\t\t\tcerr << \"Failed to open tmp log file\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tchar path[PATH_MAX];\n+\t\tsnprintf(path, PATH_MAX, \"/proc/self/fd/%d\", fd);\n+\n+\t\tlogSetFile(path);\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"DEBUG\");\n+\t\tLOG(LogAPITest, Info) << \"asdf\";\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"WARN\");\n+\t\tLOG(LogAPITest, Info) << \"asdf\";\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"WARN\");\n+\t\tLOG(LogAPITest, Info) << \"asdf\";\n+\t\tLOG(LogAPITest, Debug) << \"asdf\";\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"ERROR\");\n+\t\tLOG(LogAPITest, Error) << \"asdf\";\n+\t\tLOG(LogAPITest, Info) << \"asdf\";\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"WARN\");\n+\t\tLOG(LogAPITest, Warning) << \"asdf\";\n+\t\tLOG(LogAPITest, Info) << \"asdf\";\n+\n+\t\tchar buf[200];\n+\t\tlseek(fd, 0, SEEK_SET);\n+\t\tread(fd, buf, 1000);\n+\t\tclose(fd);\n+\n+\t\tstd::string s(buf);\n+\t\tint n = count(s.begin(), s.end(), '\\n');\n+\t\tif (n == 3)\n+\t\t\treturn TestPass;\n+\n+\t\treturn TestFail;\n+\t}\n+};\n+\n+TEST_REGISTER(LogAPITest)\ndiff --git a/test/log/meson.build b/test/log/meson.build\nnew file mode 100644\nindex 0000000..35ea553\n--- /dev/null\n+++ b/test/log/meson.build\n@@ -0,0 +1,12 @@\n+log_api_test = [\n+    ['log_api', 'log_api.cpp'],\n+]\n+\n+foreach t : log_api_test\n+    exe = executable(t[0], t[1],\n+                     dependencies : libcamera_dep,\n+                     link_with : test_libraries,\n+                     include_directories : test_includes_internal)\n+\n+    test(t[0], exe, suite : 'log')\n+endforeach\ndiff --git a/test/meson.build b/test/meson.build\nindex 60ce960..44d8495 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -4,6 +4,7 @@ subdir('camera')\n subdir('controls')\n subdir('ipa')\n subdir('ipc')\n+subdir('log')\n subdir('media_device')\n subdir('pipeline')\n subdir('stream')\n","prefixes":["libcamera-devel","v2","2/2"]}