diff mbox

[kvm-unit-tests,2/8] arch-run: provide errata from run env

Message ID 20170524160818.4326-3-drjones@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jones May 24, 2017, 4:08 p.m. UTC
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 <drjones@redhat.com>
---
 scripts/arch-run.bash | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Laurent Vivier May 29, 2017, 2:36 p.m. UTC | #1
On 24/05/2017 18:08, Andrew Jones wrote:
> 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 <drjones@redhat.com>
> ---
>  scripts/arch-run.bash | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index 581552a21f2e..3ba6354608da 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" ] && export 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=$(echo "$line" | cut -d= -f1)
> +			grep -q $errata <(env) && continue
> +			eval export "$line"
> +		done
> +	fi

If you want fun, you can get this with:

[ -f "$ENV" ] && for errata in \
        $(grep -vF "$(tr ' ' '\n' <<<${!ERRATA_@})" "$ENV"); do
    eval export $errata
done

Laurent
diff mbox

Patch

diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 581552a21f2e..3ba6354608da 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" ] && export 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=$(echo "$line" | cut -d= -f1)
+			grep -q $errata <(env) && 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
+}