An attempt at getting image data back

This commit is contained in:
2024-07-14 00:27:33 +02:00
parent e026bc93f7
commit 6452d2e774
1314 changed files with 218350 additions and 38 deletions

View File

@@ -0,0 +1,86 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* ControlInfo tests
*/
#include <iostream>
#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include "test.h"
using namespace std;
using namespace libcamera;
class ControlInfoTest : public Test
{
protected:
int run()
{
/*
* Test information retrieval from a range with no minimum and
* maximum.
*/
ControlInfo brightness;
if (brightness.min().type() != ControlType::ControlTypeNone ||
brightness.max().type() != ControlType::ControlTypeNone ||
brightness.def().type() != ControlType::ControlTypeNone) {
cout << "Invalid control range for Brightness" << endl;
return TestFail;
}
/*
* Test information retrieval from a control with a minimum and
* a maximum value, and an implicit default value.
*/
ControlInfo contrast(10, 200);
if (contrast.min().get<int32_t>() != 10 ||
contrast.max().get<int32_t>() != 200 ||
!contrast.def().isNone()) {
cout << "Invalid control range for Contrast" << endl;
return TestFail;
}
/*
* Test information retrieval from a control with boolean
* values.
*/
ControlInfo aeEnable({ false, true }, false);
if (aeEnable.min().get<bool>() != false ||
aeEnable.def().get<bool>() != false ||
aeEnable.max().get<bool>() != true) {
cout << "Invalid control range for AeEnable" << endl;
return TestFail;
}
if (aeEnable.values()[0].get<bool>() != false ||
aeEnable.values()[1].get<bool>() != true) {
cout << "Invalid control values for AeEnable" << endl;
return TestFail;
}
ControlInfo awbEnable(true);
if (awbEnable.min().get<bool>() != true ||
awbEnable.def().get<bool>() != true ||
awbEnable.max().get<bool>() != true) {
cout << "Invalid control range for AwbEnable" << endl;
return TestFail;
}
if (awbEnable.values()[0].get<bool>() != true) {
cout << "Invalid control values for AwbEnable" << endl;
return TestFail;
}
return TestPass;
}
};
TEST_REGISTER(ControlInfoTest)

View File

@@ -0,0 +1,89 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* ControlInfoMap tests
*/
#include <iostream>
#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>
#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include "libcamera/internal/camera_controls.h"
#include "camera_test.h"
#include "test.h"
using namespace std;
using namespace libcamera;
class ControlInfoMapTest : public CameraTest, public Test
{
public:
ControlInfoMapTest()
: CameraTest("platform/vimc.0 Sensor B")
{
}
protected:
int init() override
{
return status_;
}
int run() override
{
const ControlInfoMap &infoMap = camera_->controls();
/* Test looking up a valid control by ControlId. */
if (infoMap.count(&controls::Brightness) != 1) {
cerr << "count() on valid control failed" << endl;
return TestFail;
}
if (infoMap.find(&controls::Brightness) == infoMap.end()) {
cerr << "find() on valid control failed" << endl;
return TestFail;
}
infoMap.at(&controls::Brightness);
/* Test looking up a valid control by numerical ID. */
if (infoMap.count(controls::Brightness.id()) != 1) {
cerr << "count() on valid ID failed" << endl;
return TestFail;
}
if (infoMap.find(controls::Brightness.id()) == infoMap.end()) {
cerr << "find() on valid ID failed" << endl;
return TestFail;
}
infoMap.at(controls::Brightness.id());
/* Test looking up an invalid control by numerical ID. */
if (infoMap.count(12345) != 0) {
cerr << "count() on invalid ID failed" << endl;
return TestFail;
}
if (infoMap.find(12345) != infoMap.end()) {
cerr << "find() on invalid ID failed" << endl;
return TestFail;
}
/* Test looking up a control on a default-constructed infoMap */
const ControlInfoMap emptyInfoMap;
if (emptyInfoMap.find(12345) != emptyInfoMap.end()) {
cerr << "find() on empty ControlInfoMap failed" << endl;
return TestFail;
}
return TestPass;
}
};
TEST_REGISTER(ControlInfoMapTest)

View File

