summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@strace.io>2022-11-06 08:00:00 +0000
committerDmitry V. Levin <ldv@strace.io>2022-11-06 08:00:00 +0000
commit4de1a423dd9c909d356a4c29e3534d18a253653b (patch)
tree0c6221f88e3ee508ece1a7cc6ad41ee4392b59ae
parent8c3af47e434da77640d61a6bed14b5e388860e79 (diff)
downloadstrace-4de1a423dd9c909d356a4c29e3534d18a253653b.tar.gz
tests: check decoding of ioctl TIOCM* commands
* tests/ioctl_tiocm.c: New file. * tests/gen_tests.in (ioctl_tiocm): New test. * tests/pure_executables.list: Add ioctl_tiocm. * tests/.gitignore: Likewise.
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/gen_tests.in1
-rw-r--r--tests/ioctl_tiocm.c96
-rwxr-xr-xtests/pure_executables.list1
4 files changed, 99 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 581ab324d..5459d8f4b 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -378,6 +378,7 @@ ioctl_sg_io_v4
ioctl_sock
ioctl_sock_gifconf
ioctl_tee
+ioctl_tiocm
ioctl_ubi
ioctl_ubi-success
ioctl_uffdio
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index b822add55..d1cbf0e94 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -396,6 +396,7 @@ ioctl_sg_io_v4 +ioctl.test
ioctl_sock +ioctl.test -a23
ioctl_sock_gifconf +ioctl.test -a28 -s1
ioctl_tee +ioctl.test
+ioctl_tiocm +ioctl.test
ioctl_ubi +ioctl.test
ioctl_ubi-success +ioctl-success.sh -a24
ioctl_uffdio +ioctl.test
diff --git a/tests/ioctl_tiocm.c b/tests/ioctl_tiocm.c
new file mode 100644
index 000000000..402fce678
--- /dev/null
+++ b/tests/ioctl_tiocm.c
@@ -0,0 +1,96 @@
+/*
+ * Check decoding of ioctl TIOCM* commands.
+ *
+ * Copyright (c) 2020-2022 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <errno.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+
+static const char *errstr;
+
+static int
+do_ioctl(kernel_ulong_t cmd, kernel_ulong_t arg)
+{
+ int rc = ioctl(-1, cmd, arg);
+ errstr = sprintrc(rc);
+ return rc;
+}
+
+static int
+do_ioctl_ptr(kernel_ulong_t cmd, const void *arg)
+{
+ return do_ioctl(cmd, (uintptr_t) arg);
+}
+
+int
+main(int argc, const char *argv[])
+{
+ static const struct {
+ uint32_t cmd;
+ const char *str;
+ bool on_enter;
+ bool on_exit;
+ } cmds[] = {
+ { ARG_STR(TIOCMGET), false, true },
+ { ARG_STR(TIOCMBIS), true, false },
+ { ARG_STR(TIOCMBIC), true, false },
+ { ARG_STR(TIOCMSET), true, false },
+ };
+
+ TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, p_flags);
+ const void *const efault = p_flags + 1;
+
+ for (size_t i = 0; i < ARRAY_SIZE(cmds); ++i) {
+ do_ioctl(cmds[i].cmd, 0);
+ printf("ioctl(-1, " XLAT_FMT ", NULL) = %s\n",
+ XLAT_SEL(cmds[i].cmd, cmds[i].str), errstr);
+
+ do_ioctl_ptr(cmds[i].cmd, efault);
+ printf("ioctl(-1, " XLAT_FMT ", %p) = %s\n",
+ XLAT_SEL(cmds[i].cmd, cmds[i].str),
+ efault, errstr);
+
+#define VALID_FLAGS 0x1ff
+#define INVALID_FLAGS 0xfffffe00
+ *p_flags = INVALID_FLAGS;
+
+ if (cmds[i].on_enter) {
+ do_ioctl_ptr(cmds[i].cmd, p_flags);
+ printf("ioctl(-1, " XLAT_FMT ", [%s]) = %s\n",
+ XLAT_SEL(cmds[i].cmd, cmds[i].str),
+ XLAT_UNKNOWN(INVALID_FLAGS, "TIOCM_???"),
+ errstr);
+
+ *p_flags = ~*p_flags;
+ do_ioctl_ptr(cmds[i].cmd, p_flags);
+ printf("ioctl(-1, " XLAT_FMT ", [%s]) = %s\n",
+ XLAT_SEL(cmds[i].cmd, cmds[i].str),
+ XLAT_KNOWN(VALID_FLAGS,
+ "TIOCM_LE|"
+ "TIOCM_DTR|"
+ "TIOCM_RTS|"
+ "TIOCM_ST|"
+ "TIOCM_SR|"
+ "TIOCM_CTS|"
+ "TIOCM_CAR|"
+ "TIOCM_RNG|"
+ "TIOCM_DSR"),
+ errstr);
+ } else if (cmds[i].on_exit) {
+ do_ioctl_ptr(cmds[i].cmd, p_flags);
+ printf("ioctl(-1, " XLAT_FMT ", %p) = %s\n",
+ XLAT_SEL(cmds[i].cmd, cmds[i].str),
+ p_flags, errstr);
+ }
+
+ }
+
+ puts("+++ exited with 0 +++");
+ return 0;
+}
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index 3c1317adb..c1b202ea9 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -241,6 +241,7 @@ ioctl_sg_io_v4
ioctl_sock
ioctl_sock_gifconf
ioctl_tee
+ioctl_tiocm
ioctl_ubi
ioctl_uffdio
ioctl_v4l2