Received: by 2002:ac0:93d5:0:0:0:0:0 with SMTP id f21csp1147879imf; Thu, 28 Feb 2019 13:50:31 -0800 (PST) X-Google-Smtp-Source: APXvYqzMnoOR/gFRdI+DMJmnNpWYlvSqVUUJgeUOlMTlowM/rbcS/VzClVGCyTBiqrxYNf3RtJBP X-Received: by 2002:a63:455f:: with SMTP id u31mr1303922pgk.241.1551390631835; Thu, 28 Feb 2019 13:50:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551390631; cv=none; d=google.com; s=arc-20160816; b=hU8zKzwOTxvslL/fDcik6eeoS8cqxR0LgmJGpxA+qtKeV1MSrV000gAmQ/fhLvehZZ vprJT2jHZKcWcCOxVRlqcUrnFzDxLX9Flst5MO6j9JeTRWfpUk4Oq8MJAv34dgt2AEC2 RBCrMj6mIUNxvtH+fiSslKNI3h2TSDd9kUtXTHtyyCekQBGFPftuw4sBrQCUA+1S06fJ 84YGsTiMeOJTKKRx7hUzBN0X39DTrQiL8SCIP1nUbhQnovQ7LCTLWaaNA/Gdfk/wovoU N1vZ4qoBXyEu7AJfjUDsAzCWJ8v7HJzixyIugtvdHxjDomDNq/OWoTcC/fjY3DUjBJH/ lmjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=HgOGZdoHx1CaLW+oGq1QaslAUekycWJoWZkraFBYckg=; b=ppGkQSJ9Dht5iPCKFPuBm7d/oNpTGh5+0kKBWkLmokD7YtXiaBEMjqSjI3DELi0pJs +Bal4v+l0YpbNVcauImeal1UlP/9yve3yp5x1hTPrCKEKLi9oqiRhFDxA8oh9LzQ06YV Ob3K+22nYKoMG8JE7jqObScfLp+dYhNtwgzNod4PjlwlWTzKHo/ejEDbFXCRGCuxvKKS kV3zy2kRCiGh41PMSlBQhYEwfFMClVKImq4CCVlk6yNtOevwAkqXz9lEM1Utr1d7GW1D /oAyDHgjB3VGWZ4ysx8Ng5hYlonpv/ea4vsyoYqVlxLyuxXV6vQHBMnMBNOwahHGwhAp TzHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cy1si20831383plb.429.2019.02.28.13.50.08; Thu, 28 Feb 2019 13:50:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387584AbfB1USL (ORCPT + 99 others); Thu, 28 Feb 2019 15:18:11 -0500 Received: from mx2.suse.de ([195.135.220.15]:52430 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726088AbfB1USL (ORCPT ); Thu, 28 Feb 2019 15:18:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4278DAFBD; Thu, 28 Feb 2019 20:18:09 +0000 (UTC) Date: Thu, 28 Feb 2019 21:18:07 +0100 From: Petr Vorel To: Mimi Zohar Cc: linux-kselftest@vger.kernel.org, Shuah Khan , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/5] selftests/ima: define common logging functions Message-ID: <20190228201807.GB20335@dell5510> Reply-To: Petr Vorel References: <1551223620-11586-1-git-send-email-zohar@linux.ibm.com> <1551223620-11586-4-git-send-email-zohar@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1551223620-11586-4-git-send-email-zohar@linux.ibm.com> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mimi, > Define log_info, log_pass, log_fail, and log_skip functions. > Suggested-by: Petr Vorel > Signed-off-by: Mimi Zohar > --- > tools/testing/selftests/ima/common_lib.sh | 43 +++++++++++++++++++++++--- > tools/testing/selftests/ima/test_kexec_load.sh | 19 +++--------- > 2 files changed, 43 insertions(+), 19 deletions(-) > diff --git a/tools/testing/selftests/ima/common_lib.sh b/tools/testing/selftests/ima/common_lib.sh > index 5583ea74c14e..c6d04006281d 100755 > --- a/tools/testing/selftests/ima/common_lib.sh > +++ b/tools/testing/selftests/ima/common_lib.sh > @@ -1,5 +1,36 @@ > #!/bin/sh > # SPDX-License-Identifier: GPL-2.0-or-later > +# > +# Kselftest framework defines: ksft_pass=0, ksft_fail=1, ksft_skip=4 > + > +VERBOSE="${VERBOSE:-1}" > + > +log_info() > +{ > + [ $VERBOSE -ne 0 ] && echo "[INFO] $1" > +} > + > +# The ksefltest framework requirement returns 0 for PASS. > +log_pass() > +{ > + > + [ $VERBOSE -ne 0 ] && echo "$1 [PASS]" > + exit 0 > +} > + > +# The ksefltest framework requirement returns 1 for FAIL. > +log_fail() > +{ > + [ $VERBOSE -ne 0 ] && echo "$1 [FAIL]" > + exit 1 > +} > + > +# The ksefltest framework requirement returns 4 for SKIP. > +log_skip() > +{ > + [ $VERBOSE -ne 0 ] && echo "$1" > + exit 4 > +} These might be good candidates for moving to selftest specific shell helper library (for somebody who wants to do this work). > # The secure boot mode can be accessed either as the last integer > # of "od -An -t u1 /sys/firmware/efi/efivars/SecureBoot-*" or from > @@ -8,17 +39,19 @@ > get_secureboot_mode() > { > local efivarfs="/sys/firmware/efi/efivars" > + > # Make sure that efivars is mounted in the normal location > if ! grep -q "^\S\+ $efivarfs efivarfs" /proc/mounts; then > - echo "$TEST: efivars is not mounted on $efivarfs" >&2 > - exit $ksft_skip > + log_skip "efivars is not mounted on $efivarfs" > fi > # Get secureboot mode > local file="$efivarfs/../vars/SecureBoot-*/data" > if [ ! -e $file ]; then > - echo "$TEST: unknown secureboot mode" >&2 > - exit $ksft_skip > + log_skip "unknown secureboot mode" > fi > - return `od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data` > + ret=`od -An -t u1 /sys/firmware/efi/vars/SecureBoot-*/data` > + [ $ret -eq 1 ] && log_info "secure boot mode enabled" > + > + return $ret > } > diff --git a/tools/testing/selftests/ima/test_kexec_load.sh b/tools/testing/selftests/ima/test_kexec_load.sh > index 35934e0665f1..8b99017538ba 100755 > --- a/tools/testing/selftests/ima/test_kexec_load.sh > +++ b/tools/testing/selftests/ima/test_kexec_load.sh > @@ -6,15 +6,10 @@ > TEST="$0" > . ./common_lib.sh > -rc=0 > - > -# Kselftest framework requirement - SKIP code is 4. > -ksft_skip=4 > # kexec requires root privileges > if [ $(id -ru) -ne 0 ]; then > - echo "$TEST: requires root privileges" >&2 > - exit $ksft_skip > + log_skip "requires root privileges" >&2 You left here redirection to stderr. + again requiring root could be in helper library. > fi > get_secureboot_mode > @@ -26,18 +21,14 @@ kexec --load $KERNEL_IMAGE 2>&1 > /dev/null > if [ $? -eq 0 ]; then > kexec --unload > if [ $secureboot -eq 1 ]; then > - echo "$TEST: kexec_load succeeded [FAIL]" > - rc=1 > + log_fail "kexec_load succeeded" > else > - echo "$TEST: kexec_load succeeded [PASS]" > + log_pass "kexec_load succeeded" > fi > else > if [ $secureboot -eq 1 ]; then > - echo "$TEST: kexec_load failed [PASS]" > + log_pass "kexec_load failed" > else > - echo "$TEST: kexec_load failed [FAIL]" > - rc=1 > + log_fail "kexec_load failed" > fi > fi > - > -exit $rc Kind regards, Petr