From patchwork Thu Aug 9 15:23:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kodanev X-Patchwork-Id: 955700 X-Patchwork-Delegate: petr.vorel@gmail.com 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="CHe4BP0b"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41mWxX0VZHz9ryt for ; Fri, 10 Aug 2018 01:14:07 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5867D3E7220 for ; Thu, 9 Aug 2018 17:14:04 +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 03CFE3E7202 for ; Thu, 9 Aug 2018 17:14:01 +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 4151E600F2C for ; Thu, 9 Aug 2018 17:14:00 +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 w79F4oiv107013 for ; Thu, 9 Aug 2018 15:13:58 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=osuS/PkgUZbimei0iAAklXVEikZHzCuen3IM+9KuR0g=; b=CHe4BP0bWT+TRV2w7S1RkZWubtTPWt8TJJZby/juuQjNCGPzD/8YphdJYRjfxOuMJ5yP UkYTxsmfwjJMCR9+q6mFSKSEY7JvBuSlKUlYuJ14vM9mCupydkHcjPjWNNIUpoeD28LV kUK02p2pg/CMPQYgQNKiZEOO84S6izmrr5WmKrHCQza9GMq9QOVGEcpzJo5xgc8Qrx3u RsKMNbZTl2Yzut6F0nPRS2L3lsY52cDcJ7QUmpUTy1xVix+OvkUVrZ0HgxSAZcrkA63Q PeVzY7/fqYbJcxesNozlKQT8KMMaMDzxZngjTbj/sjalgt93pkNx8UCxonOc3F6ZQinp kw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2kn3jtbqev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 09 Aug 2018 15:13:58 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w79FDv7A022298 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 9 Aug 2018 15:13:57 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w79FDvU1001981 for ; Thu, 9 Aug 2018 15:13:57 GMT Received: from ak.ru.oracle.com (/10.162.80.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 09 Aug 2018 08:13:57 -0700 From: Alexey Kodanev To: ltp@lists.linux.it Date: Thu, 9 Aug 2018 18:23:43 +0300 Message-Id: <1533828226-24753-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=8979 signatures=668707 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-1808090156 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 RFC 1/4] 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 modrpobe is not available on the system, the checks are silently skipped. Signed-off-by: Alexey Kodanev Acked-by: Petr Vorel --- include/tst_test.h | 5 +++++ lib/tst_test.c | 26 ++++++++++++++++++++++++++ testcases/lib/.gitignore | 1 + testcases/lib/Makefile | 2 +- testcases/lib/tst_check_drivers.c | 24 ++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletions(-) create mode 100644 testcases/lib/tst_check_drivers.c diff --git a/include/tst_test.h b/include/tst_test.h index 98dacf3..221796d 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -170,6 +170,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; }; /* @@ -219,6 +222,8 @@ const char *tst_strstatus(int status); void tst_set_timeout(int timeout); +int tst_check_drivers(void); + #ifndef TST_NO_DEFAULT_MAIN static struct tst_test test; diff --git a/lib/tst_test.c b/lib/tst_test.c index 2f3d357..6cb74cf 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -645,6 +645,29 @@ static int needs_tmpdir(void) tst_test->needs_checkpoints; } +int tst_check_drivers(void) +{ + const char *name; + int i, res; + + for (i = 0; (name = tst_test->needs_drivers[i]); ++i) { + const char * const argv[] = { "modprobe", name, NULL }; + + res = tst_run_cmd_(NULL, argv, "/dev/null", "/dev/null", 1); + if (res == 255) + return res; /* it looks like modprobe not available */ + if (res) { + if (tst_test->test || tst_test->test_all) { + tst_brk(TCONF, "%s driver not available", name); + } else { + fprintf(stderr, "%s", name); + return res; + } + } + } + return 0; +} + static void copy_resources(void) { unsigned int i; @@ -767,6 +790,9 @@ static void do_setup(int argc, char *argv[]) if (tst_test->min_kver) check_kver(); + if (tst_test->needs_drivers) + tst_check_drivers(); + 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..3f722f2 --- /dev/null +++ b/testcases/lib/tst_check_drivers.c @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved. + */ + +#include +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" + +struct tst_test *tst_test; + +int main(int argc, const char *argv[]) +{ + if (argc < 2) { + fprintf(stderr, "Please provide kernel driver list\n"); + return 1; + } + + struct tst_test test = { + .needs_drivers = &argv[1] + }; + + tst_test = &test; + return tst_check_drivers(); +}