[PATCH 6/6] tests: add a test case for the abitrator of ioctl command overwrapping
Masatake YAMATO
yamato at redhat.com
Thu Mar 10 12:01:06 UTC 2022
* tests/ioctl_overwrap.c: New test case.
* tests/.gitignore: Add the ioctl_overwrap test case.
* tests/gen_tests.in: add an entry for ioctl_overwrap.
* tests/pure_executables.list: add ioctl_overwrap command.
Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
tests/.gitignore | 1 +
tests/gen_tests.in | 1 +
tests/ioctl_overwrap.c | 63 +++++++++++++++++++++++++++++++++++++
tests/pure_executables.list | 1 +
4 files changed, 66 insertions(+)
create mode 100644 tests/ioctl_overwrap.c
diff --git a/tests/.gitignore b/tests/.gitignore
index 6c212c38a..130d2432d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -334,6 +334,7 @@ ioctl_mtd
ioctl_mtd-success
ioctl_nbd
ioctl_nsfs
+ioctl_overwrap
ioctl_perf
ioctl_perf-success
ioctl_ptp
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index b98a733a0..79d4796c7 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -348,6 +348,7 @@ ioctl_mtd +ioctl.test
ioctl_mtd-success +ioctl-success.sh -a26
ioctl_nbd +ioctl.test -y
ioctl_nsfs +ioctl.test -esignal=none
+ioctl_overwrap +ioctl.test
ioctl_perf +ioctl.test
ioctl_perf-success +ioctl-success.sh -a35
ioctl_ptp +ioctl.test
diff --git a/tests/ioctl_overwrap.c b/tests/ioctl_overwrap.c
new file mode 100644
index 000000000..aa66aa715
--- /dev/null
+++ b/tests/ioctl_overwrap.c
@@ -0,0 +1,63 @@
+/*
+ * Test the code arbitrating the overlapped IOCTL commands
+ *
+ * Copyright (c) 2022 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#define _XOPEN_SOURCE 600
+
+#include "tests.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fcntl.h>
+#include <termios.h>
+#include <unistd.h>
+
+int
+main(int argc, char **argv)
+{
+ struct termios tos;
+ memset(&tos, 0, sizeof(tos));
+
+ int ptm = posix_openpt(O_RDWR);
+ if (ptm < 0)
+ perror_msg_and_fail("posix_openpt(_RDWR)");
+
+ if (unlockpt(ptm) < 0)
+ perror_msg_and_fail("unlockpt(%d)", ptm);
+ printf("ioctl(%d, TIOCSPTLCK, [0]) = 0\n", ptm);
+
+ char *slvname = ptsname(ptm);
+ if (!slvname)
+ error_msg_and_fail("ptsname(%d) returns NULL", ptm);
+ char *n = strrchr(slvname, '/');
+ if (!n)
+ error_msg_and_fail("ptsname returns unexpected string: %s\n",
+ slvname);
+ /* slvname may be /dev/pts/[0-9]+. */
+ printf("ioctl(%d, TIOCGPTN, [%s]) = 0\n", ptm, n + 1);
+
+ int pts = open(slvname, O_RDWR);
+ if (pts < 0)
+ perror_msg_and_fail("open(%s)", slvname);
+
+ tcsetattr(pts, TCSANOW, &tos);
+ printf("ioctl(%d, TCSETS, {B0 -opost -isig -icanon -echo ...}) = 0\n", pts);
+ printf("ioctl(%d, TCGETS, {B0 -opost -isig -icanon -echo ...}) = 0\n", pts);
+
+ int devnull = open("/dev/null", O_RDWR);
+ if (pts < 0)
+ perror_msg_and_fail("open(/dev/null)");
+
+ tcsetattr(devnull, TCSANOW, &tos);
+ printf("ioctl(%d, SNDCTL_TMR_START or TCSETS, {B0 -opost -isig -icanon -echo ...}) = -1 ENOTTY (Inappropriate ioctl for device)\n",
+ devnull);
+
+ puts("+++ exited with 0 +++");
+ return 0;
+}
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index fe02fabb7..f11cfd3ce 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -220,6 +220,7 @@ ioctl_kvm_run_auxstr_vcpu
ioctl_loop
ioctl_mtd
ioctl_nbd
+ioctl_overwrap
ioctl_perf
ioctl_ptp
ioctl_random
--
2.35.1
More information about the Strace-devel
mailing list