Skip to contentSkip to conversation

syscall/kcmp: Add tests for kcmp

PATCH New Cedric Hnyda 2 participants 2 messages Oct 8, 2015 – Oct 12, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 syscall/kcmp: Add tests for kcmp

Add tests for the syscall kcmp

---
 configure.ac                            |   2 +
 m4/ltp-kcmp.m4                          |  23 +++++
 m4/ltp-kcmp_type.m4                     |  23 +++++
 runtest/syscalls                        |   3 +
 testcases/kernel/include/aarch64.in     |   1 +
 testcases/kernel/include/arm.in         |   1 +
 testcases/kernel/include/i386.in        |   1 +
 testcases/kernel/include/powerpc.in     |   1 +
 testcases/kernel/include/powerpc64.in   |   1 +
 testcases/kernel/include/s390.in        |   1 +
 testcases/kernel/include/s390x.in       |   1 +
 testcases/kernel/include/sh.in          |   1 +
 testcases/kernel/include/sparc.in       |   1 +
 testcases/kernel/include/sparc64.in     |   1 +
 testcases/kernel/include/x86_64.in      |   1 +
 testcases/kernel/syscalls/.gitignore    |   2 +
 testcases/kernel/syscalls/kcmp/Makefile |  24 ++++++
 testcases/kernel/syscalls/kcmp/kcmp.h   |  54 ++++++++++++
 testcases/kernel/syscalls/kcmp/kcmp01.c | 146 ++++++++++++++++++++++++++++++++
 testcases/kernel/syscalls/kcmp/kcmp02.c | 138 ++++++++++++++++++++++++++++++
 20 files changed, 426 insertions(+)
 create mode 100644 m4/ltp-kcmp.m4
 create mode 100644 m4/ltp-kcmp_type.m4
 create mode 100644 testcases/kernel/syscalls/kcmp/Makefile
 create mode 100644 testcases/kernel/syscalls/kcmp/kcmp.h
 create mode 100644 testcases/kernel/syscalls/kcmp/kcmp01.c
 create mode 100644 testcases/kernel/syscalls/kcmp/kcmp02.c
configure.ac +2 -0
index ce09fbd..b63daa4 100644
@@ -178,5 +178,7 @@ LTP_CHECK_IOVEC
 LTP_CHECK_KEYCTL
 LTP_CHECK_LINUXRANDOM
 LTP_CHECK_IF_LINK
+LTP_CHECK_KCMP
+LTP_CHECK_KCMP_TYPE
 
 AC_OUTPUT
