From patchwork Tue Apr 2 22:26:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10882401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C4A115AC for ; Tue, 2 Apr 2019 22:26:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68F9527FA8 for ; Tue, 2 Apr 2019 22:26:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B3542892D; Tue, 2 Apr 2019 22:26:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B463A27FA8 for ; Tue, 2 Apr 2019 22:26:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726074AbfDBW0O (ORCPT ); Tue, 2 Apr 2019 18:26:14 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42526 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725990AbfDBW0N (ORCPT ); Tue, 2 Apr 2019 18:26:13 -0400 Received: by mail-pg1-f193.google.com with SMTP id p6so7231382pgh.9 for ; Tue, 02 Apr 2019 15:26:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=elmvZmEkYTC6U+keL4nYfg5GaFomehZ93h8XSMMJlD4=; b=NhCqjev2U2aNHIElbzNZrW02GIEhnuZGFN18Hy4rHpvvJHaeiMbzWo4CNclkhuq1jF 50l2gT5hz1NUqmfRW3+iAisSxf+VDyQh1IJJJ57IwX2GGtuUbvWu8ghpkJaJWZHNUyu1 gSnAAUnKVlt4VvlXIhYUmKeIi/yM6gE+JptJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=elmvZmEkYTC6U+keL4nYfg5GaFomehZ93h8XSMMJlD4=; b=mXdTPA5n6iC7iyLjN/9az5T+CM3burQCROwW3vZRCM3UTpzt1sRzli/Nk0dxdJ2vRs vNDuBD8//g3Lo11fLaKFVObIt5RHRDC0RLitiW62VURO5IbCZ4r5COKpSpWKF5OuOdC5 urqbcj8vPO58PPpge3+qpxc8kMrb46yO/se/GFa8WHL1sCkFzaQN3Nsz9r/oN63GKNWA m0ZzxvZqpMsTh4OA7DBURon6myI8CpcoHA1gK2DiDoN2tokWj3zzfWvHpGmAC8lDhysG 9RSSVct8SIGFLwyyC+JZkbVXRSP+f65Lea8LbcQ0zTbEobAQAiMurle5BKbY5WFB2hOB 14iw== X-Gm-Message-State: APjAAAW3NvoffLw39zEXd71TAi76xPZgFd0Lx7snAtaikNhpu6kBXiI2 iPbgQNNQRJPxuy7TOsl4A+lXIA== X-Google-Smtp-Source: APXvYqzQr7CEn3E+xqPJELWcw9r4GvSfz6BuX6LJXgsXtIS/tHsuUP1fNvL+LKZ6oabnP0xP59Uk2A== X-Received: by 2002:a63:2f44:: with SMTP id v65mr68442585pgv.141.1554243972854; Tue, 02 Apr 2019 15:26:12 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id r24sm1775549pfd.120.2019.04.02.15.26.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Apr 2019 15:26:11 -0700 (PDT) Date: Tue, 2 Apr 2019 15:26:10 -0700 From: Kees Cook To: "Tobin C. Harding" Cc: Shuah Khan , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3.1] selftests: Clean up module testing shell script Message-ID: <20190402222610.GA15100@beast> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adjusts kselftest_module.sh to take an option "args" argument for modprobe arguments, removes bash-isms (since some system's /bin/sh may not be bash), and refactors the lib/ scripts into a shorter calling convention. Signed-off-by: Kees Cook --- This is my suggested clean-up for the module testing script for the strscpy_pad() series... --- tools/testing/selftests/kselftest_module.sh | 24 ++++++++++++-------- tools/testing/selftests/lib/bitmap.sh | 17 +------------- tools/testing/selftests/lib/prime_numbers.sh | 17 ++------------ tools/testing/selftests/lib/printf.sh | 16 +------------ tools/testing/selftests/lib/strscpy.sh | 17 ++------------ 5 files changed, 20 insertions(+), 71 deletions(-) diff --git a/tools/testing/selftests/kselftest_module.sh b/tools/testing/selftests/kselftest_module.sh index b5d446738614..20a897d21fde 100755 --- a/tools/testing/selftests/kselftest_module.sh +++ b/tools/testing/selftests/kselftest_module.sh @@ -2,19 +2,20 @@ # 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 +# 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. +args="" # modprobe arguments modprobe="/sbin/modprobe" main() { - parse_args $@ + parse_args "$@" assert_root assert_have_module run_module @@ -23,17 +24,20 @@ main() { parse_args() { script=${0##*/} - if [[ ! $# -eq 2 ]]; then - echo "Usage: $script [FAIL]" + if [ $# -lt 2 ]; then + echo "Usage: $script [FAIL]" exit 1 fi - module=$1 - desc=$2 + desc="$1" + shift || true + module="$1" + shift || true + args="$@" } assert_root() { - if [[ $EUID -ne 0 ]]; then + if [ ! -w /dev ]; then skip "please run as root" fi } @@ -45,7 +49,7 @@ assert_have_module() { } run_module() { - if $modprobe -q $module; then + if $modprobe -q $module $args; then $modprobe -q -r $module say "ok" else @@ -72,4 +76,4 @@ skip() { # # Main script # -main $@ +main "$@" diff --git a/tools/testing/selftests/lib/bitmap.sh b/tools/testing/selftests/lib/bitmap.sh index ed4180ea0021..5511dddc5c2d 100755 --- a/tools/testing/selftests/lib/bitmap.sh +++ b/tools/testing/selftests/lib/bitmap.sh @@ -1,18 +1,3 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 - -module=test_bitmap -description="bitmap" - -# -# Shouldn't need to edit anything below here. -# - -file="kselftest_module.sh" -path="../$file" -if [[ ! $KBUILD_SRC == "" ]]; then - path="${KBUILD_SRC}/tools/testing/selftests/$file" -fi - -$path $module $description - +$(dirname $0)/../kselftest_module.sh "bitmap" test_bitmap diff --git a/tools/testing/selftests/lib/prime_numbers.sh b/tools/testing/selftests/lib/prime_numbers.sh index 6f782386d897..2b6be0308a6d 100755 --- a/tools/testing/selftests/lib/prime_numbers.sh +++ b/tools/testing/selftests/lib/prime_numbers.sh @@ -1,18 +1,5 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 # Checks fast/slow prime_number generation for inconsistencies - -module=prime_numbers -description="prime_numbers" - -# -# Shouldn't need to edit anything below here. -# - -file="kselftest_module.sh" -path="../$file" -if [[ ! $KBUILD_SRC == "" ]]; then - path="${KBUILD_SRC}/tools/testing/selftests/$file" -fi - -$path $module $description +$(dirname $0)/../kselftest_module.sh "prime numbers" prime_numbers \ + selftest=65536 diff --git a/tools/testing/selftests/lib/printf.sh b/tools/testing/selftests/lib/printf.sh index 89717915d028..2ffa61da0296 100755 --- a/tools/testing/selftests/lib/printf.sh +++ b/tools/testing/selftests/lib/printf.sh @@ -1,18 +1,4 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 # Tests the printf infrastructure using test_printf kernel module. - -module=test_printf -description="printf" - -# -# Shouldn't need to edit anything below here. -# - -file="kselftest_module.sh" -path="../$file" -if [[ ! $KBUILD_SRC == "" ]]; then - path="${KBUILD_SRC}/tools/testing/selftests/$file" -fi - -$path $module $description +$(dirname $0)/../kselftest_module.sh "printf" test_printf diff --git a/tools/testing/selftests/lib/strscpy.sh b/tools/testing/selftests/lib/strscpy.sh index f3ba4b90e602..1f26dac74896 100755 --- a/tools/testing/selftests/lib/strscpy.sh +++ b/tools/testing/selftests/lib/strscpy.sh @@ -1,17 +1,4 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0+ - -module=test_strscpy -description="strscpy" - -# -# Shouldn't need to edit anything below here. -# - -file="kselftest_module.sh" -path="../$file" -if [[ ! $KBUILD_SRC == "" ]]; then - path="${KBUILD_SRC}/tools/testing/selftests/$file" -fi - -$path $module $description +# Test corner cases of the strscpy()-family of functions. +$(dirname $0)/../kselftest_module.sh "strscpy" test_strscpy