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