summaryrefslogtreecommitdiff
path: root/test/controls/control_list.cpp
blob: 70cf61b85cbc04d696f87f32ba9bdbae74a90ed6 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * control_list.cpp - 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.contains(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.contains(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.contains(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.contains(controls::Brightness) ||
		    !list.contains(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.contains(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.contains(controls::Brightness) ||
		    !mergeList.contains(controls::Contrast) ||
		    !mergeList.contains(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;
		}

		return TestPass;
	}
};

TEST_REGISTER(ControlListTest)
media_pad_desc sink; __u32 flags; __u32 reserved[2]; }; struct media_links_enum { __u32 entity; /* Should have enough room for pads elements */ struct media_pad_desc *pads; /* Should have enough room for links elements */ struct media_link_desc *links; __u32 reserved[4]; }; /* Interface type ranges */ #define MEDIA_INTF_T_DVB_BASE 0x00000100 #define MEDIA_INTF_T_V4L_BASE 0x00000200 /* Interface types */ #define MEDIA_INTF_T_DVB_FE (MEDIA_INTF_T_DVB_BASE) #define MEDIA_INTF_T_DVB_DEMUX (MEDIA_INTF_T_DVB_BASE + 1) #define MEDIA_INTF_T_DVB_DVR (MEDIA_INTF_T_DVB_BASE + 2) #define MEDIA_INTF_T_DVB_CA (MEDIA_INTF_T_DVB_BASE + 3) #define MEDIA_INTF_T_DVB_NET (MEDIA_INTF_T_DVB_BASE + 4) #define MEDIA_INTF_T_V4L_VIDEO (MEDIA_INTF_T_V4L_BASE) #define MEDIA_INTF_T_V4L_VBI (MEDIA_INTF_T_V4L_BASE + 1) #define MEDIA_INTF_T_V4L_RADIO (MEDIA_INTF_T_V4L_BASE + 2) #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3) #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4) #define MEDIA_INTF_T_V4L_TOUCH (MEDIA_INTF_T_V4L_BASE + 5) #define MEDIA_INTF_T_ALSA_BASE 0x00000300 #define MEDIA_INTF_T_ALSA_PCM_CAPTURE (MEDIA_INTF_T_ALSA_BASE) #define MEDIA_INTF_T_ALSA_PCM_PLAYBACK (MEDIA_INTF_T_ALSA_BASE + 1) #define MEDIA_INTF_T_ALSA_CONTROL (MEDIA_INTF_T_ALSA_BASE + 2) /* * MC next gen API definitions */ /* * Appeared in 4.19.0. * * The media_version argument comes from the media_version field in * struct media_device_info. */ #define MEDIA_V2_ENTITY_HAS_FLAGS(media_version) \ ((media_version) >= ((4 << 16) | (19 << 8) | 0)) struct media_v2_entity { __u32 id; char name[64]; __u32 function; /* Main function of the entity */ __u32 flags; __u32 reserved[5]; } __attribute__ ((packed)); /* Should match the specific fields at media_intf_devnode */ struct media_v2_intf_devnode { __u32 major; __u32 minor; } __attribute__ ((packed)); struct media_v2_interface { __u32 id; __u32 intf_type; __u32 flags; __u32 reserved[9]; union { struct media_v2_intf_devnode devnode; __u32 raw[16]; }; } __attribute__ ((packed)); /* * Appeared in 4.19.0. * * The media_version argument comes from the media_version field in * struct media_device_info. */ #define MEDIA_V2_PAD_HAS_INDEX(media_version) \ ((media_version) >= ((4 << 16) | (19 << 8) | 0)) struct media_v2_pad { __u32 id; __u32 entity_id; __u32 flags; __u32 index; __u32 reserved[4]; } __attribute__ ((packed)); struct media_v2_link { __u32 id; __u32 source_id; __u32 sink_id; __u32 flags; __u32 reserved[6]; } __attribute__ ((packed)); struct media_v2_topology { __u64 topology_version; __u32 num_entities; __u32 reserved1; __u64 ptr_entities; __u32 num_interfaces; __u32 reserved2; __u64 ptr_interfaces; __u32 num_pads; __u32 reserved3; __u64 ptr_pads; __u32 num_links; __u32 reserved4; __u64 ptr_links; } __attribute__ ((packed)); /* ioctls */ #define MEDIA_IOC_DEVICE_INFO _IOWR('|', 0x00, struct media_device_info) #define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc) #define MEDIA_IOC_ENUM_LINKS _IOWR('|', 0x02, struct media_links_enum) #define MEDIA_IOC_SETUP_LINK _IOWR('|', 0x03, struct media_link_desc) #define MEDIA_IOC_G_TOPOLOGY _IOWR('|', 0x04, struct media_v2_topology) #define MEDIA_IOC_REQUEST_ALLOC _IOR ('|', 0x05, int) /* * These ioctls are called on the request file descriptor as returned * by MEDIA_IOC_REQUEST_ALLOC. */ #define MEDIA_REQUEST_IOC_QUEUE _IO('|', 0x80) #define MEDIA_REQUEST_IOC_REINIT _IO('|', 0x81) /* * Legacy symbols used to avoid userspace compilation breakages. * Do not use any of this in new applications! * * Those symbols map the entity function into types and should be * used only on legacy programs for legacy hardware. Don't rely * on those for MEDIA_IOC_G_TOPOLOGY. */ #define MEDIA_ENT_TYPE_SHIFT 16 #define MEDIA_ENT_TYPE_MASK 0x00ff0000 #define MEDIA_ENT_SUBTYPE_MASK 0x0000ffff #define MEDIA_ENT_T_DEVNODE_UNKNOWN (MEDIA_ENT_F_OLD_BASE | \ MEDIA_ENT_SUBTYPE_MASK) #define MEDIA_ENT_T_DEVNODE MEDIA_ENT_F_OLD_BASE #define MEDIA_ENT_T_DEVNODE_V4L MEDIA_ENT_F_IO_V4L #define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_F_OLD_BASE + 2) #define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_F_OLD_BASE + 3) #define MEDIA_ENT_T_DEVNODE_DVB (MEDIA_ENT_F_OLD_BASE + 4) #define MEDIA_ENT_T_UNKNOWN MEDIA_ENT_F_UNKNOWN #define MEDIA_ENT_T_V4L2_VIDEO MEDIA_ENT_F_IO_V4L #define MEDIA_ENT_T_V4L2_SUBDEV MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR MEDIA_ENT_F_CAM_SENSOR #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH MEDIA_ENT_F_FLASH #define MEDIA_ENT_T_V4L2_SUBDEV_LENS MEDIA_ENT_F_LENS #define MEDIA_ENT_T_V4L2_SUBDEV_DECODER MEDIA_ENT_F_ATV_DECODER #define MEDIA_ENT_T_V4L2_SUBDEV_TUNER MEDIA_ENT_F_TUNER #define MEDIA_ENT_F_DTV_DECODER MEDIA_ENT_F_DV_DECODER /* * There is still no full ALSA support in the media controller. These * defines should not have been added and we leave them here only * in case some application tries to use these defines. * * The ALSA defines that are in use have been moved into __KERNEL__ * scope. As support gets added to these interface types, they should * be moved into __KERNEL__ scope with the code that uses them. */ #define MEDIA_INTF_T_ALSA_COMPRESS (MEDIA_INTF_T_ALSA_BASE + 3) #define MEDIA_INTF_T_ALSA_RAWMIDI (MEDIA_INTF_T_ALSA_BASE + 4) #define MEDIA_INTF_T_ALSA_HWDEP (MEDIA_INTF_T_ALSA_BASE + 5) #define MEDIA_INTF_T_ALSA_SEQUENCER (MEDIA_INTF_T_ALSA_BASE + 6) #define MEDIA_INTF_T_ALSA_TIMER (MEDIA_INTF_T_ALSA_BASE + 7) /* Obsolete symbol for media_version, no longer used in the kernel */ #define MEDIA_API_VERSION ((0 << 16) | (1 << 8) | 0) #endif /* __LINUX_MEDIA_H */