[LTP] [PATCH v1 1/2] Refactor personality01 using new API
Andrea Cervesato
andrea.cervesato@suse.de
Wed Aug 30 15:25:27 CEST 2023
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
.../syscalls/personality/personality01.c | 93 +++++--------------
1 file changed, 23 insertions(+), 70 deletions(-)
diff --git a/testcases/kernel/syscalls/personality/personality01.c b/testcases/kernel/syscalls/personality/personality01.c
index b646e2a9b..47fb66256 100644
--- a/testcases/kernel/syscalls/personality/personality01.c
+++ b/testcases/kernel/syscalls/personality/personality01.c
@@ -1,24 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
+ * Copyright (c) 2016 Linux Test Project
* Copyright (c) International Business Machines Corp., 2001
* 03/2001 - Written by Wayne Boyer
* Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
*/
-/*
+/*\
+ * [Description]
+ *
* Tries to set different personalities.
*
* We set the personality in a child process since it's not guaranteed that we
@@ -26,19 +17,17 @@
* bit archs.
*/
-#include "test.h"
-#include <sys/personality.h>
-
-char *TCID = "personality01";
+#include "tst_test.h"
+#include "lapi/personality.h"
#define PAIR(id) {id, #id}
struct personalities {
- unsigned long int pers;
+ unsigned long pers;
const char *name;
};
-struct personalities pers[] = {
+static struct personalities pers[] = {
PAIR(PER_LINUX),
PAIR(PER_LINUX_32BIT),
PAIR(PER_SVR4),
@@ -62,60 +51,24 @@ struct personalities pers[] = {
PAIR(PER_HPUX),
};
-int TST_TOTAL = ARRAY_SIZE(pers);
-
-static void do_child(unsigned int i)
+static void run(unsigned int i)
{
- int ret;
+ pid_t pid;
- ret = personality(pers[i].pers);
- if (ret < 0) {
- tst_resm(TFAIL | TERRNO, "personality(%s) failed", pers[i].name);
- return;
- }
+ pid = SAFE_FORK();
+ if (!pid) {
+ SAFE_PERSONALITY(pers[i].pers);
- ret = personality(0xffffffff);
+ TST_EXP_EXPR((unsigned long)SAFE_PERSONALITY(0xffffffff) == pers[i].pers,
+ "%s personality is set",
+ pers[i].name);
- if ((unsigned long)ret != pers[i].pers) {
- tst_resm(TFAIL,
- "%s: wrong personality read back %d expected %lu",
- pers[i].name, ret, pers[i].pers);
return;
}
-
- tst_resm(TPASS, "personality(%s)", pers[i].name);
-}
-
-static void verify_personality(unsigned int i)
-{
- pid_t pid;
-
- pid = tst_fork();
- switch (pid) {
- case 0:
- do_child(i);
- tst_exit();
- break;
- case -1:
- tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
- break;
- default:
- tst_record_childstatus(NULL, pid);
- break;
- }
}
-int main(int ac, char **av)
-{
- int i, lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- for (i = 0; i < TST_TOTAL; i++) {
- verify_personality(i);
- }
- }
-
- tst_exit();
-}
+static struct tst_test test = {
+ .test = run,
+ .tcnt = ARRAY_SIZE(pers),
+ .forks_child = 1,
+};
--
2.35.3
More information about the ltp
mailing list