v4l2-compliance: support menu controls with more than 32 items
authorHans Verkuil <hans.verkuil@cisco.com>
Sat, 8 Mar 2014 11:25:13 +0000 (12:25 +0100)
committerHans Verkuil <hans.verkuil@cisco.com>
Sat, 8 Mar 2014 11:25:13 +0000 (12:25 +0100)
v4l2-compliance would fail if it encounters menu controls with more
than 32 items. This patch improves that behavior by allowing any
number of items, although only up to 64 will be tested.

This is because v4l2-compliance uses a bitmask for the valid menu
items which is now 64 bits.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/v4l2-compliance/v4l2-compliance.h
utils/v4l2-compliance/v4l2-test-controls.cpp

index 1d93004..2906f49 100644 (file)
@@ -39,7 +39,7 @@ extern int kernel_version;
 extern unsigned warnings;
 
 struct test_queryctrl: v4l2_queryctrl {
-       unsigned menu_mask;
+       __u64 menu_mask;
 };
 
 typedef std::list<test_queryctrl> qctrl_list;
index 70b8aba..70014aa 100644 (file)
@@ -145,8 +145,7 @@ static int checkQCtrl(struct node *node, struct test_queryctrl &qctrl)
                        return fail("can do querymenu on a non-menu control\n");
                return 0;
        }
-       if (qctrl.maximum >= 32)
-               return fail("currently more than 32 menu items are not supported\n");
+       bool have_default_value = false;
        for (i = 0; i <= qctrl.maximum + 1; i++) {
                memset(&qmenu, 0xff, sizeof(qmenu));
                qmenu.id = qctrl.id;
@@ -165,12 +164,14 @@ static int checkQCtrl(struct node *node, struct test_queryctrl &qctrl)
                        return fail("invalid menu name\n");
                if (qmenu.reserved)
                        return fail("reserved is non-zero\n");
-               qctrl.menu_mask |= 1 << i;
+               if (i == qctrl.default_value)
+                       have_default_value = true;
+               if (i < 64)
+                       qctrl.menu_mask |= 1ULL << i;
        }
        if (qctrl.menu_mask == 0)
                return fail("no menu items found\n");
-       if (!(qctrl.menu_mask & (1 << qctrl.default_value)))
-               return fail("the default_value is an invalid menu item\n");
+       fail_on_test(!have_default_value);
        return 0;
 }
 
@@ -405,9 +406,15 @@ int testSimpleControls(struct node *node)
                }
 
                if (iter->type == V4L2_CTRL_TYPE_MENU || iter->type == V4L2_CTRL_TYPE_INTEGER_MENU) {
+                       int max = iter->maximum;
+
+                       /* Currently menu_mask is a 64-bit value, so we can't reliably
+                        * test for menu item > 63. */
+                       if (max > 63)
+                               max = 63;
                        // check menu items
-                       for (i = iter->minimum; i <= iter->maximum; i++) {
-                               unsigned valid = iter->menu_mask & (1 << i);
+                       for (i = iter->minimum; i <= max; i++) {
+                               bool valid = iter->menu_mask & (1ULL << i);
 
                                ctrl.id = iter->id; 
                                ctrl.value = i;