[LTP] [PATCH 2/4] syscalls/modify_ldt: Replace TINFO with TPASS or TFAIL

Zhao Gongyi zhaogongyi@huawei.com
Thu Apr 29 14:52:55 CEST 2021


1)remove redundant Variables flag/fail
2)remove redundant log
3)replace TINFO with TPASS or TFAIL
4)check signal generated by child

For those:
	testcases/kernel/syscalls/modify_ldt/modify_ldt01.c
	testcases/kernel/syscalls/modify_ldt/modify_ldt02.c

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 .../kernel/syscalls/modify_ldt/modify_ldt01.c | 44 +++++--------------
 .../kernel/syscalls/modify_ldt/modify_ldt02.c | 35 ++++-----------
 2 files changed, 18 insertions(+), 61 deletions(-)

diff --git a/testcases/kernel/syscalls/modify_ldt/modify_ldt01.c b/testcases/kernel/syscalls/modify_ldt/modify_ldt01.c
index 248111814..86c5b3e5a 100644
--- a/testcases/kernel/syscalls/modify_ldt/modify_ldt01.c
+++ b/testcases/kernel/syscalls/modify_ldt/modify_ldt01.c
@@ -98,7 +98,6 @@ int main(int ac, char **av)
 	void *ptr;
 	int retval, func;

-	int flag;
 	int seg[4];

 	tst_parse_opts(ac, av, NULL, NULL);
@@ -115,8 +114,6 @@ int main(int ac, char **av)
 		/*
 		 * Check for ENOSYS.
 		 */
-		tst_resm(TINFO, "Enter block 1");
-		flag = 0;
 		ptr = malloc(10);
 		func = 100;
 		retval = modify_ldt(func, ptr, sizeof(ptr));
@@ -125,29 +122,21 @@ int main(int ac, char **av)
 				tst_resm(TFAIL, "modify_ldt() set invalid "
 					 "errno, expected ENOSYS, got: %d",
 					 errno);
-				flag = FAILED;
+			} else {
+				tst_resm(TPASS,
+					"modify_ldt() set expected errno");
 			}
 		} else {
 			tst_resm(TFAIL, "modify_ldt error: "
 				 "unexpected return value %d", retval);
-			flag = FAILED;
 		}

-		if (flag) {
-			tst_resm(TINFO, "block 1 FAILED");
-		} else {
-			tst_resm(TINFO, "block 1 PASSED");
-		}
-		tst_resm(TINFO, "Exit block 1");
 		free(ptr);

 //block2:
 		/*
 		 * Check for EINVAL
 		 */
-		tst_resm(TINFO, "Enter block 2");
-		flag = 0;
-
 		ptr = 0;

 		retval = modify_ldt(1, ptr, sizeof(ptr));
@@ -156,20 +145,14 @@ int main(int ac, char **av)
 				tst_resm(TFAIL, "modify_ldt() set invalid "
 					 "errno, expected EINVAL, got: %d",
 					 errno);
-				flag = FAILED;
+			} else {
+				tst_resm(TPASS,
+					"modify_ldt() set expected errno");
 			}
 		} else {
 			tst_resm(TFAIL, "modify_ldt error: "
 				 "unexpected return value %d", retval);
-			flag = FAILED;
-		}
-
-		if (flag) {
-			tst_resm(TINFO, "block 2 FAILED");
-		} else {
-			tst_resm(TINFO, "block 2 PASSED");
 		}
-		tst_resm(TINFO, "Exit block 2");

 //block3:

@@ -177,7 +160,7 @@ int main(int ac, char **av)
 		 * Create a new LDT segment.
 		 */
 		if (create_segment(seg, sizeof(seg)) == -1) {
-			tst_brkm(TINFO, cleanup, "Creation of segment failed");
+			tst_brkm(TBROK, cleanup, "Creation of segment failed");
 		}

 		/*
@@ -191,21 +174,14 @@ int main(int ac, char **av)
 				tst_resm(TFAIL, "modify_ldt() set invalid "
 					 "errno, expected EFAULT, got: %d",
 					 errno);
-				flag = FAILED;
+			} else {
+				tst_resm(TPASS,
+					"modify_ldt() set expected errno");
 			}
 		} else {
 			tst_resm(TFAIL, "modify_ldt error: "
 				 "unexpected return value %d", retval);
-			flag = FAILED;
 		}
-
-		if (flag) {
-			tst_resm(TINFO, "block 3 FAILED");
-		} else {
-			tst_resm(TINFO, "block 3 PASSED");
-		}
-		tst_resm(TINFO, "Exit block 3");
-
 	}
 	cleanup();
 	tst_exit();
diff --git a/testcases/kernel/syscalls/modify_ldt/modify_ldt02.c b/testcases/kernel/syscalls/modify_ldt/modify_ldt02.c
index c953ac420..769cf6701 100644
--- a/testcases/kernel/syscalls/modify_ldt/modify_ldt02.c
+++ b/testcases/kernel/syscalls/modify_ldt/modify_ldt02.c
@@ -86,15 +86,12 @@ int read_segment(unsigned int);
 void cleanup(void);
 void setup(void);

-#define FAILED 1
-
 int main(int ac, char **av)
 {
 	int lc;

 	int val, pid, status;

-	int flag;
 	int seg[4];

 	tst_parse_opts(ac, av, NULL, NULL);
@@ -108,12 +105,9 @@ int main(int ac, char **av)
 		tst_count = 0;

 //block1:
-		tst_resm(TINFO, "Enter block 1");
-		flag = 0;
-
 		seg[0] = 12345;
 		if (create_segment(seg, sizeof(seg)) == -1) {
-			tst_brkm(TINFO, cleanup, "Creation of segment failed");
+			tst_brkm(TBROK, cleanup, "Creation of segment failed");
 		}

 		val = read_segment(0);
@@ -121,23 +115,12 @@ int main(int ac, char **av)
 		if (val != seg[0]) {
 			tst_resm(TFAIL, "Invalid value read %d, expected %d",
 				 val, seg[0]);
-			flag = FAILED;
-		}
-
-		if (flag) {
-			tst_resm(TINFO, "block 1 FAILED");
-		} else {
-			tst_resm(TINFO, "block 1 PASSED");
-		}
-
-		tst_resm(TINFO, "Exit block 1");
+		} else
+			tst_resm(TPASS, "value read as expected");

 //block2:
-		tst_resm(TINFO, "Enter block 2");
-		flag = 0;
-
 		if (create_segment(0, 10) == -1) {
-			tst_brkm(TINFO, cleanup, "Creation of segment failed");
+			tst_brkm(TBROK, cleanup, "Creation of segment failed");
 		}

 		tst_old_flush();
@@ -149,15 +132,13 @@ int main(int ac, char **av)
 		(void)waitpid(pid, &status, 0);

 		if (WEXITSTATUS(status) != 0) {
-			flag = FAILED;
 			tst_resm(TFAIL, "Did not generate SEGV, child returned "
 				 "unexpected status");
-		}
-
-		if (flag) {
-			tst_resm(TINFO, "block 2 FAILED");
 		} else {
-			tst_resm(TINFO, "block 2 PASSED");
+			if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGSEGV))
+				tst_resm(TPASS, "generate SEGV as expected");
+			else
+				tst_resm(TFAIL, "Did not generate SEGV");
 		}
 	}
 	cleanup();
--
2.17.1



More information about the ltp mailing list