Skip to contentSkip to conversation

Rewrite process_vm01 test using new LTP API

PATCH Superseded Andrea Cervesato via ltp 2 participants 5 messages Aug 24, 2022 – Aug 26, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Rewrite process_vm01 test using new LTP API

Now test is run on process_vm_writev by default and process_vm_readv can be selected by passing -r command line option.

---
 runtest/syscalls                             |   2 +-
 testcases/kernel/syscalls/cma/process_vm01.c | 464 ++++++++-----------
 2 files changed, 188 insertions(+), 278 deletions(-)
runtest/syscalls +1 -1
index 3847e8af2..70f22fbd5 100644
@@ -1031,7 +1031,7 @@ profil01 profil01
 process_vm_readv01 process_vm01 -r
 process_vm_readv02 process_vm_readv02
 process_vm_readv03 process_vm_readv03
-process_vm_writev01 process_vm01 -w
+process_vm_writev01 process_vm01
 process_vm_writev02 process_vm_writev02
 
 prot_hsymlinks prot_hsymlinks
testcases/kernel/syscalls/cma/process_vm01.c +187 -277

573 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hello,

Quoted 42 lines · Andrea Cervesato via ltp
testcases/kernel/syscalls/cma/process_vm01.c +10 -23
-static void cma_test_invalid_perm(void)
+static void test_invalid_perm(void)
 {
 	char nobody_uid[] = "nobody";
 	struct passwd *ltpuser;
-	int status;
 	struct process_vm_params *params;
 	pid_t child_pid;
 	pid_t parent_pid;
-	int ret = 0;
+	int status;
+
+	tst_res(TINFO, "Testing invalid permissions on given PID");
 
-	tst_resm(TINFO, "test_invalid_perm");
 	parent_pid = getpid();
-	child_pid = fork();
-	switch (child_pid) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork");
-		break;
-	case 0:
-		ltpuser = getpwnam(nobody_uid);
-		if (ltpuser == NULL)
-			tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-		SAFE_SETUID(NULL, ltpuser->pw_uid);
-
-		params = cma_alloc_sane_params();
+	child_pid = SAFE_FORK();
+	if (!child_pid) {
+		ltpuser = SAFE_GETPWNAM(nobody_uid);
+		SAFE_SETUID(ltpuser->pw_uid);
+
+		params = alloc_params();
 		params->pid = parent_pid;
-		cma_test_params(params);
-		ret |= cma_check_ret(-1, TEST_RETURN);
-		ret |= cma_check_errno(EPERM);
-		cma_free_params(params);
-		exit(ret);
-	default:
-		SAFE_WAITPID(cleanup, child_pid, &status, 0);

testcases/kernel/syscalls/cma/process_vm01.c static void cma_free_params(struct process_vm_params *params) · line 248

Quoted 10 lines
testcases/kernel/syscalls/cma/process_vm01.c +7 -2
-		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-			tst_resm(TFAIL, "child returns %d", status);
+		test_params(params);
+		TST_EXP_EQ_LI(TST_RET, -1);
+		check_errno(EPERM);
+		free_params(params);
+		return;
 	}
+
+	SAFE_WAITPID(child_pid, &status, 0);

We want to use tst_reap_children() here which will check the exit status.

In fact, if SAFE_WAITPID is removed altogether then the exit status will be checked automatically at the end of the test when the lib calls reap_children.

Otherwise LGTM!

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi!

Quoted 59 lines · Richard Palethorpe

Hello,

Quoted 42 lines · Andrea Cervesato via ltp
testcases/kernel/syscalls/cma/process_vm01.c +10 -23
-static void cma_test_invalid_perm(void)
+static void test_invalid_perm(void)
  {
  	char nobody_uid[] = "nobody";
  	struct passwd *ltpuser;
-	int status;
  	struct process_vm_params *params;
  	pid_t child_pid;
  	pid_t parent_pid;
-	int ret = 0;
+	int status;
+
+	tst_res(TINFO, "Testing invalid permissions on given PID");
 
-	tst_resm(TINFO, "test_invalid_perm");
  	parent_pid = getpid();
-	child_pid = fork();
-	switch (child_pid) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork");
-		break;
-	case 0:
-		ltpuser = getpwnam(nobody_uid);
-		if (ltpuser == NULL)
-			tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-		SAFE_SETUID(NULL, ltpuser->pw_uid);
-
-		params = cma_alloc_sane_params();
+	child_pid = SAFE_FORK();
+	if (!child_pid) {
+		ltpuser = SAFE_GETPWNAM(nobody_uid);
+		SAFE_SETUID(ltpuser->pw_uid);
+
+		params = alloc_params();
  		params->pid = parent_pid;
-		cma_test_params(params);
-		ret |= cma_check_ret(-1, TEST_RETURN);
-		ret |= cma_check_errno(EPERM);
-		cma_free_params(params);
-		exit(ret);
-	default:
-		SAFE_WAITPID(cleanup, child_pid, &status, 0);

testcases/kernel/syscalls/cma/process_vm01.c static void cma_free_params(struct process_vm_params *params) · line 248

Quoted 10 lines
testcases/kernel/syscalls/cma/process_vm01.c +7 -2
-		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-			tst_resm(TFAIL, "child returns %d", status);
+		test_params(params);
+		TST_EXP_EQ_LI(TST_RET, -1);
+		check_errno(EPERM);
+		free_params(params);
+		return;
  	}
+
+	SAFE_WAITPID(child_pid, &status, 0);

We want to use tst_reap_children() here which will check the exit status.

Quoted 6 lines

In fact, if SAFE_WAITPID is removed altogether then the exit status will be checked automatically at the end of the test when the lib calls reap_children.

Otherwise LGTM!

Isn't tst_reap_childread() already called at the end of the test_all function? (tst_test.c:1354)

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
Quoted 65 lines · Andrea Cervesato via ltp

Hi!

Quoted 62 lines · Richard Palethorpe

Hello,

Quoted 43 lines · Andrea Cervesato via ltp
testcases/kernel/syscalls/cma/process_vm01.c +1 -1
-static void cma_test_invalid_perm(void)
+static void test_invalid_perm(void)

  {
      char nobody_uid[] = "nobody";
      struct passwd *ltpuser;
-    int status;
      struct process_vm_params *params;
      pid_t child_pid;
      pid_t parent_pid;
-    int ret = 0;
+    int status;
+
+    tst_res(TINFO, "Testing invalid permissions on given PID"); -    tst_resm(TINFO, "test_invalid_perm"); parent_pid = getpid();
-    child_pid = fork();
-    switch (child_pid) {
-    case -1:
-        tst_brkm(TBROK | TERRNO, cleanup, "fork");
-        break;
-    case 0:
-        ltpuser = getpwnam(nobody_uid);
-        if (ltpuser == NULL)
-            tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed"); -        SAFE_SETUID(NULL, ltpuser->pw_uid);

testcases/kernel/syscalls/cma/process_vm01.c +6 -2
-
-        params = cma_alloc_sane_params();
+    child_pid = SAFE_FORK();
+    if (!child_pid) {
+        ltpuser = SAFE_GETPWNAM(nobody_uid);
+        SAFE_SETUID(ltpuser->pw_uid);
+
+        params = alloc_params();

          params->pid = parent_pid;
-        cma_test_params(params);
-        ret |= cma_check_ret(-1, TEST_RETURN);
-        ret |= cma_check_errno(EPERM);
-        cma_free_params(params);
-        exit(ret);
-    default:
-        SAFE_WAITPID(cleanup, child_pid, &status, 0); -        if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) -            tst_resm(TFAIL, "child returns %d", status);

Quoted 8 lines

+        test_params(params);
+        TST_EXP_EQ_LI(TST_RET, -1);
+        check_errno(EPERM);
+        free_params(params);
+        return;
      }
+
+    SAFE_WAITPID(child_pid, &status, 0);

We want to use tst_reap_children() here which will check the exit status.

In fact, if SAFE_WAITPID is removed altogether then the exit status will be checked automatically at the end of the test when the lib calls reap_children.

Quoted 7 lines
Quoted 2 lines

Otherwise LGTM!

Isn't tst_reap_childread() already called at the end of the test_all function? (tst_test.c:1354)

Andrea

The reason why I'm using SAFE_WAITPID here is that there are many other test functions and when test_invalid_perm is called without it, the tst_res messages might come out asynchronously with the other tests messages.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hello,

Quoted 71 lines · Andrea Cervesato via ltp
Quoted 70 lines · Andrea Cervesato via ltp

Hi!

Quoted 58 lines · Richard Palethorpe

Hello,

Quoted 43 lines · Andrea Cervesato via ltp
testcases/kernel/syscalls/cma/process_vm01.c +1 -1
-static void cma_test_invalid_perm(void)
+static void test_invalid_perm(void)

  {
      char nobody_uid[] = "nobody";
      struct passwd *ltpuser;
-    int status;
      struct process_vm_params *params;
      pid_t child_pid;
      pid_t parent_pid;
-    int ret = 0;
+    int status;
+
+    tst_res(TINFO, "Testing invalid permissions on given PID"); -    tst_resm(TINFO, "test_invalid_perm"); parent_pid = getpid();
-    child_pid = fork();
-    switch (child_pid) {
-    case -1:
-        tst_brkm(TBROK | TERRNO, cleanup, "fork");
-        break;
-    case 0:
-        ltpuser = getpwnam(nobody_uid);
-        if (ltpuser == NULL)
-            tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed"); -        SAFE_SETUID(NULL, ltpuser->pw_uid);

testcases/kernel/syscalls/cma/process_vm01.c +6 -2
-
-        params = cma_alloc_sane_params();
+    child_pid = SAFE_FORK();
+    if (!child_pid) {
+        ltpuser = SAFE_GETPWNAM(nobody_uid);
+        SAFE_SETUID(ltpuser->pw_uid);
+
+        params = alloc_params();

          params->pid = parent_pid;
-        cma_test_params(params);
-        ret |= cma_check_ret(-1, TEST_RETURN);
-        ret |= cma_check_errno(EPERM);
-        cma_free_params(params);
-        exit(ret);
-    default:
-        SAFE_WAITPID(cleanup, child_pid, &status, 0); -        if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) -            tst_resm(TFAIL, "child returns %d", status);

Quoted 8 lines

+        test_params(params);
+        TST_EXP_EQ_LI(TST_RET, -1);
+        check_errno(EPERM);
+        free_params(params);
+        return;
      }
+
+    SAFE_WAITPID(child_pid, &status, 0);

We want to use tst_reap_children() here which will check the exit status.

Quoted 6 lines

In fact, if SAFE_WAITPID is removed altogether then the exit status will be checked automatically at the end of the test when the lib calls reap_children.

Otherwise LGTM!

Isn't tst_reap_childread() already called at the end of the test_all function? (tst_test.c:1354)

Quoted 7 lines
Quoted 3 lines

Andrea

The reason why I'm using SAFE_WAITPID here is that there are many other test functions and when test_invalid_perm is called without it, the tst_res messages might come out asynchronously with the other tests messages.

If asynchronous messages are a problem then you can explicitly call tst_reap_children() after fork. If you use SAFE_WAITPID then you need to check the exit status manually, it won't get checked later by the call to tst_reap_children in tst_test.c. Because the child process has already been reaped by waitpid.

I don't have a strong opinion on whether asynchronous messages are a problem.

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp