{"id":9330,"url":"https://patchwork.libcamera.org/api/1.1/patches/9330/?format=json","web_url":"https://patchwork.libcamera.org/patch/9330/","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":"<20200815151036.509376-1-vicamo.yang@canonical.com>","date":"2020-08-15T15:10:36","name":"[libcamera-devel,v3] test: log/process: check CAP_SYS_ADMIN in test init","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"fd4659e6dfe97225c27fe7c221eec9a176340685","submitter":{"id":61,"url":"https://patchwork.libcamera.org/api/1.1/people/61/?format=json","name":"You-Sheng Yang","email":"vicamo.yang@canonical.com"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/1.1/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/9330/mbox/","series":[{"id":1223,"url":"https://patchwork.libcamera.org/api/1.1/series/1223/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1223","date":"2020-08-15T15:10:36","name":"[libcamera-devel,v3] test: log/process: check CAP_SYS_ADMIN in test init","version":3,"mbox":"https://patchwork.libcamera.org/series/1223/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9330/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9330/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id DB6EDBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 15 Aug 2020 15:10:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7E3CA617BD;\n\tSat, 15 Aug 2020 17:10:43 +0200 (CEST)","from mail-pg1-f174.google.com (mail-pg1-f174.google.com\n\t[209.85.215.174])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7977060386\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 15 Aug 2020 17:10:42 +0200 (CEST)","by mail-pg1-f174.google.com with SMTP id h12so5902983pgm.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 15 Aug 2020 08:10:42 -0700 (PDT)","from localhost (36-228-82-217.dynamic-ip.hinet.net.\n\t[36.228.82.217]) by smtp.gmail.com with ESMTPSA id\n\tq5sm10755165pgv.1.2020.08.15.08.10.37\n\tfor <libcamera-devel@lists.libcamera.org>\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 15 Aug 2020 08:10:38 -0700 (PDT)"],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=DPAtEG4MbvUZOCqGMhxRyy/PvkJM4FtI6lBz8Ixu6P4=;\n\tb=rUuUMRbVC3G2gooDRKkvdUkVxgs0QQX4CvSWz9tOVIu+E3NRdX7vB5FzG2EYwZmvr4\n\tyoIrWyXPrEOByfRgdyOssoBcaKpEZYdXhMOr2QOk6h0UfHvZfwgeHk6z0yau5tA6dxQE\n\t22yG8AU4KEXafWQuB2R2lAFWm0BjTdmFg2S1KkGstokX56KhkU/r7xBytl30gvtgc6ZR\n\tBlyGCVhPcmGe6pLnwmH+0p7pyFkW3WiCx1TvaKRcYH6Vf9fQ/mCl40Yo2oxsaRC1SXds\n\tlrqIE8x/V22AweX5gUjoVAgEdE/2Dt9VbW3YGn2ASg+t1iE8fP/SVPVqhNHEj/Gfwxbk\n\twdpg==","X-Gm-Message-State":"AOAM532aLqn8dIreh0PJX7INISCjLNpWFyxK1+SI79DLDtp2DgH03UMk\n\t0G9haGKjCUiJMqQZRBczzsnEsTxnIC3tjA==","X-Google-Smtp-Source":"ABdhPJwlWisknB4A/zv/Gk+YhlevMvp7T+YfHEmX6NdRl/qhIQJMJXmtkgeEtLXflcuQrc23IUap7g==","X-Received":"by 2002:a63:e24d:: with SMTP id\n\ty13mr5026290pgj.248.1597504239854; \n\tSat, 15 Aug 2020 08:10:39 -0700 (PDT)","From":"You-Sheng Yang <vicamo.yang@canonical.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 15 Aug 2020 23:10:36 +0800","Message-Id":"<20200815151036.509376-1-vicamo.yang@canonical.com>","X-Mailer":"git-send-email 2.27.0","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3] test: log/process: check CAP_SYS_ADMIN\n\tin test init","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"While these tests may be executed as normal user at build time,\nunshare() call will fail and so are tests log_process and process_test.\nThis change checks if one is granted with necessary capabilities so that\nwe don't fail the build unexpectedly.\n\nv2:\n - add a shared capability testing util func\n - drop merge process kill(-1) patch\n - drop patch for removed list-camera test\nv3:\n - mark libcap dependency as optional\n\nSigned-off-by: You-Sheng Yang <vicamo.yang@canonical.com>\n---\n test/libtest/meson.build      |  3 ++-\n test/libtest/test.cpp         | 32 +++++++++++++++++++++++++++++++-\n test/libtest/test.h           |  6 ++++++\n test/log/log_process.cpp      | 13 ++++++++++++-\n test/log/meson.build          |  3 ++-\n test/meson.build              | 15 +++++++++++++--\n test/process/meson.build      |  3 ++-\n test/process/process_test.cpp | 15 +++++++++++++++\n 8 files changed, 83 insertions(+), 7 deletions(-)","diff":"diff --git a/test/libtest/meson.build b/test/libtest/meson.build\nindex 542335e..9e7c603 100644\n--- a/test/libtest/meson.build\n+++ b/test/libtest/meson.build\n@@ -18,7 +18,8 @@ test_includes_internal = [\n ]\n \n libtest = static_library('libtest', libtest_sources,\n-                         dependencies : libcamera_dep,\n+                         dependencies : [ libcamera_dep, libtest_dep ],\n+                         cpp_args : libtest_cpp_args,\n                          include_directories : test_includes_internal)\n \n test_libraries = [libtest]\ndiff --git a/test/libtest/test.cpp b/test/libtest/test.cpp\nindex fd9f3d7..564e0bc 100644\n--- a/test/libtest/test.cpp\n+++ b/test/libtest/test.cpp\n@@ -5,10 +5,40 @@\n  * test.cpp - libcamera test base class\n  */\n \n-#include <stdlib.h>\n+#include <stdarg.h>\n \n #include \"test.h\"\n \n+TestStatus\n+Test::testCapabilities(int nCapabilities, ...)\n+{\n+#ifdef HAVE_LIBLOG\n+\tva_list args;\n+\n+\tva_start(args, nCapabilities);\n+\n+\tcap_t caps = cap_get_proc();\n+\tif (caps == NULL)\n+\t\treturn TestFail;\n+\n+\tcap_value_t v;\n+\tcap_flag_t f;\n+\tcap_flag_value_t fv;\n+\twhile (nCapabilities-- > 0) {\n+\t\tv = (cap_value_t)va_arg(args, int);\n+\t\tf = (cap_flag_t)va_arg(args, int);\n+\t\tif ((cap_get_flag(caps, v, f, &fv) < 0) || (fv != CAP_SET))\n+\t\t\tbreak;\n+\t}\n+\n+\tcap_free(caps);\n+\n+\treturn nCapabilities >= 0 ? TestFail : TestPass;\n+#else\n+\treturn TestSkip;\n+#endif\n+}\n+\n Test::Test()\n {\n }\ndiff --git a/test/libtest/test.h b/test/libtest/test.h\nindex 26d4b94..da64179 100644\n--- a/test/libtest/test.h\n+++ b/test/libtest/test.h\n@@ -7,6 +7,10 @@\n #ifndef __TEST_TEST_H__\n #define __TEST_TEST_H__\n \n+#ifdef HAVE_LIBLOG\n+#include <sys/capability.h>\n+#endif\n+\n #include <sstream>\n \n enum TestStatus {\n@@ -23,6 +27,8 @@ public:\n \n \tint execute();\n \n+\tstatic TestStatus testCapabilities(int nCapabilities, ...);\n+\n protected:\n \tvirtual int init() { return 0; }\n \tvirtual int run() = 0;\ndiff --git a/test/log/log_process.cpp b/test/log/log_process.cpp\nindex d46d5e3..0db7e20 100644\n--- a/test/log/log_process.cpp\n+++ b/test/log/log_process.cpp\n@@ -55,13 +55,24 @@ class LogProcessTest : public Test\n protected:\n \tint init()\n \t{\n+#ifdef HAVE_LIBLOG\n+\t\t/* Check required permissions: CAP_SYS_ADMIN: unshare */\n+\t\tint ret = testCapabilities(1, CAP_SYS_ADMIN, CAP_EFFECTIVE);\n+\t\tif (ret != TestPass) {\n+\t\t\tchar *cap = cap_to_name(CAP_SYS_ADMIN);\n+\t\t\tcerr << \"Insufficient capability: \" << cap << endl;\n+\t\t\tcap_free(cap);\n+\t\t\treturn TestSkip;\n+\t\t}\n+#endif\n+\n \t\trandom_device random;\n \t\tnum_ = random();\n \t\tlogPath_ = \"/tmp/libcamera.worker.test.\" +\n \t\t\t   to_string(num_) + \".log\";\n \n \t\tproc_.finished.connect(this, &LogProcessTest::procFinished);\n-\t\treturn 0;\n+\t\treturn TestPass;\n \t}\n \n \tint run()\ndiff --git a/test/log/meson.build b/test/log/meson.build\nindex 8cd664e..d4745a1 100644\n--- a/test/log/meson.build\n+++ b/test/log/meson.build\n@@ -7,7 +7,8 @@ log_test = [\n \n foreach t : log_test\n     exe = executable(t[0], t[1],\n-                     dependencies : libcamera_dep,\n+                     dependencies : [ libcamera_dep, libtest_dep ],\n+                     cpp_args : libtest_cpp_args,\n                      link_with : test_libraries,\n                      include_directories : test_includes_internal)\n \ndiff --git a/test/meson.build b/test/meson.build\nindex 0a1d434..ea48b32 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -1,5 +1,14 @@\n # SPDX-License-Identifier: CC0-1.0\n \n+libtest_dep = []\n+libtest_cpp_args = []\n+\n+libcap = dependency('libcap', required : false)\n+if libcap.found()\n+    libtest_dep += [ libcap ]\n+    libtest_cpp_args += [ '-DHAVE_LIBLOG' ]\n+endif\n+\n subdir('libtest')\n \n subdir('camera')\n@@ -46,7 +55,8 @@ internal_tests = [\n \n foreach t : public_tests\n     exe = executable(t[0], t[1],\n-                     dependencies : libcamera_dep,\n+                     dependencies : [ libcamera_dep, libtest_dep ],\n+                     cpp_args : libtest_cpp_args,\n                      link_with : test_libraries,\n                      include_directories : test_includes_public)\n \n@@ -55,7 +65,8 @@ endforeach\n \n foreach t : internal_tests\n     exe = executable(t[0], t[1],\n-                     dependencies : libcamera_dep,\n+                     dependencies : [ libcamera_dep, libtest_dep ],\n+                     cpp_args : libtest_cpp_args,\n                      link_with : test_libraries,\n                      include_directories : test_includes_internal)\n \ndiff --git a/test/process/meson.build b/test/process/meson.build\nindex c215fa7..c141042 100644\n--- a/test/process/meson.build\n+++ b/test/process/meson.build\n@@ -6,7 +6,8 @@ process_tests = [\n \n foreach t : process_tests\n     exe = executable(t[0], t[1],\n-                     dependencies : libcamera_dep,\n+                     dependencies : [ libcamera_dep, libtest_dep ],\n+                     cpp_args : libtest_cpp_args,\n                      link_with : test_libraries,\n                      include_directories : test_includes_internal)\n \ndiff --git a/test/process/process_test.cpp b/test/process/process_test.cpp\nindex 721a7c9..6386826 100644\n--- a/test/process/process_test.cpp\n+++ b/test/process/process_test.cpp\n@@ -41,6 +41,21 @@ public:\n \t}\n \n protected:\n+\tint init()\n+\t{\n+#ifdef HAVE_LIBLOG\n+\t\t/* Check required permissions: CAP_SYS_ADMIN: unshare */\n+\t\tint ret = testCapabilities(1, CAP_SYS_ADMIN, CAP_EFFECTIVE);\n+\t\tif (ret != TestPass) {\n+\t\t\tchar *cap = cap_to_name(CAP_SYS_ADMIN);\n+\t\t\tcerr << \"Insufficient capability: \" << cap << endl;\n+\t\t\tcap_free(cap);\n+\t\t\treturn TestSkip;\n+\t\t}\n+#endif\n+\t\treturn TestPass;\n+\t}\n+\n \tint run()\n \t{\n \t\tEventDispatcher *dispatcher = Thread::current()->eventDispatcher();\n","prefixes":["libcamera-devel","v3"]}