Skip to contentSkip to conversation

syscalls/fcntl: Replace TINFO with TPASS or TFAIL

PATCH New Zhao Gongyi 3 participants 4 messages May 6, 2021 – Jun 7, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 4/4 syscalls/fcntl: Replace TINFO with TPASS or TFAIL

1)remove redundant variable
2)remove redundant log
3)replace TINFO with TPASS or TFAIL

For those:
testcases/kernel/syscalls/fcntl/fcntl16.c
testcases/kernel/syscalls/fcntl/fcntl18.c

---
v1->v2:
1)correct the patch's format error
2)remove the useless//block1: comments

 testcases/kernel/syscalls/fcntl/fcntl16.c | 73 +++++++----------------
 testcases/kernel/syscalls/fcntl/fcntl18.c | 43 ++-----------
 2 files changed, 27 insertions(+), 89 deletions(-)
testcases/kernel/syscalls/fcntl/fcntl16.c +21 -52
index a77a81298..c5c49284a 100644
@@ -441,7 +441,7 @@ void setup(void)
 	sigaction(SIGALRM, &sact, NULL);
 }
 
-int run_test(int file_flag, int file_mode, int start, int end)
+static void run_test(int file_flag, int file_mode, int start, int end)
 {
 	int child_count;
 	int child;
@@ -468,7 +468,7 @@ int run_test(int file_flag, int file_mode, int start, int end)
 				 errno);
 			close(fd);
 			unlink(tmpname);
-			return 1;
+			goto err;
 		}
 
 		/* Initialize second parent lock structure */
@@ -482,7 +482,7 @@ int run_test(int file_flag, int file_mode, int start, int end)
 					 test + 1, errno);
 				close(fd);
 				unlink(tmpname);
-				return 1;
+				goto err;
 			}
 		}
 
@@ -502,7 +502,7 @@ int run_test(int file_flag, int file_mode, int start, int end)
 					if (self_exec(argv0, "ddddd", i, parent,
 						      test, thislock, fd) < 0) {
 						perror("self_exec failed");
-						return 1;
+						goto err;
 					}
 #else
 					dochild(i);
@@ -510,7 +510,7 @@ int run_test(int file_flag, int file_mode, int start, int end)
 				}
 				if (child < 0) {
 					perror("Fork failed");
-					return 1;
+					goto err;
 				}
 				child_count++;
 				child_pid[i] = child;
@@ -553,7 +553,7 @@ int run_test(int file_flag, int file_mode, int start, int end)
 				 test + 1, errno);
 			close(fd);
 			unlink(tmpname);
-			return 1;
+			goto err;
 		}
 
 		/* Initialize fourth parent lock structure */
@@ -567,7 +567,7 @@ int run_test(int file_flag, int file_mode, int start, int end)
 					 test + 1, errno);
 				close(fd);
 				unlink(tmpname);
-				return 1;
+				goto err;
 			}
 		}
 
@@ -640,12 +640,16 @@ int run_test(int file_flag, int file_mode, int start, int end)
 		close(fd);
 	}
 	unlink(tmpname);
-	if (fail) {
-		return 1;
-	} else {
-		return 0;
+
+	if (!fail) {
+		tst_resm(TPASS, "locking test successed");
+		return;
 	}
-	return 0;
+err:
+	if (file_mode & S_ISGID && !NO_NFS)
+		tst_resm(TCONF, "NFS does not support mandatory locking");
+	else
+		tst_resm(TFAIL, "locking test failed");
 }
 
 int main(int ac, char **av)
@@ -666,60 +670,25 @@ int main(int ac, char **av)
 		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
-/* //block1: */
 		/*
 		 * Check file locks on an ordinary file without
 		 * mandatory locking
 		 */
-		tst_resm(TINFO, "Entering block 1");
-		if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, 0, 11)) {
-			tst_resm(TINFO, "Test case 1: without mandatory "
-				 "locking FAILED");
-		} else {
-			tst_resm(TINFO, "Test case 1: without manadatory "
-				 "locking PASSED");
-		}
-		tst_resm(TINFO, "Exiting block 1");
+		run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, 0, 11);
 
-/* //block2: */
 		/*
 		 * Check the file locks on a file with mandatory record
 		 * locking
 		 */
-		tst_resm(TINFO, "Entering block 2");
-		if (NO_NFS && run_test(O_CREAT | O_RDWR | O_TRUNC, S_ISGID |
-			     S_IRUSR | S_IWUSR, 0, 11)) {
-			tst_resm(TINFO, "Test case 2: with mandatory record "
-				 "locking FAILED");
-		} else {
-			if (NO_NFS)
-				tst_resm(TINFO, "Test case 2: with mandatory"
-					 " record locking PASSED");
-			else
-				tst_resm(TCONF, "Test case 2: NFS does not"
-					 " support mandatory locking");
-		}
-		tst_resm(TINFO, "Exiting block 2");
+		run_test(O_CREAT | O_RDWR | O_TRUNC,
+			S_ISGID | S_IRUSR | S_IWUSR, 0, 11);
 
