Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4448202imb; Wed, 6 Mar 2019 13:44:14 -0800 (PST) X-Google-Smtp-Source: APXvYqzZaCwkfR+v0G7UAplGlHn0tWMDfCqhoLQD4Ci265y9aJ9olfszUS2yVihkexeFgasUNEJu X-Received: by 2002:a17:902:7202:: with SMTP id ba2mr8976835plb.147.1551908654730; Wed, 06 Mar 2019 13:44:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551908654; cv=none; d=google.com; s=arc-20160816; b=sz2ThA9+kSuE7s1ZfYOomYpbx5lFxonNGWbvFou/qAoUOiO7WnY1Ui4Nq25UVkeqnf xJ1Z8Jlp+vO/e3N8FyLuT0ZdSPRu7A3RNL1kM6vfu1A/Ncl/5/3//qfwIoPhCojXiEW+ VBIeYQ2Ka9CbwhSWBUDLG0+ZhiTTBB+5kJZymF7htAQ+5xT9196hduPcWX+nVoY5HNGT Ym31SleEhoiUhlTCtaAjP7MnX+oQKUkX6ywsR80IPt9irW0P3sVATjCATrvTqAe+iZ3m eSVEb+/q20+aO3aLEhHguNcBPTEhHqXFJuQ9Tgfiy4Yqwz+QvmxWqOedUmtza6TclpdE LP9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=q01YGeCoIbHEEIB//S+2XygDhqyH/9qJaPDW3fWo93c=; b=aZxSLAQ12mxNLwKX8smNuWFWlLOAD86DciOLNRGgLqjnBYXjKM9wA9x3C+npsvR4w4 hog2GF8uW61v6pjnOBa6f0F3e9hcYUX60xrZZL+4lHJL9vix7EtKITTS78RDy9+GDRqC rwZcNwlQCiA2l3OMfiF15ruEfDOxP/BrYkJ3G2QeT8jtduKLw68+YwohNXlOR7omImiB 8+CKa33CNeD9gkgaWj/tOZjqfUBGd/aysF6ILPAAuCmbt/ef+gNm4XN1oiWIAPf+M14q ygUM7o0YrydjIIYv4rZVdtPkcwbetVA88+UtY77rlykf5TsU/tVvObenhodv+CIoNcFf YF0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=8JzgRdlI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si2256818pgs.387.2019.03.06.13.43.59; Wed, 06 Mar 2019 13:44:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=8JzgRdlI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726307AbfCFVn1 (ORCPT + 99 others); Wed, 6 Mar 2019 16:43:27 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:53963 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbfCFVn0 (ORCPT ); Wed, 6 Mar 2019 16:43:26 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D169822A8A; Wed, 6 Mar 2019 16:43:24 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 06 Mar 2019 16:43:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=q01YGeCoIbHEEIB//S+2XygDhqyH/9qJaPDW3fWo93c=; b=8JzgRdlI wlbeEOegIMH/s8GRQ+Yr/us5es7S6oCHaLVTp6BapMgZeLbIwpphXfUyKUJBn6+b SYPsf6gTkFsrG00zG6vabqdSe20TA6bM02pHFrW4yR3eMlVNQcpsspAPhaVJnnTX b1M8Q0ofUtvdD0nXjRPXlDd0EUWMSbvDE7x9gSHS/4gZzzg2abcnPS2a7ETWhkoC yj7zBKabjnau99JyIB2ptNFOftAP05N6Wq9GYL9NMTwA7OoCxejxlpV62RW8ebpb 3L6AReYf0nmbjIsPB7ZQDHakiG3a4h7moAChbyOwhzIUKUtPU0DZxjzQOJ8aT34k 9TTvxX+4g0cjsA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrfeeigdekjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepfdfvohgsihhn ucevrdcujfgrrhguihhnghdfuceothhosghinheskhgvrhhnvghlrdhorhhgqeenucfkph epuddvgedrudeiledrhedrudehkeenucfrrghrrghmpehmrghilhhfrhhomhepthhosghi nheskhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgepud X-ME-Proxy: Received: from eros.localdomain (124-169-5-158.dyn.iinet.net.au [124.169.5.158]) by mail.messagingengine.com (Postfix) with ESMTPA id 4F189E4362; Wed, 6 Mar 2019 16:43:19 -0500 (EST) From: "Tobin C. Harding" To: Kees Cook , Shuah Khan Cc: "Tobin C. Harding" , Jann Horn , Andy Shevchenko , Randy Dunlap , Rasmus Villemoes , Stephen Rothwell , Andy Lutomirski , Daniel Micay , Arnd Bergmann , Miguel Ojeda , "Gustavo A. R. Silva" , Greg Kroah-Hartman , Alexander Shishkin , kernel-hardening@lists.openwall.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/7] kselftest: Add test runner creation script Date: Thu, 7 Mar 2019 08:42:21 +1100 Message-Id: <20190306214226.14598-3-tobin@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306214226.14598-1-tobin@kernel.org> References: <20190306214226.14598-1-tobin@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently if we wish to use kselftest to run tests within a kernel module we write a small script to load/unload and do error reporting. There are a bunch of these under tools/testing/selftests/lib/ that are all identical except for the test name. We can reduce code duplication and improve maintainability if we have one version of this. However kselftest requires an executable for each test. We can move all the script logic to a central script then have each individual test script set the module name and call the main script. There is a little bit of boilerplate left in each script to handle building/running tests with the O=/path/to/out make option. Add test runner creation script. Signed-off-by: Tobin C. Harding --- tools/testing/selftests/kselftest_module.sh | 75 +++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 tools/testing/selftests/kselftest_module.sh diff --git a/tools/testing/selftests/kselftest_module.sh b/tools/testing/selftests/kselftest_module.sh new file mode 100755 index 000000000000..b5d446738614 --- /dev/null +++ b/tools/testing/selftests/kselftest_module.sh @@ -0,0 +1,75 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ + +# +# Runs an individual test module. kselftest expects a separate +# executable for each test. So test should each have an individial +# script that can call this script. +# + +# Individual test scrits should define these: +module="" # filename (without the .ko). +desc="" # Output prefix. + +modprobe="/sbin/modprobe" + +main() { + parse_args $@ + assert_root + assert_have_module + run_module +} + +parse_args() { + script=${0##*/} + + if [[ ! $# -eq 2 ]]; then + echo "Usage: $script [FAIL]" + exit 1 + fi + + module=$1 + desc=$2 +} + +assert_root() { + if [[ $EUID -ne 0 ]]; then + skip "please run as root" + fi +} + +assert_have_module() { + if ! $modprobe -q -n $module; then + skip "module $module is not found" + fi +} + +run_module() { + if $modprobe -q $module; then + $modprobe -q -r $module + say "ok" + else + fail "" + fi +} + +say() { + echo "$desc: $1" +} + + +fail() { + say "$1 [FAIL]" >&2 + exit 1 +} + +skip() { + say "$1 [SKIP]" >&2 + # Kselftest framework requirement - SKIP code is 4. + exit 4 +} + +# +# Main script +# +main $@ -- 2.20.1