lib: use tst_exit() instead of exit()
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
@@ -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
@@ -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
@@ -55,5 +55,5 @@ int main(void)wait (NULL );tst_rmdir (); -return 0 ; +tst_exit (); }
lib/tests/tst_checkpoint_wait_timeout.c +1 -1
@@ -54,5 +54,5 @@ int main(void)break ; } -return 0 ; +tst_exit (); }
lib/tests/tst_checkpoint_wake_timeout.c +1 -1
@@ -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
@@ -43,5 +43,5 @@ int main(void)cleanup ();cleanup (); -return 0 ; +tst_exit (); }
lib/tests/tst_dataroot01.c +0 -1
@@ -51,4 +51,3 @@ int main(void)tst_exit (); } -
lib/tests/tst_process_state.c +2 -2
@@ -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
@@ -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
@@ -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
@@ -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
@@ -80,5 +80,5 @@ int main(void)else printf ("Test completed successfully!\n" ); -return 0 ; +tst_exit (); }
Signature · 1 line
2.12.0
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@@ -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@@ -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@@ -55,5 +55,5 @@ int main(void)wait (NULL );tst_rmdir (); -return 0 ; +tst_exit (); }lib/tests/tst_checkpoint_wait_timeout.c +1
-1@@ -54,5 +54,5 @@ int main(void)break ; } -return 0 ; +tst_exit (); }lib/tests/tst_checkpoint_wake_timeout.c +1
-1@@ -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@@ -43,5 +43,5 @@ int main(void)cleanup ();cleanup (); -return 0 ; +tst_exit (); }lib/tests/tst_dataroot01.c +0
-1@@ -51,4 +51,3 @@ int main(void)tst_exit (); } -lib/tests/tst_process_state.c +2
-2@@ -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@@ -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@@ -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@@ -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
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]
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()andtst_exit()is thattst_exit()exits with correct exit value (bitflags stored in the test library) whentst_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