Skip to contentSkip to conversation

lib: keep the test id hidden in LTP library

PATCH New Li Wang 2 participants 2 messages Nov 1, 2017 Library code

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v3 2/2 lib: keep the test id hidden in LTP library

To avoid introducing wrong tid's typos radically, this patch keep the tid hidden in library by moving out '.tid' variable from the test struct.

Meanwhile, adding a newly string '.scall' to support LTP can get the correct syscall name for timer management library.

---
 include/tst_test.h                                          |  5 +++--
 include/tst_timer_test.h                                    |  2 +-
 lib/tst_test.c                                              | 13 +++++++------
 lib/tst_timer_test.c                                        |  4 ++--
 .../kernel/controllers/memcg/regression/memcg_test_3.c      |  1 -
 testcases/kernel/mem/ksm/ksm06.c                            |  1 -
 testcases/kernel/mem/tunable/max_map_count.c                |  1 -
 .../kernel/syscalls/clock_nanosleep/clock_nanosleep02.c     |  2 +-
 testcases/kernel/syscalls/epoll_wait/epoll_wait02.c         |  2 +-
 testcases/kernel/syscalls/futex/futex_wait05.c              |  2 +-
 testcases/kernel/syscalls/nanosleep/nanosleep01.c           |  2 +-
 testcases/kernel/syscalls/poll/poll02.c                     |  2 +-
 testcases/kernel/syscalls/pselect/pselect01.c               |  2 +-
 testcases/kernel/syscalls/select/select04.c                 |  2 +-
 testcases/lib/tst_device.c                                  |  1 -
 15 files changed, 20 insertions(+), 22 deletions(-)
include/tst_test.h +3 -2
index f9872d9..9b940d6 100644
@@ -105,8 +105,6 @@ int tst_parse_long(const char *str, long *val, long min, long max);
 int tst_parse_float(const char *str, float *val, float min, float max);
 
 struct tst_test {
-	/* test id usually the same as test filename without file suffix */
-	const char *tid;
 	/* number of tests available in test() function */
 	unsigned int tcnt;
 
@@ -150,6 +148,9 @@ struct tst_test {
 	void (*test)(unsigned int test_nr);
 	void (*test_all)(void);
 
+	/* Syscall name will pass to timer measurement library*/
+	const char *scall;
+
 	/* Sampling function for timer measurement testcases */
 	int (*sample)(int clk_id, long long usec);
 
include/tst_timer_test.h +1 -1
index 59931d3..23fc0ba 100644
@@ -37,7 +37,7 @@
     }
 
     struct tst_test test = {
-	.tid = "syscall_name()",
+	.scall = "syscall_name()",
 	.sample = sample,
     };
 
lib/tst_test.c +7 -6
index f8b3fb4..1b9f80c 100644
@@ -41,6 +41,7 @@
 
 struct tst_test *tst_test;
 
+static char *tid = NULL;
 static int iterations = 1;
 static float duration = -1;
 static pid_t main_pid, lib_pid;
@@ -77,7 +78,7 @@ static void setup_ipc(void)
 
 	if (access("/dev/shm", F_OK) == 0) {
 		snprintf(shm_path, sizeof(shm_path), "/dev/shm/ltp_%s_%d",
-		         tst_test->tid, getpid());
+		         tid, getpid());
 	} else {
 		char *tmpdir;
 
@@ -86,7 +87,7 @@ static void setup_ipc(void)
 
 		tmpdir = tst_get_tmpdir();
 		snprintf(shm_path, sizeof(shm_path), "%s/ltp_%s_%d",
-		         tmpdir, tst_test->tid, getpid());
+		         tmpdir, tid, getpid());
 		free(tmpdir);
 	}
 
@@ -688,12 +689,12 @@ static void do_setup(int argc, char *argv[])
 
 	assert_test_fn();
 
+	if (!tid)
+		tid = get_tid(argv);
+
 	if (tst_test->sample)
 		tst_test = tst_timer_test_setup(tst_test);
 
-	if (!tst_test->tid)
-		tst_test->tid = get_tid(argv);
-
 	parse_opts(argc, argv);
 
 	if (tst_test->needs_root && geteuid() != 0)
@@ -972,7 +973,7 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 
 	do_setup(argc, argv);
 
-	TCID = tst_test->tid;
+	TCID = tid;
 
 	SAFE_SIGNAL(SIGALRM, alarm_handler);
 	SAFE_SIGNAL(SIGUSR1, heartbeat_handler);
