From 10878b224a89cbc0e60f7934d3f50faf6793a9e3 Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Sat, 16 Sep 2017 03:04:40 +0200 Subject: [PATCH] tests: add kcmp-y test It is not very useful as of now, but it will allow tracking changes in fd output once they are implemented. * tests/gen_tests.in (kcmp-y): New test. * tests/kcmp-y.c: New file, wrapper for kcmp.c * tests/kcmp.c: Add opening of some files for which info may be printed in the future. * tests/pure_executables.list: Add kcmp-y. * tests/.gitignore: Likewise. --- tests/.gitignore | 3 ++- tests/gen_tests.in | 1 + tests/kcmp-y.c | 3 +++ tests/kcmp.c | 32 ++++++++++++++++++++++++++++++++ tests/pure_executables.list | 1 + 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/kcmp-y.c diff --git a/tests/.gitignore b/tests/.gitignore index e8e6d899..14a64a95 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -150,6 +150,7 @@ ipc_sem ipc_shm is_linux_mips_n64 kcmp +kcmp-y kexec_file_load kexec_load keyctl @@ -218,8 +219,8 @@ netlink_unix_diag netlink_xfrm newfstatat nlattr -nlattr_crypto_user_alg nlattr_br_port_msg +nlattr_crypto_user_alg nlattr_dcbmsg nlattr_fib_rule_hdr nlattr_ifaddrlblmsg diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 9f398e03..a7b56761 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -144,6 +144,7 @@ ipc_msg +ipc.sh ipc_sem +ipc.sh ipc_shm +ipc.sh kcmp -a22 +kcmp-y -a22 -y -e trace=kcmp kexec_file_load -s9 kexec_load -s9 keyctl -a31 -s10 diff --git a/tests/kcmp-y.c b/tests/kcmp-y.c new file mode 100644 index 00000000..02ad90e5 --- /dev/null +++ b/tests/kcmp-y.c @@ -0,0 +1,3 @@ +#define VERBOSE_FD 1 + +#include "kcmp.c" diff --git a/tests/kcmp.c b/tests/kcmp.c index 62a24d91..652352e9 100644 --- a/tests/kcmp.c +++ b/tests/kcmp.c @@ -34,9 +34,13 @@ #ifdef __NR_kcmp +# include # include # include +# ifndef VERBOSE_FD +# define VERBOSE_FD 0 +# endif /* * We prefer to use system headers in order to catch some possible deviations in @@ -55,6 +59,12 @@ # define KCMP_SYSVSEM 6 # endif +static const char null_path[] = "/dev/null"; +static const char zero_path[] = "/dev/zero"; + +# define NULL_FD 23 +# define ZERO_FD 42 + static void printpidfd(const char *prefix, pid_t pid, unsigned fd) { @@ -103,6 +113,27 @@ main(void) static const kernel_ulong_t bogus_idx2 = (kernel_ulong_t) 0xba5e1e55deadc0deULL; + int fd; + + /* Open some files to test printpidfd */ + fd = open(null_path, O_RDONLY); + if (fd < 0) + perror_msg_and_fail("open(\"%s\")", null_path); + if (fd != NULL_FD) { + if (dup2(fd, NULL_FD) < 0) + perror_msg_and_fail("dup2(fd, NULL_FD)"); + close(fd); + } + + fd = open(zero_path, O_RDONLY); + if (fd < 0) + perror_msg_and_fail("open(\"%s\")", zero_path); + if (fd != ZERO_FD) { + if (dup2(fd, ZERO_FD) < 0) + perror_msg_and_fail("dup2(fd, ZERO_FD)"); + close(fd); + } + /* Invalid values */ do_kcmp(bogus_pid1, bogus_pid2, bogus_type, NULL, bogus_idx1, bogus_idx2); @@ -112,6 +143,7 @@ main(void) /* KCMP_FILE is the only type which has additional args */ do_kcmp(3141592653U, 2718281828U, ARG_STR(KCMP_FILE), bogus_idx1, bogus_idx2); + do_kcmp(-1, -1, ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD); /* Types without additional args */ do_kcmp(-1, -1, ARG_STR(KCMP_VM), bogus_idx1, bogus_idx2); diff --git a/tests/pure_executables.list b/tests/pure_executables.list index 8210c910..957674a2 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -122,6 +122,7 @@ ipc_msgbuf ipc_sem ipc_shm kcmp +kcmp-y kexec_file_load kexec_load keyctl -- 2.40.0