Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp239769ybt; Tue, 23 Jun 2020 20:51:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWQmSbrBT59eGJlqGwjM/4Pb7TExnSg2Fv1LncbwxFdwrA5QlXPxtAELCNIFIEVw9wcyac X-Received: by 2002:a17:906:cb94:: with SMTP id mf20mr22915667ejb.46.1592970682759; Tue, 23 Jun 2020 20:51:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592970682; cv=none; d=google.com; s=arc-20160816; b=RulZvc0nR0UT8i+nnLtmdjVdrhgSddZGK9hyMs32Hr+mTA/NaOmH5MUEvr7pfFQ5CL BR9LnhrmI0jySDvKyEUYpiOykgQTwIRsj00BirAcUI8KpFpgdRV5FIh+ghg8FAAlOYC+ z+ufTLOd7YLbY5ybYMeRKd7waOQijKLk87Ppjcukbi2K1qAZdexy1xjMkl+iI+KgFigq K1edhZZg5TkJzF+V3mXGKDsTs5Apt0e7SJpHuZ4+hiRt6YL49huB6QmnvW062tEckwjr t2vcjjmRRSo8CowEWY7uRc+P4ARTFsbYIjRkFYbiVDRFA3xcprfgDLXtUUqCtwu+3AJz 0e/Q== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=d9mmmSYUQts29pccjkqtdI3xyAW6oFJFtioXZrdF2dE=; b=oEInk9URfk/cWJw7Y+ylXyvI0QwDG0LxIh7Ds4fc264b87zW48o4Od2li9ixW5ro2s 3dvX+olcxAoDDub7ik9R8NNNwgNJsez5ci/0dCqy9VOpAGZtVhFstV8fGm4RwEw+NYJk WszLk8z1uweegCh04ArkbtZOFnXiTU57P+Kp6WloZxIfGGKYjx2G5MfLze568UdgJAYH 58W7JKdAnyVbab3qc8Ivb2ME2rSNTINrYuUv7q0x/qJJcxZUjTSeM4hVXLpBnH7y5B9c adH+FPDQypvKktZFuW2QwAfqg7IUFkF0OZ2gcy3uVjpbYVTQhtYzB+6gNpkRvchsTPdy s5NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e6hzjuDf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k91si13457813edc.296.2020.06.23.20.51.00; Tue, 23 Jun 2020 20:51:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e6hzjuDf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388671AbgFXDsu (ORCPT + 99 others); Tue, 23 Jun 2020 23:48:50 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:31385 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388572AbgFXDsu (ORCPT ); Tue, 23 Jun 2020 23:48:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592970528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d9mmmSYUQts29pccjkqtdI3xyAW6oFJFtioXZrdF2dE=; b=e6hzjuDfT8K6mw4lrgDetWM+RdAPZ4GjHouZLZ8LDHAj1nnHckj1th2N4POuajfNA1CQCE 1/FxkoL1XSr6+jhGqBCvECp6seZ+6uocZ9fDAOx3WtieQ+s916ADAg0Fa4bhcsVmiCIlDM tBsna+yPFD5Mb0ObdqD/5ktoj9QE0OQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-3-6d5_5QTQNo-JDVy78zrAaA-1; Tue, 23 Jun 2020 23:48:40 -0400 X-MC-Unique: 6d5_5QTQNo-JDVy78zrAaA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE6DB805EE3; Wed, 24 Jun 2020 03:48:38 +0000 (UTC) Received: from [10.10.112.56] (ovpn-112-56.rdu2.redhat.com [10.10.112.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BD2B10013C1; Wed, 24 Jun 2020 03:48:37 +0000 (UTC) Subject: Re: [PATCH 1/2] selftests/lkdtm: Don't clear dmesg when running tests To: Naresh Kamboju , Michael Ellerman , "open list:KERNEL SELFTEST FRAMEWORK" , open list Cc: Kees Cook , Anders Roxell , =?UTF-8?Q?Daniel_D=c3=adaz?= , Justin Cook , lkft-triage@lists.linaro.org, Miroslav Benes , Petr Mladek , Shuah Khan References: <20200508065356.2493343-1-mpe@ellerman.id.au> From: Joe Lawrence Message-ID: Date: Tue, 23 Jun 2020 23:48:36 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/22/20 4:51 AM, Naresh Kamboju wrote: > On Fri, 8 May 2020 at 12:23, Michael Ellerman wrote: >> >> 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 >> --- >> tools/testing/selftests/lkdtm/run.sh | 14 ++++++++------ >> 1 file changed, 8 insertions(+), 6 deletions(-) >> >> 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 > > We are facing problems with the diff `=%>` part of the option. > This report is from the OpenEmbedded environment. > We have the same problem from livepatch_testcases. > > # selftests lkdtm BUG.sh > lkdtm: BUG.sh_ # > # diff unrecognized option '--changed-group-format=%>' > unrecognized: option_'--changed-group-format=%>' # > # BusyBox v1.27.2 (2020-03-30 164108 UTC) multi-call binary. > v1.27.2: (2020-03-30_164108 # > # > : _ # > # Usage diff [-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2 > diff: [-abBdiNqrTstw]_[-L # > # BUG missing 'kernel BUG at' [FAIL] > > Full test output log, > https://qa-reports.linaro.org/lkft/linux-next-oe/build/next-20200621/testrun/2850083/suite/kselftest/test/lkdtm_BUG.sh/log > D'oh! Using diff's changed/unchanged group format was a nice trick to easily fetch the new kernel log messages. I can't think of any simple alternative off the top of my head, so here's a kludgy tested-once awk script: SAVED_DMESG="$(dmesg | tail -n1)" ... tests ... NEW_DMESG=$(dmesg | awk -v last="$SAVED_DMESG" 'p; $0 == last{p=1}') I think timestamps should make each log line unique, but this probably won't handle kernel log buffer overflow. Maybe it would be easier to log a known unique test delimiter msg and then fetch all new messages after that? -- Joe