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