@@ -0,0 +1,253 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* ControlList tests
*/
#include <iostream>
#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>
#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include "libcamera/internal/camera_controls.h"
#include "camera_test.h"
#include "test.h"
using namespace std;
using namespace libcamera;
class ControlListTest : public CameraTest, public Test
{
public:
ControlListTest()
: CameraTest("platform/vimc.0 Sensor B")
{
}
protected:
int init() override
{
return status_;
}
int run() override
{
CameraControlValidator validator(camera_.get());
ControlList list(controls::controls, &validator);
/* Test that the list is initially empty. */
if (!list.empty()) {
cout << "List should to be empty" << endl;
return TestFail;
}
if (list.size() != 0) {
cout << "List should contain zero items" << endl;
return TestFail;
}
if (list.get(controls::Brightness)) {
cout << "List should not contain Brightness control" << endl;
return TestFail;
}
unsigned int count = 0;
for (auto iter = list.begin(); iter != list.end(); ++iter)
count++;
if (count != 0) {
cout << "List iteration should not produce any item" << endl;
return TestFail;
}
/*
* Set a control, and verify that the list now contains it, and
* nothing else.
*/
list.set(controls::Brightness, -0.5f);
if (list.empty()) {
cout << "List should not be empty" << endl;
return TestFail;
}
if (list.size() != 1) {
cout << "List should contain one item" << endl;
return TestFail;
}
if (!list.get(controls::Brightness)) {
cout << "List should contain Brightness control" << endl;
return TestFail;
}
count = 0;
for (auto iter = list.begin(); iter != list.end(); ++iter)
count++;
if (count != 1) {
cout << "List iteration should produce one item" << endl;
return TestFail;
}
if (list.get(controls::Brightness) != -0.5f) {
cout << "Incorrest Brightness control value" << endl;
return TestFail;
}
if (list.get(controls::Contrast)) {
cout << "List should not contain Contract control" << endl;
return TestFail;
}
/* Update the first control and set a second one. */
list.set(controls::Brightness, 0.0f);
list.set(controls::Contrast, 1.5f);
if (!list.get(controls::Brightness) ||
!list.get(controls::Contrast)) {
cout << "List should contain Brightness and Contrast controls"
<< endl;
return TestFail;
}
if (list.get(controls::Brightness) != 0.0f ||
list.get(controls::Contrast) != 1.5f) {
cout << "Failed to retrieve control value" << endl;
return TestFail;
}
/*
* Update both controls and verify that the container doesn't
* grow.
*/
list.set(controls::Brightness, 0.5f);
list.set(controls::Contrast, 1.1f);
if (list.get(controls::Brightness) != 0.5f ||
list.get(controls::Contrast) != 1.1f) {
cout << "Failed to update control value" << endl;
return TestFail;
}
if (list.size() != 2) {
cout << "List should contain two elements" << endl;
return TestFail;
}
/*
* Attempt to set an invalid control and verify that the
* operation failed.
*/
list.set(controls::AwbEnable, true);
if (list.get(controls::AwbEnable)) {
cout << "List shouldn't contain AwbEnable control" << endl;
return TestFail;
}
/*
* Create a new list with a new control and merge it with the
* existing one, verifying that the existing controls
* values don't get overwritten.
*/
ControlList mergeList(controls::controls, &validator);
mergeList.set(controls::Brightness, 0.7f);
mergeList.set(controls::Saturation, 0.4f);
mergeList.merge(list);
if (mergeList.size() != 3) {
cout << "Merged list should contain three elements" << endl;
return TestFail;
}
if (list.size() != 2) {
cout << "The list to merge should contain two elements"
<< endl;
return TestFail;
}
if (!mergeList.get(controls::Brightness) ||
!mergeList.get(controls::Contrast) ||
!mergeList.get(controls::Saturation)) {
cout << "Merged list does not contain all controls" << endl;
return TestFail;
}
if (mergeList.get(controls::Brightness) != 0.7f) {
cout << "Brightness control value changed after merging lists"
<< endl;
return TestFail;
}
if (mergeList.get(controls::Contrast) != 1.1f) {
cout << "Contrast control value changed after merging lists"
<< endl;
return TestFail;
}
if (mergeList.get(controls::Saturation) != 0.4f) {
cout << "Saturation control value changed after merging lists"
<< endl;
return TestFail;
}
/*
* Create two lists with overlapping controls. Merge them with
* overwriteExisting = true, verifying that the existing control
* values *get* overwritten.
*/
mergeList.clear();
mergeList.set(controls::Brightness, 0.7f);
mergeList.set(controls::Saturation, 0.4f);
list.clear();
list.set(controls::Brightness, 0.5f);
list.set(controls::Contrast, 1.1f);
mergeList.merge(list, ControlList::MergePolicy::OverwriteExisting);
if (mergeList.size() != 3) {
cout << "Merged list should contain three elements" << endl;
return TestFail;
}
if (list.size() != 2) {
cout << "The list to merge should contain two elements"
<< endl;
return TestFail;
}
if (!mergeList.get(controls::Brightness) ||
!mergeList.get(controls::Contrast) ||
!mergeList.get(controls::Saturation)) {
cout << "Merged list does not contain all controls" << endl;
return TestFail;
}
if (mergeList.get(controls::Brightness) != 0.5f) {
cout << "Brightness control value did not change after merging lists"
<< endl;
return TestFail;
}
if (mergeList.get(controls::Contrast) != 1.1f) {
cout << "Contrast control value changed after merging lists"
<< endl;
return TestFail;
}
if (mergeList.get(controls::Saturation) != 0.4f) {
cout << "Saturation control value changed after merging lists"
<< endl;
return TestFail;
}
return TestPass;
}
};
TEST_REGISTER(ControlListTest)

