Skip to contentSkip to conversation

setpriority01: Skip only PRIO_USER when unable to add test user

PATCH Superseded Saravana Kannan 2 participants 3 messages Mar 7, 2019 – Mar 19, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 setpriority01: Skip only PRIO_USER when unable to add test user

We don't need to skip all the tests just because we are unable to add a test user. Not having a test user only affects PRIO_USER test case. So just skip that one and continue running the rest of the tests.

This also allows this test case to be built and run on Android.

Change-Id Ie6eaf771002842fc1c768adf70bb2d1ef534f120
---
 .../kernel/syscalls/setpriority/Makefile      |  5 ----
 .../syscalls/setpriority/setpriority01.c      | 29 +++++++++++++------
 2 files changed, 20 insertions(+), 14 deletions(-)
testcases/kernel/syscalls/setpriority/Makefile +0 -5
index 5d00984ea..7a1a87a28 100644
@@ -19,9 +19,4 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-
-ifeq ($(ANDROID), 1)
-FILTER_OUT_MAKE_TARGETS	+= setpriority01
-endif
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/setpriority/setpriority01.c +20 -9
index 38b77b77f..92b1b4ef4 100644
@@ -92,9 +92,16 @@ static void verify_setpriority(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
 
+	if (tc->which == PRIO_USER && !user_added) {
+		tst_res(TCONF, "setpriority(%s(%d), %d, -20..19) skipped - Can't add user",
+			str_which(tc->which), tc->which, *tc->who);
+		return;
+	}
+
 	pid = SAFE_FORK();
 	if (pid == 0) {
-		SAFE_SETUID(uid);
+		if (user_added)
+			SAFE_SETUID(uid);
 		SAFE_SETPGID(0, 0);
 
 		TST_CHECKPOINT_WAKE_AND_WAIT(0);
@@ -115,15 +122,19 @@ static void setup(void)
 {
 	const char *const cmd_useradd[] = {"useradd", username, NULL};
 	struct passwd *ltpuser;
+	int rc;
 
-	if (eaccess("/etc/passwd", W_OK))
-		tst_brk(TCONF, "/etc/passwd is not accessible");
-
-	tst_run_cmd(cmd_useradd, NULL, NULL, 0);
-	user_added = 1;
-
-	ltpuser = SAFE_GETPWNAM(username);
-	uid = ltpuser->pw_uid;
+	switch ((rc = tst_run_cmd(cmd_useradd, NULL, NULL, 1))) {
+	case 0:
+		user_added = 1;
+		ltpuser = SAFE_GETPWNAM(username);
+		uid = ltpuser->pw_uid;
+		return;
+	case 255:
+		return;
+	default:
+		tst_brk(TBROK, "Useradd failed (%d)", rc);
+	}
 }
 
 static void cleanup(void)
Signature · 1 line
2.21.0.360.g471c308f928-goog
#1 lore raw

PATCH v2 1/1 setpriority01: Skip only PRIO_USER when unable to add test user

Sent the wrong patch by mistake. Sending the right one (with minor edits to commit text).

Quoted 81 lines · Saravana Kannan

We don't need to skip all the tests just because we are unable to add a test user. Not having a test user only affects PRIO_USER test case. So just skip that one and continue running the rest of the tests.

This also allows this test case to be built and run on Android.

Change-Id Ie6eaf771002842fc1c768adf70bb2d1ef534f120
---
 .../kernel/syscalls/setpriority/Makefile      |  5 ----
 .../syscalls/setpriority/setpriority01.c      | 29 +++++++++++++------
 2 files changed, 20 insertions(+), 14 deletions(-)
testcases/kernel/syscalls/setpriority/Makefile +0 -5
index 5d00984ea..7a1a87a28 100644
@@ -19,9 +19,4 @@
 top_srcdir             ?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-
-ifeq ($(ANDROID), 1)
-FILTER_OUT_MAKE_TARGETS        += setpriority01
-endif
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/setpriority/setpriority01.c +8 -1
index 38b77b77f..92b1b4ef4 100644
@@ -92,9 +92,16 @@ static void verify_setpriority(unsigned int n)
 {
        struct tcase *tc = &tcases[n];
 
+       if (tc->which == PRIO_USER && !user_added) {
+               tst_res(TCONF, "setpriority(%s(%d), %d, -20..19) skipped -
 Can't add user",
+                       str_which(tc->which), tc->which, *tc->who);
+               return;
+       }
+
        pid = SAFE_FORK();
        if (pid == 0) {
-               SAFE_SETUID(uid);
+               if (user_added)
+                       SAFE_SETUID(uid);
                SAFE_SETPGID(0, 0);
 
                TST_CHECKPOINT_WAKE_AND_WAIT(0);
testcases/kernel/syscalls/setpriority/setpriority01.c +12 -9
@@ -115,15 +122,19 @@ static void setup(void)
 {
        const char *const cmd_useradd[] = {"useradd", username, NULL};
        struct passwd *ltpuser;
+       int rc;
 
-       if (eaccess("/etc/passwd", W_OK))
-               tst_brk(TCONF, "/etc/passwd is not accessible");
-
-       tst_run_cmd(cmd_useradd, NULL, NULL, 0);
-       user_added = 1;
-
-       ltpuser = SAFE_GETPWNAM(username);
-       uid = ltpuser->pw_uid;
+       switch ((rc = tst_run_cmd(cmd_useradd, NULL, NULL, 1))) {
+       case 0:
+               user_added = 1;
+               ltpuser = SAFE_GETPWNAM(username);
+               uid = ltpuser->pw_uid;
+               return;
+       case 255:
+               return;
+       default:
+               tst_brk(TBROK, "Useradd failed (%d)", rc);
+       }
 }
 
 static void cleanup(void)
--
Quoted 3 lines

2.21.0.360.g471c308f928-goog

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190307/2746ea65/attachment.html>

#2 lore raw

PATCH v2 1/1 setpriority01: Skip only PRIO_USER when unable to add test user

In reply to Saravana Kannan

Hi,

FYI: Closing this one in patchwork as superseded (there is another v2).

Kind regards,
Petr