From patchwork Tue Apr 9 23:55:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10892875 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 F14281708 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 D9D0C28387 for ; Tue, 9 Apr 2019 23:56:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE29D28701; 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 59BC8288BB for ; Tue, 9 Apr 2019 23:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726680AbfDIX4K (ORCPT ); Tue, 9 Apr 2019 19:56:10 -0400 Received: from mail-pf1-f171.google.com ([209.85.210.171]:34719 "EHLO mail-pf1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726741AbfDIX4J (ORCPT ); Tue, 9 Apr 2019 19:56:09 -0400 Received: by mail-pf1-f171.google.com with SMTP id b3so250454pfd.1 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=FFT1aVePQMmOXt7Bx8AXONIyJ3gNRAjMM6LapXIRXhg=; b=nCH9VZ1jjr8A0YYdyXW87NLqn/Yg2isK7BH876WqeZimsOgmvOqy2bBRMrC0YQN8El 9Pu1uXKyPVfToPKjyO6uK4HURg50W0U9BzD2WayZVU9iCs682iCOp+9i1bXfAv68Vjbg t2ysjgaofcRJ3s9xisOl2gXiurWq8xdm4ftgY= 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=FFT1aVePQMmOXt7Bx8AXONIyJ3gNRAjMM6LapXIRXhg=; b=cEla6+wLnG6vXaxDn1T0MYVUhBgAj/iJRF698WbqGqlgMC99y3iEnRCRqmJzTuozWQ A5H34LlSJfffTC6lcaU86+yRPQBQ6TtMKu5Q1NGMU15mALuwkNwsA0EsoKVlbN+FDU// psyD9oFYnnoUJBjP+zSHWyhDoOVG3iQm6vvzSBFAgYWSYFGPwYBwe1C6aSWwiQsf3XI9 WZgYkQ4Zigpk8vDEQcxWf+pMOQ9cP69WCosTH14nA3ijwXB7W4en/GxJjYLdXqP5ohYu P9c4VAhnSrzPYDocI09ma0tdboCUPUu8wJvmJ6i9fixbzEHq2ALyaKsHaLW4ngDBmZuW Rx1g== X-Gm-Message-State: APjAAAVdEdvBD4Z3ApV8nH3blWOqqazmKHKuv7c5PAtdjC71J/uMEbno ACkU+JhAGUoUahQ3SR2LCRJPYPxsWtA= X-Google-Smtp-Source: APXvYqyUngpl0+K4riscqnwr7X+TY7gbTYIiZfYt14mRMUMw1iVvp993M755n7Ies6KLu+t7Dvp/qQ== X-Received: by 2002:a63:c302:: with SMTP id c2mr38195144pgd.235.1554854169078; Tue, 09 Apr 2019 16:56:09 -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 c1sm9564851pgq.33.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 1/6] selftests: Extract single-test shell logic from lib.mk Date: Tue, 9 Apr 2019 16:55:51 -0700 Message-Id: <20190409235556.3967-2-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 In order to improve the reusability of the kselftest test running logic, this extracts the single-test logic from lib.mk into kselftest/runner.sh which lib.mk can call directly. No changes in output. As part of the change, this removes the unused "summary" Makefile variable (and tests). However, future merging with the "emit_tests" target needs to be able to redirect output, so a new "logfile" variable is introduced. Signed-off-by: Kees Cook --- tools/testing/selftests/.gitignore | 1 - tools/testing/selftests/kselftest/runner.sh | 31 +++++++++++++++++++ tools/testing/selftests/lib.mk | 33 ++------------------- 3 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 tools/testing/selftests/kselftest/runner.sh diff --git a/tools/testing/selftests/.gitignore b/tools/testing/selftests/.gitignore index 91750352459d..8059ce834247 100644 --- a/tools/testing/selftests/.gitignore +++ b/tools/testing/selftests/.gitignore @@ -1,4 +1,3 @@ -kselftest gpiogpio-event-mon gpiogpio-hammer gpioinclude/ diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh new file mode 100644 index 000000000000..77d5510ac4c5 --- /dev/null +++ b/tools/testing/selftests/kselftest/runner.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Runs a set of tests in a given subdirectory. +export skip_rc=4 +export logfile=/dev/stdout + +run_one() +{ + TEST="$1" + NUM="$2" + + BASENAME_TEST=$(basename $TEST) + + TEST_HDR_MSG="selftests: "`basename $PWD`:" $BASENAME_TEST" + echo "$TEST_HDR_MSG" + echo "========================================" + if [ ! -x "$TEST" ]; then + echo "$TEST_HDR_MSG: Warning: file $TEST is not executable, correct this." + echo "not ok 1..$test_num $TEST_HDR_MSG [FAIL]" + else + cd `dirname $TEST` > /dev/null + (./$BASENAME_TEST >> "$logfile" 2>&1 && + echo "ok 1..$test_num $TEST_HDR_MSG [PASS]") || + (if [ $? -eq $skip_rc ]; then \ + echo "not ok 1..$test_num $TEST_HDR_MSG [SKIP]" + else + echo "not ok 1..$test_num $TEST_HDR_MSG [FAIL]" + fi) + cd - >/dev/null + fi +} diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 8b0f16409ed7..7da79fe0bb78 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -5,6 +5,7 @@ CC := $(CROSS_COMPILE)gcc ifeq (0,$(MAKELEVEL)) OUTPUT := $(shell pwd) endif +selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) # The following are built by lib.mk common compile rules. # TEST_CUSTOM_PROGS should be used by tests that require @@ -31,43 +32,15 @@ all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) endif .ONESHELL: -define RUN_TEST_PRINT_RESULT - TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST"; \ - echo $$TEST_HDR_MSG; \ - echo "========================================"; \ - if [ ! -x $$TEST ]; then \ - echo "$$TEST_HDR_MSG: Warning: file $$BASENAME_TEST is not executable, correct this.";\ - echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]"; \ - else \ - cd `dirname $$TEST` > /dev/null; \ - if [ "X$(summary)" != "X" ]; then \ - (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && \ - echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") || \ - (if [ $$? -eq $$skip ]; then \ - echo "not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]"; \ - else echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]"; \ - fi;) \ - else \ - (./$$BASENAME_TEST && \ - echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") || \ - (if [ $$? -eq $$skip ]; then \ - echo "not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]"; \ - else echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]"; \ - fi;) \ - fi; \ - cd - > /dev/null; \ - fi; -endef - define RUN_TESTS @export KSFT_TAP_LEVEL=`echo 1`; \ test_num=`echo 0`; \ - skip=`echo 4`; \ + . $(selfdir)/kselftest/runner.sh; \ echo "TAP version 13"; \ for TEST in $(1); do \ BASENAME_TEST=`basename $$TEST`; \ test_num=`echo $$test_num+1 | bc`; \ - $(call RUN_TEST_PRINT_RESULT,$(TEST),$(BASENAME_TEST),$(test_num),$(skip)) \ + run_one "$$BASENAME_TEST" "$$test_num"; \ done; endef