View File

@@ -0,0 +1,264 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* ControlValue tests
*/
#include <algorithm>
#include <iostream>
#include <libcamera/controls.h>
#include "test.h"
using namespace std;
using namespace libcamera;
class ControlValueTest : public Test
{
protected:
int run()
{
/*
* None type.
*/
ControlValue value;
if (!value.isNone() || value.isArray()) {
cerr << "Empty value is non-null" << endl;
return TestFail;
}
/*
* Bool type.
*/
value.set(true);
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeBool) {
cerr << "Control type mismatch after setting to bool" << endl;
return TestFail;
}
if (value.get<bool>() != true) {
cerr << "Control value mismatch after setting to bool" << endl;
return TestFail;
}
if (value.toString() != "true") {
cerr << "Control string mismatch after setting to bool" << endl;
return TestFail;
}
std::array<bool, 2> bools{ true, false };
value.set(Span<bool>(bools));
if (value.isNone() || !value.isArray() ||
value.type() != ControlTypeBool) {
cerr << "Control type mismatch after setting to bool array" << endl;
return TestFail;
}
Span<const bool> boolsResult = value.get<Span<const bool>>();
if (bools.size() != boolsResult.size() ||
!std::equal(bools.begin(), bools.end(), boolsResult.begin())) {
cerr << "Control value mismatch after setting to bool" << endl;
return TestFail;
}
if (value.toString() != "[ true, false ]") {
cerr << "Control string mismatch after setting to bool array" << endl;
return TestFail;
}
/*
* Integer8 type.
*/
value.set(static_cast<uint8_t>(42));
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeByte) {
cerr << "Control type mismatch after setting to uint8_t" << endl;
return TestFail;
}
if (value.get<uint8_t>() != 42) {
cerr << "Control value mismatch after setting to uint8_t" << endl;
return TestFail;
}
if (value.toString() != "42") {
cerr << "Control string mismatch after setting to uint8_t" << endl;
return TestFail;
}
std::array<uint8_t, 4> bytes{ 3, 14, 15, 9 };
value.set(Span<uint8_t>(bytes));
if (value.isNone() || !value.isArray() ||
value.type() != ControlTypeByte) {
cerr << "Control type mismatch after setting to uint8_t array" << endl;
return TestFail;
}
Span<const uint8_t> int8sResult = value.get<Span<const uint8_t>>();
if (bytes.size() != int8sResult.size() ||
!std::equal(bytes.begin(), bytes.end(), int8sResult.begin())) {
cerr << "Control value mismatch after setting to uint8_t array" << endl;
return TestFail;
}
if (value.toString() != "[ 3, 14, 15, 9 ]") {
cerr << "Control string mismatch after setting to uint8_t array" << endl;
return TestFail;
}
/*
* Integer32 type.
*/
value.set(0x42000000);
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeInteger32) {
cerr << "Control type mismatch after setting to int32_t" << endl;
return TestFail;
}
if (value.get<int32_t>() != 0x42000000) {
cerr << "Control value mismatch after setting to int32_t" << endl;
return TestFail;
}
if (value.toString() != "1107296256") {
cerr << "Control string mismatch after setting to int32_t" << endl;
return TestFail;
}
std::array<int32_t, 4> int32s{ 3, 14, 15, 9 };
value.set(Span<int32_t>(int32s));
if (value.isNone() || !value.isArray() ||
value.type() != ControlTypeInteger32) {
cerr << "Control type mismatch after setting to int32_t array" << endl;
return TestFail;
}
Span<const int32_t> int32sResult = value.get<Span<const int32_t>>();
if (int32s.size() != int32sResult.size() ||
!std::equal(int32s.begin(), int32s.end(), int32sResult.begin())) {
cerr << "Control value mismatch after setting to int32_t array" << endl;
return TestFail;
}
if (value.toString() != "[ 3, 14, 15, 9 ]") {
cerr << "Control string mismatch after setting to int32_t array" << endl;
return TestFail;
}
/*
* Integer64 type.
*/
value.set(static_cast<int64_t>(-42));
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeInteger64) {
cerr << "Control type mismatch after setting to int64_t" << endl;
return TestFail;
}
if (value.get<int64_t>() != -42) {
cerr << "Control value mismatch after setting to int64_t" << endl;
return TestFail;
}
if (value.toString() != "-42") {
cerr << "Control string mismatch after setting to int64_t" << endl;
return TestFail;
}
std::array<int64_t, 4> int64s{ 3, 14, 15, 9 };
value.set(Span<int64_t>(int64s));
if (value.isNone() || !value.isArray() ||
value.type() != ControlTypeInteger64) {
cerr << "Control type mismatch after setting to int64_t array" << endl;
return TestFail;
}
Span<const int64_t> int64sResult = value.get<Span<const int64_t>>();
if (int64s.size() != int64sResult.size() ||
!std::equal(int64s.begin(), int64s.end(), int64sResult.begin())) {
cerr << "Control value mismatch after setting to int64_t array" << endl;
return TestFail;
}
if (value.toString() != "[ 3, 14, 15, 9 ]") {
cerr << "Control string mismatch after setting to int64_t array" << endl;
return TestFail;
}
/*
* Float type.
*/
value.set(-0.42f);
if (value.isNone() || value.isArray() ||
value.type() != ControlTypeFloat) {
cerr << "Control type mismatch after setting to float" << endl;
return TestFail;
}
if (value.get<float>() != -0.42f) {
cerr << "Control value mismatch after setting to float" << endl;
return TestFail;
}
if (value.toString() != "-0.420000") {
cerr << "Control string mismatch after setting to float" << endl;
return TestFail;
}
std::array<float, 3> floats{ 3.141593, 2.718282, 299792458.0 };
value.set(Span<float>(floats));
if (value.isNone() || !value.isArray() ||
value.type() != ControlTypeFloat) {
cerr << "Control type mismatch after setting to float array" << endl;
return TestFail;
}
Span<const float> floatsResult = value.get<Span<const float>>();
if (floats.size() != floatsResult.size() ||
!std::equal(floats.begin(), floats.end(), floatsResult.begin())) {
cerr << "Control value mismatch after setting to float array" << endl;
return TestFail;
}
/*
* The string representation for the third value doesn't match
* the value in the floats array above, due to limited precision
* of the float type that can't properly represent the speed of
* light.
*/
if (value.toString() != "[ 3.141593, 2.718282, 299792448.000000 ]") {
cerr << "Control string mismatch after setting to float array" << endl;
return TestFail;
}
/*
* String type.
*/
std::string string{ "libcamera" };
value.set(string);
if (value.isNone() || !value.isArray() ||
value.type() != ControlTypeString ||
value.numElements() != string.size()) {
cerr << "Control type mismatch after setting to string" << endl;
return TestFail;
}
if (value.get<std::string>() != string) {
cerr << "Control value mismatch after setting to string" << endl;
return TestFail;
}
if (value.toString() != string) {
cerr << "Control string mismatch after setting to string" << endl;
return TestFail;
}
return TestPass;
}
};
TEST_REGISTER(ControlValueTest)

View File

@@ -0,0 +1,16 @@
# SPDX-License-Identifier: CC0-1.0
control_tests = [
{'name': 'control_info', 'sources': ['control_info.cpp']},
{'name': 'control_info_map', 'sources': ['control_info_map.cpp']},
{'name': 'control_list', 'sources': ['control_list.cpp']},
{'name': 'control_value', 'sources': ['control_value.cpp']},
]
foreach test : control_tests
exe = executable(test['name'], test['sources'],
dependencies : libcamera_public,
link_with : test_libraries,
include_directories : test_includes_internal)
test(test['name'], exe, suite : 'controls', is_parallel : false)
endforeach