Skip to contentSkip to conversation

lib: use tst_exit() instead of exit()

PATCH New Petr Vorel 2 participants 3 messages Mar 16, 2017 – Mar 20, 2017 Library code

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 lib: use tst_exit() instead of exit()

---
I'm sorry for not important commit. It's more for me to understand whether tst_exit() should be used only for normal tests, or also for lib's tests or even in lib itself.

---
 lib/parse_opts.c                        | 2 +-
 lib/random_range.c                      | 4 ++--
 lib/tests/tst_checkpoint.c              | 2 +-
 lib/tests/tst_checkpoint_wait_timeout.c | 2 +-
 lib/tests/tst_checkpoint_wake_timeout.c | 2 +-
 lib/tests/tst_cleanup_once.c            | 2 +-
 lib/tests/tst_dataroot01.c              | 1 -
 lib/tests/tst_process_state.c           | 4 ++--
 lib/tests/tst_safe_macros.c             | 2 +-
 lib/tests/tst_strerrno.c                | 2 +-
 lib/tests/tst_strsig.c                  | 2 +-
 lib/tests/tst_tmpdir_test.c             | 2 +-
 12 files changed, 13 insertions(+), 14 deletions(-)
lib/parse_opts.c +1 -1
index 3a879e44e..1af8e9a6e 100644
@@ -618,7 +618,7 @@ int main(int argc, char **argv)
 
 	TEST_CLEANUP;
 
-	exit(0);
+	tst_exit();
 }
 
 #endif /* UNIT_TEST */
lib/random_range.c +2 -2
index 510a4a1ff..c2534e0c7 100644
@@ -706,7 +706,7 @@ char **argv;
 			}
 		}
 	}
-	exit(0);
+	tst_exit();
 }
 
 #endif /* end if RANDOM_BIT_UNITTEST */
@@ -886,7 +886,7 @@ char **argv;
 
 	}
 
-	exit(0);
+	tst_exit();
 }
 
 #endif
lib/tests/tst_checkpoint.c +1 -1
index 2cb17a5f7..7008171db 100644
@@ -55,5 +55,5 @@ int main(void)
 
 	wait(NULL);
 	tst_rmdir();
-	return 0;
+	tst_exit();
 }
lib/tests/tst_checkpoint_wait_timeout.c +1 -1
index c5fae670e..eb69565c2 100644
@@ -54,5 +54,5 @@ int main(void)
 	break;
 	}
 
-	return 0;
+	tst_exit();
 }
lib/tests/tst_checkpoint_wake_timeout.c +1 -1
index 8af1feb18..6a71d80b6 100644
@@ -37,5 +37,5 @@ int main(void)
 	TST_SAFE_CHECKPOINT_WAKE(tst_rmdir, 0);
 	fprintf(stderr, "Parent: checkpoint reached\n");
 
-	return 0;
+	tst_exit();
 }
lib/tests/tst_cleanup_once.c +1 -1
index 328ed7492..73ac88db1 100644
@@ -43,5 +43,5 @@ int main(void)
 	cleanup();
 	cleanup();
 
-	return 0;
+	tst_exit();
 }
lib/tests/tst_dataroot01.c +0 -1
index fab8bfea2..e4d8a3875 100644
@@ -51,4 +51,3 @@ int main(void)
 
 	tst_exit();
 }
-
lib/tests/tst_process_state.c +2 -2
index dd4f0535d..33b87c569 100644
@@ -59,7 +59,7 @@ int main(void)
 
 		fprintf(stderr, "Child woken up\n");
 
-		return 0;
+		tst_exit();
 		break;
 	default:
 		/* Wait for child to sleep */
@@ -71,5 +71,5 @@ int main(void)
 	}
 
 	wait(NULL);
-	return 0;
+	tst_exit();
 }
lib/tests/tst_safe_macros.c +1 -1
index b5809f40d..6a417eff5 100644
@@ -36,5 +36,5 @@ int main(int argc LTP_ATTRIBUTE_UNUSED, char **argv)
 	SAFE_WRITE(NULL, 1, fd, buf, 9);
 	SAFE_PIPE(NULL, fds);
 
-	return 0;
+	tst_exit();
 }
lib/tests/tst_strerrno.c +1 -1
index dbee7642f..e9ad39cfd 100644
@@ -31,5 +31,5 @@ int main(void)
 {
 	fprintf(stderr, "0 = %s\n", tst_strerrno(0));
 	fprintf(stderr, "EINVAL = %s\n", tst_strerrno(EINVAL));
-	return 0;
+	tst_exit();
 }
lib/tests/tst_strsig.c +1 -1
index 9a5ca80aa..d0b2184f2 100644
@@ -31,5 +31,5 @@ int main(void)
 {
 	fprintf(stderr, "SIGKILL = %s\n", tst_strsig(SIGKILL));
 	fprintf(stderr, "SIGALRM = %s\n", tst_strsig(SIGALRM));
-	return 0;
+	tst_exit();
 }
lib/tests/tst_tmpdir_test.c +1 -1
index f394893a4..f58afc26a 100644
@@ -80,5 +80,5 @@ int main(void)
 	else
 		printf("Test completed successfully!\n");
 
-	return 0;
+	tst_exit();
 }
Signature · 1 line
2.12.0
#1 lore raw

PATCH 1/1 lib: use tst_exit() instead of exit()

Hi!

Quoted 3 lines

I'm sorry for not important commit. It's more for me to understand whether tst_exit() should be used only for normal tests, or also for lib's tests or even in lib itself.

