From dc048059e4ff89628da0ac87ff372f870f99f507 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Thu, 19 Apr 2012 16:21:02 +0200 Subject: [PATCH] v4l2-compliance: add tests for control events. Signed-off-by: Hans Verkuil --- utils/v4l2-compliance/v4l2-compliance.cpp | 2 +- utils/v4l2-compliance/v4l2-compliance.h | 1 + utils/v4l2-compliance/v4l2-test-controls.cpp | 42 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/utils/v4l2-compliance/v4l2-compliance.cpp b/utils/v4l2-compliance/v4l2-compliance.cpp index 857d236..9de3df4 100644 --- a/utils/v4l2-compliance/v4l2-compliance.cpp +++ b/utils/v4l2-compliance/v4l2-compliance.cpp @@ -590,6 +590,7 @@ int main(int argc, char **argv) printf("\ttest VIDIOC_QUERYCTRL/MENU: %s\n", ok(testQueryControls(&node))); printf("\ttest VIDIOC_G/S_CTRL: %s\n", ok(testSimpleControls(&node))); printf("\ttest VIDIOC_G/S/TRY_EXT_CTRLS: %s\n", ok(testExtendedControls(&node))); + printf("\ttest VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: %s\n", ok(testControlEvents(&node))); printf("\tStandard Controls: %d Private Controls: %d\n", node.std_controls, node.priv_controls); printf("\n"); @@ -618,7 +619,6 @@ int main(int argc, char **argv) VIDIOC_G/S_PARM VIDIOC_G/S_JPEGCOMP VIDIOC_S_HW_FREQ_SEEK - VIDIOC_SUBSCRIBE_EVENT/UNSUBSCRIBE_EVENT/DQEVENT VIDIOC_(TRY_)ENCODER_CMD VIDIOC_G_ENC_INDEX VIDIOC_REQBUFS/QBUF/DQBUF/QUERYBUF diff --git a/utils/v4l2-compliance/v4l2-compliance.h b/utils/v4l2-compliance/v4l2-compliance.h index 6c8f607..951f839 100644 --- a/utils/v4l2-compliance/v4l2-compliance.h +++ b/utils/v4l2-compliance/v4l2-compliance.h @@ -151,6 +151,7 @@ int testOutputAudio(struct node *node); int testQueryControls(struct node *node); int testSimpleControls(struct node *node); int testExtendedControls(struct node *node); +int testControlEvents(struct node *node); // I/O configuration ioctl tests int testStd(struct node *node); diff --git a/utils/v4l2-compliance/v4l2-test-controls.cpp b/utils/v4l2-compliance/v4l2-test-controls.cpp index 4a0712d..db0c326 100644 --- a/utils/v4l2-compliance/v4l2-test-controls.cpp +++ b/utils/v4l2-compliance/v4l2-test-controls.cpp @@ -651,3 +651,45 @@ int testExtendedControls(struct node *node) return fail("error_idx should be equal to count\n"); return 0; } + +int testControlEvents(struct node *node) +{ + qctrl_list::iterator iter; + + for (iter = node->controls.begin(); iter != node->controls.end(); ++iter) { + struct v4l2_event_subscription sub = { 0 }; + struct v4l2_event ev; + struct timeval timeout = { 0, 100 }; + fd_set set; + int ret; + + info("checking control event '%s' (0x%08x)\n", iter->name, iter->id); + sub.type = V4L2_EVENT_CTRL; + sub.id = iter->id; + sub.flags = V4L2_EVENT_SUB_FL_SEND_INITIAL; + ret = doioctl(node, VIDIOC_SUBSCRIBE_EVENT, &sub); + if (ret) + return fail("subscribe event for control '%s' failed\n", iter->name); + //if (iter->type == V4L2_CTRL_TYPE_CTRL_CLASS) + FD_ZERO(&set); + FD_SET(node->fd, &set); + ret = select(node->fd + 1, NULL, NULL, &set, &timeout); + if (ret == 0) { + if (iter->type != V4L2_CTRL_TYPE_CTRL_CLASS) + return fail("failed to find event for control '%s'\n", iter->name); + } else if (iter->type == V4L2_CTRL_TYPE_CTRL_CLASS) { + return fail("found event for control class '%s'\n", iter->name); + } + if (ret) { + ret = doioctl(node, VIDIOC_DQEVENT, &ev); + if (ret) + return fail("couldn't get event for control '%s'\n", iter->name); + if (ev.type != V4L2_EVENT_CTRL || ev.id != iter->id) + return fail("dequeued wrong event\n"); + } + ret = doioctl(node, VIDIOC_UNSUBSCRIBE_EVENT, &sub); + if (ret) + return fail("unsubscribe event for control '%s' failed\n", iter->name); + } + return 0; +} -- 2.7.4