1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2002
4 * 01/02/2003 Port to LTP [email protected]
5 * 06/30/2001 Port to Linux [email protected]
6 */
7
8 /*
9 * Basic test for syscall().
10 */
11
12 #define _GNU_SOURCE
13 #include <unistd.h>
14 #include <sys/syscall.h>
15 #include <sys/types.h>
16
17 #include "tst_test.h"
18 #include "lapi/syscalls.h"
19
verify_getpid(void)20 static void verify_getpid(void)
21 {
22 pid_t p1, p2;
23
24 p1 = getpid();
25 p2 = syscall(SYS_getpid);
26
27 if (p1 == p2) {
28 tst_res(TPASS, "getpid() == syscall(SYS_getpid)");
29 } else {
30 tst_res(TFAIL, "getpid() = %i, syscall(SYS_getpid) = %i",
31 p1, p2);
32 }
33 }
34
verify_getuid(void)35 static void verify_getuid(void)
36 {
37 uid_t u1, u2;
38
39 u1 = getuid();
40 #ifdef SYS_getuid32
41 u2 = syscall(SYS_getuid32);
42 #else
43 u2 = syscall(SYS_getuid);
44 #endif
45
46 if (u1 == u2) {
47 tst_res(TPASS, "getuid() == syscall(SYS_getuid)");
48 } else {
49 tst_res(TFAIL, "getuid() = %i, syscall(SYS_getuid) = %i",
50 u1, u2);
51 }
52 }
53
verify_getgid(void)54 static void verify_getgid(void)
55 {
56 gid_t g1, g2;
57
58 g1 = getgid();
59 #ifdef SYS_getgid32
60 g2 = syscall(SYS_getgid32);
61 #else
62 g2 = syscall(SYS_getgid);
63 #endif
64
65 if (g1 == g2) {
66 tst_res(TPASS, "getgid() == syscall(SYS_getgid)");
67 } else {
68 tst_res(TFAIL, "getgid() = %i, syscall(SYS_getgid) = %i",
69 g1, g2);
70 }
71 }
72
73
74 static void (*tcases[])(void) = {
75 verify_getpid,
76 verify_getuid,
77 verify_getgid,
78 };
79
verify_syscall(unsigned int n)80 static void verify_syscall(unsigned int n)
81 {
82 tcases[n]();
83 }
84
85 static struct tst_test test = {
86 .test = verify_syscall,
87 .tcnt = ARRAY_SIZE(tcases),
88 };
89
90