From: Andrew Jones Subject: [PATCH kvm-unit-tests v2 2/9] arch-run: provide errata from run env Date: Tue, 6 Jun 2017 20:22:42 +0200 Message-ID: <20170606182249.19313-3-drjones@redhat.com> References: <20170606182249.19313-1-drjones@redhat.com> Cc: pbonzini@redhat.com, rkrcmar@redhat.com, lvivier@redhat.com, thuth@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:57432 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751247AbdFFSXG (ORCPT ); Tue, 6 Jun 2017 14:23:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EFEA61D10 for ; Tue, 6 Jun 2017 18:22:56 +0000 (UTC) In-Reply-To: <20170606182249.19313-1-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Allow the run script environment to provide ERRATA_* variables to the unit tests. These variables will augment/override variables in any provided unit test environ (the file specified with $ENV) or trigger the creation of a temporary environ file, which contains them. Now something like ERRATA_abcd01234567=y ./run_tests.sh may be run in order to inform all unit tests that they may execute all subtests guarded by ERRATA_abcd01234567. Signed-off-by: Andrew Jones --- scripts/arch-run.bash | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index fc95e263458f..09072ee46366 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -158,5 +158,33 @@ search_qemu_binary () initrd_create () { + env_add_errata [ -f "$ENV" ] && INITRD="-initrd $ENV" } + +env_add_errata () +{ + local line errata + + if [ -f "$ENV" ] && grep -q '^ERRATA_' <(env); then + for line in $(grep '^ERRATA_' "$ENV"); do + errata=${line%%=*} + test -v $errata && continue + eval export "$line" + done + fi + + if grep -q '^ERRATA_' <(env); then + export ENV_OLD="$ENV" + export ENV=$(mktemp) + trap_exit_push 'rm -f $ENV; [ "$ENV_OLD" ] && export ENV="$ENV_OLD" || unset ENV; unset ENV_OLD' + [ -f "$ENV_OLD" ] && grep -v '^ERRATA_' "$ENV_OLD" > $ENV + grep '^ERRATA_' <(env) >> $ENV + fi +} + +trap_exit_push () +{ + local old_exit=$(trap -p EXIT | sed "s/^[^']*'//;s/'[^']*$//") + trap -- "$1; $old_exit" EXIT +} -- 2.9.4