Skip to contentSkip to conversation

Implement syscall multiplexing

PATCH Superseded Cyril Hrubis 2 participants 5 messages Mar 21, 2019 – Mar 22, 2019 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Implement syscall multiplexing

This is version 2 of the patchset, the main changes are documentation for the multiplex function and also fixes in the select multiplexing function.

Cyril Hrubis (2):
tst_test: Add test multiplex function
syscalls/select04: Test four syscall variants

 doc/test-writing-guidelines.txt               | 80 +++++++++++++++++
 include/tst_test.h                            | 14 +++
 lib/tst_test.c                                | 11 ++-
 testcases/kernel/syscalls/select/select04.c   |  5 +-
 testcases/kernel/syscalls/select/select_mpx.h | 87 +++++++++++++++++++
 5 files changed, 194 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/select/select_mpx.h
Signature · 1 line
2.19.2
#1 lore raw

PATCH v2 1/2 tst_test: Add test multiplex function

The test multiplex function is intended for running the test function in a loop for a different settings. The indended purpose is to run tests for both libc wrapper and raw syscall as well as for different syscall variants.

The commit itself adds a test_multiplex() function into the tst_test structure, if set this function is called in a loop before each test iteration and is responsible for changing the test variant into next one. The iterations continue until the function returns zero.

---
 doc/test-writing-guidelines.txt | 80 +++++++++++++++++++++++++++++++++
 include/tst_test.h              | 14 ++++++
 lib/tst_test.c                  | 11 ++++-
 3 files changed, 103 insertions(+), 2 deletions(-)
doc/test-writing-guidelines.txt +80 -0
index c36b2a424..e5aa456e2 100644
@@ -1603,6 +1603,86 @@ sturct tst_test test = {
 };
 -------------------------------------------------------------------------------
 
+2.2.29 Testing similar syscalls in one test
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+In some cases kernel has several very similar syscalls that do either the same
+or very similar job. This is most noticeable on i386 where we commonly have
+two or three syscall versions because i386 was first platform that Linux was
+developed on and because of that most mistakes in API happened there as well.
+However this is not limited to i386 at all, it's quite common that version two
+syscall has added missing flags parameters or so.
+
+In such cases it does not make much sense to copy&paste the test code over and
+over, rather than that the test library provides mutiplexing support. The idea
+behind multiplexing is simple, we run the test function several times each
+time with different syscall variant.
+
+The implemenation consist of multiplex fuction that is called before each
+iteration of the run function, this fuction is responsible for switching the
+syscall variant and also controlls the number of iterations. The testrun is
+done once the function returns zero.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static int mpx = -1;
+
+static int foo_mpx(void)
+{
+	switch (++mpx) {
+	case 0:
+		tst_res(TINFO, "Testing foo variant 1");
+	break;
+	case 1:
+		tst_res(TINFO, "Testing foo variant 2");
+	break;
+	case 2:
+		mpx = -1;
+		return 0;
+	}
+
+	return 1;
+}
+
+static int do_foo(void)
+{
+	switch (mpx) {
+	case 0:
+		return foo();
+	case 1:
+		return syscall(__NR_foo);
+	}
+
+	return -1;
+}
+
+static void setup(void)
+{
+	...
+}
+
+static void run(void)
+{
+	...
+
+	TEST(do_foo);
+
+	...
+}
+
+
+sturct tst_test test = {
+	...
+	.setup = setup,
+	.test_all = run,
+	.test_multiplex = foo_mpx,
+	...
+};
+-------------------------------------------------------------------------------
+
+
 2.3 Writing a testcase in shell
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
include/tst_test.h +14 -0
index da41f776d..b747b24d5 100644
@@ -146,6 +146,20 @@ struct tst_test {
 	 */
 	int all_filesystems:1;
 
+	/*
+	 * If set this function is used to mutiplex between different test
+	 * variants.
+	 *
+	 * Multiplexers are the way how to run the same test for different
+	 * settings. The intended use is to test different syscall
+	 * wrappers/variants but the API is generic and does not limit the
+	 * usage in any way.
+	 *
+	 * Each time the function is called it switches to next test variant,
+	 * returns zero if all variants has been iterated over.
+	 */
+	int (*test_multiplex)(void);
+
 	/* Minimal device size in megabytes */
 	unsigned int dev_min_size;
 
lib/tst_test.c +9 -2
index ba5eab011..aae7651c2 100644
@@ -1009,8 +1009,15 @@ static void testrun(void)
 		if (!cont)
 			break;
 
-		run_tests();
-		heartbeat();
+		if (tst_test->test_multiplex) {
+			while (tst_test->test_multiplex()) {
+				run_tests();
+				heartbeat();
+			}
+		} else {
+			run_tests();
+			heartbeat();
+		}
 	}
 
 	do_test_cleanup();
