From patchwork Fri May 21 13:30:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 12350 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 D536AC31FF for ; Fri, 21 May 2021 13:32:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8CBA368923; Fri, 21 May 2021 15:32:03 +0200 (CEST) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C67368911 for ; Fri, 21 May 2021 15:32:02 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2804:14c:1a9:2978:fc03:8702:eda1:a1f8]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: nfraprado) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 5E99C1F44089; Fri, 21 May 2021 14:32:00 +0100 (BST) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= To: libcamera-devel@lists.libcamera.org Date: Fri, 21 May 2021 10:30:54 -0300 Message-Id: <20210521133054.274502-6-nfraprado@collabora.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210521133054.274502-1-nfraprado@collabora.com> References: <20210521133054.274502-1-nfraprado@collabora.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/5] lc-compliance: Add list and filter parameters 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: , Cc: kernel@collabora.com, =?utf-8?q?Andr=C3=A9_Almeida?= Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a --list parameter that lists all current tests (by mapping to googletest's --gtest_list_tests). Add a --filter 'filterString' parameter that filters the tests to run (by mapping to googletest's --gtest_filter). Signed-off-by: NĂ­colas F. R. A. Prado --- No changes in v4 src/lc-compliance/main.cpp | 71 +++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/src/lc-compliance/main.cpp b/src/lc-compliance/main.cpp index 37884ff70a69..92ef9c1fa082 100644 --- a/src/lc-compliance/main.cpp +++ b/src/lc-compliance/main.cpp @@ -20,6 +20,8 @@ using namespace libcamera; enum { OptCamera = 'c', + OptList = 'l', + OptFilter = 'f', OptHelp = 'h', }; @@ -44,17 +46,25 @@ public: ~Harness(); int init(); - int run(int argc, char **argv); + int run(); + int buildGtestParameters(char *arg0); private: void listCameras(); OptionsParser::Options options_; std::unique_ptr cm_; + + const std::map gtestFlag_ = {{"list", "--gtest_list_tests"}, + {"filter", "--gtest_filter"}}; + + int gtestArgc_; + char **gtestArgv_; + std::string gtestFilterParam_; }; Harness::Harness(const OptionsParser::Options &options) - : options_(options) + : options_(options), gtestArgv_(nullptr) { cm_ = std::make_unique(); } @@ -64,6 +74,8 @@ Harness::~Harness() Environment::instance()->destroy(); cm_->stop(); + + free(gtestArgv_); } int Harness::init() @@ -77,6 +89,9 @@ int Harness::init() return ret; } + if (options_.isSet(OptList)) + return 0; + if (!options_.isSet(OptCamera)) { std::cout << "No camera specified, available cameras:" << std::endl; listCameras(); @@ -103,9 +118,9 @@ int Harness::init() return 0; } -int Harness::run(int argc, char **argv) +int Harness::run() { - ::testing::InitGoogleTest(&argc, argv); + ::testing::InitGoogleTest(>estArgc_, gtestArgv_); testing::UnitTest::GetInstance()->listeners().Append(new ThrowListener); @@ -118,12 +133,54 @@ void Harness::listCameras() std::cout << "- " << cam.get()->id() << std::endl; } +int Harness::buildGtestParameters(char *arg0) +{ + int argc = 0; + + /* + * +2 to have space for both the 0th argument that is needed but not + * used and the null at the end. + */ + gtestArgv_ = (char**) malloc((gtestFlag_.size() + 2) * sizeof(char*)); + if (!gtestArgv_) + return -ENOMEM; + + gtestArgv_[argc] = arg0; + argc++; + + if (options_.isSet(OptList)) { + gtestArgv_[argc] = const_cast(gtestFlag_.at("list").c_str()); + argc++; + } + + if (options_.isSet(OptFilter)) { + /* + * The filter flag needs to be passed as a single parameter, in + * the format --gtest_filter=filterStr + */ + const std::string &filter = options_[OptFilter]; + gtestFilterParam_ = gtestFlag_.at("filter") + "=" + filter; + + gtestArgv_[argc] = const_cast(gtestFilterParam_.c_str()); + argc++; + } + + gtestArgv_[argc] = 0; + gtestArgc_ = argc; + + return 0; +} + static int parseOptions(int argc, char **argv, OptionsParser::Options *options) { OptionsParser parser; parser.addOption(OptCamera, OptionString, "Specify which camera to operate on, by id", "camera", ArgumentRequired, "camera"); + parser.addOption(OptList, OptionNone, "List all tests and exit", "list"); + parser.addOption(OptFilter, OptionString, + "Specify which tests to run", "filter", + ArgumentRequired, "filter"); parser.addOption(OptHelp, OptionNone, "Display this help message", "help"); @@ -153,5 +210,9 @@ int main(int argc, char **argv) if (ret) return ret; - return harness.run(argc, argv); + ret = harness.buildGtestParameters(argv[0]); + if (ret) + return ret; + + return harness.run(); }