v4l2-compliance: simplify doioctl
authorHans Verkuil <hverkuil@xs4all.nl>
Sat, 8 Jan 2011 17:48:45 +0000 (18:48 +0100)
committerHans Verkuil <hverkuil@xs4all.nl>
Sat, 8 Jan 2011 17:48:45 +0000 (18:48 +0100)
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
utils/v4l2-compliance/v4l2-compliance.cpp
utils/v4l2-compliance/v4l2-compliance.h
utils/v4l2-compliance/v4l2-test-debug.cpp
utils/v4l2-compliance/v4l2-test-input-output.cpp

index 07dd7c1..1e3661e 100644 (file)
@@ -106,7 +106,7 @@ static void usage(void)
        exit(0);
 }
 
-int doioctl(struct node *node, unsigned long int request, void *parm, const char *name)
+int doioctl_name(struct node *node, unsigned long int request, void *parm, const char *name)
 {
        int retval;
        int e;
@@ -217,7 +217,7 @@ static int testCap(struct node *node)
        struct v4l2_capability vcap;
        __u32 caps;
 
-       if (doioctl(node, VIDIOC_QUERYCAP, &vcap, "VIDIOC_QUERYCAP"))
+       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");
@@ -236,14 +236,14 @@ static int check_prio(struct node *node, struct node *node2, enum v4l2_priority
        enum v4l2_priority prio;
        int err;
 
-       err = doioctl(node, VIDIOC_G_PRIORITY, &prio, "VIDIOC_G_PRIORITY");
+       err = doioctl(node, VIDIOC_G_PRIORITY, &prio);
        if (err == EINVAL)
                return -ENOSYS;
        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, "VIDIOC_G_PRIORITY"))
+       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);
@@ -260,16 +260,16 @@ static int testPrio(struct node *node, struct node *node2)
                return err;
 
        prio = V4L2_PRIORITY_RECORD;
-       if (doioctl(node, VIDIOC_S_PRIORITY, &prio, "VIDIOC_S_PRIORITY"))
+       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");
 
        prio = V4L2_PRIORITY_INTERACTIVE;
-       if (!doioctl(node2, VIDIOC_S_PRIORITY, &prio, "VIDIOC_S_PRIORITY"))
+       if (!doioctl(node2, VIDIOC_S_PRIORITY, &prio))
                return fail("Can lower prio on second filehandle\n");
        prio = V4L2_PRIORITY_INTERACTIVE;
-       if (doioctl(node, VIDIOC_S_PRIORITY, &prio, "VIDIOC_S_PRIORITY"))
+       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");
index 0e95877..cbd7e7b 100644 (file)
@@ -43,7 +43,9 @@ struct node {
        1;                                      \
 })
 
-int doioctl(struct node *node, unsigned long int request, void *parm, const char *name);
+int doioctl_name(struct node *node, unsigned long int request, void *parm, const char *name);
+#define doioctl(n, r, p) doioctl_name(n, r, p, #r)
+
 std::string cap2s(unsigned cap);
 const char *ok(int res);
 int check_string(const char *s, size_t len);
index 8a14dab..07652e7 100644 (file)
@@ -43,7 +43,7 @@ int testChipIdent(struct node *node)
        memset(&chip, 0, sizeof(chip));
        chip.match.type = V4L2_CHIP_MATCH_HOST;
        chip.match.addr = 0;
-       ret = doioctl(node, VIDIOC_DBG_G_CHIP_IDENT, &chip, "VIDIOC_DBG_G_CHIP_IDENT");
+       ret = doioctl(node, VIDIOC_DBG_G_CHIP_IDENT, &chip);
        // Must return either 0 (OK) or EINVAL (not supported)
        if (ret == 0) {
                struct v4l2_dbg_chip_ident orig;
@@ -55,7 +55,7 @@ int testChipIdent(struct node *node)
                chip.ident = 0xdeadbeef;
                chip.revision = 0xdeadbeef;
                orig = chip;
-               ret = doioctl(node, VIDIOC_DBG_G_CHIP_IDENT, &chip, "VIDIOC_DBG_G_CHIP_IDENT");
+               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)))
@@ -75,7 +75,7 @@ int testRegister(struct node *node)
        reg.match.type = V4L2_CHIP_MATCH_HOST;
        reg.match.addr = 0;
        reg.reg = 0;
-       ret = doioctl(node, VIDIOC_DBG_G_REGISTER, &reg, "VIDIOC_DBG_G_REGISTER");
+       ret = doioctl(node, VIDIOC_DBG_G_REGISTER, &reg);
        if (ret == EINVAL)
                return -ENOSYS;
        if (uid && ret != EPERM)
