Patch Detail
Show a patch.
GET /api/patches/1708/?format=api
{ "id": 1708, "url": "https://patchwork.libcamera.org/api/patches/1708/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1708/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190716070508.24589-2-paul.elder@ideasonboard.com>", "date": "2019-07-16T07:05:06", "name": "[libcamera-devel,v2,2/4] test: logging: add logSetStream test", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "ff799b1734319424fbd00af1f724b2bd09e18557", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1708/mbox/", "series": [ { "id": 435, "url": "https://patchwork.libcamera.org/api/series/435/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=435", "date": "2019-07-16T07:05:05", "name": "[libcamera-devel,v2,1/4] libcamera: logging: add syslog, stream, and nowhere logging targets", "version": 2, "mbox": "https://patchwork.libcamera.org/series/435/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1708/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1708/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 673EE61AA8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Jul 2019 09:05:21 +0200 (CEST)", "from emerald.amanokami.net (unknown\n\t[IPv6:2a00:79e1:abc:3602:b57a:2dda:be67:ac6e])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1C6C6564;\n\tTue, 16 Jul 2019 09:05:19 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1563260721;\n\tbh=vodG6dCzfOrde6CqMZrEEa+sgZMXVDKMDloBFibbjUg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=hMvpUtnMa93apSTey7/s6wETbOUsGwldCbveabwl7UxxhaOd+W5aTyzNlMr9dlcrT\n\tUNQStuhkTbD4ZCso9Zim7pdIbU4PH41hEMc8tQV7HxIwugBDAHHtN7No5L/1FLXhtn\n\tmxu4IFfcX+Z1upEh3MVCkPBHDXxA2OU2cfP9Sg44=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 16 Jul 2019 16:05:06 +0900", "Message-Id": "<20190716070508.24589-2-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.17.1", "In-Reply-To": "<20190716070508.24589-1-paul.elder@ideasonboard.com>", "References": "<20190716070508.24589-1-paul.elder@ideasonboard.com>", "Subject": "[libcamera-devel] [PATCH v2 2/4] test: logging: add logSetStream\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": "Tue, 16 Jul 2019 07:05:21 -0000" }, "content": "Test the new logSetStream logging API call. Reorganize the logging API\ntests at the same time.\n\nlogSetTarget for the syslog logging destination is not tested.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nChanges in v2:\n- add testing for logSetTarget, to test that writing to none doesn't\n crash, and to test that setting to file or stream fail\n- make verifyOutput() take an istream (instead of a string)\n- make total test passage checking nicer\n\n test/log.cpp | 106 +++++++++++++++++++++++++++++++++++++++------------\n 1 file changed, 81 insertions(+), 25 deletions(-)", "diff": "diff --git a/test/log.cpp b/test/log.cpp\nindex 89fb5ca..33622f8 100644\n--- a/test/log.cpp\n+++ b/test/log.cpp\n@@ -29,19 +29,8 @@ LOG_DEFINE_CATEGORY(LogAPITest)\n class LogAPITest : public Test\n {\n protected:\n-\tint run() override\n+\tvoid doLogging()\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@@ -55,20 +44,13 @@ protected:\n \t\tlogSetLevel(\"LogAPITest\", \"WARN\");\n \t\tLOG(LogAPITest, Warning) << \"good 5\";\n \t\tLOG(LogAPITest, Info) << \"bad\";\n+\t}\n \n-\t\tchar buf[1000];\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\tstd::list<int> goodList = { 1, 3, 5 };\n-\t\tstd::basic_istringstream<char> iss((std::string(buf)));\n-\t\tstd::string line;\n-\t\twhile (getline(iss, line)) {\n+\tint verifyOutput(istream &is)\n+\t{\n+\t\tlist<int> goodList = { 1, 3, 5 };\n+\t\tstring line;\n+\t\twhile (getline(is, line)) {\n \t\t\tif (goodList.empty()) {\n \t\t\t\tcout << \"Too many log lines\" << endl;\n \t\t\t\treturn TestFail;\n@@ -90,6 +72,80 @@ protected:\n \n \t\treturn TestPass;\n \t}\n+\n+\tint testFile()\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\tif (logSetFile(path) < 0) {\n+\t\t\tcerr << \"Failed to set log file\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tdoLogging();\n+\n+\t\tchar buf[1000];\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\tistringstream iss(buf);\n+\t\treturn verifyOutput(iss);\n+\t}\n+\n+\tint testStream()\n+\t{\n+\t\tstringstream log;\n+\t\t/* Never fails, so no need to check return value */\n+\t\tlogSetStream(&log);\n+\n+\t\tdoLogging();\n+\n+\t\treturn verifyOutput(log);\n+\t}\n+\n+\tint testTarget()\n+\t{\n+\t\tlogSetTarget(LoggingTargetNone);\n+\t\tlogSetLevel(\"LogAPITest\", \"DEBUG\");\n+\t\tLOG(LogAPITest, Info) << \"don't crash please\";\n+\n+\t\tif (!logSetTarget(LoggingTargetFile))\n+\t\t\treturn TestFail;\n+\n+\t\tif (!logSetTarget(LoggingTargetStream))\n+\t\t\treturn TestFail;\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tint run() override\n+\t{\n+\t\tint ret = testFile();\n+\t\tif (ret != TestPass)\n+\t\t\treturn TestFail;\n+\n+\t\tret = testStream();\n+\t\tif (ret != TestPass)\n+\t\t\treturn TestFail;\n+\n+\t\tret = testTarget();\n+\t\tif (ret != TestPass)\n+\t\t\treturn TestFail;\n+\n+\t\treturn TestPass;\n+\t}\n };\n \n TEST_REGISTER(LogAPITest)\n", "prefixes": [ "libcamera-devel", "v2", "2/4" ] }