m4/ltp-kcmp.m4 new file +23 -0
new file mode 100644
index 0000000..70bf375
@@ -0,0 +1,23 @@
+dnl
+dnl Copyright (c) Linux Test Project, 2015
+dnl
+dnl This program is free software;  you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY;  without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+dnl the GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program;  if not, write to the Free Software Foundation,
+dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+dnl
+dnl Author: Cedric Hnyda <[email protected]>
+dnl
+
+AC_DEFUN([LTP_CHECK_KCMP],[
+AC_CHECK_FUNCS(kcmp,,)
+])
m4/ltp-kcmp_type.m4 new file +23 -0
new file mode 100644
index 0000000..17571e2
@@ -0,0 +1,23 @@
+dnl
+dnl Copyright (c) Linux Test Project, 2015
+dnl
+dnl This program is free software;  you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY;  without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+dnl the GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program;  if not, write to the Free Software Foundation,
+dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+dnl
+dnl Author: Cedric Hnyda <[email protected]>
+dnl
+
+AC_DEFUN([LTP_CHECK_KCMP_TYPE],[
+AC_CHECK_TYPES([enum kcmp_type],,,[#include <linux/kcmp.h>])
+])
runtest/syscalls +3 -0
index 25d10ac..3427aaa 100644
@@ -472,6 +472,9 @@ io_submit01 io_submit01
 
 keyctl01 keyctl01
 
+kcmp01 kcmp01
+kcmp02 kcmp02
+
 kill01 kill01
 kill02 kill02
 kill03 kill03
testcases/kernel/include/aarch64.in +1 -0
index ceb67c6..4dda026 100644
@@ -253,3 +253,4 @@ clock_adjtime 266
 syncfs 267
 setns 268
 sendmmsg 269
+kcmp 378
testcases/kernel/include/arm.in +1 -0
index 841b064..ba6e07e 100644
@@ -333,4 +333,5 @@ accept4 (__NR_SYSCALL_BASE+366)
 fanotify_init (__NR_SYSCALL_BASE+367)
 fanotify_mark (__NR_SYSCALL_BASE+368)
 prlimit64 (__NR_SYSCALL_BASE+369)
+kcmp (__NR_SYSCALL_BASE+378)
 getrandom (__NR_SYSCALL_BASE+384)
testcases/kernel/include/i386.in +1 -0
index a4585c2..e4631a3 100644
@@ -333,4 +333,5 @@ recvmmsg 337
 fanotify_init 338
 fanotify_mark 339
 prlimit64 340
+kcmp 349
 getrandom 355
testcases/kernel/include/powerpc.in +1 -0
index 4025436..450ed39 100644
@@ -340,4 +340,5 @@ recvmsg 342
 recvmmsg 343
 accept4 344
 syscalls 345
+kcmp 354
 getrandom 359
testcases/kernel/include/powerpc64.in +1 -0
index 4025436..450ed39 100644
@@ -340,4 +340,5 @@ recvmsg 342
 recvmmsg 343
 accept4 344
 syscalls 345
+kcmp 354
 getrandom 359
testcases/kernel/include/s390.in +1 -0
index 9c7cfa1..92b0b94 100644
@@ -324,4 +324,5 @@ setgid 214
 setfsuid 215
 setfsgid 216
 newfstatat 293
+kcmp 343
 getrandom 349
testcases/kernel/include/s390x.in +1 -0
index 9c7cfa1..92b0b94 100644
@@ -324,4 +324,5 @@ setgid 214
 setfsuid 215
 setfsgid 216
 newfstatat 293
+kcmp 343
 getrandom 349
testcases/kernel/include/sh.in +1 -0
index c6e8aa5..3cb7e21 100644
@@ -361,3 +361,4 @@ accept4 366
 fanotify_init 367
 fanotify_mark 368
 prlimit64 369
+kcmp 378
testcases/kernel/include/sparc.in +1 -0
index 697378f..182db25 100644
@@ -331,3 +331,4 @@ recvmmsg 328
 fanotify_init 329
 fanotify_mark 330
 prlimit64 331
+kcmp 341
testcases/kernel/include/sparc64.in +1 -0
index 83c1792..b5b817b 100644
@@ -307,3 +307,4 @@ recvmmsg 328
 fanotify_init 329
 fanotify_mark 330
 prlimit64 331
+kcmp 341
testcases/kernel/include/x86_64.in +1 -0
index 860e726..d4b5756 100644
@@ -300,4 +300,5 @@ recvmmsg 299
 fanotify_init 300
 fanotify_mark 301
 prlimit64 302
+kcmp 312
 getrandom 318
testcases/kernel/syscalls/.gitignore +2 -0
index f3a18ab..3fb91a3 100644
@@ -440,6 +440,8 @@
 /ipc/shmget/shmget04
 /ipc/shmget/shmget05
 /keyctl/keyctl01
+/kcmp/kcmp01
+/kcmp/kcmp02
 /kill/kill01
 /kill/kill02
 /kill/kill03
testcases/kernel/syscalls/kcmp/Makefile new file +24 -0
new file mode 100644
index 0000000..083a071
@@ -0,0 +1,24 @@
+#
+#  Copyright (C) 2015 Cedric Hnyda [email protected]
+#
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+#  the GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/kcmp/kcmp.h new file +54 -0

54 lines not on this page · raw message

testcases/kernel/syscalls/kcmp/kcmp01.c new file +146 -0

146 lines not on this page · raw message

testcases/kernel/syscalls/kcmp/kcmp02.c new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/1 syscall/kcmp: Add tests for kcmp

Hi!
Pushed with a few changes (explained below), thanks.

Quoted 17 lines
testcases/kernel/syscalls/kcmp/kcmp.h new file +17 -0
+#if !defined(HAVE_ENUM_KCMP_TYPE)
+
+enum kcmp_type {
+	KCMP_FILE,
+	KCMP_VM,
+	KCMP_FILES,
+	KCMP_FS,
+	KCMP_SIGHAND,
+	KCMP_IO,
+	KCMP_SYSVSEM,
+	KCMP_TYPES,
+};
+
+#endif
+
+#if !defined(HAVE_KCMP)
+

testcases/kernel/syscalls/kcmp/kcmp.h line 52

Quoted 10 lines
testcases/kernel/syscalls/kcmp/kcmp.h new file +10 -0
+int kcmp(int pid1, int pid2, int type, int fd1, int fd2)
+{
+	return ltp_syscall(__NR_kcmp, pid1, pid2, type, fd1, fd2);
+}
+
+#else
+
+#include <linux/kcmp.h>
+
+#endif

This was wrong #if to add the #else to, the kcmp.h defines the enum not the syscall. I've fixed that.

testcases/kernel/syscalls/kcmp/kcmp01.c line 56

Quoted 11 lines
testcases/kernel/syscalls/kcmp/kcmp01.c new file +11 -0
+static struct test_case {
+	int *pid1;
+	int *pid2;
+	int type;
+	int *fd1;
+	int *fd2;
+	int exp_different;
+} test_cases[] = {
+	{&pid1, &pid2, KCMP_FILE, &fd1, &fd2, 0},
+	{&pid1, &pid2, KCMP_FILE, &fd1, &fd3, 1},
+};

I've added a few more tests here. Case where pid1 == pid2, fd1 == fd2 and both at the same time.

testcases/kernel/syscalls/kcmp/kcmp02.c line 102

Quoted 5 lines
testcases/kernel/syscalls/kcmp/kcmp02.c new file +5 -0
+	if (test->exp_errno && TEST_RETURN != -1) {
+		tst_resm(TFAIL, "kcmp() succeeded unexpectedly");
+		return;
+	}
+

And I've removed the test->exp_errno from this condition, since we test only failures in this test.

Signature · 2 lines
Cyril Hrubis
[email protected]