diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2020-03-01 18:50:04 +0100 |
---|---|---|
committer | Eugene Syromyatnikov <evgsyr@gmail.com> | 2020-03-30 23:14:24 +0200 |
commit | c9f8760b283f77e1316f3d61329b335d0e4ae8f2 (patch) | |
tree | 297231ddfdc1550bc92cd34f6d57e4b4337bd317 | |
parent | ae7217e3c42173007f6924faf5d983effa24bdb5 (diff) | |
download | strace-c9f8760b283f77e1316f3d61329b335d0e4ae8f2.tar.gz |
v4l2: simplify print_v4l2_queryctrl and use print_v4l2_cid
Instead of fragile hacks aroung V4L2_CTRL_FLAG_NEXT_CTRL flag, (always)
save the id field on entering, restore it later on exiting, and print it
second time only if it has changed. That also simplifies the flow
with clear entering/exiting code parts separation.
The usage of print_v4l2_cid for id field printing has introduced several
(anticipated) output formatting changes, hence the changes in expected
output.
* v4l2.c (print_v4l2_queryctrl): Save c.id on entering, print it using
print_v4l2_cid with next_flags set to true, and return 0; remove
"entering(tcp) || get_tcb_priv_ulong(tcp)" logic; restore the entering
id value into entry_id variable on exiting, compare it to the exiting
c.id value and print c.id again if it is different; do not check if tcp
is exiting; always return RVAL_IOCTL_DECODED at the end of the function.
* tests/ioctl_v4l2.c: Update expected output.
* tests/ioctl_v4l2-success.c: Likewise.
-rw-r--r-- | tests/ioctl_v4l2-success.c | 21 | ||||
-rw-r--r-- | tests/ioctl_v4l2.c | 17 | ||||
-rw-r--r-- | v4l2.c | 50 |
3 files changed, 50 insertions, 38 deletions
diff --git a/tests/ioctl_v4l2-success.c b/tests/ioctl_v4l2-success.c index a68e507b4..0e458815f 100644 --- a/tests/ioctl_v4l2-success.c +++ b/tests/ioctl_v4l2-success.c @@ -1064,13 +1064,20 @@ main(int argc, char **argv) static const struct strval32 cids[] = { { ARG_XLAT_UNKNOWN(0, "V4L2_CID_???") }, { ARG_XLAT_UNKNOWN(0x97abcd, "V4L2_CID_???") }, - { ARG_XLAT_UNKNOWN(0x980000, "V4L2_CID_???") }, + { ARG_XLAT_KNOWN(0x980000, "V4L2_CTRL_CLASS_USER+0") }, { ARG_XLAT_KNOWN(0x990a64, "V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE") }, - { ARG_XLAT_UNKNOWN(0xa31234, "V4L2_CID_???") }, + { ARG_XLAT_KNOWN(0xa31234, "V4L2_CTRL_CLASS_DETECT+0x1234") }, { ARG_XLAT_UNKNOWN(0xa40000, "V4L2_CID_???") }, - { 0xdeadc0de, XLAT_KNOWN(0x80000000, "V4L2_CTRL_FLAG_NEXT_CTRL") - "|" XLAT_UNKNOWN(0x5eadc0de, "V4L2_CID_???") }, + { 0xdeadc0de, +#if XLAT_RAW + "0xdeadc0de" +#else + XLAT_KNOWN(0xc0000000, "V4L2_CTRL_FLAG_NEXT_CTRL" + "|V4L2_CTRL_FLAG_NEXT_COMPOUND") + "|0x1eadc0de /* V4L2_CID_??? */" +#endif + }, }; static const struct strval32 ctrl_types[] = { { ARG_XLAT_UNKNOWN(0, "V4L2_CTRL_TYPE_???") }, @@ -1140,13 +1147,9 @@ main(int argc, char **argv) qctrl->flags = ctrl_flags[i % ARRAY_SIZE(ctrl_flags)].val; ioctl(-1, VIDIOC_QUERYCTRL, qctrl); - printf("ioctl(-1, %s, {id=%s%s%s, type=%s, name=", + printf("ioctl(-1, %s, {id=%s, type=%s, name=", XLAT_STR(VIDIOC_QUERYCTRL), cids[i % ARRAY_SIZE(cids)].str, - cids[i % ARRAY_SIZE(cids)].val & 0x80000000 - ? " => " : "", - cids[i % ARRAY_SIZE(cids)].val & 0x80000000 - ? cids[i % ARRAY_SIZE(cids)].str : "", ctrl_types[i % ARRAY_SIZE(ctrl_types)].str); print_quoted_cstring((char *) qctrl->name, sizeof(qctrl->name)); printf(", minimum=-2136948502, maximum=-2136948501" diff --git a/tests/ioctl_v4l2.c b/tests/ioctl_v4l2.c index 4e9ed4881..b83e4ef45 100644 --- a/tests/ioctl_v4l2.c +++ b/tests/ioctl_v4l2.c @@ -1160,10 +1160,21 @@ main(void) struct v4l2_queryctrl *const p_v4l2_queryctrl = page_end - sizeof(*p_v4l2_queryctrl); ioctl(-1, VIDIOC_QUERYCTRL, p_v4l2_queryctrl); - printf("ioctl(-1, %s, {id=" XLAT_FMT "|%#x" NRAW(" /* V4L2_CID_??? */") + printf("ioctl(-1, %s, {id=" +#if XLAT_RAW + "%#x" +#else + XLAT_FMT "|%#x /* V4L2_CID_??? */" +#endif "}) = -1 EBADF (%m)\n", - XLAT_STR(VIDIOC_QUERYCTRL), XLAT_ARGS(V4L2_CTRL_FLAG_NEXT_CTRL), - p_v4l2_queryctrl->id & ~V4L2_CTRL_FLAG_NEXT_CTRL); + XLAT_STR(VIDIOC_QUERYCTRL), +#if XLAT_RAW + p_v4l2_queryctrl->id +#else + XLAT_ARGS(V4L2_CTRL_FLAG_NEXT_CTRL), + p_v4l2_queryctrl->id & ~V4L2_CTRL_FLAG_NEXT_CTRL +#endif + ); TAIL_ALLOC_OBJECT_CONST_PTR(struct v4l2_queryctrl, p_queryctrl); p_queryctrl->id = V4L2_CID_SATURATION; @@ -796,38 +796,36 @@ print_v4l2_queryctrl(struct tcb *const tcp, const kernel_ulong_t arg) tprints(", "); if (umove_or_printaddr(tcp, arg, &c)) return RVAL_IOCTL_DECODED; + set_tcb_priv_ulong(tcp, c.id); tprints("{id="); - } else { - if (syserror(tcp) || umove(tcp, arg, &c) < 0) { - tprints("}"); - return RVAL_IOCTL_DECODED; - } - if (get_tcb_priv_ulong(tcp)) - tprints(" => "); - } + print_v4l2_cid(c.id, true); - if (entering(tcp) || get_tcb_priv_ulong(tcp)) { - const unsigned long next = c.id & V4L2_CTRL_FLAG_NEXT_CTRL; - set_tcb_priv_ulong(tcp, next); - if (next) { - print_xlat(V4L2_CTRL_FLAG_NEXT_CTRL); - tprints("|"); - c.id &= ~V4L2_CTRL_FLAG_NEXT_CTRL; - } - printxval(v4l2_control_ids, c.id, "V4L2_CID_???"); + return 0; } - if (exiting(tcp)) { - tprints(", type="); - printxval(v4l2_control_types, c.type, "V4L2_CTRL_TYPE_???"); - PRINT_FIELD_CSTRING(", ", c, name); - tprintf(", minimum=%d, maximum=%d, step=%d" - ", default_value=%d, flags=", - c.minimum, c.maximum, c.step, c.default_value); - printflags(v4l2_control_flags, c.flags, "V4L2_CTRL_FLAG_???"); + /* exiting */ + if (syserror(tcp) || umove(tcp, arg, &c) < 0) { tprints("}"); + return RVAL_IOCTL_DECODED; } - return entering(tcp) ? 0 : RVAL_IOCTL_DECODED; + + unsigned long entry_id = get_tcb_priv_ulong(tcp); + + if (c.id != entry_id) { + tprints(" => "); + print_v4l2_cid(c.id, false); + } + + tprints(", type="); + printxval(v4l2_control_types, c.type, "V4L2_CTRL_TYPE_???"); + PRINT_FIELD_CSTRING(", ", c, name); + tprintf(", minimum=%d, maximum=%d, step=%d" + ", default_value=%d, flags=", + c.minimum, c.maximum, c.step, c.default_value); + printflags(v4l2_control_flags, c.flags, "V4L2_CTRL_FLAG_???"); + tprints("}"); + + return RVAL_IOCTL_DECODED; } static int |