12 #include <linux/unistd.h>
13 #include <linux/kcmp.h>
15 #include <sys/syscall.h>
16 #include <sys/types.h>
20 #include "../kselftest.h"
22 static long sys_kcmp(int pid1, int pid2, int type, int fd1, int fd2)
24 return syscall(__NR_kcmp, pid1, pid2, type, fd1, fd2);
27 int main(int argc, char **argv)
29 const char kpath[] = "kcmp-test-file";
34 fd1 = open(kpath, O_RDWR | O_CREAT | O_TRUNC, 0644);
38 perror("Can't create file");
44 perror("fork failed");
52 fd2 = open(kpath, O_RDWR, 0644);
54 perror("Can't open file");
58 /* An example of output and arguments */
59 printf("pid1: %6d pid2: %6d FD: %2ld FILES: %2ld VM: %2ld "
60 "FS: %2ld SIGHAND: %2ld IO: %2ld SYSVSEM: %2ld "
63 sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd2),
64 sys_kcmp(pid1, pid2, KCMP_FILES, 0, 0),
65 sys_kcmp(pid1, pid2, KCMP_VM, 0, 0),
66 sys_kcmp(pid1, pid2, KCMP_FS, 0, 0),
67 sys_kcmp(pid1, pid2, KCMP_SIGHAND, 0, 0),
68 sys_kcmp(pid1, pid2, KCMP_IO, 0, 0),
69 sys_kcmp(pid1, pid2, KCMP_SYSVSEM, 0, 0),
71 /* This one should fail */
72 sys_kcmp(pid1, pid2, KCMP_TYPES + 1, 0, 0));
74 /* This one should return same fd */
75 ret = sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd1);
77 printf("FAIL: 0 expected but %d returned (%s)\n",
78 ret, strerror(errno));
82 printf("PASS: 0 returned as expected\n");
86 /* Compare with self */
87 ret = sys_kcmp(pid1, pid1, KCMP_VM, 0, 0);
89 printf("FAIL: 0 expected but %d returned (%s)\n",
90 ret, strerror(errno));
94 printf("PASS: 0 returned as expected\n");
106 waitpid(pid2, &status, P_ALL);
108 return ksft_exit_pass();