xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/gettid/gettid01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2007-2008, Hitachi, Ltd.
4  * Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]>
5  */
6 /*\
7  * [Description]
8  *
9  * This test checks if parent pid is equal to tid in single-threaded
10  * application.
11  */
12 
13 #include "tst_test.h"
14 #include "lapi/syscalls.h"
15 
run(void)16 static void run(void)
17 {
18 	long pid, tid;
19 
20 	SAFE_FILE_LINES_SCANF("/proc/self/status", "Pid: %ld", &pid);
21 	SAFE_FILE_LINES_SCANF("/proc/self/status", "Tgid: %ld", &tid);
22 
23 	if (pid != tid)
24 		tst_brk(TBROK, "Test function has been moved inside a thread?");
25 
26 	TST_EXP_EQ_LI(tst_syscall(__NR_gettid), tst_syscall(__NR_getpid));
27 	TST_EXP_EQ_LI(tst_syscall(__NR_gettid), pid);
28 }
29 
30 static struct tst_test test = {
31 	.test_all = run,
32 };
33