diff options
Diffstat (limited to 'src/lc-compliance/main.cpp')
-rw-r--r-- | src/lc-compliance/main.cpp | 107 |
1 files changed, 41 insertions, 66 deletions
diff --git a/src/lc-compliance/main.cpp b/src/lc-compliance/main.cpp index 54cee54a..ff14474c 100644 --- a/src/lc-compliance/main.cpp +++ b/src/lc-compliance/main.cpp @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2020, Google Inc. + * Copyright (C) 2021, Collabora Ltd. * * main.cpp - lc-compliance - The libcamera compliance tool */ @@ -9,10 +10,12 @@ #include <iostream> #include <string.h> +#include <gtest/gtest.h> + #include <libcamera/libcamera.h> +#include "environment.h" #include "../cam/options.h" -#include "tests.h" using namespace libcamera; @@ -21,97 +24,59 @@ enum { OptHelp = 'h', }; -class Harness +/* + * Make asserts act like exceptions, otherwise they only fail (or skip) the + * current function. From gtest documentation: + * https://google.github.io/googletest/advanced.html#asserting-on-subroutines-with-an-exception + */ +class ThrowListener : public testing::EmptyTestEventListener { -public: - Harness(const OptionsParser::Options &options); - ~Harness(); - - int exec(); - -private: - int init(); - void listCameras(); - - OptionsParser::Options options_; - std::unique_ptr<CameraManager> cm_; - std::shared_ptr<Camera> camera_; + void OnTestPartResult(const testing::TestPartResult &result) override + { + if (result.type() == testing::TestPartResult::kFatalFailure || + result.type() == testing::TestPartResult::kSkip) + throw testing::AssertionException(result); + } }; -Harness::Harness(const OptionsParser::Options &options) - : options_(options) -{ - cm_ = std::make_unique<CameraManager>(); -} - -Harness::~Harness() +static void listCameras(CameraManager *cm) { - if (camera_) { - camera_->release(); - camera_.reset(); - } - - cm_->stop(); + for (const std::shared_ptr<Camera> &cam : cm->cameras()) + std::cout << "- " << cam.get()->id() << std::endl; } -int Harness::exec() +static int initCamera(CameraManager *cm, OptionsParser::Options options) { - int ret = init(); - if (ret) - return ret; - - std::vector<Results> results; + std::shared_ptr<Camera> camera; - results.push_back(testSingleStream(camera_)); - - for (const Results &result : results) { - ret = result.summary(); - if (ret) - return ret; - } - - return 0; -} - -int Harness::init() -{ - int ret = cm_->start(); + int ret = cm->start(); if (ret) { std::cout << "Failed to start camera manager: " << strerror(-ret) << std::endl; return ret; } - if (!options_.isSet(OptCamera)) { + if (!options.isSet(OptCamera)) { std::cout << "No camera specified, available cameras:" << std::endl; - listCameras(); + listCameras(cm); return -ENODEV; } - const std::string &cameraId = options_[OptCamera]; - camera_ = cm_->get(cameraId); - if (!camera_) { + const std::string &cameraId = options[OptCamera]; + camera = cm->get(cameraId); + if (!camera) { std::cout << "Camera " << cameraId << " not found, available cameras:" << std::endl; - listCameras(); + listCameras(cm); return -ENODEV; } - if (camera_->acquire()) { - std::cout << "Failed to acquire camera" << std::endl; - return -EINVAL; - } + Environment::get()->setup(cm, cameraId); std::cout << "Using camera " << cameraId << std::endl; return 0; } -void Harness::listCameras() -{ - for (const std::shared_ptr<Camera> &cam : cm_->cameras()) - std::cout << "- " << cam.get()->id() << std::endl; -} - static int parseOptions(int argc, char **argv, OptionsParser::Options *options) { OptionsParser parser; @@ -142,7 +107,17 @@ int main(int argc, char **argv) if (ret < 0) return EXIT_FAILURE; - Harness harness(options); + std::unique_ptr<CameraManager> cm = std::make_unique<CameraManager>(); + + ret = initCamera(cm.get(), options); + if (ret) + return ret; + + testing::UnitTest::GetInstance()->listeners().Append(new ThrowListener); + + ret = RUN_ALL_TESTS(); + + cm->stop(); - return harness.exec() ? EXIT_FAILURE : EXIT_SUCCESS; + return ret; } |