{"id":1658,"url":"https://patchwork.libcamera.org/api/patches/1658/?format=json","web_url":"https://patchwork.libcamera.org/patch/1658/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190711180525.31519-2-paul.elder@ideasonboard.com>","date":"2019-07-11T18:05:25","name":"[libcamera-devel,v3,2/2] test: add logging API test","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"a61e02652712e51fc80285b863f3b816c30ff439","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1658/mbox/","series":[{"id":419,"url":"https://patchwork.libcamera.org/api/series/419/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=419","date":"2019-07-11T18:05:24","name":"[libcamera-devel,v3,1/2] libcamera: logging: add logging API for applications","version":3,"mbox":"https://patchwork.libcamera.org/series/419/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1658/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1658/checks/","tags":{},"headers":{"Return-Path":"<paul.elder@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F23A960C3A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Jul 2019 20:05:35 +0200 (CEST)","from neptunite.amanokami.net (softbank126163157105.bbtec.net\n\t[126.163.157.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9E4A731C;\n\tThu, 11 Jul 2019 20:05:34 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562868335;\n\tbh=s8VIPqbYtHom8+IvFSFYRW+HZvu97OqmC3zDedcLv5A=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=cst2NABi0u+92z82FH86o4Sgi5mXANbi7iicKPaNDYkJH6qH4aWkMo3SvMb8coSRG\n\txu1dqQbp0V57u3tYYYuuAE78vIdVdkyeimZ7L8ArBfhvZOEdWS6MSdvU8k7m+RgNLd\n\thNQ+eNiY36MXPNkEowAdX+r3w+rJSj6EjgdDtpoA=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 12 Jul 2019 03:05:25 +0900","Message-Id":"<20190711180525.31519-2-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190711180525.31519-1-paul.elder@ideasonboard.com>","References":"<20190711180525.31519-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel]  [PATCH v3 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 18:05:36 -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 v3:\n- better testing (actually check logging output)\n- move and rename test file into main testing directory\n\nChanges in v2:\n- added more test cases to catch if log level changes fail\n\n test/log.cpp     | 84 ++++++++++++++++++++++++++++++++++++++++++++++++\n test/meson.build |  1 +\n 2 files changed, 85 insertions(+)\n create mode 100644 test/log.cpp","diff":"diff --git a/test/log.cpp b/test/log.cpp\nnew file mode 100644\nindex 0000000..ffe066f\n--- /dev/null\n+++ b/test/log.cpp\n@@ -0,0 +1,84 @@\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 <list>\n+#include <sstream>\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[32];\n+\t\tsnprintf(path, sizeof(path), \"/proc/self/fd/%u\", fd);\n+\n+\t\tlogSetFile(path);\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"DEBUG\");\n+\t\tLOG(LogAPITest, Info) << \"good 1\";\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"WARN\");\n+\t\tLOG(LogAPITest, Info) << \"bad\";\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"ERROR\");\n+\t\tLOG(LogAPITest, Error) << \"good 3\";\n+\t\tLOG(LogAPITest, Info) << \"bad\";\n+\n+\t\tlogSetLevel(\"LogAPITest\", \"WARN\");\n+\t\tLOG(LogAPITest, Warning) << \"good 5\";\n+\t\tLOG(LogAPITest, Info) << \"bad\";\n+\n+\t\tchar buf[1000];\n+\t\tmemset(buf, 0, sizeof(buf));\n+\t\tlseek(fd, 0, SEEK_SET);\n+\t\tread(fd, buf, sizeof(buf));\n+\t\tclose(fd);\n+\n+\t\tstd::list<int> goodList = { 1, 3, 5 };\n+\t\tstd::basic_istringstream<char> iss((std::string(buf)));\n+\t\tchar str[100];\n+\t\twhile (iss.getline(str, sizeof(str))) {\n+\t\t\tchar tmp = std::string(str).back();\n+\t\t\tint i = tmp - '0';\n+\t\t\tint j = goodList.front();\n+\t\t\tgoodList.pop_front();\n+\t\t\tif (i != j)\n+\t\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (!goodList.empty())\n+\t\t\treturn TestFail;\n+\n+\t\treturn TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(LogAPITest)\ndiff --git a/test/meson.build b/test/meson.build\nindex 60ce960..d308ac9 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -21,6 +21,7 @@ public_tests = [\n \n internal_tests = [\n     ['camera-sensor',                   'camera-sensor.cpp'],\n+    ['log',                             'log.cpp'],\n     ['message',                         'message.cpp'],\n     ['signal-threads',                  'signal-threads.cpp'],\n     ['threads',                         'threads.cpp'],\n","prefixes":["libcamera-devel","v3","2/2"]}