@@ -84,13 +84,13 @@ int testRegister(struct node *node)
                return fail("Not allowed to call VIDIOC_DBG_G_REGISTER even though we are root\n");
        chip.match.type = V4L2_CHIP_MATCH_HOST;
        chip.match.addr = 0;
-       if (doioctl(node, VIDIOC_DBG_G_CHIP_IDENT, &chip, "VIDIOC_DBG_G_CHIP_IDENT"))
+       if (doioctl(node, VIDIOC_DBG_G_CHIP_IDENT, &chip))
                return fail("Must support VIDIOC_DBG_G_CHIP_IDENT\n");
        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, "VIDIOC_DBG_S_REGISTER");
+               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");
        }
@@ -99,7 +99,7 @@ int testRegister(struct node *node)
 
 int testLogStatus(struct node *node)
 {
-       int ret = doioctl(node, VIDIOC_LOG_STATUS, NULL, "VIDIOC_LOG_STATUS");
+       int ret = doioctl(node, VIDIOC_LOG_STATUS, NULL);
 
        return (ret == EINVAL) ? -ENOSYS : ret;
 }
index d42af58..6f9fabe 100644 (file)
@@ -68,7 +68,7 @@ int testInput(struct node *node)
        struct v4l2_audio audio;
        int cur_input = MAGIC;
        int input;
-       int ret = doioctl(node, VIDIOC_G_INPUT, &cur_input, "VIDIOC_G_INPUT");
+       int ret = doioctl(node, VIDIOC_G_INPUT, &cur_input);
        int i = 0;
        unsigned a;
 
@@ -81,13 +81,13 @@ int testInput(struct node *node)
        for (;;) {
                memset(&descr, 0xff, sizeof(descr));
                descr.index = i;
-               ret = doioctl(node, VIDIOC_ENUMINPUT, &descr, "VIDIOC_ENUMINPUT");
+               ret = doioctl(node, VIDIOC_ENUMINPUT, &descr);
                if (ret == EINVAL)
                        break;
                if (ret)
                        return fail("could not enumerate input %d\n", i);
                input = i;
-               if (doioctl(node, VIDIOC_S_INPUT, &input, "VIDIOC_S_INPUT"))
+               if (doioctl(node, VIDIOC_S_INPUT, &input))
                        return fail("could not set input to %d\n", i);
                if (input != i)
                        return fail("input set to %d, but becomes %d?!\n", i, input);
@@ -96,7 +96,7 @@ int testInput(struct node *node)
                for (a = 0; a <= node->audio_inputs; a++) {
                        memset(&audio, 0, sizeof(audio));
                        audio.index = a;
-                       ret = doioctl(node, VIDIOC_S_AUDIO, &audio, "VIDIOC_S_AUDIO");
+                       ret = doioctl(node, VIDIOC_S_AUDIO, &audio);
                        if (ret && (descr.audioset & (1 << a)))
                                return fail("could not set audio input to %d for video input %d\n", a, i);
                        if (ret != EINVAL && !(descr.audioset & (1 << a)))
@@ -105,9 +105,9 @@ int testInput(struct node *node)
                i++;
        }
        input = i;
-       if (doioctl(node, VIDIOC_S_INPUT, &input, "VIDIOC_S_INPUT") != EINVAL)
+       if (doioctl(node, VIDIOC_S_INPUT, &input) != EINVAL)
                return fail("could set input to invalid input %d\n", i);
-       if (doioctl(node, VIDIOC_S_INPUT, &cur_input, "VIDIOC_S_INPUT"))
+       if (doioctl(node, VIDIOC_S_INPUT, &cur_input))
                return fail("couldn't set input to the original input %d\n", cur_input);
        return 0;
 }
@@ -139,7 +139,7 @@ int testInputAudio(struct node *node)
                memset(&input, 0xff, sizeof(input));
                input.index = i;
 
-               ret = doioctl(node, VIDIOC_ENUMAUDIO, &input, "VIDIOC_ENUMAUDIO");
+               ret = doioctl(node, VIDIOC_ENUMAUDIO, &input);
                if (i == 0 && ret == EINVAL)
                        return -ENOSYS;
                if (ret == EINVAL)
@@ -155,10 +155,10 @@ int testInputAudio(struct node *node)
        memset(input.reserved, 0, sizeof(input.reserved));
        input.index = i;
        input.mode = 0;
