From patchwork Tue Apr 9 23:55:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10892873 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 747A118B7 for ; Tue, 9 Apr 2019 23:56:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5772928387 for ; Tue, 9 Apr 2019 23:56:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BCB828701; Tue, 9 Apr 2019 23:56:10 +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 D3BC02883B for ; Tue, 9 Apr 2019 23:56:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726755AbfDIX4J (ORCPT ); Tue, 9 Apr 2019 19:56:09 -0400 Received: from mail-pg1-f169.google.com ([209.85.215.169]:43282 "EHLO mail-pg1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726680AbfDIX4J (ORCPT ); Tue, 9 Apr 2019 19:56:09 -0400 Received: by mail-pg1-f169.google.com with SMTP id z9so333802pgu.10 for ; Tue, 09 Apr 2019 16:56:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BBz3uzW2MkXRWFcDEhL/aWwf5vAxjd4KRec/q6yV/Yk=; b=ME+Jm/IUhSyjts8heL5egIe0w7S0fbc+6ib8//R5yLBxYbA8wyfUmxZLy5QbuM7DEG MdGw3XEd0bGfg/OgzoDQRNYZja0dYeNpjZhSH0YdMpwjA1hBBVeJICxuQG9/+lLPc8Ba GVcKUBPefA30it7UEp+csbkKLwlfD4IEMLrdA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BBz3uzW2MkXRWFcDEhL/aWwf5vAxjd4KRec/q6yV/Yk=; b=t566WU7aiWRVNkJC0K0leaeS2I9UE0IvzoZqcCJlskt0BmSA5t9QCcM9+Y8Drm652J Y0M2bQoKKFBy1Lth7QfkPygy3HRXwmx5UCff4xXRWlwpOoH4/7a+nOt7BcWbbVg0ZH74 OmruyV8v1m8NO1XKLkyvUrtLSx5IUHlJwydBMKrb8oClFqDUjRZTawDe7vCF1FSEg1yw Bfi7rv+Qybr4tcgNspkr1IW4clFKXLR5viZLf0C5/MBGnvgzXNNDpqJlVWU/fN0+90Ua IjMblWno+RX7vpgBaZyKIsichNW44OV3ERG49OB2QCQdJmLGj2gC6H7i+Y/uAX5M3UU9 OqWQ== X-Gm-Message-State: APjAAAUUeNqLMyhH0/DxtweiTmp2H5SS8ftdoPlbVjMB58zbQzuPDULi +GjdO8Bvk8VJl0mMwrYFE+eZMQ== X-Google-Smtp-Source: APXvYqz1Mtoq+4WhLun89pzJ4yACc/wtjhxkrxjJxbbg+ncCv9AjEyE1KOlIg7Fq5duSqRbTqdvJTA== X-Received: by 2002:aa7:8ac8:: with SMTP id b8mr39828381pfd.234.1554854168596; Tue, 09 Apr 2019 16:56:08 -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 i15sm17011592pfr.8.2019.04.09.16.56.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Apr 2019 16:56:05 -0700 (PDT) From: Kees Cook To: Shuah Khan Cc: Kees Cook , linux-kselftest@vger.kernel.org Subject: [PATCH 3/6] selftests: Extract logic for multiple test runs Date: Tue, 9 Apr 2019 16:55:53 -0700 Message-Id: <20190409235556.3967-4-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190409235556.3967-1-keescook@chromium.org> References: <20190409235556.3967-1-keescook@chromium.org> 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 moves the logic for running multiple tests into a single "run_many" function of runner.sh. Both "run_tests" and "emit_tests" are modified to use it. Signed-off-by: Kees Cook --- tools/testing/selftests/Makefile | 6 ++---- tools/testing/selftests/kselftest/runner.sh | 19 ++++++++++++++++--- tools/testing/selftests/lib.mk | 16 ++++------------ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 45327e921169..72178d28f9c6 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -148,16 +148,14 @@ ifdef INSTALL_PATH echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT) echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT) echo "fi" >> $(ALL_SCRIPT) - echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT) for TARGET in $(TARGETS); do \ BUILD_TARGET=$$BUILD/$$TARGET; \ - echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT); \ - echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \ - echo "echo ========================================" >> $(ALL_SCRIPT); \ echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ echo "cd $$TARGET" >> $(ALL_SCRIPT); \ + echo -n "run_many" >> $(ALL_SCRIPT); \ make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ + echo "" >> $(ALL_SCRIPT); \ echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ done; diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh index 77d5510ac4c5..51139f42a6ca 100644 --- a/tools/testing/selftests/kselftest/runner.sh +++ b/tools/testing/selftests/kselftest/runner.sh @@ -1,17 +1,19 @@ #!/bin/sh # # Runs a set of tests in a given subdirectory. +export KSFT_TAP_LEVEL=1 export skip_rc=4 export logfile=/dev/stdout run_one() { - TEST="$1" - NUM="$2" + DIR="$1" + TEST="$2" + NUM="$3" BASENAME_TEST=$(basename $TEST) - TEST_HDR_MSG="selftests: "`basename $PWD`:" $BASENAME_TEST" + TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST" echo "$TEST_HDR_MSG" echo "========================================" if [ ! -x "$TEST" ]; then @@ -29,3 +31,14 @@ run_one() cd - >/dev/null fi } + +run_many() +{ + echo "TAP version 13" + DIR=$(basename "$PWD") + test_num=0 + for TEST in "$@"; do + test_num=$(( test_num + 1 )) + run_one "$DIR" "$TEST" "$test_num" + done +} diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 8a4fad5d3934..8be13d117101 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -33,15 +33,8 @@ endif .ONESHELL: define RUN_TESTS - @export KSFT_TAP_LEVEL=`echo 1`; \ - test_num=`echo 0`; \ . $(selfdir)/kselftest/runner.sh; \ - echo "TAP version 13"; \ - for TEST in $(1); do \ - BASENAME_TEST=`basename $$TEST`; \ - test_num=`echo $$test_num+1 | bc`; \ - run_one "$$BASENAME_TEST" "$$test_num"; \ - done; + run_many $(1) endef run_tests: all @@ -79,12 +72,11 @@ else endif emit_tests: - @test_num=`echo 0`; \ for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ BASENAME_TEST=`basename $$TEST`; \ - test_num=`echo $$test_num+1 | bc`; \ - echo "run_one \"$$BASENAME_TEST\" \"$$test_num\""; \ - done; + echo " \\"; \ + echo -n " \"$$BASENAME_TEST\""; \ + done; \ # define if isn't already. It is undefined in make O= case. ifeq ($(RM),)