From patchwork Tue Oct 5 05:40:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14493 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id D2ED6BDB1C for ; Tue, 9 Nov 2021 17:40:47 +0000 (UTC) Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 569AD501 for ; Tue, 9 Nov 2021 18:40:47 +0100 (CET) Authentication-Results: perceval.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="IWN4iFH8"; dkim-atps=neutral Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id yKkYEVXlW2H7WQAA4E0KoQ (envelope-from ) for ; Tue, 05 Oct 2021 07:40:37 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [IPv6:2001:4b98:dc0:43:216:3eff:fe33:f827]) by perceval.ideasonboard.com (Postfix) with ESMTPS id 2325425B; Tue, 5 Oct 2021 07:40:37 +0200 (CEST) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8A5F6691B8; Tue, 5 Oct 2021 07:40:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="IWN4iFH8"; dkim-atps=neutral Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2576D6023D for ; Tue, 5 Oct 2021 07:40:35 +0200 (CEST) Received: by mail-pl1-x62b.google.com with SMTP id x8so1514797plv.8 for ; Mon, 04 Oct 2021 22:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=W0jUU9MNQbwRMBCjneLvhD881RbhbYVXd4f3lblf084=; b=IWN4iFH8i0XNJEbvxZxhlmrHl984OtC7F6qd4CsGAieOLKqORw2RiBRpsrhg0Aw+Wf X+hXVWeiAxhogqvQt8WSL5tvis3bQPrWhUs5Lvpd/5c1Yw6NaQYl6BiCmYrxXFm4EbOf RhnHG0D1b47BSYE22fJlkSMsZoD88jAqpoin4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=W0jUU9MNQbwRMBCjneLvhD881RbhbYVXd4f3lblf084=; b=bg4haxnN/KABmC0ZFgjnCVirmicYNjXpJ/GRse23QF3LemCXnsoPa1btXqK9SD0MZQ i7skGFuC2Y5MxaUOGf+fjvmuV3c75f7KPohar8yDeqCEr7fAloyH3XOC8D2coouk4OI6 S4LYbKmL12NhPGgN7dMpwViZkvFs9FU9PJQV7XKG9KhHmD3rHKEA0JwxxqDkOtWKoMAO gDzvpoiBxvcG1dVpbmbA2VzE/saN8Vtp4KEOPinNipRHwOdg8yKjQD8WSiMryu/28wFX B/t/tr/kVqCXRhHBbJMVh0/ErOimQIbmm2p7TXNuXGBDmrpfezfUIxjVP6veYObCzJGm Jf9w== X-Gm-Message-State: AOAM531d0laGglnVf2pwKelqApYFXI0JOZYUY4mGMUdMS0MTcM5YJHFt YJJQ85WbtHIW4Lt3JAcNG7EeVgBvLah+lg== X-Google-Smtp-Source: =?utf-8?q?ABdhPJyEftznEgSmM+EDkERhHt1dPrab798XZQfRd?= =?utf-8?q?RCd50Z4QrsN8kBtaJv9pk9Y9SK8Zp0EW2RhtA=3D=3D?= X-Received: by 2002:a17:90a:4b4d:: with SMTP id o13mr1508239pjl.236.1633412433142; Mon, 04 Oct 2021 22:40:33 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:debc:d0db:3bd8:f961]) by smtp.gmail.com with ESMTPSA id e20sm16309581pfc.11.2021.10.04.22.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 22:40:32 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 5 Oct 2021 14:40:27 +0900 Message-Id: <20211005054027.688044-1-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2] lc-compliance: Add test to set test pattern mode 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" X-TUID: zwJfEiUBGBtL Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org This adds the test to verify the requested test pattern mode is correctly applied in request metadata. Signed-off-by: Hirokazu Honda --- src/lc-compliance/meson.build | 1 + src/lc-compliance/test_pattern_mode_test.cpp | 157 +++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 src/lc-compliance/test_pattern_mode_test.cpp diff --git a/src/lc-compliance/meson.build b/src/lc-compliance/meson.build index aa5852f6..0fd280df 100644 --- a/src/lc-compliance/meson.build +++ b/src/lc-compliance/meson.build @@ -17,6 +17,7 @@ lc_compliance_sources = files([ 'main.cpp', 'simple_capture.cpp', 'capture_test.cpp', + 'test_pattern_mode_test.cpp', ]) lc_compliance = executable('lc-compliance', lc_compliance_sources, diff --git a/src/lc-compliance/test_pattern_mode_test.cpp b/src/lc-compliance/test_pattern_mode_test.cpp new file mode 100644 index 00000000..d8599b64 --- /dev/null +++ b/src/lc-compliance/test_pattern_mode_test.cpp @@ -0,0 +1,157 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * Copyright (C) 2021, Collabora Ltd. + * + * test_pattern_mode_test.cpp - Test a capture with a test pattern mode + */ + +#include + +#include + +#include "environment.h" +#include "simple_capture.h" + +using namespace libcamera; + +namespace { +/* + * SimpleCaptureTestPatternMode verifies captures with a test pattern mode. It + * checks the request has the specified test pattern mode in the metadata, but + * doesn't verify the capture content. + */ +class SimpleCaptureTestPatternMode : public SimpleCapture +{ +public: + SimpleCaptureTestPatternMode(std::shared_ptr camera); + + std::vector availableTestPatternModes() const; + void capture(int32_t testPatternMode); + +private: + void requestComplete(Request *request) override; + + unsigned int captureCount_; + unsigned int captureLimit_; + int32_t testPatternMode_; +}; + +/* SimpleCaptureTestPatternMode */ + +SimpleCaptureTestPatternMode::SimpleCaptureTestPatternMode(std::shared_ptr camera) + : SimpleCapture(camera) +{ +} + +std::vector SimpleCaptureTestPatternMode::availableTestPatternModes() const +{ + const auto &controls = camera_->controls(); + const auto it = controls.find(&controls::draft::TestPatternMode); + if (it == controls.end()) + return {}; + + std::vector testPatternModes; + const std::vector &values = it->second.values(); + for (const auto &value : values) + testPatternModes.push_back(value.get()); + + return testPatternModes; +} + +void SimpleCaptureTestPatternMode::capture(int32_t testPatternMode) +{ + start(); + + Stream *stream = config_->at(0).stream(); + const std::vector> &buffers = allocator_->buffers(stream); + ASSERT_FALSE(buffers.empty()); + + captureCount_ = 0; + captureLimit_ = buffers.size(); + testPatternMode_ = testPatternMode; + + std::vector> requests; + for (const std::unique_ptr &buffer : buffers) { + std::unique_ptr request = camera_->createRequest(); + ASSERT_TRUE(request) << "Can't create request"; + + request->controls().set(controls::draft::TestPatternMode, + testPatternMode); + + ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) + << "Can't set buffer for request"; + + ASSERT_EQ(camera_->queueRequest(request.get()), 0) + << "Failed to queue request"; + + requests.push_back(std::move(request)); + } + + /* Run capture session. */ + loop_ = new EventLoop(); + int status = loop_->exec(); + stop(); + delete loop_; + + ASSERT_EQ(status, 0); +} + +void SimpleCaptureTestPatternMode::requestComplete(Request *request) +{ + captureCount_++; + if (captureCount_ > captureLimit_) { + loop_->exit(0); + return; + } + + if (!request->metadata().contains(controls::draft::TestPatternMode)) { + if (testPatternMode_ != controls::draft::TestPatternModeOff) { + std::cerr << "No test pattern mode mismatch: expected=" + << testPatternMode_ << std::endl; + loop_->exit(-EINVAL); + return; + } + } else { + const int32_t testPatternMode = + request->metadata().get(controls::draft::TestPatternMode); + if (testPatternMode_ != testPatternMode) { + std::cerr << "Test pattern mode mismatch: expected=" + << testPatternMode_ << ", actual=" + << testPatternMode << std::endl; + + loop_->exit(-EINVAL); + return; + } + } + + request->reuse(Request::ReuseBuffers); + request->controls().set(controls::draft::TestPatternMode, + testPatternMode_); + if (camera_->queueRequest(request)) + loop_->exit(-EINVAL); +} +} /* namespace */ + +TEST(TestPatternModeTest, SetTestPatternMode) +{ + Environment *env = Environment::get(); + + auto camera = env->cm()->get(env->cameraId()); + ASSERT_TRUE(camera); + ASSERT_EQ(camera->acquire(), 0); + + SimpleCaptureTestPatternMode capture(camera); + capture.configure(StreamRole::Viewfinder); + + auto testPatternModes = capture.availableTestPatternModes(); + if (testPatternModes.empty()) { + camera->release(); + GTEST_SKIP() << "No test pattern is available"; + } + + for (const int32_t testPatternMode : testPatternModes) + capture.capture(testPatternMode); + + camera->release(); +}