1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines  Corp., 2001
4f08c3bdfSopenharmony_ci *   07/2001 Ported by Wayne Boyer
5f08c3bdfSopenharmony_ci * Copyright (c) 2023 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
6f08c3bdfSopenharmony_ci */
7f08c3bdfSopenharmony_ci
8f08c3bdfSopenharmony_ci/*\
9f08c3bdfSopenharmony_ci * [Description]
10f08c3bdfSopenharmony_ci *
11f08c3bdfSopenharmony_ci * Verify the basic functionality of getpgid(2) syscall.
12f08c3bdfSopenharmony_ci */
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_ci#include "tst_test.h"
15f08c3bdfSopenharmony_ci
16f08c3bdfSopenharmony_cistatic void run(void)
17f08c3bdfSopenharmony_ci{
18f08c3bdfSopenharmony_ci	pid_t pid_1, child_pid, pgid;
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci	pgid = getpgid(0);
21f08c3bdfSopenharmony_ci	tst_res(TINFO, "getpgid(0) in parent = %d", pgid);
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_ci	pid_1 = SAFE_FORK();
24f08c3bdfSopenharmony_ci	if (!pid_1) {
25f08c3bdfSopenharmony_ci		child_pid = getpid();
26f08c3bdfSopenharmony_ci
27f08c3bdfSopenharmony_ci		tst_res(TINFO, "getpid() in child = %d", child_pid);
28f08c3bdfSopenharmony_ci		tst_res(TINFO, "Running getpgid() in child");
29f08c3bdfSopenharmony_ci
30f08c3bdfSopenharmony_ci		TST_EXP_PID(getpgid(0));
31f08c3bdfSopenharmony_ci		TST_EXP_EQ_LI(TST_RET, pgid);
32f08c3bdfSopenharmony_ci
33f08c3bdfSopenharmony_ci		TST_EXP_PID(getpgid(child_pid), "getpgid(%d)", child_pid);
34f08c3bdfSopenharmony_ci		TST_EXP_EQ_LI(TST_RET, pgid);
35f08c3bdfSopenharmony_ci
36f08c3bdfSopenharmony_ci		TST_EXP_PID(getpgid(pgid), "getpgid(%d)", pgid);
37f08c3bdfSopenharmony_ci		TST_EXP_EQ_LI(TST_RET, pgid);
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_ci		TST_EXP_PID(getpgid(1));
40f08c3bdfSopenharmony_ci		TST_EXP_EQ_LI(TST_RET, 1);
41f08c3bdfSopenharmony_ci	}
42f08c3bdfSopenharmony_ci
43f08c3bdfSopenharmony_ci	tst_reap_children();
44f08c3bdfSopenharmony_ci}
45f08c3bdfSopenharmony_ci
46f08c3bdfSopenharmony_cistatic struct tst_test test = {
47f08c3bdfSopenharmony_ci	.test_all = run,
48f08c3bdfSopenharmony_ci	.forks_child = 1
49f08c3bdfSopenharmony_ci};
50