Signature · 1 line
2.19.2
#2 lore raw

PATCH v2 2/2 syscalls/select04: Test four syscall variants

In reply to Cyril Hrubis

This commit makes use of the newly added test_multiplex() function to switch between different syscall variants/wrappers at runtime.

---
 testcases/kernel/syscalls/select/select04.c   |  5 +-
 testcases/kernel/syscalls/select/select_mpx.h | 87 +++++++++++++++++++
 2 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/select/select_mpx.h
testcases/kernel/syscalls/select/select04.c +4 -1
index 86bdffcdf..300992233 100644
@@ -27,6 +27,8 @@
 
 #include "tst_timer_test.h"
 
+#include "select_mpx.h"
+
 static int fds[2];
 
 static int sample_fn(int clk_id, long long usec)
@@ -39,7 +41,7 @@ static int sample_fn(int clk_id, long long usec)
 	FD_SET(fds[0], &sfds);
 
 	tst_timer_start(clk_id);
-	TEST(select(1, &sfds, NULL, NULL, &timeout));
+	TEST(do_select(1, &sfds, NULL, NULL, &timeout));
 	tst_timer_stop();
 	tst_timer_sample();
 
@@ -69,5 +71,6 @@ static struct tst_test test = {
 	.scall = "select()",
 	.sample = sample_fn,
 	.setup = setup,
+	.test_multiplex = select_mpx,
 	.cleanup = cleanup,
 };
testcases/kernel/syscalls/select/select_mpx.h new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.19.2
#3 lore raw

v2 cover Implement syscall multiplexing

In reply to Cyril Hrubis

----- Original Message -----

Quoted 3 lines

This is version 2 of the patchset, the main changes are documentation for the multiplex function and also fixes in the select multiplexing function.

This made me think, if we need something like tst_syscall_supported(). If in future we'll have multiplex function with couple #ifdefs, we may hit TCONF (due to ENOSYS) before we iterate over all of them.

Quoted 20 lines

Cyril Hrubis (2):
tst_test: Add test multiplex function
syscalls/select04: Test four syscall variants

 doc/test-writing-guidelines.txt               | 80 +++++++++++++++++
 include/tst_test.h                            | 14 +++
 lib/tst_test.c                                | 11 ++-
 testcases/kernel/syscalls/select/select04.c   |  5 +-
 testcases/kernel/syscalls/select/select_mpx.h | 87 +++++++++++++++++++
 5 files changed, 194 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/select/select_mpx.h

--
2.19.2

--
Mailing list info: https://lists.linux.it/listinfo/ltp

#4 lore raw

v2 cover Implement syscall multiplexing

Hi!

Quoted 5 lines

This made me think, if we need something like tst_syscall_supported(). If in future we'll have multiplex function with couple #ifdefs, we may hit TCONF (due to ENOSYS) before we iterate over all of them.

Valid point.

Another fix may involve forking a process for each testrun and handling the exit value same way as we do for the all_filesystems flag, we would have to hook up the multiplex before we fork the test process into the tst_run_tcases() function.

Signature · 2 lines
Cyril Hrubis
[email protected]