blob: d4b7588eb362cad64d39d9d1334c89091f376f1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* controls.cpp - V4L2 device controls handling test
*/
#include <climits>
#include <iostream>
#include "v4l2_videodevice.h"
#include "v4l2_videodevice_test.h"
using namespace std;
using namespace libcamera;
class V4L2ControlTest : public V4L2VideoDeviceTest
{
public:
V4L2ControlTest()
: V4L2VideoDeviceTest("vivid", "vivid-000-vid-cap")
{
}
protected:
int run()
{
const V4L2ControlInfoMap &info = capture_->controls();
/* Test control enumeration. */
if (info.empty()) {
cerr << "Failed to enumerate controls" << endl;
return TestFail;
}
if (info.find(V4L2_CID_BRIGHTNESS) == info.end() ||
info.find(V4L2_CID_CONTRAST) == info.end() ||
info.find(V4L2_CID_SATURATION) == info.end()) {
cerr << "Missing controls" << endl;
return TestFail;
}
const V4L2ControlRange &brightness = info.find(V4L2_CID_BRIGHTNESS)->second;
const V4L2ControlRange &contrast = info.find(V4L2_CID_CONTRAST)->second;
const V4L2ControlRange &saturation = info.find(V4L2_CID_SATURATION)->second;
/* Test getting controls. */
V4L2ControlList ctrls(info);
ctrls.set(V4L2_CID_BRIGHTNESS, -1);
ctrls.set(V4L2_CID_CONTRAST, -1);
ctrls.set(V4L2_CID_SATURATION, -1);
int ret = capture_->getControls(&ctrls);
if (ret) {
cerr << "Failed to get controls" << endl;
return TestFail;
}
if (ctrls.get(V4L2_CID_BRIGHTNESS).get<int32_t>() == -1 ||
ctrls.get(V4L2_CID_CONTRAST).get<int32_t>() == -1 ||
ctrls.get(V4L2_CID_SATURATION).get<int32_t>() == -1) {
cerr << "Incorrect value for retrieved controls" << endl;
return TestFail;
}
/* Test setting controls. */
ctrls.set(V4L2_CID_BRIGHTNESS, brightness.min());
ctrls.set(V4L2_CID_CONTRAST, contrast.max());
ctrls.set(V4L2_CID_SATURATION, saturation.min());
ret = capture_->setControls(&ctrls);
if (ret) {
cerr << "Failed to set controls" << endl;
return TestFail;
}
/* Test setting controls outside of range. */
ctrls.set(V4L2_CID_BRIGHTNESS, brightness.min().get<int32_t>() - 1);
ctrls.set(V4L2_CID_CONTRAST, contrast.max().get<int32_t>() + 1);
ctrls.set(V4L2_CID_SATURATION, saturation.min().get<int32_t>() + 1);
ret = capture_->setControls(&ctrls);
if (ret) {
cerr << "Failed to set controls (out of range)" << endl;
return TestFail;
}
if (ctrls.get(V4L2_CID_BRIGHTNESS) != brightness.min() ||
ctrls.get(V4L2_CID_CONTRAST) != contrast.max() ||
ctrls.get(V4L2_CID_SATURATION) != saturation.min().get<int32_t>() + 1) {
cerr << "Controls not updated when set" << endl;
return TestFail;
}
return TestPass;
}
};
TEST_REGISTER(V4L2ControlTest);
|