From patchwork Fri Sep 14 15:02:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kodanev X-Patchwork-Id: 969910 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=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="gQYZiG6/"; dkim-atps=neutral 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 42Bdlm4wHWz9s3l for ; Sat, 15 Sep 2018 00:52:18 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 89CDD3E764B for ; Fri, 14 Sep 2018 16:52:14 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id C065A3E63A6 for ; Fri, 14 Sep 2018 16:52:13 +0200 (CEST) Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 994CB600F8C for ; Fri, 14 Sep 2018 16:52:12 +0200 (CEST) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w8EEhf1m095931 for ; Fri, 14 Sep 2018 14:52:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=hOVCyirou4IzCX95TDx1YpBbV5gNG/uG7fTEYJiW3Ag=; b=gQYZiG6/l2NATI8M4hHRWDtGWkmEDwn329zuEuObj82iF1vVxSJWd+Yn16NU/HOtqZWh ZTaXBz4zIDrUjUKgKeStnfE3WjUNlZpGoo2RDTisBMqwDzrjy5UiIWQAQCbQhHUUjHwu 1ZHM4MYVwGfXc9HrLhgSpllHHlWLDFl+vWysR9U+ZnxHrNH1Q3n0qHVo9Pb7hrYz0mEw emK0rf4wnyOt1Sku+ZxrnfsCe+S27AC+XYwl7BJJbW7oS8jDzLKLOjcqU0MVkmBlCaEY D4pl5MXXbYZ/VxNb8VoqqqtacP18sA1Bdx1+KublJ3qrIqHwJtnezKDT8CFNxaHYqRNw jw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2mc5utyk0j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 14 Sep 2018 14:52:10 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w8EEq9oh008853 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 14 Sep 2018 14:52:09 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w8EEq9Nf012366 for ; Fri, 14 Sep 2018 14:52:09 GMT Received: from ak.ru.oracle.com (/10.162.80.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 14 Sep 2018 07:52:08 -0700 From: Alexey Kodanev To: ltp@lists.linux.it Date: Fri, 14 Sep 2018 18:02:08 +0300 Message-Id: <1536937329-13902-1-git-send-email-alexey.kodanev@oracle.com> X-Mailer: git-send-email 1.7.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9015 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809140153 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/2] lib/tst_test.c: add 'needs_drivers' option with tst_check_drivers cmd 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" The drivers are checked with modprobe. If modprobe is not available on the system, the checks are silently skipped. Signed-off-by: Alexey Kodanev Reviewed-by: Petr Vorel --- v3: * Changed the docs according to the Cyril's comment * Added curly braces in tst_check_drivers.c * Added dry-run option to modprobe v2: * moved tst_check_driver() from tst_test.h to tst_kernel.h * added the new option description to the doc and comment to tst_kernel.h * iterating over the driver list moved out from tst_check_drivers(), the function renamed accordingly. doc/test-writing-guidelines.txt | 11 +++++++++++ include/tst_kernel.h | 8 ++++++++ include/tst_test.h | 3 +++ lib/tst_kernel.c | 9 +++++++++ lib/tst_test.c | 9 +++++++++ testcases/lib/.gitignore | 1 + testcases/lib/Makefile | 2 +- testcases/lib/tst_check_drivers.c | 25 +++++++++++++++++++++++++ 8 files changed, 67 insertions(+), 1 deletions(-) create mode 100644 testcases/lib/tst_check_drivers.c diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index aae2b38..78c524f 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -1457,6 +1457,17 @@ https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html CRC32c checksum generation is supported by LTP. In order to use it, the test should include "tst_checksum.h" header, then can call tst_crc32c(). +2.2.26 Checking kernel for the driver support +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Some tests may need specific kernel drivers, either compiled in, or built +as a module. If .need_drivers points to a NULL-terminated array of kernel +module names these are all checked and the test exits with TCONF on the +first missing driver. + +Since it relies on modprobe command, the check will be skipped if the command +itself is not available on the system. + 2.3 Writing a testcase in shell ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/tst_kernel.h b/include/tst_kernel.h index 5d5c04c..88941e1 100644 --- a/include/tst_kernel.h +++ b/include/tst_kernel.h @@ -23,4 +23,12 @@ */ int tst_kernel_bits(void); +/** + * Checks support for the kernel driver. + * + * @param name The name of the driver. + * @return Returns 0 if the kernel has the driver or modprobe is missing. + */ +int tst_check_driver(const char *name); + #endif /* TST_KERNEL_H__ */ diff --git a/include/tst_test.h b/include/tst_test.h index ea23c8b..080b017 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -172,6 +172,9 @@ struct tst_test { /* NULL terminated array of resource file names */ const char *const *resource_files; + + /* NULL terminated array of needed kernel drivers */ + const char * const *needs_drivers; }; /* diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c index 42d64cb..4206e3c 100644 --- a/lib/tst_kernel.c +++ b/lib/tst_kernel.c @@ -45,3 +45,12 @@ int tst_kernel_bits(void) return kernel_bits; } + +int tst_check_driver(const char *name) +{ + const char * const argv[] = { "modprobe", "-n", name, NULL }; + int res = tst_run_cmd_(NULL, argv, "/dev/null", "/dev/null", 1); + + /* 255 - it looks like modprobe not available */ + return (res == 255) ? 0 : res; +} diff --git a/lib/tst_test.c b/lib/tst_test.c index 1280400..117e614 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -784,6 +784,15 @@ static void do_setup(int argc, char *argv[]) if (tst_test->min_kver) check_kver(); + if (tst_test->needs_drivers) { + const char *name; + int i; + + for (i = 0; (name = tst_test->needs_drivers[i]); ++i) + if (tst_check_driver(name)) + tst_brk(TCONF, "%s driver not available", name); + } + if (tst_test->format_device) tst_test->needs_device = 1; diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore index a9034e4..d83a48e 100644 --- a/testcases/lib/.gitignore +++ b/testcases/lib/.gitignore @@ -1,5 +1,6 @@ /tst_sleep /tst_random +/tst_check_drivers /tst_checkpoint /tst_rod /tst_kvcmp diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile index 3547e16..e1dea3b 100644 --- a/testcases/lib/Makefile +++ b/testcases/lib/Makefile @@ -28,6 +28,6 @@ INSTALL_TARGETS := *.sh MAKE_TARGETS := tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\ tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\ - tst_getconf tst_supported_fs + tst_getconf tst_supported_fs tst_check_drivers include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/lib/tst_check_drivers.c b/testcases/lib/tst_check_drivers.c new file mode 100644 index 0000000..e21bdab --- /dev/null +++ b/testcases/lib/tst_check_drivers.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved. */ + +#include +#include "tst_kernel.h" + +int main(int argc, const char *argv[]) +{ + const char *name; + int i; + + if (argc < 2) { + fprintf(stderr, "Please provide kernel driver list\n"); + return 1; + } + + for (i = 1; (name = argv[i]); ++i) { + if (tst_check_driver(name)) { + fprintf(stderr, "%s", name); + return 1; + } + } + + return 0; +} From patchwork Fri Sep 14 15:02:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kodanev X-Patchwork-Id: 969911 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=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="wpF+ehSq"; dkim-atps=neutral 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 42Bdln3pCwz9s9N for ; Sat, 15 Sep 2018 00:52:21 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 07FB73E772C for ; Fri, 14 Sep 2018 16:52:19 +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 7DE3E3E76BD for ; Fri, 14 Sep 2018 16:52:16 +0200 (CEST) Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id A66CC1A00F46 for ; Fri, 14 Sep 2018 16:52:15 +0200 (CEST) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w8EEhaL2116043 for ; Fri, 14 Sep 2018 14:52:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=dAEfMgAlf0V09X/7HB2DaY9n5zsCuUT/VTX3f7vtA1o=; b=wpF+ehSqgzvxW+q5LeeP0NB25KLmgXl6Ng+90ff+sjKUBfK2JuxjMiGuaIOEu+IkWNPX F0QsDm6PMWhwKPT7dK7CvYtVkk/Xd8hP9oIT913piWnG73s4zKUkKoL/9ZMT6GouUTvm CBxPOaspowAw8rgOuS2v/uU5rce10LYs1oTfnVpID4/+eZUNiTpK9hYY7qWLVMPz+Bnk XF9dFkbssLwYQMPwlfIczT2sEfbhCrZY5e+8EeiRkb396OVTEEF6c8MZLRxSslcQvJl3 t1sbUUMJUWq63oeWUx8nIN3/Oj6TQaNDm0SHuUVF4LHSxRvxqy4Ztx4RukquTYEsR+4f Vw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2mc6cq7ju2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 14 Sep 2018 14:52:13 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w8EEqCI6001081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 14 Sep 2018 14:52:13 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w8EEqCNf026536 for ; Fri, 14 Sep 2018 14:52:12 GMT Received: from ak.ru.oracle.com (/10.162.80.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 14 Sep 2018 07:52:11 -0700 From: Alexey Kodanev To: ltp@lists.linux.it Date: Fri, 14 Sep 2018 18:02:09 +0300 Message-Id: <1536937329-13902-2-git-send-email-alexey.kodanev@oracle.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1536937329-13902-1-git-send-email-alexey.kodanev@oracle.com> References: <1536937329-13902-1-git-send-email-alexey.kodanev@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9015 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=683 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809140153 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, 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 v3 2/2] lib/tst_test.sh: add TST_NEEDS_DRIVERS parameter 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" The drivers are checked with 'tst_check_drivers' command. Signed-off-by: Alexey Kodanev Reviewed-by: Petr Vorel --- v3: check the command exit status instead of the returned error message v2: add a check for empty TST_NEEDS_DRIVERS doc/test-writing-guidelines.txt | 1 + testcases/lib/tst_test.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index 78c524f..f590896 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -1662,6 +1662,7 @@ simply by setting right '$TST_NEEDS_FOO'. | 'TST_NEEDS_CMDS' | String with command names that has to be present for the test (see below). | 'TST_NEEDS_MODULE' | Test module name needed for the test (see below). +| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test. |============================================================================= Checking for presence of commands diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh index faf3bd5..7a41309 100644 --- a/testcases/lib/tst_test.sh +++ b/testcases/lib/tst_test.sh @@ -302,6 +302,18 @@ tst_check_cmds() return 0 } +tst_test_drivers() +{ + [ $# -eq 0 ] && return 0 + + local drv + + drv="$(tst_check_drivers $@ 2>&1)" + + [ $? -ne 0 ] && tst_brk TCONF "$drv driver not available" + return 0 +} + tst_is_int() { [ "$1" -eq "$1" ] 2>/dev/null @@ -349,6 +361,7 @@ tst_run() OPTS|USAGE|PARSE_ARGS|POS_ARGS);; NEEDS_ROOT|NEEDS_TMPDIR|NEEDS_DEVICE|DEVICE);; NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);; + NEEDS_DRIVERS);; IPV6|IPVER|TEST_DATA|TEST_DATA_IFS);; RETRY_FUNC|RETRY_FN_EXP_BACKOFF);; *) tst_res TWARN "Reserved variable TST_$_tst_i used!";; @@ -386,6 +399,7 @@ tst_run() fi tst_test_cmds $TST_NEEDS_CMDS + tst_test_drivers $TST_NEEDS_DRIVERS if [ -n "$TST_MIN_KVER" ]; then tst_kvcmp -lt "$TST_MIN_KVER" && \