lib/tst_timer_test.c +2 -2
index cd4ebca..2aa2792 100644
@@ -459,10 +459,10 @@ struct tst_test *tst_timer_test_setup(struct tst_test *timer_test)
 {
 	setup = timer_test->setup;
 	cleanup = timer_test->cleanup;
-	scall = timer_test->tid;
+	scall = timer_test->scall;
 	sample = timer_test->sample;
 
-	timer_test->tid = NULL;
+	timer_test->scall = NULL;
 	timer_test->setup = timer_setup;
 	timer_test->cleanup = timer_cleanup;
 	timer_test->test = timer_test_fn;
testcases/kernel/controllers/memcg/regression/memcg_test_3.c +0 -1
index 994d87b..3b25f84 100644
@@ -112,7 +112,6 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
-	.tid = "memcg_test_3",
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.forks_child = 1,
testcases/kernel/mem/ksm/ksm06.c +0 -1
index 334a048..4272a42 100644
@@ -97,7 +97,6 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
-	.tid = "ksm06",
 	.needs_root = 1,
 	.options = ksm_options,
 	.setup = setup,
testcases/kernel/mem/tunable/max_map_count.c +0 -1
index e47543d..93a764d 100644
@@ -208,7 +208,6 @@ static void max_map_count_test(void)
 }
 
 static struct tst_test test = {
-	.tid = "max_map_count",
 	.needs_root = 1,
 	.forks_child = 1,
 	.setup = setup,
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep02.c +1 -1
index f114013..9b0b243 100644
@@ -44,6 +44,6 @@ int sample_fn(int clk_id, long long usec)
 }
 
 static struct tst_test test = {
-	.tid = "nanosleep()",
+	.scall = "clock_nanosleep()",
 	.sample = sample_fn,
 };
testcases/kernel/syscalls/epoll_wait/epoll_wait02.c +1 -1
index aa1bd0d..70cddb9 100644
@@ -77,7 +77,7 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
-	.tid = "epoll_wait()",
+	.scall = "epoll_wait()",
 	.sample = sample_fn,
 	.setup = setup,
 	.cleanup = cleanup,
testcases/kernel/syscalls/futex/futex_wait05.c +1 -1
index f6b0aa1..066944f 100644
@@ -52,6 +52,6 @@ int sample_fn(int clk_id, long long usec)
 }
 
 static struct tst_test test = {
-	.tid = "futex_wait()",
+	.scall = "futex_wait()",
 	.sample = sample_fn,
 };
testcases/kernel/syscalls/nanosleep/nanosleep01.c +1 -1
index 6d90a60..bcec1f8 100644
@@ -47,6 +47,6 @@ int sample_fn(int clk_id, long long usec)
 }
 
 static struct tst_test test = {
-	.tid = "nanosleep()",
+	.scall = "nanosleep()",
 	.sample = sample_fn,
 };
testcases/kernel/syscalls/poll/poll02.c +1 -1
index 0aa228c..b85df29 100644
@@ -64,7 +64,7 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
-	.tid = "poll()",
+	.scall = "poll()",
 	.sample = sample_fn,
 	.setup = setup,
 	.cleanup = cleanup,
testcases/kernel/syscalls/pselect/pselect01.c +1 -1
index a2b5339..1392689 100644
@@ -44,6 +44,6 @@ int sample_fn(int clk_id, long long usec)
 }
 
 static struct tst_test test = {
-	.tid = "pselect()",
+	.scall = "pselect()",
 	.sample = sample_fn,
 };
testcases/kernel/syscalls/select/select04.c +1 -1
index 1431785..4ca7a31 100644
@@ -66,7 +66,7 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
-	.tid = "select()",
+	.scall = "select()",
 	.sample = sample_fn,
 	.setup = setup,
 	.cleanup = cleanup,
testcases/lib/tst_device.c +0 -1
index d33cac6..1640662 100644
@@ -27,7 +27,6 @@
 extern struct tst_test *tst_test;
 
 static struct tst_test test = {
-	.tid = "tst_device"
 };
 
 static void print_help(void)
Signature · 1 line
2.9.3
#1 lore raw

PATCH v3 2/2 lib: keep the test id hidden in LTP library

Hi!
Pushed with minor changes (the tid has to be const, there is no need to initialize it to NULL, etc.), thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]