From patchwork Fri May 8 06:53:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 11535743 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 67B571668 for ; Fri, 8 May 2020 06:53:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3615720643 for ; Fri, 8 May 2020 06:53:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="pRFFc4jh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726009AbgEHGxq (ORCPT ); Fri, 8 May 2020 02:53:46 -0400 Received: from ozlabs.org ([203.11.71.1]:33791 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbgEHGxp (ORCPT ); Fri, 8 May 2020 02:53:45 -0400 Received: by ozlabs.org (Postfix, from userid 1034) id 49JLdg623nz9sSs; Fri, 8 May 2020 16:53:43 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1588920823; bh=acAgab8g6yhDEvTaya+ecKBQqSHAhREHhSbZFn0j3sY=; h=From:To:Cc:Subject:Date:From; b=pRFFc4jh4HLz9bwkFCuTkCFdIwklxYYg6WoWqUvG2tbuebKPlO+q2Eyc45+pcGlRh JFhRjsVFi7AflB108Hman1pd3K3r2vV1pDrn7HepYny22964LV6ireFqjx/gzBCEMj Xje5vDl2YuXJuBObStk4wFk3cnQdOtJmqNQK/HTRFSGn1/tkfqzsvC01wtVAPgR41u JlyELZ20QPqTfwMT+yGNgNx6f/SkQrkuN+Uh8ZvcnV5h2HQC8EB/zY6XiXwEq/KOba Mgw5VMIHMwRgAVqYH4QQpMVI2Sq+X5O7cHzkJpF7RwDtW5OxOUCJyTviT+3dO2Y5nW lnyS5wm+xTvwQ== From: Michael Ellerman To: keescook@chromium.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] selftests/lkdtm: Don't clear dmesg when running tests Date: Fri, 8 May 2020 16:53:55 +1000 Message-Id: <20200508065356.2493343-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org It is Very Rude to clear dmesg in test scripts. That's because the script may be part of a larger test run, and clearing dmesg potentially destroys the output of other tests. We can avoid using dmesg -c by saving the content of dmesg before the test, and then using diff to compare that to the dmesg afterward, producing a log with just the added lines. Signed-off-by: Michael Ellerman Acked-by: Kees Cook Reported-by: Naresh Kamboju Signed-off-by: Joe Lawrence --- tools/testing/selftests/lkdtm/run.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) base-commit: 192ffb7515839b1cc8457e0a8c1e09783de019d3 diff --git a/tools/testing/selftests/lkdtm/run.sh b/tools/testing/selftests/lkdtm/run.sh index dadf819148a4..0b409e187c7b 100755 --- a/tools/testing/selftests/lkdtm/run.sh +++ b/tools/testing/selftests/lkdtm/run.sh @@ -59,23 +59,25 @@ if [ -z "$expect" ]; then expect="call trace:" fi -# Clear out dmesg for output reporting -dmesg -c >/dev/null - # Prepare log for report checking -LOG=$(mktemp --tmpdir -t lkdtm-XXXXXX) +LOG=$(mktemp --tmpdir -t lkdtm-log-XXXXXX) +DMESG=$(mktemp --tmpdir -t lkdtm-dmesg-XXXXXX) cleanup() { - rm -f "$LOG" + rm -f "$LOG" "$DMESG" } trap cleanup EXIT +# Save existing dmesg so we can detect new content below +dmesg > "$DMESG" + # Most shells yell about signals and we're expecting the "cat" process # to usually be killed by the kernel. So we have to run it in a sub-shell # and silence errors. ($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true # Record and dump the results -dmesg -c >"$LOG" +dmesg | diff --changed-group-format='%>' --unchanged-group-format='' "$DMESG" - > "$LOG" || true + cat "$LOG" # Check for expected output if egrep -qi "$expect" "$LOG" ; then From patchwork Fri May 8 06:53:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 11535745 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5F2A15AB for ; Fri, 8 May 2020 06:53:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AC5C20870 for ; Fri, 8 May 2020 06:53:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="lBieyN44" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726926AbgEHGxt (ORCPT ); Fri, 8 May 2020 02:53:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725971AbgEHGxs (ORCPT ); Fri, 8 May 2020 02:53:48 -0400 Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38809C05BD43; Thu, 7 May 2020 23:53:48 -0700 (PDT) Received: by ozlabs.org (Postfix, from userid 1034) id 49JLdh6JfQz9sSy; Fri, 8 May 2020 16:53:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1588920824; bh=9Ynms6h27w3AbHNpPH8n4uEonv1y0P/FM3hzIpDmeh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lBieyN440rRpPXdGKZOP/FUv65pTIR2LQbC4+L21Xu6LA4zmzWIQafdUr6+jxSeiW l5m5McNHxwk5XIa9VtBvcx4dmDfD0zH0b8hNkXEp2ql0y+HcaISvLyNHR+lJb+8bRq IJl+jgMjI2qVUVFUiQUTz/ouKLyiCeMr9O3bEiZBfKGsxKcKp3tQXfPqfFuPVZXsQj MXK4NEVfsv/qDbYdI7o+J1iw2jpjgJUOrs4V0HcNJ6r6KCmmi85gVAiiJ6Aj/3R4EP V9wtD8tWLW6JeC6uV8EAiRVXYJXdSmITh0po6xMm/O73AXtX3HWCXA2ayzGF7V8sLL 6dfxqUlxwidog== From: Michael Ellerman To: keescook@chromium.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/2] selftests/lkdtm: Use grep -E instead of egrep Date: Fri, 8 May 2020 16:53:56 +1000 Message-Id: <20200508065356.2493343-2-mpe@ellerman.id.au> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200508065356.2493343-1-mpe@ellerman.id.au> References: <20200508065356.2493343-1-mpe@ellerman.id.au> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org shellcheck complains that egrep is deprecated, and the grep man page agrees. Use grep -E instead. Signed-off-by: Michael Ellerman Acked-by: Kees Cook --- tools/testing/selftests/lkdtm/run.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/lkdtm/run.sh b/tools/testing/selftests/lkdtm/run.sh index 0b409e187c7b..ee64ff8df8f4 100755 --- a/tools/testing/selftests/lkdtm/run.sh +++ b/tools/testing/selftests/lkdtm/run.sh @@ -25,13 +25,13 @@ fi # Figure out which test to run from our script name. test=$(basename $0 .sh) # Look up details about the test from master list of LKDTM tests. -line=$(egrep '^#?'"$test"'\b' tests.txt) +line=$(grep -E '^#?'"$test"'\b' tests.txt) if [ -z "$line" ]; then echo "Skipped: missing test '$test' in tests.txt" exit $KSELFTEST_SKIP_TEST fi # Check that the test is known to LKDTM. -if ! egrep -q '^'"$test"'$' "$TRIGGER" ; then +if ! grep -E -q '^'"$test"'$' "$TRIGGER" ; then echo "Skipped: test '$test' missing in $TRIGGER!" exit $KSELFTEST_SKIP_TEST fi @@ -80,11 +80,11 @@ dmesg | diff --changed-group-format='%>' --unchanged-group-format='' "$DMESG" - cat "$LOG" # Check for expected output -if egrep -qi "$expect" "$LOG" ; then +if grep -E -qi "$expect" "$LOG" ; then echo "$test: saw '$expect': ok" exit 0 else - if egrep -qi XFAIL: "$LOG" ; then + if grep -E -qi XFAIL: "$LOG" ; then echo "$test: saw 'XFAIL': [SKIP]" exit $KSELFTEST_SKIP_TEST else