From patchwork Sat Jul 25 12:24:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 8998 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 20BCEBD878 for ; Sat, 25 Jul 2020 13:03:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B586D61392; Sat, 25 Jul 2020 15:03:28 +0200 (CEST) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DAC561247 for ; Sat, 25 Jul 2020 14:24:52 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id k4so5897073pld.12 for ; Sat, 25 Jul 2020 05:24:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ozfoK3uawtbjSmM8oTXxM7sgf8Ans2dye0VC8eogObo=; b=DtsR2lBZdbHjeJ5eQEM8SBfXhkAbxlgGLjUqD2hus5gx/gsvCjcF5FTKFJ6fFBoUFG wvBpHi4g5KLWb+MukaZFUzqBphdSInBkrRaWZfQiioPP/IZPCkamC4FoD77/CDyP8l3/ fwJaPgkABd2tnTX3mm3GiM3pQgeSciqCWJaBtikzVgTR/uXXB0jPlTcvv9+bA1p6GNWv lnOd/L5VQeKTe37bZEf2FUhxyHEWMZg+RzKhFKVLT1ej+qyJZtnLshEOPxROVcNahSGj LQuSdHvpHyUit1ZSU/E7rx1czZgb0r8sgCLSFvdZJUVQ3cFHTRuZWKrxYYEFXq/nfJxl 0Keg== X-Gm-Message-State: AOAM531YaDHdqm+h9pJ60N9RtFhjun78Y2f/cEmEqbp41kBM2TyCkxFW VdHFopIqFNre62Zc0z6pP/2d9fEd5nI= X-Google-Smtp-Source: ABdhPJxUYEFlWO0YXnDFtTrZ9KtyFguDArp/wrQPEVSBw3i6uds1hmad/TDYfSf9qrR7yJ7vF8eW7A== X-Received: by 2002:a17:902:7e01:: with SMTP id b1mr12317419plm.310.1595679890537; Sat, 25 Jul 2020 05:24:50 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id q24sm9479757pfg.95.2020.07.25.05.24.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2020 05:24:49 -0700 (PDT) From: You-Sheng Yang To: libcamera-devel@lists.libcamera.org Date: Sat, 25 Jul 2020 20:24:41 +0800 Message-Id: <20200725122442.1679820-3-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200725122442.1679820-1-vicamo.yang@canonical.com> References: <20200725122442.1679820-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 25 Jul 2020 15:03:26 +0200 Subject: [libcamera-devel] [PATCH 2/3] test: log/process: check CAP_SYS_ADMIN in test init X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" While these tests may be executed as normal user at build time, unshare() call will fail and so are tests log_process and process_test. This change checks if one is granted with necessary capabilities so that we don't fail the build unexpectedly. Signed-off-by: You-Sheng Yang --- test/log/log_process.cpp | 20 ++++++++++++++++++++ test/log/meson.build | 2 +- test/meson.build | 2 ++ test/process/meson.build | 2 +- test/process/process_test.cpp | 23 +++++++++++++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/test/log/log_process.cpp b/test/log/log_process.cpp index d46d5e3..876da22 100644 --- a/test/log/log_process.cpp +++ b/test/log/log_process.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,25 @@ class LogProcessTest : public Test protected: int init() { + int ret = TestPass; + + cap_t caps = cap_get_proc(); + if (caps == NULL) { + cerr << "failed to check process capabilities" << endl; + return TestFail; + } + + /* Check required permissions: CAP_SYS_ADMIN: unshare */ + cap_flag_value_t fv; + if ((cap_get_flag(caps, CAP_SYS_ADMIN, CAP_EFFECTIVE, &fv) < 0) || (fv != CAP_SET)) { + cerr << "skip due to insufficient capability" << endl; + ret = TestSkip; + } + + cap_free(caps); + if (ret != TestPass) + return ret; + random_device random; num_ = random(); logPath_ = "/tmp/libcamera.worker.test." + diff --git a/test/log/meson.build b/test/log/meson.build index 8cd664e..000f980 100644 --- a/test/log/meson.build +++ b/test/log/meson.build @@ -7,7 +7,7 @@ log_test = [ foreach t : log_test exe = executable(t[0], t[1], - dependencies : libcamera_dep, + dependencies : [libcamera_dep, libcap], link_with : test_libraries, include_directories : test_includes_internal) diff --git a/test/meson.build b/test/meson.build index f41d6e7..b4db328 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,5 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 +libcap = dependency('libcap', required : true) + subdir('libtest') subdir('camera') diff --git a/test/process/meson.build b/test/process/meson.build index c215fa7..828c17b 100644 --- a/test/process/meson.build +++ b/test/process/meson.build @@ -6,7 +6,7 @@ process_tests = [ foreach t : process_tests exe = executable(t[0], t[1], - dependencies : libcamera_dep, + dependencies : [libcamera_dep, libcap], link_with : test_libraries, include_directories : test_includes_internal) diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp index ce0cc7c..ffa2143 100644 --- a/test/process/process_test.cpp +++ b/test/process/process_test.cpp @@ -5,6 +5,8 @@ * process_test.cpp - Process test */ +#include + #include #include #include @@ -41,6 +43,27 @@ public: } protected: + int init() + { + int ret = TestPass; + + cap_t caps = cap_get_proc(); + if (caps == NULL) { + cerr << "failed to check process capabilities" << endl; + return TestFail; + } + + /* Check required permissions: CAP_SYS_ADMIN: unshare */ + cap_flag_value_t fv; + if ((cap_get_flag(caps, CAP_SYS_ADMIN, CAP_EFFECTIVE, &fv) < 0) || (fv != CAP_SET)) { + cerr << "skip due to insufficient capability" << endl; + ret = TestSkip; + } + + cap_free(caps); + return ret; + } + int run() { EventDispatcher *dispatcher = Thread::current()->eventDispatcher();