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