Skip to contentSkip to conversation

syscalls/fcntl: Replace TINFO with TPASS or TFAIL

PATCH Superseded Zhao Gongyi 2 participants 2 messages Apr 29, 2021 – Apr 30, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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

---
 testcases/kernel/syscalls/fcntl/fcntl16.c | 70 +++++++----------------
 testcases/kernel/syscalls/fcntl/fcntl18.c | 40 ++-----------
 2 files changed, 27 insertions(+), 83 deletions(-)
testcases/kernel/syscalls/fcntl/fcntl16.c +4 -4
index a77a81298..04d86202c 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)
@@ -671,55 +675,23 @@ int main(int ac, char **av)
* 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 -34
index 5eefbd128..7a6c545c0 100644
@@ -72,11 +72,8 @@ int main(int ac, char **av)
 /* //block1: */
 #ifndef UCLINUX
 	/* Skip since uClinux does not implement memory protection */
-	tst_resm(TINFO, "Enter block 1");
-	fail = 0;
 	if ((fd = open("temp.dat", O_CREAT | O_RDWR, 0777)) < 0) {	//mode must be specified when O_CREATE is in the flag
 		tst_resm(TFAIL, "file opening error");
-		fail = 1;
 	}
 
 	/* Error condition if address is bad */
@@ -84,15 +81,8 @@ int main(int ac, char **av)
 	if (errno == EFAULT) {
 		tst_resm(TPASS, "Test F_GETLK: for errno EFAULT PASSED");
 	} else {
-		tst_resm(TFAIL, "Test F_GETLK: for errno EFAULT FAILED");
-		fail = 1;
+		tst_resm(TFAIL | TERRNO, "Test F_GETLK: for errno EFAULT FAILED");
 	}
-	if (fail) {
-		tst_resm(TINFO, "Block 1 FAILED");
-	} else {
-		tst_resm(TINFO, "Block 1 PASSED");
-	}
-	tst_resm(TINFO, "Exit block 1");
 #else
 	tst_resm(TINFO, "Skip block 1 on uClinux");
 #endif
@@ -100,29 +90,18 @@ int main(int ac, char **av)
 /* //block2: */
 #ifndef UCLINUX
 	/* Skip since uClinux does not implement memory protection */
-	tst_resm(TINFO, "Enter block 2");
-	fail = 0;
 	/* Error condition if address is bad */
 	retval = fcntl(fd, F_GETLK64, (struct flock *)INVAL_FLAG);
 	if (errno == EFAULT) {
 		tst_resm(TPASS, "Test F_GETLK64: for errno EFAULT PASSED");
 	} else {
-		tst_resm(TFAIL, "Test F_GETLK64: for errno EFAULT FAILED");
-		fail = 1;
-	}
-	if (fail) {
-		tst_resm(TINFO, "Block 2 FAILED");
-	} else {
-		tst_resm(TINFO, "Block 2 PASSED");
+		tst_resm(TFAIL | TERRNO, "Test F_GETLK64: for errno EFAULT FAILED");
 	}
-	tst_resm(TINFO, "Exit block 2");
 #else
 	tst_resm(TINFO, "Skip block 2 on uClinux");
 #endif
 
 /* //block3: */
-	tst_resm(TINFO, "Enter block 3");
-	fail = 0;
 	if ((pid = FORK_OR_VFORK()) == 0) {	/* child */
 		fail = 0;
 		pass = getpwnam("nobody");
@@ -138,24 +117,17 @@ int main(int ac, char **av)
 		if (errno == EINVAL) {
 			tst_resm(TPASS, "Test for errno EINVAL PASSED");
 		} else {
-			tst_resm(TFAIL, "Test for errno EINVAL FAILED, "
-				 "got: %d", errno);
+			tst_resm(TFAIL | TERRNO, "Test for errno EINVAL FAILED");
 			fail = 1;
 		}
 		exit(fail);
 	} else {		/* parent */
 		waitpid(pid, &status, 0);
-		if (WEXITSTATUS(status) != 0) {
+		if (WEXITSTATUS(status) != 0)
 			tst_resm(TFAIL, "child returned bad exit status");
-			fail = 1;
-		}
-		if (fail) {
-			tst_resm(TINFO, "Block 3 FAILED");
-		} else {
-			tst_resm(TINFO, "Block 3 PASSED");
-		}
+		else
+			tst_resm(TPASS, "child returned as expected");
 	}
-	tst_resm(TINFO, "Exit block 3");
 
 	cleanup();
 	tst_exit();

--
2.17.1

#1 lore raw

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

Hi!

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

First of all it looks like the patch got corrupted, possibly by your email client, there is a missing space somewhere in the middle of the patch which prevents it from being applied.

Quoted 82 lines
---
 testcases/kernel/syscalls/fcntl/fcntl16.c | 70 +++++++----------------
 testcases/kernel/syscalls/fcntl/fcntl18.c | 40 ++-----------
 2 files changed, 27 insertions(+), 83 deletions(-)
testcases/kernel/syscalls/fcntl/fcntl16.c +8 -11
index a77a81298..04d86202c 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;
+

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

Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl16.c +8 -1
+	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");

This does not help at all, we print TFAIL messages before we do goto err, so this would be still a failed test.

Looking at the code 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");
Signature · 2 lines
Cyril Hrubis
[email protected]