-       if (doioctl(node, VIDIOC_S_AUDIO, &input, "VIDIOC_S_AUDIO") != EINVAL)
+       if (doioctl(node, VIDIOC_S_AUDIO, &input) != EINVAL)
                return fail("can set invalid audio input\n");
        memset(&input, 0xff, sizeof(input));
-       ret = doioctl(node, VIDIOC_G_AUDIO, &input, "VIDIOC_G_AUDIO");
+       ret = doioctl(node, VIDIOC_G_AUDIO, &input);
        if (i == 0) {
                if (ret != EINVAL)
                        return fail("can get current audio input, but no inputs enumerated\n");
@@ -204,7 +204,7 @@ int testOutput(struct node *node)
        struct v4l2_audioout audio;
        int cur_output = MAGIC;
        int output;
-       int ret = doioctl(node, VIDIOC_G_OUTPUT, &cur_output, "VIDIOC_G_OUTPUT");
+       int ret = doioctl(node, VIDIOC_G_OUTPUT, &cur_output);
        int o = 0;
        unsigned a;
 
@@ -217,11 +217,11 @@ int testOutput(struct node *node)
        for (;;) {
                memset(&descr, 0xff, sizeof(descr));
                descr.index = o;
-               ret = doioctl(node, VIDIOC_ENUMOUTPUT, &descr, "VIDIOC_ENUMOUTPUT");
+               ret = doioctl(node, VIDIOC_ENUMOUTPUT, &descr);
                if (ret)
                        break;
                output = o;
-               if (doioctl(node, VIDIOC_S_OUTPUT, &output, "VIDIOC_S_OUTPUT"))
+               if (doioctl(node, VIDIOC_S_OUTPUT, &output))
                        return fail("could not set output to %d\n", o);
                if (output != o)
                        return fail("output set to %d, but becomes %d?!\n", o, output);
@@ -230,7 +230,7 @@ int testOutput(struct node *node)
                for (a = 0; a <= node->audio_outputs; a++) {
                        memset(&audio, 0, sizeof(audio));
                        audio.index = a;
-                       ret = doioctl(node, VIDIOC_S_AUDOUT, &audio, "VIDIOC_S_AUDOUT");
+                       ret = doioctl(node, VIDIOC_S_AUDOUT, &audio);
                        if (ret && (descr.audioset & (1 << a)))
                                return fail("could not set audio output to %d for video output %d\n", a, o);
                        if (ret != EINVAL && !(descr.audioset & (1 << a)))
@@ -239,9 +239,9 @@ int testOutput(struct node *node)
                o++;
        }
        output = o;
-       if (doioctl(node, VIDIOC_S_OUTPUT, &output, "VIDIOC_S_OUTPUT") != EINVAL)
+       if (doioctl(node, VIDIOC_S_OUTPUT, &output) != EINVAL)
                return fail("could set output to invalid output %d\n", o);
-       if (doioctl(node, VIDIOC_S_OUTPUT, &cur_output, "VIDIOC_S_OUTPUT"))
+       if (doioctl(node, VIDIOC_S_OUTPUT, &cur_output))
                return fail("couldn't set output to the original output %d\n", cur_output);
        return 0;
 }
@@ -271,7 +271,7 @@ int testOutputAudio(struct node *node)
                memset(&output, 0xff, sizeof(output));
                output.index = o;
 
-               ret = doioctl(node, VIDIOC_ENUMAUDOUT, &output, "VIDIOC_ENUMAUDOUT");
+               ret = doioctl(node, VIDIOC_ENUMAUDOUT, &output);
                if (o == 0 && ret == EINVAL)
                        return -ENOSYS;
                if (ret == EINVAL)
@@ -287,10 +287,10 @@ int testOutputAudio(struct node *node)
        memset(output.reserved, 0, sizeof(output.reserved));
        output.index = o;
        output.mode = 0;
-       if (doioctl(node, VIDIOC_S_AUDOUT, &output, "VIDIOC_S_AUDOUT") != EINVAL)
+       if (doioctl(node, VIDIOC_S_AUDOUT, &output) != EINVAL)
                return fail("can set invalid audio output\n");
        memset(&output, 0xff, sizeof(output));
-       ret = doioctl(node, VIDIOC_G_AUDOUT, &output, "VIDIOC_G_AUDOUT");
+       ret = doioctl(node, VIDIOC_G_AUDOUT, &output);
        if (o == 0) {
                if (ret != EINVAL)
                        return fail("can get current audio output, but no outputs enumerated\n");