v4l2-compliance: add file/line for all fails. Do some cleanups.
authorHans Verkuil <hans.verkuil@cisco.com>
Mon, 27 Jun 2011 12:47:47 +0000 (14:47 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Mon, 27 Jun 2011 12:47:47 +0000 (14:47 +0200)
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/v4l2-compliance/v4l2-compliance.cpp
utils/v4l2-compliance/v4l2-compliance.h
utils/v4l2-compliance/v4l2-test-debug.cpp

index c0ce966..bde4047 100644 (file)
@@ -240,33 +240,24 @@ static int testCap(struct node *node)
        struct v4l2_capability vcap;
        __u32 caps;
 
-       if (doioctl(node, VIDIOC_QUERYCAP, &vcap))
-               return fail("VIDIOC_QUERYCAP not implemented\n");
-       if (check_ustring(vcap.driver, sizeof(vcap.driver)))
-               return fail("invalid driver name\n");
-       if (check_ustring(vcap.card, sizeof(vcap.card)))
-               return fail("invalid card name\n");
+       // Must always be there
+       fail_on_test(doioctl(node, VIDIOC_QUERYCAP, &vcap));
+       fail_on_test(check_ustring(vcap.driver, sizeof(vcap.driver)));
+       fail_on_test(check_ustring(vcap.card, sizeof(vcap.card)));
        if (check_ustring(vcap.bus_info, sizeof(vcap.bus_info))) {
-               if (vcap.bus_info[0])
-                       return fail("invalid bus_info\n");
-               else
-                       warn("VIDIOC_QUERYCAP: empty bus_info\n");
+               fail_on_test(vcap.bus_info[0]);
+               warn("VIDIOC_QUERYCAP: empty bus_info\n");
        }
-       if (check_0(vcap.reserved, sizeof(vcap.reserved)))
-               return fail("non-zero reserved fields\n");
+       fail_on_test(check_0(vcap.reserved, sizeof(vcap.reserved)));
        caps = vcap.capabilities;
-       if (caps == 0)
-               return fail("no capabilities set\n");
-       if (node->is_video && !(caps & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT |
-                                       V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_VIDEO_OUTPUT_OVERLAY)))
-               return fail("video node without the relevant capabilities\n");
-       if (node->is_radio && !(caps & (V4L2_CAP_RADIO | V4L2_CAP_MODULATOR)))
-               return fail("radio node without the relevant capabilities\n");
-       if (node->is_radio && (caps & V4L2_CAP_AUDIO))
-               return fail("radio node cannot have CAP_AUDIO set\n");
-       if (node->is_vbi && !(caps & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE |
-                                     V4L2_CAP_VBI_OUTPUT | V4L2_CAP_SLICED_VBI_OUTPUT)))
-               return fail("vbi node without the relevant capabilities\n");
+       fail_on_test(vcap.capabilities == 0);
+       fail_on_test(node->is_video && !(caps & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT |
+                                       V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_VIDEO_OUTPUT_OVERLAY)));
+       fail_on_test(node->is_radio && !(caps & (V4L2_CAP_RADIO | V4L2_CAP_MODULATOR)));
+       // V4L2_CAP_AUDIO is invalid for radio
+       fail_on_test(node->is_radio && (caps & V4L2_CAP_AUDIO));
+       fail_on_test(node->is_vbi && !(caps & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE |
+                                     V4L2_CAP_VBI_OUTPUT | V4L2_CAP_SLICED_VBI_OUTPUT)));
        // You can't have both set due to missing buffer type in VIDIOC_G/S_FBUF
        fail_on_test((caps & (V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_VIDEO_OUTPUT_OVERLAY)) ==
                        (V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_VIDEO_OUTPUT_OVERLAY));
@@ -277,17 +268,13 @@ static int testCap(struct node *node)
 static int check_prio(struct node *node, struct node *node2, enum v4l2_priority match)
 {
        enum v4l2_priority prio;
-       int err;
 
-       err = doioctl(node, VIDIOC_G_PRIORITY, &prio);
-       if (err)
-               return fail("VIDIOC_G_PRIORITY failed\n");
-       if (prio != match)
-               return fail("wrong priority returned (%d, expected %d)\n", prio, match);
-       if (doioctl(node2, VIDIOC_G_PRIORITY, &prio))
-               return fail("second VIDIOC_G_PRIORITY failed\n");
-       if (prio != match)
-               return fail("wrong priority returned on second fh (%d, expected %d)\n", prio, match);
+       // Must be able to get priority
+       fail_on_test(doioctl(node, VIDIOC_G_PRIORITY, &prio));
+       // Must match the expected prio
+       fail_on_test(prio != match);
+       fail_on_test(doioctl(node2, VIDIOC_G_PRIORITY, &prio));
+       fail_on_test(prio != match);
        return 0;
 }
 
