Skip to content

Commit 0598b54

Browse files
committed
drivers: video: emul_rx: add basic support for video_set_stats()
Add support for the new API video_set_stats() to the emulated video RX driver, and use it to implement simple API tests. The data returned is arbitrary for the sake of testing the API itself. Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent 80f83f7 commit 0598b54

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

drivers/video/video_emul_rx.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ static int emul_rx_get_caps(const struct device *dev, enum video_endpoint_id ep,
117117
return video_get_caps(cfg->source_dev, VIDEO_EP_OUT, caps);
118118
}
119119

120+
static int emul_rx_get_stats(const struct device *dev, enum video_endpoint_id ep,
121+
struct video_stats *stats)
122+
{
123+
struct video_stats_channels *chan = (void *)stats;
124+
125+
if ((stats->flags & VIDEO_STATS_CHANNELS_Y) == 0) {
126+
return -ENOTSUP;
127+
}
128+
129+
/* Fake data for the sake of demonstrating and testing the APIs */
130+
chan->y = 0x7f;
131+
stats->frame_counter = k_cycle_get_32() / 1024;
132+
133+
/* Let the caller know what type of statistics is collected */
134+
stats->flags = VIDEO_STATS_CHANNELS_Y;
135+
136+
return 0;
137+
}
138+
120139
static int emul_rx_set_stream(const struct device *dev, bool enable)
121140
{
122141
const struct emul_rx_config *cfg = dev->config;
@@ -238,6 +257,7 @@ static DEVICE_API(video, emul_rx_driver_api) = {
238257
.set_format = emul_rx_set_fmt,
239258
.get_format = emul_rx_get_fmt,
240259
.get_caps = emul_rx_get_caps,
260+
.get_stats = emul_rx_get_stats,
241261
.set_stream = emul_rx_set_stream,
242262
.enqueue = emul_rx_enqueue,
243263
.dequeue = emul_rx_dequeue,

tests/drivers/video/api/src/video_emul.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,33 @@ ZTEST(video_common, test_video_vbuf)
185185
video_buffer_release(vbuf);
186186
}
187187

188+
ZTEST(video_emul, test_video_stats)
189+
{
190+
struct video_stats_channels chan = {
191+
.base.flags = VIDEO_STATS_CHANNELS,
192+
};
193+
194+
zexpect_ok(video_get_stats(rx_dev, VIDEO_EP_OUT, &chan.base),
195+
"statistics collection should succeed for the emulated device");
196+
197+
zexpect_equal(chan.base.flags & VIDEO_STATS_HISTOGRAM, 0, "histogram was not requested");
198+
199+
zexpect_not_equal(chan.base.flags & VIDEO_STATS_CHANNELS, 0,
200+
"this emulated device is known to support channel averages.");
201+
202+
if (chan.base.flags & VIDEO_STATS_CHANNELS_Y) {
203+
zexpect_not_equal(chan.y, 0x00, "Test data likely not completely black.");
204+
zexpect_not_equal(chan.y, 0xff, "Test data likely not completely white.");
205+
}
206+
207+
if (chan.base.flags & VIDEO_STATS_CHANNELS_RGB) {
208+
zexpect_not_equal(chan.rgb[0], 0x00, "Red channel likely not completely 0x00.");
209+
zexpect_not_equal(chan.rgb[0], 0xff, "Red channel likely not completely 0xff.");
210+
zexpect_not_equal(chan.rgb[1], 0x00, "Green channel likely not completely 0x00.");
211+
zexpect_not_equal(chan.rgb[1], 0xff, "Green channel likely not completely 0xff.");
212+
zexpect_not_equal(chan.rgb[2], 0x00, "Blue channel likely not completely 0x00.");
213+
zexpect_not_equal(chan.rgb[2], 0xff, "Blue channel likely not completely 0xff.");
214+
}
215+
}
216+
188217
ZTEST_SUITE(video_emul, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)