xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/getuid/getuid03.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) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker  *  Ported by Wayne Boyer
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker /*\
8*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  * Check that getuid() return value matches value from /proc/self/status.
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 "compat_tst_16.h"
15*49cdfc7eSAndroid Build Coastguard Worker 
verify_getuid(void)16*49cdfc7eSAndroid Build Coastguard Worker static void verify_getuid(void)
17*49cdfc7eSAndroid Build Coastguard Worker {
18*49cdfc7eSAndroid Build Coastguard Worker 	long uid;
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_POSITIVE(GETUID(), "getuid()");
21*49cdfc7eSAndroid Build Coastguard Worker 
22*49cdfc7eSAndroid Build Coastguard Worker 	if (!TST_PASS)
23*49cdfc7eSAndroid Build Coastguard Worker 		return;
24*49cdfc7eSAndroid Build Coastguard Worker 
25*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_FILE_LINES_SCANF("/proc/self/status", "Uid: %ld", &uid);
26*49cdfc7eSAndroid Build Coastguard Worker 
27*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET != uid) {
28*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL,
29*49cdfc7eSAndroid Build Coastguard Worker 			"getuid() ret %ld != /proc/self/status Uid: %ld",
30*49cdfc7eSAndroid Build Coastguard Worker 			TST_RET, uid);
31*49cdfc7eSAndroid Build Coastguard Worker 	} else {
32*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS,
33*49cdfc7eSAndroid Build Coastguard Worker 			"getuid() ret == /proc/self/status Uid: %ld", uid);
34*49cdfc7eSAndroid Build Coastguard Worker 	}
35*49cdfc7eSAndroid Build Coastguard Worker }
36*49cdfc7eSAndroid Build Coastguard Worker 
37*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
38*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = verify_getuid,
39*49cdfc7eSAndroid Build Coastguard Worker };
40