@@ -301,19 +288,18 @@ static int testPrio(struct node *node, struct node *node2)
                return err;
 
        prio = V4L2_PRIORITY_RECORD;
-       if (doioctl(node, VIDIOC_S_PRIORITY, &prio))
-               return fail("VIDIOC_S_PRIORITY RECORD failed\n");
-       if (check_prio(node, node2, V4L2_PRIORITY_RECORD))
-               return fail("expected priority RECORD");
+       // Must be able to change priority
+       fail_on_test(doioctl(node, VIDIOC_S_PRIORITY, &prio));
+       // Must match the new prio
+       fail_on_test(check_prio(node, node2, V4L2_PRIORITY_RECORD));
 
        prio = V4L2_PRIORITY_INTERACTIVE;
-       if (!doioctl(node2, VIDIOC_S_PRIORITY, &prio))
-               return fail("Can lower prio on second filehandle\n");
+       // Going back to interactive on the other node must fail
+       fail_on_test(!doioctl(node2, VIDIOC_S_PRIORITY, &prio));
        prio = V4L2_PRIORITY_INTERACTIVE;
-       if (doioctl(node, VIDIOC_S_PRIORITY, &prio))
-               return fail("Could not lower prio\n");
-       if (check_prio(node, node2, V4L2_PRIORITY_INTERACTIVE))
-               return fail("expected priority INTERACTIVE");
+       // Changing it on the first node must work.
+       fail_on_test(doioctl(node, VIDIOC_S_PRIORITY, &prio));
+       fail_on_test(check_prio(node, node2, V4L2_PRIORITY_INTERACTIVE));
        return 0;
 }
 
index 67adc78..72aa203 100644 (file)
@@ -74,16 +74,16 @@ struct node {
                        printf("\t\twarn: " fmt, ##args);       \
        } while (0)
 
-#define fail(fmt, args...)                     \
-({                                             \
-       printf("\t\tfail: " fmt, ##args);       \
-       1;                                      \
+#define fail(fmt, args...)                                             \
+({                                                                     \
+       printf("\t\tfail: %s(%d): " fmt, __FILE__, __LINE__, ##args);   \
+       1;                                                              \
 })
 
-#define fail_on_test(test)                                     \
-       do {                                                    \
-               if (test)                                       \
-               return fail("%s(%d): %s\n", __FILE__, __LINE__, #test); \
+#define fail_on_test(test)                             \
+       do {                                            \
+               if (test)                               \
+                       return fail("%s\n", #test);     \
        } while (0)
 
 static inline int test_open(const char *file, int oflag)
index 2bb7cc0..d624e81 100644 (file)
@@ -58,8 +58,7 @@ int testChipIdent(struct node *node)
                ret = doioctl(node, VIDIOC_DBG_G_CHIP_IDENT, &chip);
                if (ret != EINVAL)
                        return fail("Invalid match_type accepted\n");
-               if (memcmp(&orig, &chip, sizeof(chip)))
-                       return fail("Error, but struct modified\n");
+               fail_on_test(memcmp(&orig, &chip, sizeof(chip)));
                return 0;
        }
        return ret == EINVAL ? -ENOSYS : ret;
@@ -78,21 +77,18 @@ int testRegister(struct node *node)
        ret = doioctl(node, VIDIOC_DBG_G_REGISTER, &reg);
        if (ret == EINVAL)
                return -ENOSYS;
-       if (uid && ret != EPERM)
-               return fail("Not allowed to call VIDIOC_DBG_G_REGISTER unless root\n");
-       if (uid == 0 && ret)
-               return fail("Not allowed to call VIDIOC_DBG_G_REGISTER even though we are root\n");
+       // Not allowed to call VIDIOC_DBG_G_REGISTER unless root
+       fail_on_test(uid && ret != EPERM);
+       fail_on_test(uid == 0 && ret);
        chip.match.type = V4L2_CHIP_MATCH_HOST;
        chip.match.addr = 0;
-       if (doioctl(node, VIDIOC_DBG_G_CHIP_IDENT, &chip))
-               return fail("Must support VIDIOC_DBG_G_CHIP_IDENT\n");
+       fail_on_test(doioctl(node, VIDIOC_DBG_G_CHIP_IDENT, &chip));
        if (uid) {
                // Don't test S_REGISTER as root, don't want to risk
                // messing with registers in the compliance test.
                reg.reg = reg.val = 0;
                ret = doioctl(node, VIDIOC_DBG_S_REGISTER, &reg);
-               if (ret != EINVAL && ret != EPERM)
-                       return fail("Invalid error calling VIDIOC_DBG_S_REGISTER as non-root\n");
+               fail_on_test(ret != EINVAL && ret != EPERM);
        }
        return 0;
 }