From patchwork Sat Jun 8 05:45:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1112397 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=fail (p=none dis=none) header.from=redhat.com 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 45LT0Y0ST6z9s9y for ; Sat, 8 Jun 2019 15:46:20 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A3CE73EB1BF for ; Sat, 8 Jun 2019 07:46:09 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id A0CD13EAA01 for ; Sat, 8 Jun 2019 07:46:00 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 448241A00E4D for ; Sat, 8 Jun 2019 07:45:57 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F72281F2F for ; Sat, 8 Jun 2019 05:45:55 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F33A5D707 for ; Sat, 8 Jun 2019 05:45:54 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sat, 8 Jun 2019 13:45:48 +0800 Message-Id: <20190608054550.13744-1-liwang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 08 Jun 2019 05:45:55 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH RFC 1/3] lib: adding tst_on_arch function in library 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Testcases for specified arch should be limited on that only being supported platform to run, we now create a function tst_on_arch to achieve this new feature in LTP library. All you need to run a test on the expected arch is to set the '.arch' string in the 'struct tst_test' to choose the required arch list. e.g. '.arch = "x86_64, i386"'. For more complicated usages such as customize your test code for a special arch, the tst_on_arch function could be invoked in the test directly. Signed-off-by: Li Wang --- doc/test-writing-guidelines.txt | 54 +++++++++++++++++++++++++ include/tst_arch.h | 16 ++++++++ include/tst_test.h | 7 +++- lib/tst_arch.c | 71 +++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 include/tst_arch.h create mode 100644 lib/tst_arch.c diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index f1912dc12..10442d756 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -1668,6 +1668,60 @@ sturct tst_test test = { }; ------------------------------------------------------------------------------- +2.2.30 Testing on specified architecture +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Testcases for specified arch should be limited on that only being supported +platform to run, we now create a function tst_on_arch to achieve this new +feature in LTP library. All you need to run a test on the expected arch is +to set the '.arch' string in the 'struct tst_test' to choose the required +arch list. e.g. '.arch = "x86_64, i386"'. + +[source,c] +------------------------------------------------------------------------------- +#include "tst_test.h" + +static void setup(void) +{ + ... +} + +static struct tst_test test = { + ... + .setup = setup, + .arch = "x86_64, i386", + ... +} +------------------------------------------------------------------------------- + +For more complicated usages such as customize your test code for a special +arch, the tst_on_arch function could be invoked in the test directly. + +[source,c] +------------------------------------------------------------------------------- +#include "tst_test.h" + +static void do_test(void) +{ + if (tst_on_arch("x86_64, i386")) { + /* code for x86_64, i386 */ + ... + } else if (tst_on_arch("ppc64")) { + /* code for ppc64 */ + ... + } else if (tst_on_arch("s390, s390x")) { + /* code for s390x */ + ... + } +} + +static struct tst_test test = { + ... + .test_all = do_test, + ... +} +------------------------------------------------------------------------------- + 2.3 Writing a testcase in shell ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/tst_arch.h b/include/tst_arch.h new file mode 100644 index 000000000..7bf0493ce --- /dev/null +++ b/include/tst_arch.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (c) 2019 Li Wang + */ + +#ifndef TST_ARCH_H__ +#define TST_ARCH_H__ + +/* + * Check if test platform is in the given arch list. If yes return 1, + * otherwise return 0. + * + * @arch, NULL or vliad arch list + */ +int tst_on_arch(const char *arch); + +#endif /* TST_ARCH_H__ */ diff --git a/include/tst_test.h b/include/tst_test.h index 8bdf38482..cafcb1a89 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -28,6 +28,7 @@ #include "tst_atomic.h" #include "tst_kvercmp.h" #include "tst_clone.h" +#include "tst_arch.h" #include "tst_kernel.h" #include "tst_minmax.h" #include "tst_get_bad_addr.h" @@ -114,6 +115,8 @@ struct tst_test { const char *min_kver; + const char *arch; + /* If set the test is compiled out */ const char *tconf_msg; @@ -253,7 +256,6 @@ const char *tst_strstatus(int status); unsigned int tst_timeout_remaining(void); void tst_set_timeout(int timeout); - /* * Returns path to the test temporary directory in a newly allocated buffer. */ @@ -265,6 +267,9 @@ static struct tst_test test; int main(int argc, char *argv[]) { + if (!tst_on_arch(test.arch)) + tst_brk(TCONF, "Test needs running on %s arch!", test.arch); + tst_run_tcases(argc, argv, &test); } diff --git a/lib/tst_arch.c b/lib/tst_arch.c new file mode 100644 index 000000000..a9f2775b4 --- /dev/null +++ b/lib/tst_arch.c @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (c) 2019 Li Wang + */ + +#include + +#define TST_NO_DEFAULT_MAIN +#include "tst_arch.h" +#include "tst_test.h" + +static const char *const arch_type_list[] = { + "i386", + "x86", + "x86_64", + "ia64", + "ppc", + "ppc64", + "s390", + "s390x", + "arm", + "aarch64", + "sparc", + NULL +}; + +static int is_valid_arch(const char *arch) +{ + unsigned int i; + + for (i = 0; arch_type_list[i]; i++) { + if (strstr(arch, arch_type_list[i])) + return 1; + } + + return 0; +} + +int tst_on_arch(const char *arch) +{ +#if defined(__i386__) + char *tst_arch = "i386"; +#elif defined(__x86__) + char *tst_arch = "x86"; +#elif defined(__x86_64__) + char *tst_arch = "x86_64"; +#elif defined(__ia64__) + char *tst_arch = "ia64"; +#elif defined(__powerpc__) + char *tst_arch = "ppc"; +#elif defined(__powerpc64__) + char *tst_arch = "ppc64"; +#elif defined(__s390__) + char *tst_arch = "s390"; +#elif defined(__s390x__) + char *tst_arch = "s390x"; +#elif defined(__arm__) + char *tst_arch = "arm"; +#elif defined(__arch64__) + char *tst_arch = "aarch64"; +#elif defined(__sparc__) + char *tst_arch = "sparc"; +#endif + + if (arch != NULL && !is_valid_arch(arch)) + tst_brk(TBROK, "please set valid arches!"); + + if (arch == NULL || strstr(arch, tst_arch)) + return 1; + + return 0; +} From patchwork Sat Jun 8 05:45:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1112396 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=fail (p=none dis=none) header.from=redhat.com 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 45LT0L2N2Gz9s9y for ; Sat, 8 Jun 2019 15:46:07 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 69F753EB16F for ; Sat, 8 Jun 2019 07:46:02 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 5B8913EAA01 for ; Sat, 8 Jun 2019 07:46:00 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 4B49E1401104 for ; Sat, 8 Jun 2019 07:45:57 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A69ED368E6 for ; Sat, 8 Jun 2019 05:45:56 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7C545D707 for ; Sat, 8 Jun 2019 05:45:55 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sat, 8 Jun 2019 13:45:49 +0800 Message-Id: <20190608054550.13744-2-liwang@redhat.com> In-Reply-To: <20190608054550.13744-1-liwang@redhat.com> References: <20190608054550.13744-1-liwang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 08 Jun 2019 05:45:56 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH RFC 2/3] max_map_count: taking use of tst_on_arch in testcase 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" We have two different ways to use tst_on_arch, first is to set .arch = "xxx, yyy" in test struct to limit testcase running on some specified arch, the second is calling it directly in test functions. Demo: 1. ptrace07.c, cve-2017-17053.c, meltdown.c 2. max_map_count.c Signed-off-by: Li Wang --- testcases/cve/cve-2017-17053.c | 1 + testcases/cve/meltdown.c | 9 +---- testcases/kernel/mem/tunable/max_map_count.c | 36 ++++++++++---------- testcases/kernel/syscalls/ptrace/ptrace07.c | 8 ++--- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/testcases/cve/cve-2017-17053.c b/testcases/cve/cve-2017-17053.c index e01db3d4f..67bf4135f 100644 --- a/testcases/cve/cve-2017-17053.c +++ b/testcases/cve/cve-2017-17053.c @@ -162,6 +162,7 @@ void run(void) } static struct tst_test test = { + .arch = "x86_64, i386", .forks_child = 1, .setup = setup, .cleanup = cleanup, diff --git a/testcases/cve/meltdown.c b/testcases/cve/meltdown.c index a53ea9b8e..da35213ec 100644 --- a/testcases/cve/meltdown.c +++ b/testcases/cve/meltdown.c @@ -20,8 +20,6 @@ #include "config.h" #include "tst_test.h" -#if defined(__x86_64__) || defined(__i386__) - #include #include #include @@ -382,15 +380,10 @@ static void cleanup(void) } static struct tst_test test = { + .arch = "x86_64, i386", .needs_root = 1, .setup = setup, .test_all = run, .cleanup = cleanup, .min_kver = "2.6.32" }; - -#else /* #if defined(__x86_64__) || defined(__i386__) */ - -TST_TEST_TCONF("not x86_64 or i386"); - -#endif /* #else #if defined(__x86_64__) || defined(__i386__) */ diff --git a/testcases/kernel/mem/tunable/max_map_count.c b/testcases/kernel/mem/tunable/max_map_count.c index 5b03a60ec..ae86288bf 100644 --- a/testcases/kernel/mem/tunable/max_map_count.c +++ b/testcases/kernel/mem/tunable/max_map_count.c @@ -91,24 +91,24 @@ static bool filter_map(const char *line) if (ret != 1) return false; -#if defined(__x86_64__) || defined(__x86__) - /* On x86, there's an old compat vsyscall page */ - if (!strcmp(buf, "[vsyscall]")) - return true; -#elif defined(__ia64__) - /* On ia64, the vdso is not a proper mapping */ - if (!strcmp(buf, "[vdso]")) - return true; -#elif defined(__arm__) - /* Skip it when run it in aarch64 */ - if ((!strcmp(un.machine, "aarch64")) - || (!strcmp(un.machine, "aarch64_be"))) - return false; - - /* Older arm kernels didn't label their vdso maps */ - if (!strncmp(line, "ffff0000-ffff1000", 17)) - return true; -#endif + if (tst_on_arch("x86_64, x86")) { + /* On x86, there's an old compat vsyscall page */ + if (!strcmp(buf, "[vsyscall]")) + return true; + } else if (tst_on_arch("ia64")) { + /* On ia64, the vdso is not a proper mapping */ + if (!strcmp(buf, "[vdso]")) + return true; + } else if (tst_on_arch("arm")) { + /* Skip it when run it in aarch64 */ + if ((!strcmp(un.machine, "aarch64")) + || (!strcmp(un.machine, "aarch64_be"))) + return false; + + /* Older arm kernels didn't label their vdso maps */ + if (!strncmp(line, "ffff0000-ffff1000", 17)) + return true; + } return false; } diff --git a/testcases/kernel/syscalls/ptrace/ptrace07.c b/testcases/kernel/syscalls/ptrace/ptrace07.c index 9cbaefc3f..67e47ce16 100644 --- a/testcases/kernel/syscalls/ptrace/ptrace07.c +++ b/testcases/kernel/syscalls/ptrace/ptrace07.c @@ -60,13 +60,13 @@ # define NT_X86_XSTATE 0x202 #endif -#ifdef __x86_64__ static void check_regs_loop(uint32_t initval) { const unsigned long num_iters = 1000000000; uint32_t xmm0[4] = { initval, initval, initval, initval }; int status = 1; +#ifdef __x86_64__ asm volatile(" movdqu %0, %%xmm0\n" " mov %0, %%rbx\n" "1: dec %2\n" @@ -80,6 +80,7 @@ static void check_regs_loop(uint32_t initval) "3:\n" : "+m" (xmm0), "+r" (status) : "r" (num_iters) : "rax", "rbx", "xmm0"); +#endif if (status) { tst_res(TFAIL, @@ -188,10 +189,7 @@ static void do_test(void) static struct tst_test test = { .test_all = do_test, + .arch = "x86_64", .forks_child = 1, .needs_checkpoints = 1, }; - -#else /* !__x86_64__ */ - TST_TEST_TCONF("this test is only supported on x86_64"); -#endif /* __x86_64__ */ From patchwork Sat Jun 8 05:45:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1112398 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=fail (p=none dis=none) header.from=redhat.com 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 45LT0Y1KrRz9sBb for ; Sat, 8 Jun 2019 15:46:20 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E80463EB1A8 for ; Sat, 8 Jun 2019 07:46:14 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id 81E253EB18F for ; Sat, 8 Jun 2019 07:46:07 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 3455D601AE7 for ; Sat, 8 Jun 2019 07:45:59 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB96AC01F28C for ; Sat, 8 Jun 2019 05:45:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 292F25D707 for ; Sat, 8 Jun 2019 05:45:56 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sat, 8 Jun 2019 13:45:50 +0800 Message-Id: <20190608054550.13744-3-liwang@redhat.com> In-Reply-To: <20190608054550.13744-1-liwang@redhat.com> References: <20190608054550.13744-1-liwang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 08 Jun 2019 05:45:57 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH RFC 3/3] testcase: get rid of compiling errors 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Li Wang --- configure.ac | 1 + testcases/cve/meltdown.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 5a3dc5b62..39b2d6da7 100644 --- a/configure.ac +++ b/configure.ac @@ -58,6 +58,7 @@ AC_CHECK_HEADERS([ \ sys/shm.h \ sys/ustat.h \ sys/xattr.h \ + emmintrin.h \ ]) AC_CHECK_FUNCS([ \ diff --git a/testcases/cve/meltdown.c b/testcases/cve/meltdown.c index da35213ec..e6e911fcc 100644 --- a/testcases/cve/meltdown.c +++ b/testcases/cve/meltdown.c @@ -29,6 +29,7 @@ #include #include +#ifdef HAVE_EMMINTRIN_H #include #include "libtsc.h" @@ -387,3 +388,7 @@ static struct tst_test test = { .cleanup = cleanup, .min_kver = "2.6.32" }; + +#else /* HAVE_EMMINTRIN_H */ + TST_TEST_TCONF(" is not supported"); +#endif