• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 avenkat@us.ibm.com
5  * 06/30/2001	Port to Linux nsharoff@us.ibm.com
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 	u2 = syscall(SYS_getuid);
41 
42 	if (u1 == u2) {
43 		tst_res(TPASS, "getuid() == syscall(SYS_getuid)");
44 	} else {
45 		tst_res(TFAIL, "getuid() = %i, syscall(SYS_getuid) = %i",
46 			u1, u2);
47 	}
48 }
49 
verify_getgid(void)50 static void verify_getgid(void)
51 {
52 	gid_t g1, g2;
53 
54 	g1 = getgid();
55 	g2 = syscall(SYS_getgid);
56 
57 	if (g1 == g2) {
58 		tst_res(TPASS, "getgid() == syscall(SYS_getgid)");
59 	} else {
60 		tst_res(TFAIL, "getgid() = %i, syscall(SYS_getgid) = %i",
61 			g1, g2);
62 	}
63 }
64 
65 
66 static void (*tcases[])(void) = {
67 	verify_getpid,
68 	verify_getuid,
69 	verify_getgid,
70 };
71 
verify_syscall(unsigned int n)72 static void verify_syscall(unsigned int n)
73 {
74 	tcases[n]();
75 }
76 
77 static struct tst_test test = {
78 	.test = verify_syscall,
79 	.tcnt = ARRAY_SIZE(tcases),
80 };
81 
82