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) 2016 Linux Test Project
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
5*49cdfc7eSAndroid Build Coastguard Worker * 03/2001 - Written by Wayne Boyer
6*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2016 Cyril Hrubis <[email protected]>
7*49cdfc7eSAndroid Build Coastguard Worker * Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]>
8*49cdfc7eSAndroid Build Coastguard Worker */
9*49cdfc7eSAndroid Build Coastguard Worker
10*49cdfc7eSAndroid Build Coastguard Worker /*\
11*49cdfc7eSAndroid Build Coastguard Worker * [Description]
12*49cdfc7eSAndroid Build Coastguard Worker *
13*49cdfc7eSAndroid Build Coastguard Worker * Tries to set different personalities.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * We set the personality in a child process since it's not guaranteed that we
16*49cdfc7eSAndroid Build Coastguard Worker * can set it back in some cases. I.e. PER_LINUX32 cannot be unset on some 64
17*49cdfc7eSAndroid Build Coastguard Worker * bit archs.
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
21*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/personality.h"
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker #define PAIR(id) {id, #id}
24*49cdfc7eSAndroid Build Coastguard Worker
25*49cdfc7eSAndroid Build Coastguard Worker struct personalities {
26*49cdfc7eSAndroid Build Coastguard Worker unsigned long pers;
27*49cdfc7eSAndroid Build Coastguard Worker const char *name;
28*49cdfc7eSAndroid Build Coastguard Worker };
29*49cdfc7eSAndroid Build Coastguard Worker
30*49cdfc7eSAndroid Build Coastguard Worker static struct personalities pers[] = {
31*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_LINUX),
32*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_LINUX_32BIT),
33*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_SVR4),
34*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_SVR3),
35*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_SCOSVR3),
36*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_OSR5),
37*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_WYSEV386),
38*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_ISCR4),
39*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_BSD),
40*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_XENIX),
41*49cdfc7eSAndroid Build Coastguard Worker #if defined(__x86_64__)
42*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_LINUX32),
43*49cdfc7eSAndroid Build Coastguard Worker #endif
44*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_IRIX32),
45*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_IRIXN32),
46*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_IRIX64),
47*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_RISCOS),
48*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_SOLARIS),
49*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_UW7),
50*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_OSF4),
51*49cdfc7eSAndroid Build Coastguard Worker PAIR(PER_HPUX),
52*49cdfc7eSAndroid Build Coastguard Worker };
53*49cdfc7eSAndroid Build Coastguard Worker
run(unsigned int i)54*49cdfc7eSAndroid Build Coastguard Worker static void run(unsigned int i)
55*49cdfc7eSAndroid Build Coastguard Worker {
56*49cdfc7eSAndroid Build Coastguard Worker pid_t pid;
57*49cdfc7eSAndroid Build Coastguard Worker
58*49cdfc7eSAndroid Build Coastguard Worker pid = SAFE_FORK();
59*49cdfc7eSAndroid Build Coastguard Worker if (!pid) {
60*49cdfc7eSAndroid Build Coastguard Worker SAFE_PERSONALITY(pers[i].pers);
61*49cdfc7eSAndroid Build Coastguard Worker
62*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EXPR((unsigned long)SAFE_PERSONALITY(0xffffffff) == pers[i].pers,
63*49cdfc7eSAndroid Build Coastguard Worker "%s personality is set",
64*49cdfc7eSAndroid Build Coastguard Worker pers[i].name);
65*49cdfc7eSAndroid Build Coastguard Worker
66*49cdfc7eSAndroid Build Coastguard Worker return;
67*49cdfc7eSAndroid Build Coastguard Worker }
68*49cdfc7eSAndroid Build Coastguard Worker }
69*49cdfc7eSAndroid Build Coastguard Worker
70*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
71*49cdfc7eSAndroid Build Coastguard Worker .test = run,
72*49cdfc7eSAndroid Build Coastguard Worker .tcnt = ARRAY_SIZE(pers),
73*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1,
74*49cdfc7eSAndroid Build Coastguard Worker };
75