From patchwork Thu Mar 21 15:51:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1060259 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44QBB71KDpz9sRM for ; Fri, 22 Mar 2019 02:52:15 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AD724294ADC for ; Thu, 21 Mar 2019 16:52:12 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 0FE203EA4FC for ; Thu, 21 Mar 2019 16:52:02 +0100 (CET) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 597C61000B55 for ; Thu, 21 Mar 2019 16:51:59 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 92BE4AF25; Thu, 21 Mar 2019 15:52:00 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 21 Mar 2019 16:51:11 +0100 Message-Id: <20190321155112.13449-2-chrubis@suse.cz> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190321155112.13449-1-chrubis@suse.cz> References: <20190321155112.13449-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: Mark Salyzyn Subject: [LTP] [PATCH v2 1/2] tst_test: Add test multiplex function X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 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. Signed-off-by: Cyril Hrubis Reviewed-by: Steve Muckle CC: Mark Salyzyn CC: Steve Muckle CC: Jan Stancek --- doc/test-writing-guidelines.txt | 80 +++++++++++++++++++++++++++++++++ include/tst_test.h | 14 ++++++ lib/tst_test.c | 11 ++++- 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index c36b2a424..e5aa456e2 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/tst_test.h b/include/tst_test.h index da41f776d..b747b24d5 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -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; diff --git a/lib/tst_test.c b/lib/tst_test.c index ba5eab011..aae7651c2 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -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(); From patchwork Thu Mar 21 15:51:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1060258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44QBB253v7z9sPd for ; Fri, 22 Mar 2019 02:52:10 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E84C33EA5C6 for ; Thu, 21 Mar 2019 16:52:07 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id EFD9D3EA1B6 for ; Thu, 21 Mar 2019 16:52:01 +0100 (CET) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 9D66F2003BE for ; Thu, 21 Mar 2019 16:52:01 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 43425AF49; Thu, 21 Mar 2019 15:52:01 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 21 Mar 2019 16:51:12 +0100 Message-Id: <20190321155112.13449-3-chrubis@suse.cz> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190321155112.13449-1-chrubis@suse.cz> References: <20190321155112.13449-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Cc: Mark Salyzyn Subject: [LTP] [PATCH v2 2/2] syscalls/select04: Test four syscall variants X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This commit makes use of the newly added test_multiplex() function to switch between different syscall variants/wrappers at runtime. Signed-off-by: Cyril Hrubis Signed-off-by: Mark Salyzyn CC: Steve Muckle CC: Jan Stancek --- 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 diff --git a/testcases/kernel/syscalls/select/select04.c b/testcases/kernel/syscalls/select/select04.c index 86bdffcdf..300992233 100644 --- a/testcases/kernel/syscalls/select/select04.c +++ b/testcases/kernel/syscalls/select/select04.c @@ -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, }; diff --git a/testcases/kernel/syscalls/select/select_mpx.h b/testcases/kernel/syscalls/select/select_mpx.h new file mode 100644 index 000000000..be079b8d8 --- /dev/null +++ b/testcases/kernel/syscalls/select/select_mpx.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2019 Cyril Hrubis + */ + +#ifndef SELECT_MPX +#define SELECT_MPX + +#include "lapi/syscalls.h" + +static int sys_mpx = -1; + +struct compat_sel_arg_struct { + long _n; + long _inp; + long _outp; + long _exp; + long _tvp; +}; + +static int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) +{ + switch (sys_mpx) { + case 0: + return select(nfds, readfds, writefds, exceptfds, timeout); + break; + case 1: { +#ifdef __LP64__ + return tst_syscall(__NR_select, nfds, readfds, writefds, exceptfds, timeout); +#else + struct compat_sel_arg_struct arg = { + ._n = (long)nfds, + ._inp = (long)readfds, + ._outp = (long)writefds, + ._exp = (long)exceptfds, + ._tvp = (long)timeout, + }; + + return tst_syscall(__NR_select, &arg); +#endif /* __LP64__ */ + } + case 2: { + int ret; + struct timespec ts = { + .tv_sec = timeout->tv_sec, + .tv_nsec = timeout->tv_usec * 1000, + }; + ret = tst_syscall(__NR_pselect6, nfds, readfds, writefds, exceptfds, &ts, NULL); + timeout->tv_sec = ts.tv_sec; + timeout->tv_usec = ts.tv_nsec / 1000; + return ret; + } +#ifdef __NR__newselect + case 3: + return tst_syscall(__NR__newselect, nfds, readfds, writefds, exceptfds, timeout); + break; +#endif + } + + return -1; +} + +static int select_mpx(void) +{ + switch (++sys_mpx) { + case 0: + tst_res(TINFO, "Testing glibc select()"); + break; + case 1: + tst_res(TINFO, "Testing SYS_select syscall"); + break; + case 2: + tst_res(TINFO, "Testing SYS_pselect6 syscall"); + break; + case 3: +#ifdef __NR__newselect + tst_res(TINFO, "Testing SYS__newselect syscall"); + break; +#endif + case 4: + sys_mpx = -1; + return 0; + } + + return 1; +} + +#endif /* SELECT_MPX */