1 /*
2 * Copyright (c) International Business Machines Corp., 2001
3 * 03/2001 - Written by Wayne Boyer
4 * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /*
22 * Tries to set different personalities.
23 *
24 * We set the personality in a child process since it's not guaranteed that we
25 * can set it back in some cases. I.e. PER_LINUX32 cannot be unset on some 64
26 * bit archs.
27 */
28
29 #include "test.h"
30 #include <sys/personality.h>
31
32 char *TCID = "personality01";
33
34 #define PAIR(id) {id, #id}
35
36 struct personalities {
37 unsigned long int pers;
38 const char *name;
39 };
40
41 struct personalities pers[] = {
42 PAIR(PER_LINUX),
43 PAIR(PER_LINUX_32BIT),
44 PAIR(PER_SVR4),
45 PAIR(PER_SVR3),
46 PAIR(PER_SCOSVR3),
47 PAIR(PER_OSR5),
48 PAIR(PER_WYSEV386),
49 PAIR(PER_ISCR4),
50 PAIR(PER_BSD),
51 PAIR(PER_XENIX),
52 #if defined(__x86_64__)
53 PAIR(PER_LINUX32),
54 #endif
55 PAIR(PER_IRIX32),
56 PAIR(PER_IRIXN32),
57 PAIR(PER_IRIX64),
58 PAIR(PER_RISCOS),
59 PAIR(PER_SOLARIS),
60 PAIR(PER_UW7),
61 PAIR(PER_OSF4),
62 PAIR(PER_HPUX),
63 };
64
65 int TST_TOTAL = ARRAY_SIZE(pers);
66
do_child(unsigned int i)67 static void do_child(unsigned int i)
68 {
69 int ret;
70
71 ret = personality(pers[i].pers);
72 if (ret < 0) {
73 tst_resm(TFAIL | TERRNO, "personality(%s) failed", pers[i].name);
74 return;
75 }
76
77 ret = personality(0xffffffff);
78
79 if ((unsigned long)ret != pers[i].pers) {
80 tst_resm(TFAIL,
81 "%s: wrong personality read back %d expected %lu",
82 pers[i].name, ret, pers[i].pers);
83 return;
84 }
85
86 tst_resm(TPASS, "personality(%s)", pers[i].name);
87 }
88
verify_personality(unsigned int i)89 static void verify_personality(unsigned int i)
90 {
91 pid_t pid;
92
93 pid = tst_fork();
94 switch (pid) {
95 case 0:
96 do_child(i);
97 tst_exit();
98 break;
99 case -1:
100 tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
101 break;
102 default:
103 tst_record_childstatus(NULL, pid);
104 break;
105 }
106 }
107
main(int ac,char ** av)108 int main(int ac, char **av)
109 {
110 int i, lc;
111
112 tst_parse_opts(ac, av, NULL, NULL);
113
114 for (lc = 0; TEST_LOOPING(lc); lc++) {
115 for (i = 0; i < TST_TOTAL; i++) {
116 verify_personality(i);
117 }
118 }
119
120 tst_exit();
121 }
122