[LTP] [PATCH v1 2/2] Refactor personality02 using new API

Andrea Cervesato andrea.cervesato@suse.de
Wed Aug 30 15:25:28 CEST 2023


From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 .../syscalls/personality/personality02.c      | 64 +++++++------------
 1 file changed, 22 insertions(+), 42 deletions(-)

diff --git a/testcases/kernel/syscalls/personality/personality02.c b/testcases/kernel/syscalls/personality/personality02.c
index eb18c9951..e080284f4 100644
--- a/testcases/kernel/syscalls/personality/personality02.c
+++ b/testcases/kernel/syscalls/personality/personality02.c
@@ -1,62 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) 2016 Linux Test Project
  * 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, see <http://www.gnu.org/licenses/>.
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * If personality with STICKY_TIMEOUTS is used select() timeout is not updated.
+/*\
+ * [Description]
+ *
+ * This test checks if select() timeout is not updated when personality with
+ * STICKY_TIMEOUTS is used.
  */
 
-#include "test.h"
-#include <sys/personality.h>
+#include "tst_test.h"
+#include "lapi/personality.h"
 #include <sys/select.h>
 
-char *TCID = "personality02";
-int TST_TOTAL = 1;
-
 #define USEC 10
 
-static void verify_personality(void)
+static void run(void)
 {
-	struct timeval tv = {.tv_sec = 0, .tv_usec = USEC};
-	int ret;
+	struct timeval tv = { .tv_sec = 0, .tv_usec = USEC };
 	fd_set rfds;
 
 	FD_ZERO(&rfds);
 	FD_SET(1, &rfds);
 
-	personality(PER_LINUX | STICKY_TIMEOUTS);
-	ret = select(2, &rfds, NULL, NULL, &tv);
-	personality(PER_LINUX);
-	if (ret < 0)
-		tst_resm(TBROK | TERRNO, "select()");
+	SAFE_PERSONALITY(PER_LINUX | STICKY_TIMEOUTS);
 
-	if (tv.tv_usec != USEC)
-		tst_resm(TFAIL, "Timeout was modified");
-	else
-		tst_resm(TPASS, "Timeout wasn't modified");
-}
-
-int main(int ac, char **av)
-{
-	int lc;
+	TEST(select(2, &rfds, NULL, NULL, &tv));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TERRNO, "select() error");
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	SAFE_PERSONALITY(PER_LINUX);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		verify_personality();
-
-	tst_exit();
+	TST_EXP_EQ_LI(tv.tv_usec, USEC);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.35.3



More information about the ltp mailing list