The answer here is that we do not care in these cases. The difference between exit() and tst_exit() is that tst_exit() exits with correct exit value (bitflags stored in the test library) when tst_res() is used to report test results. And since the exit value from the code changed below is not used the difference is merely cosmetic.

lib/parse_opts.c int main(int argc, char **argv) · line 622

Quoted 11 lines
lib/parse_opts.c +1 -1
index 3a879e44e..1af8e9a6e 100644
@@ -618,7 +618,7 @@ int main(int argc, char **argv)
 
 	TEST_CLEANUP;
 
-	exit(0);
+	tst_exit();
 }

This is ifdefed out testing code for the parse_opts() function, we should rather remove it since it's not compiled by default...

Quoted 15 lines
lib/parse_opts.c +0 -0
 #endif /* UNIT_TEST */
lib/random_range.c +1 -1
index 510a4a1ff..c2534e0c7 100644
@@ -706,7 +706,7 @@ char **argv;
 			}
 		}
 	}
-	exit(0);
+	tst_exit();
 }
 
 #endif /* end if RANDOM_BIT_UNITTEST */

lib/random_range.c char **argv; · line 890

Quoted 6 lines
lib/random_range.c +1 -1
@@ -886,7 +886,7 @@ char **argv;
 
 	}
 
-	exit(0);
+	tst_exit();
 }

This is the same case.

Quoted 112 lines
lib/random_range.c +0 -0
 #endif
lib/tests/tst_checkpoint.c +1 -1
index 2cb17a5f7..7008171db 100644
@@ -55,5 +55,5 @@ int main(void)
 
 	wait(NULL);
 	tst_rmdir();
-	return 0;
+	tst_exit();
 }
lib/tests/tst_checkpoint_wait_timeout.c +1 -1
index c5fae670e..eb69565c2 100644
@@ -54,5 +54,5 @@ int main(void)
 	break;
 	}
 
-	return 0;
+	tst_exit();
 }
lib/tests/tst_checkpoint_wake_timeout.c +1 -1
index 8af1feb18..6a71d80b6 100644
@@ -37,5 +37,5 @@ int main(void)
 	TST_SAFE_CHECKPOINT_WAKE(tst_rmdir, 0);
 	fprintf(stderr, "Parent: checkpoint reached\n");
 
-	return 0;
+	tst_exit();
 }
lib/tests/tst_cleanup_once.c +1 -1
index 328ed7492..73ac88db1 100644
@@ -43,5 +43,5 @@ int main(void)
 	cleanup();
 	cleanup();
 
-	return 0;
+	tst_exit();
 }
lib/tests/tst_dataroot01.c +0 -1
index fab8bfea2..e4d8a3875 100644
@@ -51,4 +51,3 @@ int main(void)
 
 	tst_exit();
 }
-
lib/tests/tst_process_state.c +2 -2
index dd4f0535d..33b87c569 100644
@@ -59,7 +59,7 @@ int main(void)
 
 		fprintf(stderr, "Child woken up\n");
 
-		return 0;
+		tst_exit();
 		break;
 	default:
 		/* Wait for child to sleep */
@@ -71,5 +71,5 @@ int main(void)
 	}
 
 	wait(NULL);
-	return 0;
+	tst_exit();
 }
lib/tests/tst_safe_macros.c +1 -1
index b5809f40d..6a417eff5 100644
@@ -36,5 +36,5 @@ int main(int argc LTP_ATTRIBUTE_UNUSED, char **argv)
 	SAFE_WRITE(NULL, 1, fd, buf, 9);
 	SAFE_PIPE(NULL, fds);
 
-	return 0;
+	tst_exit();
 }
lib/tests/tst_strerrno.c +1 -1
index dbee7642f..e9ad39cfd 100644
@@ -31,5 +31,5 @@ int main(void)
 {
 	fprintf(stderr, "0 = %s\n", tst_strerrno(0));
 	fprintf(stderr, "EINVAL = %s\n", tst_strerrno(EINVAL));
-	return 0;
+	tst_exit();
 }
lib/tests/tst_strsig.c +1 -1
index 9a5ca80aa..d0b2184f2 100644
@@ -31,5 +31,5 @@ int main(void)
 {
 	fprintf(stderr, "SIGKILL = %s\n", tst_strsig(SIGKILL));
 	fprintf(stderr, "SIGALRM = %s\n", tst_strsig(SIGALRM));
-	return 0;
+	tst_exit();
 }
lib/tests/tst_tmpdir_test.c +0 -0
index f394893a4..f58afc26a 100644

lib/tests/tst_tmpdir_test.c int main(void) · line 84

Quoted 6 lines
lib/tests/tst_tmpdir_test.c +1 -1
@@ -80,5 +80,5 @@ int main(void)
 	else
 		printf("Test completed successfully!\n");
 
-	return 0;
+	tst_exit();
 }

We can apply these since we should be using tst_exit() there, but in practice it does not matter, since we are not executing these in LTP run and hence the test exit value is not used at all.

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

PATCH 1/1 lib: use tst_exit() instead of exit()

Hi Cyril,

Quoted 5 lines

The answer here is that we do not care in these cases. The difference between exit() and tst_exit() is that tst_exit() exits with correct exit value (bitflags stored in the test library) when tst_res() is used to report test results. And since the exit value from the code changed below is not used the difference is merely cosmetic.

Thanks for explaining. OK, forget on it. Sorry for wasting your time.

Kind regards,
Petr