-/* //block3: */
 		/*
 		 * Check file locks on a file with mandatory record locking
 		 * and no delay
 		 */
-		tst_resm(TINFO, "Entering block 3");
-		if (NO_NFS && run_test(O_CREAT | O_RDWR | O_TRUNC | O_NDELAY,
-			     S_ISGID | S_IRUSR | S_IWUSR, 0, 11)) {
-			tst_resm(TINFO, "Test case 3: mandatory locking with "
-				 "NODELAY FAILED");
-		} else {
-			if (NO_NFS)
-				tst_resm(TINFO, "Test case 3: mandatory"
-					 " locking with NODELAY PASSED");
-			else
-				tst_resm(TCONF, "Test case 3: NFS does not"
-					 " support mandatory locking");
-		}
-		tst_resm(TINFO, "Exiting block 3");
+		run_test(O_CREAT | O_RDWR | O_TRUNC | O_NDELAY,
+			S_ISGID | S_IRUSR | S_IWUSR, 0, 11);
 	}
 	cleanup();
 	tst_exit();
testcases/kernel/syscalls/fcntl/fcntl18.c +6 -37

89 lines not on this page · raw message

--
2.17.1

#1 lore raw

PATCH v2 4/4 syscalls/fcntl: Replace TINFO with TPASS or TFAIL

Hi Zhao,

Quoted 7 lines

1)remove redundant variable
2)remove redundant log
3)replace TINFO with TPASS or TFAIL

For those:
testcases/kernel/syscalls/fcntl/fcntl16.c
testcases/kernel/syscalls/fcntl/fcntl18.c

nit: we have git log to see what files has been changed. IMHO it's better to add fcntl18{16,18}: to the first line.

Quoted 23 lines

---
v1->v2:
1)correct the patch's format error
2)remove the useless//block1: comments

 testcases/kernel/syscalls/fcntl/fcntl16.c | 73 +++++++----------------
 testcases/kernel/syscalls/fcntl/fcntl18.c | 43 ++-----------
 2 files changed, 27 insertions(+), 89 deletions(-)
testcases/kernel/syscalls/fcntl/fcntl16.c +1 -1
index a77a81298..c5c49284a 100644
@@ -441,7 +441,7 @@ void setup(void)
 	sigaction(SIGALRM, &sact, NULL);
 }
 
-int run_test(int file_flag, int file_mode, int start, int end)
+static void run_test(int file_flag, int file_mode, int start, int end)
 {
 	int child_count;
 	int child;

testcases/kernel/syscalls/fcntl/fcntl16.c int run_test(int file_flag, int file_mode, int start, int end) · line 471

Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl16.c +1 -1
@@ -468,7 +468,7 @@ int run_test(int file_flag, int file_mode, int start, int end)
 				 errno);
 			close(fd);
 			unlink(tmpname);
-			return 1;
+			goto err;

not sure if change to use goto satisfied Cyril's requirement:

we should rather skip the test in the main instead as it was done in the original code as:

	if (NO_NFS)
		run_test(...);
	else
		tst_resm(TCONF, "Skipping mandatory locking on NFS");

other than that LGTM

Also test ignores -i N parameter, because it does not use TEST_LOOPING(). But that's another issue which should be fixed by rewriting the test to new API.

Kind regards,
Petr

#2 lore raw

PATCH v2 4/4 syscalls/fcntl: Replace TINFO with TPASS or TFAIL

Hi!

Quoted 9 lines

not sure if change to use goto satisfied Cyril's requirement:

we should rather skip the test in the main instead as it was done in the original code as:

	if (NO_NFS)
		run_test(...);
	else
		tst_resm(TCONF, "Skipping mandatory locking on NFS");

Yes I still think that the code looks better if we skip the test in the main here.

Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH v2 4/4 syscalls/fcntl: Replace TINFO with TPASS or TFAIL

Hi Zhao, Cyril,

Quoted 6 lines

Hi!

Quoted 4 lines

not sure if change to use goto satisfied Cyril's requirement:

we should rather skip the test in the main instead as it was done in the original code as:

Quoted 7 lines
Quoted 4 lines
	if (NO_NFS)
		run_test(...);
	else
		tst_resm(TCONF, "Skipping mandatory locking on NFS");

Yes I still think that the code looks better if we skip the test in the main here.

+1. Replacing int return with goto err for no reason is ugly. Zhao, would you please send v3 with this fixed?

Kind regards,
Petr