[{"id":2287,"web_url":"https://patchwork.libcamera.org/comment/2287/","msgid":"<20190716074728.GB22355@pendragon.ideasonboard.com>","date":"2019-07-16T07:47:28","subject":"Re: [libcamera-devel] [PATCH v2 2/4] test: logging: add\n\tlogSetStream test","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Tue, Jul 16, 2019 at 04:05:06PM +0900, Paul Elder wrote:\n> Test the new logSetStream logging API call. Reorganize the logging API\n> tests at the same time.\n> \n> logSetTarget for the syslog logging destination is not tested.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> Changes 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(-)\n> \n> diff --git a/test/log.cpp b/test/log.cpp\n> index 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)","headers":{"Return-Path":"<laurent.pinchart@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 8342661AD3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 Jul 2019 09:47:57 +0200 (CEST)","from pendragon.ideasonboard.com (unknown\n\t[IPv6:2a00:79e1:abc:3602:59ec:6c:1869:337])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2BD9D564;\n\tTue, 16 Jul 2019 09:47:55 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1563263277;\n\tbh=1FulaU34NOoEt/DrrXYTsxUFGsDflQY45S2Z4TkXcB8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=nUtMoHxWO8UXlSsNrGCOEVHwowyTdK0bdefMhVBqv20vQ39s7XCTYA+CuUTvV/5Mr\n\tQQRv0qW5l+6X5/fZeSJNrHh287CG4xsSPylT6CmYc9L7+6+aG8aS6+l4vXaeODjyk3\n\tVGMnOPUaFv4FnNJ7M/wYjZCgId3y9D9r7io4RT8E=","Date":"Tue, 16 Jul 2019 10:47:28 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190716074728.GB22355@pendragon.ideasonboard.com>","References":"<20190716070508.24589-1-paul.elder@ideasonboard.com>\n\t<20190716070508.24589-2-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190716070508.24589-2-paul.elder@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2 2/4] test: logging: add\n\tlogSetStream 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":"Tue, 16 Jul 2019 07:47:57 -0000"}}]