{"id":1677,"url":"https://patchwork.libcamera.org/api/1.1/patches/1677/?format=json","web_url":"https://patchwork.libcamera.org/patch/1677/","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":"<20190712201620.30457-3-paul.elder@ideasonboard.com>","date":"2019-07-12T20:16:19","name":"[libcamera-devel,3/4] test: logging: add logging process test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e752c0e5d18458792cb1f6cfba818b4a7d284995","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/1677/mbox/","series":[{"id":427,"url":"https://patchwork.libcamera.org/api/1.1/series/427/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=427","date":"2019-07-12T20:16:17","name":"[libcamera-devel,1/4] libcamera: logging: add syslog, stream, and nowhere logging targets","version":1,"mbox":"https://patchwork.libcamera.org/series/427/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1677/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1677/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 C357861607\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Jul 2019 22:16:33 +0200 (CEST)","from neptunite.amanokami.net (softbank126209254147.bbtec.net\n\t[126.209.254.147])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 37A4652A;\n\tFri, 12 Jul 2019 22:16:31 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562962593;\n\tbh=gbfLOx3cNidhrGPTI4nj/hVvML5EWPVOtM1C3D6c2MM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=d18Sbdz4n1tPWBFFKJLsWoz+Z8/4aVQ/EP1QqldlZh9oK1JgiC9CPLeGY8GhEcDYR\n\tu5Y5rch1Q3DNEZnPFMk8NpehDgal4uqXfBZvkO5e70WNnJXVH0mo/YV9ugg49D8WTZ\n\txnWfpfRElx830gqMUHe4Cv0YFoN29yKl3qGAJ5Tg=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 13 Jul 2019 05:16:19 +0900","Message-Id":"<20190712201620.30457-3-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190712201620.30457-1-paul.elder@ideasonboard.com>","References":"<20190712201620.30457-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 3/4] test: logging: add logging process\n\ttest","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":"Fri, 12 Jul 2019 20:16:34 -0000"},"content":"Add a test to test that logging works in child processes. Only\nlogSetFile is tested.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n test/log_process.cpp | 147 +++++++++++++++++++++++++++++++++++++++++++\n test/meson.build     |   1 +\n 2 files changed, 148 insertions(+)\n create mode 100644 test/log_process.cpp","diff":"diff --git a/test/log_process.cpp b/test/log_process.cpp\nnew file mode 100644\nindex 0000000..feda687\n--- /dev/null\n+++ b/test/log_process.cpp\n@@ -0,0 +1,147 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * process_test.cpp - Process test\n+ */\n+\n+#include <ctime>\n+#include <cstdlib>\n+#include <fcntl.h>\n+#include <iostream>\n+#include <string.h>\n+#include <sys/stat.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n+#include <vector>\n+\n+#include <libcamera/camera_manager.h>\n+#include <libcamera/event_dispatcher.h>\n+#include <libcamera/logging.h>\n+#include <libcamera/timer.h>\n+\n+#include \"log.h\"\n+#include \"process.h\"\n+#include \"test.h\"\n+#include \"utils.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+static string message(\"hello from the child\");\n+\n+LOG_DEFINE_CATEGORY(LogProcessTest)\n+\n+class LogProcessTestChild\n+{\n+public:\n+\tint run(int status, int num)\n+\t{\n+\t\tusleep(50000);\n+\n+\t\tstring logPath = \"/tmp/libcamera.worker.test.\" +\n+\t\t\t\t to_string(num) + \".log\";\n+\t\tif (logSetFile(logPath.c_str()) < 0)\n+\t\t\treturn TestSkip;\n+\t\tLOG(LogProcessTest, Warning) << message;\n+\n+\t\treturn status;\n+\t}\n+};\n+\n+class LogProcessTest : public Test\n+{\n+public:\n+\tLogProcessTest()\n+\t{\n+\t}\n+\n+protected:\n+\tint run()\n+\t{\n+\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n+\t\tTimer timeout;\n+\n+\t\tsrand(time(0));\n+\t\tint num = rand();\n+\n+\t\tint exitCode = 42;\n+\t\tvector<std::string> args;\n+\t\targs.push_back(to_string(exitCode));\n+\t\targs.push_back(to_string(num));\n+\t\tint ret = proc_.start(\"/proc/self/exe\", args);\n+\t\tif (ret) {\n+\t\t\tcerr << \"failed to start process\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\t\tproc_.finished.connect(this, &LogProcessTest::procFinished);\n+\n+\t\ttimeout.start(200);\n+\t\twhile (timeout.isRunning())\n+\t\t\tdispatcher->processEvents();\n+\n+\t\tif (exitStatus_ != Process::NormalExit) {\n+\t\t\tcerr << \"process did not exit normally\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (exitCode_ == TestSkip)\n+\t\t\treturn TestSkip;\n+\n+\t\tif (exitCode != exitCode_) {\n+\t\t\tcerr << \"exit code should be \" << exitCode\n+\t\t\t     << \", actual is \" << exitCode_ << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tstring logPath = \"/tmp/libcamera.worker.test.\" +\n+\t\t\t\t to_string(num) + \".log\";\n+\t\tint fd = open(logPath.c_str(), O_RDONLY, S_IRUSR);\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 buf[200];\n+\t\tmemset(buf, 0, sizeof(buf));\n+\t\tlseek(fd, 0, SEEK_SET);\n+\t\tif (read(fd, buf, sizeof(buf)) < 0) {\n+\t\t\tcerr << \"Failed to read tmp log file\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\t\tclose(fd);\n+\n+\t\tstring str(buf);\n+\t\tif (str.find(message) == string::npos)\n+\t\t\treturn TestFail;\n+\n+\t\treturn TestPass;\n+\t}\n+\n+private:\n+\tvoid procFinished(Process *proc, enum Process::ExitStatus exitStatus, int exitCode)\n+\t{\n+\t\texitStatus_ = exitStatus;\n+\t\texitCode_ = exitCode;\n+\t}\n+\n+\tProcess proc_;\n+\tenum Process::ExitStatus exitStatus_;\n+\tint exitCode_;\n+};\n+\n+/*\n+ * Can't use TEST_REGISTER() as single binary needs to act as both\n+ * parent and child processes.\n+ */\n+int main(int argc, char **argv)\n+{\n+\tif (argc == 3) {\n+\t\tint status = std::stoi(argv[1]);\n+\t\tint num = std::stoi(argv[2]);\n+\t\tLogProcessTestChild child;\n+\t\treturn child.run(status, num);\n+\t}\n+\n+\treturn LogProcessTest().execute();\n+}\ndiff --git a/test/meson.build b/test/meson.build\nindex ad1a2f2..658f283 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -23,6 +23,7 @@ public_tests = [\n internal_tests = [\n     ['camera-sensor',                   'camera-sensor.cpp'],\n     ['log',                             'log.cpp'],\n+    ['log_process',                     'log_process.cpp'],\n     ['message',                         'message.cpp'],\n     ['signal-threads',                  'signal-threads.cpp'],\n     ['threads',                         'threads.cpp'],\n","prefixes":["libcamera-devel","3/4"]}