ltp: detect the test id automatically
PATCH 1/1 ltp: detect the test id automatically
For the purpose of detecting LTP test id(tst_test->tid) correctly. Here achieve a new function get_tid() to replace that work by manual which easily involve typos. :)
Henceforth, there will be no need to define ".tid = filename" in new testcase, unless the LTP default main() is not in use.
Also, moving TCID and parse_opts() to the right place in this patch.
--- lib/newlib_tests/test01.c | 1 - lib/newlib_tests/test02.c | 1 - lib/newlib_tests/test03.c | 1 - lib/newlib_tests/test04.c | 1 - lib/newlib_tests/test05.c | 1 - lib/newlib_tests/test06.c | 1 - lib/newlib_tests/test07.c | 1 - lib/newlib_tests/test08.c | 1 - lib/newlib_tests/test09.c | 1 - lib/newlib_tests/test10.c | 1 - lib/newlib_tests/test11.c | 1 - lib/newlib_tests/test12.c | 1 - lib/newlib_tests/test13.c | 1 - lib/newlib_tests/test14.c | 1 - lib/newlib_tests/tst_device.c | 1 - lib/newlib_tests/tst_res_hexd.c | 1 - lib/newlib_tests/tst_safe_fileops.c | 1 - lib/tst_test.c | 16 ++++++++++++---- testcases/kernel/mem/mtest06/mmap3.c | 1 - testcases/kernel/security/dirtyc0w/dirtyc0w.c | 1 - testcases/kernel/syscalls/access/access01.c | 1 - testcases/kernel/syscalls/access/access02.c | 1 - testcases/kernel/syscalls/access/access03.c | 1 - testcases/kernel/syscalls/access/access04.c | 1 - testcases/kernel/syscalls/add_key/add_key01.c | 1 - testcases/kernel/syscalls/add_key/add_key02.c | 1 - testcases/kernel/syscalls/alarm/alarm06.c | 1 - testcases/kernel/syscalls/clock_getres/clock_getres01.c | 1 - .../kernel/syscalls/clock_nanosleep/clock_nanosleep01.c | 1 - .../syscalls/clock_nanosleep2/clock_nanosleep2_01.c | 1 - testcases/kernel/syscalls/creat/creat01.c | 1 - testcases/kernel/syscalls/creat/creat03.c | 1 - testcases/kernel/syscalls/creat/creat04.c | 1 - testcases/kernel/syscalls/creat/creat05.c | 1 - testcases/kernel/syscalls/creat/creat06.c | 1 - testcases/kernel/syscalls/creat/creat07.c | 1 - .../kernel/syscalls/epoll_create1/epoll_create1_01.c | 1 - testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c | 1 - testcases/kernel/syscalls/epoll_ctl/epoll_ctl02.c | 1 - testcases/kernel/syscalls/fcntl/fcntl02.c | 1 - testcases/kernel/syscalls/fcntl/fcntl03.c | 1 - testcases/kernel/syscalls/fcntl/fcntl04.c | 1 - testcases/kernel/syscalls/fcntl/fcntl34.c | 1 - testcases/kernel/syscalls/flistxattr/flistxattr01.c | 1 - testcases/kernel/syscalls/flistxattr/flistxattr02.c | 1 - testcases/kernel/syscalls/flistxattr/flistxattr03.c | 1 - testcases/kernel/syscalls/getcwd/getcwd01.c | 1 - testcases/kernel/syscalls/getcwd/getcwd02.c | 1 - testcases/kernel/syscalls/getcwd/getcwd03.c | 1 - testcases/kernel/syscalls/getcwd/getcwd04.c | 1 - testcases/kernel/syscalls/getpriority/getpriority01.c | 1 - testcases/kernel/syscalls/getpriority/getpriority02.c | 1 - testcases/kernel/syscalls/getrandom/getrandom01.c | 1 - testcases/kernel/syscalls/getrandom/getrandom02.c | 1 - testcases/kernel/syscalls/getrandom/getrandom03.c | 1 - testcases/kernel/syscalls/getrandom/getrandom04.c | 1 - testcases/kernel/syscalls/gettimeofday/gettimeofday02.c | 1 - testcases/kernel/syscalls/getxattr/getxattr04.c | 1 - testcases/kernel/syscalls/ioctl/ioctl04.c | 1 - testcases/kernel/syscalls/ioctl/ioctl05.c | 1 - testcases/kernel/syscalls/ioctl/ioctl06.c | 1 - testcases/kernel/syscalls/ipc/msgget/msgget01.c | 1 - testcases/kernel/syscalls/ipc/msgget/msgget02.c | 1 - testcases/kernel/syscalls/ipc/msgget/msgget03.c | 1 - testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c | 1 - testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c | 1 - testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c | 1 - testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c | 1 - testcases/kernel/syscalls/kcmp/kcmp01.c | 1 - testcases/kernel/syscalls/kcmp/kcmp02.c | 1 - testcases/kernel/syscalls/kcmp/kcmp03.c | 1 - testcases/kernel/syscalls/keyctl/keyctl02.c | 1 - testcases/kernel/syscalls/lgetxattr/lgetxattr01.c | 1 - testcases/kernel/syscalls/lgetxattr/lgetxattr02.c | 1 - testcases/kernel/syscalls/listxattr/listxattr01.c | 1 - testcases/kernel/syscalls/listxattr/listxattr02.c | 1 - testcases/kernel/syscalls/listxattr/listxattr03.c | 1 - testcases/kernel/syscalls/llistxattr/llistxattr01.c | 1 - testcases/kernel/syscalls/llistxattr/llistxattr02.c | 1 - testcases/kernel/syscalls/llistxattr/llistxattr03.c | 1 - testcases/kernel/syscalls/madvise/madvise01.c | 1 - testcases/kernel/syscalls/madvise/madvise02.c | 1 - testcases/kernel/syscalls/madvise/madvise05.c | 1 - testcases/kernel/syscalls/madvise/madvise06.c | 1 - testcases/kernel/syscalls/madvise/madvise07.c | 1 - testcases/kernel/syscalls/madvise/madvise08.c | 1 - testcases/kernel/syscalls/move_pages/move_pages12.c | 1 - testcases/kernel/syscalls/mq_notify/mq_notify01.c | 1 - testcases/kernel/syscalls/mq_open/mq_open01.c | 1 - .../kernel/syscalls/mq_timedreceive/mq_timedreceive01.c | 1 - testcases/kernel/syscalls/mq_unlink/mq_unlink01.c | 1 - testcases/kernel/syscalls/nice/nice01.c | 1 - testcases/kernel/syscalls/nice/nice02.c | 1 - testcases/kernel/syscalls/nice/nice03.c | 1 - testcases/kernel/syscalls/nice/nice04.c | 1 - testcases/kernel/syscalls/pause/pause01.c | 1 - testcases/kernel/syscalls/pipe/pipe01.c | 1 - testcases/kernel/syscalls/pipe/pipe02.c | 1 - testcases/kernel/syscalls/pipe/pipe03.c | 1 - testcases/kernel/syscalls/ppoll/ppoll01.c | 1 - testcases/kernel/syscalls/preadv/preadv01.c | 1 - testcases/kernel/syscalls/preadv/preadv02.c | 1 - testcases/kernel/syscalls/pwritev/pwritev01.c | 1 - testcases/kernel/syscalls/pwritev/pwritev02.c | 1 - testcases/kernel/syscalls/quotactl/quotactl01.c | 1 - testcases/kernel/syscalls/quotactl/quotactl02.c | 1 - testcases/kernel/syscalls/recvmsg/recvmsg02.c | 1 - testcases/kernel/syscalls/request_key/request_key01.c | 1 - testcases/kernel/syscalls/request_key/request_key02.c | 1 - testcases/kernel/syscalls/sbrk/sbrk03.c | 1 - .../syscalls/sched_setscheduler/sched_setscheduler03.c | 1 - testcases/kernel/syscalls/sendto/sendto02.c | 1 - testcases/kernel/syscalls/setpriority/setpriority01.c | 1 - testcases/kernel/syscalls/setpriority/setpriority02.c | 1 - testcases/kernel/syscalls/socket/socket01.c | 1 - testcases/kernel/syscalls/socket/socket02.c | 1 - testcases/kernel/syscalls/socketcall/socketcall01.c | 1 - testcases/kernel/syscalls/socketpair/socketpair01.c | 1 - testcases/kernel/syscalls/socketpair/socketpair02.c | 1 - testcases/kernel/syscalls/syscall/syscall01.c | 1 - testcases/kernel/syscalls/times/times03.c | 1 - testcases/kernel/syscalls/umask/umask01.c | 1 - testcases/kernel/syscalls/umount/umount01.c | 1 - testcases/kernel/syscalls/umount/umount02.c | 1 - testcases/kernel/syscalls/umount/umount03.c | 1 - testcases/kernel/syscalls/waitpid/waitpid06.c | 1 - testcases/kernel/syscalls/waitpid/waitpid07.c | 1 - testcases/kernel/syscalls/waitpid/waitpid08.c | 1 - testcases/kernel/syscalls/waitpid/waitpid09.c | 1 - testcases/kernel/syscalls/waitpid/waitpid10.c | 1 - testcases/kernel/syscalls/waitpid/waitpid11.c | 1 - testcases/kernel/syscalls/waitpid/waitpid12.c | 1 - testcases/kernel/syscalls/waitpid/waitpid13.c | 1 - testcases/kernel/syscalls/writev/writev01.c | 1 - testcases/kernel/syscalls/writev/writev07.c | 1 - testcases/network/netstress/netstress.c | 1 - testcases/network/nfs/nfs_stress/nfs05_make_tree.c | 1 - 137 files changed, 12 insertions(+), 140 deletions(-)
lib/newlib_tests/test01.c +0 -1
@@ -30,6 +30,5 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test01" , .test_all = do_test, };
lib/newlib_tests/test02.c +0 -1
@@ -43,7 +43,6 @@ static void do_test(unsigned int i) }static struct tst_test test = { - .tid ="test02" , .tcnt =2 , .test = do_test, };
lib/newlib_tests/test03.c +0 -1
@@ -28,6 +28,5 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test03" , .test_all = do_test, };
lib/newlib_tests/test04.c +0 -1
@@ -51,7 +51,6 @@ static void do_test(unsigned int i) }static struct tst_test test = { - .tid ="test04" , .tcnt =2 , .test = do_test, .setup = setup,
lib/newlib_tests/test05.c +0 -1
@@ -47,7 +47,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test05" , .test_all = do_test, .setup = setup, .cleanup = cleanup,
lib/newlib_tests/test06.c +0 -1
@@ -47,7 +47,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test06" , .test_all = do_test, .setup = setup, .cleanup = cleanup,
lib/newlib_tests/test07.c +0 -1
@@ -45,7 +45,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test07" , .test_all = do_test, .setup = setup, .cleanup = cleanup,
lib/newlib_tests/test08.c +0 -1
@@ -70,7 +70,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test08" , .test_all = do_test, .setup = setup, .cleanup = cleanup,
lib/newlib_tests/test09.c +0 -1
@@ -56,6 +56,5 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test09" , .test_all = do_test, };
lib/newlib_tests/test10.c +0 -1
@@ -27,7 +27,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test10" , .test_all = do_test, .timeout =1 , };
lib/newlib_tests/test11.c +0 -1
@@ -29,6 +29,5 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test11" , .test_all = do_test, };
lib/newlib_tests/test12.c +0 -1
@@ -26,7 +26,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test12" , .timeout =2 , .test_all = do_test, };
lib/newlib_tests/test13.c +0 -1
@@ -30,7 +30,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test13" , .timeout =1 , .forks_child =1 , .test_all = do_test,
lib/newlib_tests/test14.c +0 -1
@@ -39,7 +39,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="test14" , .test_all = do_test, .cleanup = cleanup, };
lib/newlib_tests/tst_device.c +0 -1
@@ -44,7 +44,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="tst_device" , .needs_tmpdir =1 , .needs_device =1 , .dev_min_size =300 ,
lib/newlib_tests/tst_res_hexd.c +0 -1
@@ -26,6 +26,5 @@ static void do_test(void) }static struct tst_test test = { - .tid ="tst_res_hexd" , .test_all = do_test, };
lib/newlib_tests/tst_safe_fileops.c +0 -1
@@ -35,6 +35,5 @@ static void do_test(void) }static struct tst_test test = { - .tid ="tst_safe_fileops" , .test_all = do_test, };
lib/tst_test.c +12 -4
@@ -616,16 +616,25 @@ static void copy_resources(void)TST_RESOURCE_COPY (NULL , tst_test->resource_files[i],NULL ); } +static void get_tid (char *argv[]) +{ +char *p; + + tst_test->tid = (p =strrchr (argv[0 ],'/' )) ? p+1 : argv[0 ]; +} +static struct tst_device tdev;struct tst_device *tst_device;static void do_setup (int argc,char *argv[]) { +parse_opts (argc, argv); +if (!tst_test)tst_brk (TBROK ,"No tests to run" );if (!tst_test->tid) -tst_brk (TBROK ,"No tid set in test structure" ); +get_tid (argv);if (!tst_test->test && !tst_test->test_all)tst_brk (TBROK ,"No test function speficied" );
@@ -653,8 +662,6 @@ static void do_setup(int argc, char *argv[]) tst_test->format_device =1 ; } -parse_opts (argc, argv); -setup_ipc ();if (needs_tmpdir () && !tst_tmpdir_created ())
@@ -858,10 +865,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self) lib_pid =getpid (); tst_test = self; -TCID = tst_test->tid;do_setup (argc, argv); +TCID = tst_test->tid; +SAFE_SIGNAL (SIGALRM , alarm_handler);SAFE_SIGNAL (SIGUSR1 , heartbeat_handler);
testcases/kernel/mem/mtest06/mmap3.c +0 -1
@@ -205,7 +205,6 @@ static struct tst_option options[] = { };static struct tst_test test = { - .tid ="mmap3" , .options = options, .needs_tmpdir =1 , .setup = setup,
testcases/kernel/security/dirtyc0w/dirtyc0w.c +0 -1
@@ -103,7 +103,6 @@ void dirtyc0w_test(void) }static struct tst_test test = { - .tid ="dirtyc0w" , .needs_tmpdir =1 , .forks_child =1 , .needs_root =1 ,
testcases/kernel/syscalls/access/access01.c +0 -1
@@ -357,7 +357,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="access01" , .needs_tmpdir =1 , .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/access/access02.c +0 -1
@@ -195,7 +195,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="access02" , .tcnt =ARRAY_SIZE (tcases), .needs_tmpdir =1 , .needs_root =1 ,
testcases/kernel/syscalls/access/access03.c +0 -1
@@ -94,7 +94,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="access03" , .tcnt =ARRAY_SIZE (tcases), .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/access/access04.c +0 -1
@@ -121,7 +121,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="access04" , .tcnt =ARRAY_SIZE (tcases), .needs_tmpdir =1 , .needs_root =1 ,
testcases/kernel/syscalls/add_key/add_key01.c +0 -1
@@ -49,6 +49,5 @@ static void verify_add_key(void) }static struct tst_test test = { - .tid ="add_key01" , .test_all = verify_add_key, };
testcases/kernel/syscalls/add_key/add_key02.c +0 -1
@@ -69,7 +69,6 @@ static void verify_add_key(unsigned int i) }static struct tst_test test = { - .tid ="add_key02" , .tcnt =ARRAY_SIZE (tcases), .test = verify_add_key, };
testcases/kernel/syscalls/alarm/alarm06.c +0 -1
@@ -76,7 +76,6 @@ static void verify_alarm(void) }static struct tst_test test = { - .tid ="alarm06" , .setup = setup, .test_all = verify_alarm, };
testcases/kernel/syscalls/clock_getres/clock_getres01.c +0 -1
@@ -80,7 +80,6 @@ static void do_test(unsigned int i) }static struct tst_test test = { - .tid ="clock_getres01" , .test = do_test, .tcnt =ARRAY_SIZE (tcase), };
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +0 -1
@@ -178,7 +178,6 @@ static void do_test(unsigned int i) }static struct tst_test test = { - .tid ="clock_nanosleep01" , .tcnt =ARRAY_SIZE (tcase), .test = do_test, .setup = setup,
testcases/kernel/syscalls/clock_nanosleep2/clock_nanosleep2_01.c +0 -1
@@ -57,6 +57,5 @@ static void verify_clock_nanosleep2(void) }static struct tst_test test = { - .tid ="clock_nanosleep2_01" , .test_all = verify_clock_nanosleep2, };
testcases/kernel/syscalls/creat/creat01.c +0 -1
@@ -85,7 +85,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="creat01" , .tcnt =2 , .test = verify_creat, .needs_tmpdir =1 ,
testcases/kernel/syscalls/creat/creat03.c +0 -1
@@ -68,7 +68,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="creat03" , .test_all = verify_creat, .needs_tmpdir =1 , .setup = setup,
testcases/kernel/syscalls/creat/creat04.c +0 -1
@@ -82,7 +82,6 @@ void setup(void) }static struct tst_test test = { - .tid ="creat04" , .tcnt =ARRAY_SIZE (tcases), .test = verify_creat, .needs_tmpdir =1 ,
testcases/kernel/syscalls/creat/creat05.c +0 -1
@@ -87,7 +87,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="creat05" , .test_all = verify_creat, .needs_tmpdir =1 , .setup = setup,
testcases/kernel/syscalls/creat/creat06.c +0 -1
@@ -162,7 +162,6 @@ static void test6_cleanup(void) }static struct tst_test test = { - .tid ="creat06" , .tcnt =ARRAY_SIZE (tcases), .test = verify_creat, .needs_root =1 ,
testcases/kernel/syscalls/creat/creat07.c +0 -1
@@ -68,7 +68,6 @@ static const char *const resource_files[] = { };static struct tst_test test = { - .tid ="creat07" , .test_all = verify_creat, .needs_checkpoints =1 , .forks_child =1 ,
testcases/kernel/syscalls/epoll_create1/epoll_create1_01.c +0 -1
@@ -62,7 +62,6 @@ static void verify_epoll_create1(void) }static struct tst_test test = { - .tid ="epoll_create1_01" , .min_kver ="2.6.27" , .test_all = verify_epoll_create1, };
testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c +0 -1
@@ -150,7 +150,6 @@ static void verify_epoll_ctl(void) }static struct tst_test test = { - .tid ="epoll_ctl01" , .setup = setup, .cleanup = cleanup, .test_all = verify_epoll_ctl,
testcases/kernel/syscalls/epoll_ctl/epoll_ctl02.c +0 -1
@@ -117,7 +117,6 @@ static void verify_epoll_ctl(unsigned int n) }static struct tst_test test = { - .tid ="epoll_ctl02" , .tcnt =ARRAY_SIZE (tcases), .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/fcntl/fcntl02.c +0 -1
@@ -85,7 +85,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="fcntl02" , .needs_tmpdir =1 , .test = verify_fcntl, .tcnt =ARRAY_SIZE (min_fds),
testcases/kernel/syscalls/fcntl/fcntl03.c +0 -1
@@ -74,7 +74,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="fcntl03" , .needs_tmpdir =1 , .test_all = verify_fcntl, .setup = setup,
testcases/kernel/syscalls/fcntl/fcntl04.c +0 -1
@@ -80,7 +80,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="fcntl04" , .needs_tmpdir =1 , .test_all = verify_fcntl, .setup = setup,
testcases/kernel/syscalls/fcntl/fcntl34.c +0 -1
@@ -143,7 +143,6 @@ static void test01(void) }static struct tst_test test = { - .tid ="fcntl34" , .min_kver ="3.15.0" , .needs_tmpdir =1 , .test_all = test01,
testcases/kernel/syscalls/flistxattr/flistxattr01.c +0 -1
@@ -90,7 +90,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="flistxattr01" , .needs_tmpdir =1 , .needs_root =1 , .test_all = verify_flistxattr,
testcases/kernel/syscalls/flistxattr/flistxattr02.c +0 -1
@@ -92,7 +92,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="flistxattr02" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_flistxattr,
testcases/kernel/syscalls/flistxattr/flistxattr03.c +0 -1
@@ -83,7 +83,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="flistxattr03" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_flistxattr,
testcases/kernel/syscalls/getcwd/getcwd01.c +0 -1
@@ -80,7 +80,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="getcwd01" , .setup = setup, .tcnt =ARRAY_SIZE (tcases), .test = verify_getcwd
testcases/kernel/syscalls/getcwd/getcwd02.c +0 -1
@@ -80,7 +80,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="getcwd02" , .setup = setup, .tcnt =ARRAY_SIZE (tcases), .test = verify_getcwd
testcases/kernel/syscalls/getcwd/getcwd03.c +0 -1
@@ -98,7 +98,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="getcwd03" , .needs_tmpdir =1 , .setup = setup, .test_all = verify_getcwd
testcases/kernel/syscalls/getcwd/getcwd04.c +0 -1
@@ -107,7 +107,6 @@ static void do_child(void) }static struct tst_test test = { - .tid ="getcwd04" , .setup = setup, .test_all = verify_getcwd, .needs_tmpdir =1 ,
testcases/kernel/syscalls/getpriority/getpriority01.c +0 -1
@@ -63,7 +63,6 @@ static void verify_getpriority(unsigned int n) }static struct tst_test test = { - .tid ="getpriority01" , .tcnt =ARRAY_SIZE (tcases), .test = verify_getpriority, };
testcases/kernel/syscalls/getpriority/getpriority02.c +0 -1
@@ -71,7 +71,6 @@ static void verify_getpriority(unsigned int n) }static struct tst_test test = { - .tid ="getpriority02" , .tcnt =ARRAY_SIZE (tcases), .test = verify_getpriority, };
testcases/kernel/syscalls/getrandom/getrandom01.c +0 -1
@@ -46,7 +46,6 @@ static void verify_getrandom(unsigned int n) }static struct tst_test test = { - .tid ="getrandom01" , .tcnt =ARRAY_SIZE (modes), .test = verify_getrandom, };
testcases/kernel/syscalls/getrandom/getrandom02.c +0 -1
@@ -73,7 +73,6 @@ static void verify_getrandom(unsigned int n) }static struct tst_test test = { - .tid ="getrandom02" , .tcnt =ARRAY_SIZE (modes), .test = verify_getrandom, };
testcases/kernel/syscalls/getrandom/getrandom03.c +0 -1
@@ -63,7 +63,6 @@ static void verify_getrandom(unsigned int n) }static struct tst_test test = { - .tid ="getrandom03" , .tcnt =ARRAY_SIZE (sizes), .test = verify_getrandom, };
testcases/kernel/syscalls/getrandom/getrandom04.c +0 -1
@@ -55,6 +55,5 @@ static void verify_getrandom(void) }static struct tst_test test = { - .tid ="getrandom04" , .test_all = verify_getrandom, };
testcases/kernel/syscalls/gettimeofday/gettimeofday02.c +0 -1
@@ -103,7 +103,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="gettimeofday02" , .setup = setup, .options = options, .test_all = verify_gettimeofday,
testcases/kernel/syscalls/getxattr/getxattr04.c +0 -1
@@ -118,7 +118,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="getxattr04" , .needs_tmpdir =1 , .needs_root =1 , .mount_device =1 ,
testcases/kernel/syscalls/ioctl/ioctl04.c +0 -1
@@ -93,7 +93,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="ioctl04" , .needs_tmpdir =1 , .format_device =1 , .setup = setup,
testcases/kernel/syscalls/ioctl/ioctl05.c +0 -1
@@ -78,7 +78,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="ioctl05" , .needs_device =1 , .cleanup = cleanup, .test_all = verify_ioctl,
testcases/kernel/syscalls/ioctl/ioctl06.c +0 -1
@@ -63,7 +63,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="ioctl06" , .needs_device =1 , .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/ipc/msgget/msgget01.c +0 -1
@@ -71,7 +71,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="msgget01" , .setup = setup, .cleanup = cleanup, .test_all = verify_msgget,
testcases/kernel/syscalls/ipc/msgget/msgget02.c +0 -1
@@ -109,7 +109,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="msgget02" , .needs_tmpdir =1 , .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/ipc/msgget/msgget03.c +0 -1
@@ -88,7 +88,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="msgget03" , .needs_tmpdir =1 , .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c +0 -1
@@ -70,7 +70,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="msgsnd01" , .setup = setup, .cleanup = cleanup, .test_all = verify_msgsnd,
testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c +0 -1
@@ -122,7 +122,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="msgsnd02" , .needs_tmpdir =1 , .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c +0 -1
@@ -114,7 +114,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="msgsnd05" , .needs_tmpdir =1 , .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c +0 -1
@@ -88,7 +88,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="msgsnd06" , .needs_tmpdir =1 , .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/kcmp/kcmp01.c +0 -1
@@ -111,7 +111,6 @@ static void verify_kcmp(unsigned int n) }static struct tst_test test = { - .tid ="kcmp01" , .tcnt =ARRAY_SIZE (test_cases), .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/kcmp/kcmp02.c +0 -1
@@ -103,7 +103,6 @@ static void verify_kcmp(unsigned int n) }static struct tst_test test = { - .tid ="kcmp02" , .tcnt =ARRAY_SIZE (test_cases), .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/kcmp/kcmp03.c +0 -1
@@ -95,7 +95,6 @@ static void verify_kcmp(unsigned int n) }static struct tst_test test = { - .tid ="kcmp03" , .tcnt =ARRAY_SIZE (tcases), .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/keyctl/keyctl02.c +0 -1
@@ -99,7 +99,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="keyctl02" , .test_all = do_test, };
testcases/kernel/syscalls/lgetxattr/lgetxattr01.c +0 -1
@@ -105,7 +105,6 @@ next: }static struct tst_test test = { - .tid ="lgetxattr01" , .needs_tmpdir =1 , .needs_root =1 , .test_all = verify_lgetxattr,
testcases/kernel/syscalls/lgetxattr/lgetxattr02.c +0 -1
@@ -95,7 +95,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="lgetxattr02" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_lgetxattr,
testcases/kernel/syscalls/listxattr/listxattr01.c +0 -1
@@ -83,7 +83,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="listxattr01" , .needs_tmpdir =1 , .needs_root =1 , .test_all = verify_listxattr,
testcases/kernel/syscalls/listxattr/listxattr02.c +0 -1
@@ -96,7 +96,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="listxattr02" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_listxattr,
testcases/kernel/syscalls/listxattr/listxattr03.c +0 -1
@@ -78,7 +78,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="listxattr03" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_listxattr,
testcases/kernel/syscalls/llistxattr/llistxattr01.c +0 -1
@@ -93,7 +93,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="llistxattr01" , .needs_tmpdir =1 , .needs_root =1 , .test_all = verify_llistxattr,
testcases/kernel/syscalls/llistxattr/llistxattr02.c +0 -1
@@ -97,7 +97,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="llistxattr02" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_llistxattr,
testcases/kernel/syscalls/llistxattr/llistxattr03.c +0 -1
@@ -77,7 +77,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="llistxattr03" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_llistxattr,
testcases/kernel/syscalls/madvise/madvise01.c +0 -1
@@ -120,7 +120,6 @@ static void verify_madvise(unsigned int i) }static struct tst_test test = { - .tid ="madvise01" , .tcnt =ARRAY_SIZE (tcases), .test = verify_madvise, .needs_tmpdir =1 ,
testcases/kernel/syscalls/madvise/madvise02.c +0 -1
@@ -180,7 +180,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="madvise02" , .tcnt =ARRAY_SIZE (tcases), .test = advice_test, .needs_tmpdir =1 ,
testcases/kernel/syscalls/madvise/madvise05.c +0 -1
@@ -55,7 +55,6 @@ static void verify_madvise(void) }static struct tst_test test = { - .tid ="madvise05" , .min_kver ="3.9.0" , .test_all = verify_madvise, };
testcases/kernel/syscalls/madvise/madvise06.c +0 -1
@@ -173,7 +173,6 @@ static void test_advice_willneed(void) }static struct tst_test test = { - .tid ="madvise06" , .test_all = test_advice_willneed, .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/madvise/madvise07.c +0 -1
@@ -93,7 +93,6 @@ static void run(unsigned int n) }static struct tst_test test = { - .tid ="madvise07" , .test = run, .tcnt =ARRAY_SIZE (maptypes), .min_kver ="2.6.31" ,
testcases/kernel/syscalls/madvise/madvise08.c +0 -1
@@ -225,7 +225,6 @@ static void run(unsigned int test_nr) }static struct tst_test test = { - .tid ="madvise08" , .test = run, .tcnt =2 , .setup = setup,
testcases/kernel/syscalls/move_pages/move_pages12.c +0 -1
@@ -159,7 +159,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="move_pages12" , .min_kver ="2.6.32" , .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/mq_notify/mq_notify01.c +0 -1
@@ -243,7 +243,6 @@ static struct tst_option options[] = { };static struct tst_test test = { - .tid ="mq_notify01" , .tcnt =ARRAY_SIZE (tcase), .test = do_test, .options = options,
testcases/kernel/syscalls/mq_open/mq_open01.c +0 -1
@@ -298,7 +298,6 @@ CLEANUP: }static struct tst_test test = { - .tid ="mq_open01" , .tcnt =ARRAY_SIZE (tcase), .test = do_test, .needs_root =1 ,
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +0 -1
@@ -312,7 +312,6 @@ static void do_test(unsigned int i) }static struct tst_test test = { - .tid ="mq_timedreceive01" , .tcnt =ARRAY_SIZE (tcase), .test = do_test, .setup = setup,
testcases/kernel/syscalls/mq_unlink/mq_unlink01.c +0 -1
@@ -124,7 +124,6 @@ EXIT: }static struct tst_test test = { - .tid ="mq_unlink01" , .tcnt =ARRAY_SIZE (tcase), .test = do_test, .needs_root =1 ,
testcases/kernel/syscalls/nice/nice01.c +0 -1
@@ -66,7 +66,6 @@ static void verify_nice(void) }static struct tst_test test = { - .tid ="nice01" , .test_all = verify_nice, .needs_root =1 , };
testcases/kernel/syscalls/nice/nice02.c +0 -1
@@ -64,6 +64,5 @@ static void verify_nice(void) }static struct tst_test test = { - .tid ="nice02" , .test_all = verify_nice, };
testcases/kernel/syscalls/nice/nice03.c +0 -1
@@ -71,7 +71,6 @@ static void verify_nice(void) }static struct tst_test test = { - .tid ="nice03" , .forks_child =1 , .test_all = verify_nice, };
testcases/kernel/syscalls/nice/nice04.c +0 -1
@@ -56,7 +56,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="nice04" , .setup = setup, .test_all = verify_nice, .needs_root =1 ,
testcases/kernel/syscalls/pause/pause01.c +0 -1
@@ -61,7 +61,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="pause01" , .forks_child =1 , .needs_checkpoints =1 , .test_all = do_test,
testcases/kernel/syscalls/pipe/pipe01.c +0 -1
@@ -61,6 +61,5 @@ static void verify_pipe(void) }static struct tst_test test = { - .tid ="pipe01" , .test_all = verify_pipe, };
testcases/kernel/syscalls/pipe/pipe02.c +0 -1
@@ -101,7 +101,6 @@ static void verify_pipe(void) }static struct tst_test test = { - .tid ="pipe02" , .forks_child =1 , .needs_checkpoints =1 , .test_all = verify_pipe,
testcases/kernel/syscalls/pipe/pipe03.c +0 -1
@@ -59,6 +59,5 @@ static void verify_pipe(void) }static struct tst_test test = { - .tid ="pipe03" , .test_all = verify_pipe, };
testcases/kernel/syscalls/ppoll/ppoll01.c +0 -1
@@ -268,7 +268,6 @@ static void do_test(unsigned int i) }static struct tst_test test = { - .tid ="ppoll01" , .tcnt =ARRAY_SIZE (tcase), .test = do_test, .setup = setup,
testcases/kernel/syscalls/preadv/preadv01.c +0 -1
@@ -113,7 +113,6 @@ void cleanup(void) }static struct tst_test test = { - .tid ="preadv01" , .tcnt =ARRAY_SIZE (tcases), .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/preadv/preadv02.c +0 -1
@@ -130,7 +130,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="preadv02" , .tcnt =ARRAY_SIZE (tcases), .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/pwritev/pwritev01.c +0 -1
@@ -109,7 +109,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="pwritev01" , .tcnt =ARRAY_SIZE (tcases), .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/pwritev/pwritev02.c +0 -1
@@ -121,7 +121,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="pwritev02" , .tcnt =ARRAY_SIZE (tcases), .setup = setup, .cleanup = cleanup,
testcases/kernel/syscalls/quotactl/quotactl01.c +0 -1
@@ -207,7 +207,6 @@ static void verify_quota(unsigned int n) }static struct tst_test test = { - .tid ="quotactl01" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_quota,
testcases/kernel/syscalls/quotactl/quotactl02.c +0 -1
@@ -154,7 +154,6 @@ static void verify_quota(unsigned int n) }static struct tst_test test = { - .tid ="quotactl02" , .needs_tmpdir =1 , .needs_root =1 , .test = verify_quota,
testcases/kernel/syscalls/recvmsg/recvmsg02.c +0 -1
@@ -106,7 +106,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="recvmsg02" , .min_kver ="2.6.27" , .test_all = verify_recvmsg, .cleanup = cleanup,
testcases/kernel/syscalls/request_key/request_key01.c +0 -1
@@ -61,7 +61,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="request_key01" , .setup = setup, .test_all = verify_request_key, };
testcases/kernel/syscalls/request_key/request_key02.c +0 -1
@@ -107,7 +107,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="request_key02" , .setup = setup, .tcnt =ARRAY_SIZE (tcases), .test = verify_request_key,
testcases/kernel/syscalls/sbrk/sbrk03.c +0 -1
@@ -76,6 +76,5 @@ static void sbrk_test(void) }static struct tst_test test = { - .tid ="sbrk03" , .test_all = sbrk_test, };
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler03.c +0 -1
@@ -171,7 +171,6 @@ static void do_test(unsigned int i) }static struct tst_test test = { - .tid ="sched_setscheduler03" , .tcnt =ARRAY_SIZE (cases), .test = do_test, .setup = setup,
testcases/kernel/syscalls/sendto/sendto02.c +0 -1
@@ -84,7 +84,6 @@ static void verify_sendto(void) }static struct tst_test test = { - .tid ="sendto02" , .setup = setup, .cleanup = cleanup, .test_all = verify_sendto,
testcases/kernel/syscalls/setpriority/setpriority01.c +0 -1
@@ -130,7 +130,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="setpriority01" , .tcnt =ARRAY_SIZE (tcases), .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/setpriority/setpriority02.c +0 -1
@@ -121,7 +121,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="setpriority02" , .tcnt =ARRAY_SIZE (tcases), .needs_root =1 , .forks_child =1 ,
testcases/kernel/syscalls/socket/socket01.c +0 -1
@@ -98,7 +98,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="socket01" , .tcnt =ARRAY_SIZE (tdat), .setup = setup, .test = verify_socket
testcases/kernel/syscalls/socket/socket02.c +0 -1
@@ -79,7 +79,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="socket02" , .tcnt =ARRAY_SIZE (tcases), .test = verify_socket, .min_kver ="2.6.27" ,
testcases/kernel/syscalls/socketcall/socketcall01.c +0 -1
@@ -61,7 +61,6 @@ void verify_socketcall(unsigned int i) }static struct tst_test test = { - .tid ="socketcall01" , .test = verify_socketcall, .tcnt =ARRAY_SIZE (TC ), .needs_root =1 ,
testcases/kernel/syscalls/socketpair/socketpair01.c +0 -1
@@ -102,7 +102,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="socketpair01" , .tcnt =ARRAY_SIZE (tdat), .setup = setup, .test = verify_socketpair
testcases/kernel/syscalls/socketpair/socketpair02.c +0 -1
@@ -92,7 +92,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="socketpair02" , .tcnt =ARRAY_SIZE (tcases), .test = verify_socketpair, .min_kver ="2.6.27" ,
testcases/kernel/syscalls/syscall/syscall01.c +0 -1
@@ -88,7 +88,6 @@ static void verify_syscall(unsigned int n) }static struct tst_test test = { - .tid ="syscall01" , .test = verify_syscall, .tcnt =ARRAY_SIZE (tcases), };
testcases/kernel/syscalls/times/times03.c +0 -1
@@ -207,7 +207,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="times03" , .setup = setup, .forks_child =1 , .test_all = do_test,
testcases/kernel/syscalls/umask/umask01.c +0 -1
@@ -71,7 +71,6 @@ static void verify_umask(void) }static struct tst_test test = { - .tid ="umask01" , .test_all = verify_umask, .needs_tmpdir =1 , };
testcases/kernel/syscalls/umount/umount01.c +0 -1
@@ -65,7 +65,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="umount01" , .needs_root =1 , .needs_tmpdir =1 , .format_device =1 ,
testcases/kernel/syscalls/umount/umount02.c +0 -1
@@ -93,7 +93,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="umount02" , .tcnt =ARRAY_SIZE (tcases), .needs_root =1 , .needs_tmpdir =1 ,
testcases/kernel/syscalls/umount/umount03.c +0 -1
@@ -70,7 +70,6 @@ static void cleanup(void) }static struct tst_test test = { - .tid ="umount03" , .needs_root =1 , .needs_tmpdir =1 , .format_device =1 ,
testcases/kernel/syscalls/waitpid/waitpid06.c +0 -1
@@ -55,7 +55,6 @@ static void do_child_1(void) }static struct tst_test test = { - .tid ="waitpid06" , .forks_child =1 , .needs_checkpoints =1 , .setup = waitpid_setup,
testcases/kernel/syscalls/waitpid/waitpid07.c +0 -1
@@ -60,7 +60,6 @@ static void do_child_1(void) }static struct tst_test test = { - .tid ="waitpid07" , .forks_child =1 , .needs_checkpoints =1 , .setup = waitpid_setup,
testcases/kernel/syscalls/waitpid/waitpid08.c +0 -1
@@ -63,7 +63,6 @@ static void do_child_1(void) }static struct tst_test test = { - .tid ="waitpid08" , .forks_child =1 , .needs_checkpoints =1 , .setup = waitpid_setup,
testcases/kernel/syscalls/waitpid/waitpid09.c +0 -1
@@ -170,7 +170,6 @@ static void waitpid09_test(unsigned int id) }static struct tst_test test = { - .tid ="waitpid09" , .forks_child =1 , .needs_checkpoints =1 , .test = waitpid09_test,
testcases/kernel/syscalls/waitpid/waitpid10.c +0 -1
@@ -112,7 +112,6 @@ static void do_sleep(void) }static struct tst_test test = { - .tid ="waitpid10" , .forks_child =1 , .needs_checkpoints =1 , .setup = waitpid_setup,
testcases/kernel/syscalls/waitpid/waitpid11.c +0 -1
@@ -61,7 +61,6 @@ static void do_child_1(void) }static struct tst_test test = { - .tid ="waitpid11" , .forks_child =1 , .needs_checkpoints =1 , .setup = waitpid_setup,
testcases/kernel/syscalls/waitpid/waitpid12.c +0 -1
@@ -71,7 +71,6 @@ static void do_child_1(void) }static struct tst_test test = { - .tid ="waitpid12" , .forks_child =1 , .needs_checkpoints =1 , .setup = waitpid_setup,
testcases/kernel/syscalls/waitpid/waitpid13.c +0 -1
@@ -71,7 +71,6 @@ static void do_child_1(void) }static struct tst_test test = { - .tid ="waitpid13" , .forks_child =1 , .needs_checkpoints =1 , .setup = waitpid_setup,
testcases/kernel/syscalls/writev/writev01.c +0 -1
@@ -145,7 +145,6 @@ static void test_writev(unsigned int i) }static struct tst_test test = { - .tid ="writev01" , .needs_tmpdir =1 , .setup = setup, .test = test_writev,
testcases/kernel/syscalls/writev/writev07.c +0 -1
@@ -144,7 +144,6 @@ static void setup(void) }static struct tst_test test = { - .tid ="writev07" , .needs_tmpdir =1 , .setup = setup, .test_all = test_writev,
testcases/network/netstress/netstress.c +0 -1
@@ -752,7 +752,6 @@ static struct tst_option options[] = { };static struct tst_test test = { - .tid ="netstress" , .test_all = do_test, .setup = setup, .cleanup = cleanup,
testcases/network/nfs/nfs_stress/nfs05_make_tree.c +0 -1
@@ -226,7 +226,6 @@ static void do_test(void) }static struct tst_test test = { - .tid ="nfs05_make_tree" , .options = opts, .test_all = do_test, .setup = setup,
Signature · 1 line
2.9.3
PATCH 1/1 ltp: detect the test id automatically
Hi!
lib/tst_test.c static void copy_resources(void) · line 624
Quoted 6 lines
lib/tst_test.c +6
-0+static void get_tid (char *argv[]) +{ +char *p; + + tst_test->tid = (p =strrchr (argv[0 ],'/' )) ? p+1 : argv[0 ]; +}
This is interesting idea, but this oneliner is ugly and does not work when you execute the testcase by full path, i.e. /opt/ltp/testcases/bin/foo01 would end up with opt/ltp/testcases/bin/foo01 in tid.
And I wonder if we can avoid runtime detection, which is always tricky. Maybe we can just do:
struct tst_test test = {
.id = __FILE__,
};And strip the .c suffix in the test library if present. That way we would avoid this kind of copy&paste errors.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 ltp: detect the test id automatically
Quoted 12 lines · Cyril Hrubis
Hi!
lib/tst_test.c static void copy_resources(void) · line 624
Quoted 6 lines
lib/tst_test.c +6
-0+static void get_tid (char *argv[]) +{ +char *p; + + tst_test->tid = (p =strrchr (argv[0 ],'/' )) ? p+1 : argv[0 ]; +}This is interesting idea, but this oneliner is ugly and does not work when you execute the testcase by full path, i.e.
/opt/ltp/testcases/bin/foo01would end up with opt/ltp/testcases/bin/foo01 in tid.
Really?
This words is cut from strrchr() Manual page.
"DESCRIPTION
The strrchr() function returns a pointer to the last occurrence
of the character c in the
string s.
"
And it does work while testing from this simple C program:
$ cat get_filename.c
#include <stdio.h>
#include <string.h>
void main(int argc, char *argv[])
{
char *f, *p ;
f = (p=strrchr(argv[0],'/')) ? p+1 : argv[0];
printf("file name = %s\n", f);
}$ gcc get_filename.c -o get_filename
$ ./testcases/kernel/syscalls/ioctl/get_filename file name = get_filename
Actually I have tested some kind of situation and compile the whole LTP with this change, I didn't find any abnormal things which involved by this path :)
Quoted 10 lines
And I wonder if we can avoid runtime detection, which is always tricky. Maybe we can just do:
struct tst_test test = { .id = __FILE__, };And strip the .c suffix in the test library if present. That way we would avoid this kind of copy&paste errors.
Hmm, I have no objection with this method, but it seems still need the author to write ".tid = __FILE__" each time. To strip the .c suffix is also need additional work in some place.
Signature · 3 lines
Regards, Li Wang Email: [email protected]
PATCH 1/1 ltp: detect the test id automatically
Hi!
Quoted 14 lines
Quoted 11 lines
lib/tst_test.c static void copy_resources(void) · line 624
Quoted 6 lines
lib/tst_test.c +6
-0+static void get_tid (char *argv[]) +{ +char *p; + + tst_test->tid = (p =strrchr (argv[0 ],'/' )) ? p+1 : argv[0 ]; +}This is interesting idea, but this oneliner is ugly and does not work when you execute the testcase by full path, i.e.
/opt/ltp/testcases/bin/foo01would end up with opt/ltp/testcases/bin/foo01 in tid.Really?
Quoted 8 lines
This words is cut from
strrchr()Manual page."DESCRIPTION
The
strrchr()function returns a pointer to the last occurrence
of the character c in the
string s.
"
Ah, I was blind and missed the r in the middle, indeed the strrchr() returns the last occurence.
Quoted 3 lines
Actually I have tested some kind of situation and compile the whole LTP with this change, I didn't find any abnormal things which involved by this path :)
It will work fine I guess. But the standard allows argv[0] to be empty string though and you can pass any string as argv[0] to the execve() as well.
So if we go this way we should add sanity checks if there is something sensible in the argv[0].
Quoted 7 lines
Quoted 7 lines
And I wonder if we can avoid runtime detection, which is always tricky. Maybe we can just do:
struct tst_test test = { .id = __FILE__, };
Quoted 6 lines
Quoted 2 lines
And strip the .c suffix in the test library if present. That way we would avoid this kind of copy&paste errors.
Hmm, I have no objection with this method, but it seems still need the author to write ".tid =
__FILE__" each time. To strip the .c suffix is also need additional work in some place.
I think that this is just a little more robust solution, but yes it's less elegant one.
Anyway looking at the code the tid is only used when creating temporary directory/shm so that it's clear which testcase these global resources belongs to. So as far as we can easily identify which test has created the temp directory given it's name it's fine.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 ltp: detect the test id automatically
Quoted 27 lines · Cyril Hrubis
Hi!
Quoted 14 lines
Quoted 11 lines
lib/tst_test.c static void copy_resources(void) · line 624
Quoted 6 lines
lib/tst_test.c +6
-0+static void get_tid (char *argv[]) +{ +char *p; + + tst_test->tid = (p =strrchr (argv[0 ],'/' )) ? p+1 : argv[0 ]; +}This is interesting idea, but this oneliner is ugly and does not work when you execute the testcase by full path, i.e.
/opt/ltp/testcases/bin/foo01would end up with opt/ltp/testcases/bin/foo01 in tid.Really?
Quoted 8 lines
This words is cut from
strrchr()Manual page."DESCRIPTION
The
strrchr()function returns a pointer to the last occurrence
of the character c in the
string s.
"Ah, I was blind and missed the r in the middle, indeed the
strrchr()returns the last occurence.
Quoted 7 lines
Quoted 3 lines
Actually I have tested some kind of situation and compile the whole LTP with this change, I didn't find any abnormal things which involved by this path :)
It will work fine I guess. But the standard allows argv[0] to be empty string though and you can pass any string as argv[0] to the
execve()as well.
Yes! we should make sure that argv[0] is neither 'NULL' nor point to an empty string before assigned to tst_test->tid. And then no matter what the string it is like, we only using it as a string. I think that would be safe for LTP.
Method_1:
-------------
$cat tst_test.c
static void get_tid(char *argv[])
{
char *p;
int chk = 1;
chk = argv[0] == NULL ? 0 : strcmp(argv[0], "\0");
if (chk == 0)
tst_brk(TBROK, "No tid set in test structure");
tst_test->tid = (p = strrchr(argv[0], '/')) ? p+1 : argv[0];
}static void do_setup(int argc, char *argv[])
{
...
if (!tst_test->tid)
get_tid(argv);...
}
Quoted 14 lines
So if we go this way we should add sanity checks if there is something sensible in the argv[0].
Quoted 10 lines
Quoted 9 lines
And I wonder if we can avoid runtime detection, which is always tricky. Maybe we can just do:
struct tst_test test = { .id = __FILE__, };And strip the .c suffix in the test library if present. That way we would avoid this kind of copy&paste errors.
Quoted 6 lines
Quoted 3 lines
Hmm, I have no objection with this method, but it seems still need the author to write ".tid =
__FILE__" each time. To strip the .c suffix is also need additional work in some place.I think that this is just a little more robust solution, but yes it's less elegant one.
Not sure if I understand this way correctly, something achieved as:
Method_2:
------------
$ cat tst_test.h
struct tst_test {
char tid[128];...
}
$ cat tst_test.c
static void get_tid(void)
{
char *p;
p = (strrchr(tst_test->tid, '.'));
if (p)
*p = '\0';
}static void do_setup(int argc, char *argv[])
{
if (tst_test->tid[0] == '\0')
tst_brk(TBROK, "No tid set in test structure");
else
get_tid();...
}
$ cat ioctl06.c
static struct tst_test test = {
.tid = __FILE__,...
}
Quoted 6 lines
Anyway looking at the code the tid is only used when creating temporary directory/shm so that it's clear which testcase these global resources belongs to. So as far as we can easily identify which test has created the temp directory given it's name it's fine.
What we do to get tid is early than create a temp directory. Looking at function setup_ipc(), no matter if we need temp dir or not, the tst_test->tid should be available there. So this is a general demand to ltp testcase not specified.
I drafted above two methods for comparison, I prefer to go method_1, because it makes LTP authors no need to consider ".tid=" any more. what do you think?
Signature · 3 lines
Regards, Li Wang Email: [email protected]
PATCH 1/1 ltp: detect the test id automatically
Hi!
Quoted 21 lines
Quoted 10 lines
Ah, I was blind and missed the r in the middle, indeed the
strrchr()returns the last occurence.Quoted 3 lines
Actually I have tested some kind of situation and compile the whole LTP with this change, I didn't find any abnormal things which involved by this path :)
It will work fine I guess. But the standard allows argv[0] to be empty string though and you can pass any string as argv[0] to the
execve()as well.Yes! we should make sure that argv[0] is neither 'NULL' nor point to an empty string before assigned to
tst_test->tid. And then no matter what the string it is like, we only using it as a string. I think that would be safe for LTP.
Method_1:
-------------
$cattst_test.c
Quoted 8 lines
static void
get_tid(char *argv[]){ char *p; int chk = 1; chk = argv[0] == NULL ? 0 : strcmp(argv[0], "\0"); if (chk == 0) tst_brk(TBROK, "No tid set in test structure");
Well, this is messy and unnecessarily uses strcmp where simple comparsion would do. Also the error message is not really describing the problem. So this should rather be something as:
if (!argv[0] || !argv[0][0]) {
tst_brk(TBROK,
"No tid set in test structure and argv[0] is empty");
}Quoted 9 lines
tst_test->tid = (p = strrchr(argv[0], '/')) ? p+1 : argv[0]; }static void
do_setup(int argc, char *argv[])
{
...if (!tst_test->tid) get_tid(argv);
This should be called set_tid(), get_tid() would probably mean that the function returns a pointer to the string.
Quoted 58 lines
...
}Quoted 14 lines
So if we go this way we should add sanity checks if there is something sensible in the argv[0].
Quoted 10 lines
Quoted 9 lines
And I wonder if we can avoid runtime detection, which is always tricky. Maybe we can just do:
struct tst_test test = { .id = __FILE__, };And strip the .c suffix in the test library if present. That way we would avoid this kind of copy&paste errors.
Quoted 6 lines
Quoted 3 lines
Hmm, I have no objection with this method, but it seems still need the author to write ".tid =
__FILE__" each time. To strip the .c suffix is also need additional work in some place.I think that this is just a little more robust solution, but yes it's less elegant one.
Not sure if I understand this way correctly, something achieved as:
Method_2:
------------$ cat tst_test.hstruct tst_test { char tid[128];...
}$ cat tst_test.cstatic void
get_tid(void){ char *p; p = (strrchr(tst_test->tid, '.')); if (p) *p = '\0'; }static void
do_setup(int argc, char *argv[]){ if (tst_test->tid[0] == '\0') tst_brk(TBROK, "No tid set in test structure"); else get_tid();...
}
Quoted 6 lines
$ cat ioctl06.cstatic struct tst_test test = { .tid = __FILE__,...
}
Or we may just store the __FILE__ string as a const char * pointer in the tst_test structure and copy part of it to a static array in the do_setup() function in the library and replace the .tid with that.
Quoted 7 lines
Quoted 6 lines
Anyway looking at the code the tid is only used when creating temporary directory/shm so that it's clear which testcase these global resources belongs to. So as far as we can easily identify which test has created the temp directory given it's name it's fine.
Quoted 8 lines
What we do to get tid is early than create a temp directory. Looking at function
setup_ipc(), no matter if we need temp dir or not, thetst_test->tidshould be available there. So this is a general demand to ltp testcase not specified.I drafted above two methods for comparison, I prefer to go
method_1, because it makes LTP authors no need to consider ".tid=" any more. what do you think?
Still undecided. CCing Jan, Jan do you have a preference on which way would be better?
Signature · 2 lines
Cyril Hrubis [email protected]