Patch Detail
Show a patch.
GET /api/patches/9329/?format=api
{ "id": 9329, "url": "https://patchwork.libcamera.org/api/patches/9329/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9329/", "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": "<20200815150123.504718-1-vicamo.yang@canonical.com>", "date": "2020-08-15T15:01:23", "name": "[libcamera-devel,v2] test: log/process: check CAP_SYS_ADMIN in test init", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "f66016f62a77135f6ea13496e18dd6702b11b670", "submitter": { "id": 61, "url": "https://patchwork.libcamera.org/api/people/61/?format=api", "name": "You-Sheng Yang", "email": "vicamo.yang@canonical.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/9329/mbox/", "series": [ { "id": 1222, "url": "https://patchwork.libcamera.org/api/series/1222/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1222", "date": "2020-08-15T15:01:23", "name": "[libcamera-devel,v2] test: log/process: check CAP_SYS_ADMIN in test init", "version": 2, "mbox": "https://patchwork.libcamera.org/series/1222/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9329/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9329/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 445C0BD879\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 15 Aug 2020 15:01:31 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C8D09617BD;\n\tSat, 15 Aug 2020 17:01:30 +0200 (CEST)", "from mail-pf1-f193.google.com (mail-pf1-f193.google.com\n\t[209.85.210.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F2EC60386\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 15 Aug 2020 17:01:29 +0200 (CEST)", "by mail-pf1-f193.google.com with SMTP id f193so5948173pfa.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 15 Aug 2020 08:01:29 -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\tr25sm10506898pgv.88.2020.08.15.08.01.24\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:01:25 -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=Txk3EJJAu2GpFmH52zo4ZZsRgnMVFRt2438LfRVV1GA=;\n\tb=Bq8KBxcWabS25w2aOFVR0tnRq7Mr7vve3/w77LeDE9m3ohCyo+gNTX3uqJz4yrvgUT\n\tEMPFJxGr1Ce/a6rrfDDvG8pgwoqDQm1Wn5ENmWmzfG+CCZldxkEBT4nN5GvsRZI5J0fu\n\tfCu8uDr5kVyJOeCqIP4+J+jt3MWzpN7J+1tqaAnrROi2dZLfBDbuoxQMUK5RACTqSVFD\n\tCxI/NuU6mS+DPdE2m4i7ikdp24DmiLOhQwACoUm5042678kul2MCtT87NOJNLp93it4X\n\tnSdEbYNbBWw2pi6YVE/azc2P3WQ1/C8jwPB5TiOdeKRp7qUTxJ58r7SQ47cGp4MH5Mc1\n\t3hVQ==", "X-Gm-Message-State": "AOAM530/9MNIXreI0Z/zJQBLrndz8hroaqwrzI3stWLH4S7i0864AA8K\n\tRgFykYe/0eWYjlTM5sKdy0bLygit1iB6nA==", "X-Google-Smtp-Source": "ABdhPJw5OOT+5pI1jkhunHazkhIdNhgCxlkiwZ+WNRcLx5/O0amdWFmbWSn7qy9nvcCj/vyEa7/Gow==", "X-Received": "by 2002:a62:5e04:: with SMTP id s4mr5542904pfb.67.1597503686768; \n\tSat, 15 Aug 2020 08:01:26 -0700 (PDT)", "From": "You-Sheng Yang <vicamo.yang@canonical.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 15 Aug 2020 23:01:23 +0800", "Message-Id": "<20200815150123.504718-1-vicamo.yang@canonical.com>", "X-Mailer": "git-send-email 2.27.0", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v2] 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\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..280b545 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')\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", "v2" ] }