All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework
@ 2017-06-06 18:22 Andrew Jones
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create Andrew Jones
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

We've had an errata framework merged in for a while, but it hasn't been
getting used (at least not upstream). This series extends it to allow
run script environment provided and host kernel version based generated
errata variables to be automatically provided to unit tests. It then
changes a couple arm unit tests to use the errata framework, now that
it's more useful.

The benefit of this over always using the 'nodefault' group is that
once a host has been patched the unit test will automatically start
running as a regression test - no need to manually run it, meaning no
concern that it will likely never actually be run...

v2:
 - apply a couple good bash suggestions from Laurent
 - apply some debatable bashisms for string manipulation, which
   swaps readability for reduced pipes... [me]

Andrew Jones (9):
  arch-run: introduce initrd_create
  arch-run: provide errata from run env
  x86/run: source config.mak
  arch-run: generate errata when no environ is provided
  mkstandalone: provide errata to tests
  errata: add ERRATA_FORCE
  README: add section on guarding unsafe tests
  AArch32: apply errata framework to unsafe pmccntr64 test
  arm/arm64: apply errata framework to unsafe cpu-on test

 README.md               | 34 +++++++++++++++++++++
 arm/pmu.c               | 26 +++++++++++-----
 arm/psci.c              |  7 ++++-
 arm/run                 |  5 ++--
 arm/unittests.cfg       |  2 +-
 configure               | 12 ++++++++
 errata.txt              |  7 +++++
 lib/errata.h            | 21 +++++++++++--
 powerpc/run             |  5 ++--
 run_tests.sh            |  2 ++
 scripts/arch-run.bash   | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/mkstandalone.sh |  6 ++++
 x86/run                 | 14 +++++++--
 13 files changed, 201 insertions(+), 19 deletions(-)
 create mode 100644 errata.txt

-- 
2.9.4

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  2017-06-08 10:04   ` Laurent Vivier
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 2/9] arch-run: provide errata from run env Andrew Jones
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

Encapsulate the preparation of the optional initrd command line
option.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/run               | 5 +++--
 powerpc/run           | 5 +++--
 scripts/arch-run.bash | 5 +++++
 x86/run               | 5 +++--
 4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/arm/run b/arm/run
index f73593bc01af..1b1602c74970 100755
--- a/arm/run
+++ b/arm/run
@@ -71,10 +71,11 @@ if $qemu $M -device '?' 2>&1 | grep pci-testdev > /dev/null; then
 	pci_testdev="-device pci-testdev"
 fi
 
+initrd_create
+
 M+=",accel=$ACCEL"
 command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev"
-[ -f "$ENV" ] && command+=" -initrd $ENV"
-command+=" -display none -serial stdio -kernel"
+command+=" -display none -serial stdio $INITRD -kernel"
 command="$(timeout_cmd) $command"
 echo $command "$@"
 
diff --git a/powerpc/run b/powerpc/run
index d73f721680b5..7ccf1a36ff49 100755
--- a/powerpc/run
+++ b/powerpc/run
@@ -35,11 +35,12 @@ if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then
 	exit 2
 fi
 
+initrd_create
+
 M='-machine pseries'
 M+=",accel=$ACCEL"
 command="$qemu -nodefaults $M -bios $FIRMWARE"
-[ -f "$ENV" ] && command+=" -initrd $ENV"
-command+=" -display none -serial stdio -kernel"
+command+=" -display none -serial stdio $INITRD -kernel"
 command="$(migration_cmd) $(timeout_cmd) $command"
 echo $command "$@"
 
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 5c10828e30f9..fc95e263458f 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -155,3 +155,8 @@ search_qemu_binary ()
 	command -v $qemu
 	export PATH=$save_path
 }
+
+initrd_create ()
+{
+	[ -f "$ENV" ] && INITRD="-initrd $ENV"
+}
diff --git a/x86/run b/x86/run
index c0502c7c3fcb..5b402a680cc7 100755
--- a/x86/run
+++ b/x86/run
@@ -26,9 +26,10 @@ else
 	pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out"
 fi
 
+initrd_create
+
 command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev"
-[ -f "$ENV" ] && command+=" -initrd $ENV"
-command+=" -kernel"
+command+=" $INITRD -kernel"
 command="$(timeout_cmd) $command"
 echo ${command} "$@"
 
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 2/9] arch-run: provide errata from run env
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  2017-06-08 10:25   ` Laurent Vivier
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 3/9] x86/run: source config.mak Andrew Jones
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

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 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

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 3/9] x86/run: source config.mak
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create Andrew Jones
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 2/9] arch-run: provide errata from run env Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  2017-06-08 10:25   ` Laurent Vivier
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 4/9] arch-run: generate errata when no environ is provided Andrew Jones
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

x86/run will need to start looking at config vars with
the next patch.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 x86/run | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/x86/run b/x86/run
index 5b402a680cc7..88f5ff771140 100755
--- a/x86/run
+++ b/x86/run
@@ -1,6 +1,13 @@
 #!/usr/bin/env bash
 
-[ -z "$STANDALONE" ] && source scripts/arch-run.bash
+if [ -z "$STANDALONE" ]; then
+	if [ ! -f config.mak ]; then
+		echo "run ./configure && make first. See ./configure -h"
+		exit 2
+	fi
+	source config.mak
+	source scripts/arch-run.bash
+fi
 
 qemu=$(search_qemu_binary)
 
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 4/9] arch-run: generate errata when no environ is provided
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
                   ` (2 preceding siblings ...)
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 3/9] x86/run: source config.mak Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  2017-06-08 10:43   ` Laurent Vivier
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 5/9] mkstandalone: provide errata to tests Andrew Jones
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

Provide a table mapping errata to minimum kernel versions and
a function that will use the host's kernel version to determine
the values for each errata variable. These errata variables, with
values based on the host kernel, are now provided to all unit
tests by default, if no environ is provided. Errata variables
passed from the run script environment still take precedence.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 configure             | 11 +++++++++++
 errata.txt            |  5 +++++
 scripts/arch-run.bash | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 errata.txt

diff --git a/configure b/configure
index 64722c9b263b..cde2cfe9db61 100755
--- a/configure
+++ b/configure
@@ -14,6 +14,7 @@ host=$arch
 cross_prefix=
 endian=""
 pretty_print_stacks=yes
+environ_default=yes
 u32_long=
 
 usage() {
@@ -31,6 +32,9 @@ usage() {
 	    --endian=ENDIAN        endianness to compile for (little or big, ppc64 only)
 	    --[enable|disable]-pretty-print-stacks
 	                           enable or disable pretty stack printing (enabled by default)
+	    --[enable|disable]-default-environ
+	                           enable or disable the generation of a default environ when
+	                           no environ is provided by the user (enabled by default)
 EOF
     exit 1
 }
@@ -73,6 +77,12 @@ while [[ "$1" = -* ]]; do
 	--disable-pretty-print-stacks)
 	    pretty_print_stacks=no
 	    ;;
+	--enable-default-environ)
+	    environ_default=yes
+	    ;;
+	--disable-default-environ)
+	    environ_default=no
+	    ;;
 	--help)
 	    usage
 	    ;;
@@ -183,5 +193,6 @@ TEST_DIR=$testdir
 FIRMWARE=$firmware
 ENDIAN=$endian
 PRETTY_PRINT_STACKS=$pretty_print_stacks
+ENVIRON_DEFAULT=$environ_default
 U32_LONG_FMT=$u32_long
 EOF
diff --git a/errata.txt b/errata.txt
new file mode 100644
index 000000000000..95b66c837c63
--- /dev/null
+++ b/errata.txt
@@ -0,0 +1,5 @@
+#---------------:-----------------------:--------------------------------------
+# commit	: minimum kernel	: summary
+# 12 hex digits	: version		:
+#---------------:-----------------------:--------------------------------------
+#---------------:-----------------------:--------------------------------------
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 09072ee46366..b4aa67f3c94c 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -172,6 +172,8 @@ env_add_errata ()
 			test -v $errata && continue
 			eval export "$line"
 		done
+	elif [ ! -f "$ENV" ]; then
+		env_generate_errata
 	fi
 
 	if grep -q '^ERRATA_' <(env); then
@@ -183,6 +185,50 @@ env_add_errata ()
 	fi
 }
 
+env_generate_errata ()
+{
+	local kernel_version_string=$(uname -r)
+	local kernel_version kernel_patchlevel kernel_sublevel
+	local line commit minver errata v p s have
+
+	IFS=. read kernel_version kernel_patchlevel kernel_sublevel <<<$kernel_version_string
+	kernel_sublevel=${kernel_sublevel%%[!0-9]*}
+
+	[ "$ENVIRON_DEFAULT" != "yes" ] && return
+	[ ! -f errata.txt ] && return
+
+	for line in $(grep -v '^#' errata.txt | tr -d '[:blank:]' | cut -d: -f1,2); do
+		commit=${line%:*}
+		minver=${line#*:}
+
+		errata="ERRATA_$commit"
+		test -v $errata && continue
+
+		IFS=. read v p s <<<$minver
+		s=${s%%[!0-9]*}
+
+		if (( $kernel_version > $v ||
+		      ($kernel_version == $v && $kernel_patchlevel > $p) )); then
+			have=y
+		elif (( $kernel_version == $v && $kernel_patchlevel == $p )); then
+			if [ "$kernel_sublevel" ] && [ "$s" ]; then
+				if (( $kernel_sublevel >= $s )); then
+					have=y
+				else
+					have=n
+				fi
+			elif [ "$s" ] && (( $s != 0 )); then
+				have=n
+			else
+				have=y
+			fi
+		else
+			have=n
+		fi
+		eval export "$errata=$have"
+	done
+}
+
 trap_exit_push ()
 {
 	local old_exit=$(trap -p EXIT | sed "s/^[^']*'//;s/'[^']*$//")
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 5/9] mkstandalone: provide errata to tests
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
                   ` (3 preceding siblings ...)
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 4/9] arch-run: generate errata when no environ is provided Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 6/9] errata: add ERRATA_FORCE Andrew Jones
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 configure               | 1 +
 scripts/arch-run.bash   | 4 ++--
 scripts/mkstandalone.sh | 6 ++++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index cde2cfe9db61..e1efb3ca0cca 100755
--- a/configure
+++ b/configure
@@ -194,5 +194,6 @@ FIRMWARE=$firmware
 ENDIAN=$endian
 PRETTY_PRINT_STACKS=$pretty_print_stacks
 ENVIRON_DEFAULT=$environ_default
+ERRATATXT=errata.txt
 U32_LONG_FMT=$u32_long
 EOF
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index b4aa67f3c94c..4267d3f95dd8 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -195,9 +195,9 @@ env_generate_errata ()
 	kernel_sublevel=${kernel_sublevel%%[!0-9]*}
 
 	[ "$ENVIRON_DEFAULT" != "yes" ] && return
-	[ ! -f errata.txt ] && return
+	[ ! -f "$ERRATATXT" ] && return
 
-	for line in $(grep -v '^#' errata.txt | tr -d '[:blank:]' | cut -d: -f1,2); do
+	for line in $(grep -v '^#' "$ERRATATXT" | tr -d '[:blank:]' | cut -d: -f1,2); do
 		commit=${line%:*}
 		minver=${line#*:}
 
diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
index 55cfc4ef8c00..a15941f75375 100755
--- a/scripts/mkstandalone.sh
+++ b/scripts/mkstandalone.sh
@@ -40,6 +40,7 @@ generate_test ()
 
 	echo "#!/usr/bin/env bash"
 	echo "export STANDALONE=yes"
+	echo "export ENVIRON_DEFAULT=yes"
 	echo "export HOST=\$(uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/')"
 	echo "export PRETTY_PRINT_STACKS=no"
 
@@ -62,6 +63,11 @@ generate_test ()
 		echo 'export FIRMWARE'
 	fi
 
+	if [ "$ERRATATXT" ]; then
+		temp_file ERRATATXT "$ERRATATXT"
+		echo 'export ERRATATXT'
+	fi
+
 	temp_file bin "$kernel"
 	args[3]='$bin'
 
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 6/9] errata: add ERRATA_FORCE
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
                   ` (4 preceding siblings ...)
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 5/9] mkstandalone: provide errata to tests Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  2017-06-08 10:56   ` Laurent Vivier
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 7/9] README: add section on guarding unsafe tests Andrew Jones
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

Provide an easy way for test runners to run all tests, even those
guarded by an erratum. Setting ERRATA_FORCE forces errata() and
errata_relaxed() to always return true. ./run_tests.sh -a is
also updated to set it.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/errata.h | 21 +++++++++++++++++++--
 run_tests.sh |  2 ++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/lib/errata.h b/lib/errata.h
index 7b089c2578ad..f3ebca2d8a6c 100644
--- a/lib/errata.h
+++ b/lib/errata.h
@@ -13,16 +13,33 @@
 #define _ERRATA_RELAXED(erratum) errata_relaxed("ERRATA_" # erratum)
 #define ERRATA_RELAXED(erratum) _ERRATA_RELAXED(erratum)
 
+static inline bool errata_force(void)
+{
+	char *s = getenv("ERRATA_FORCE");
+
+	return s && (*s == '1' || *s == 'y' || *s == 'Y');
+}
+
 static inline bool errata(const char *erratum)
 {
-	char *s = getenv(erratum);
+	char *s;
+
+	if (errata_force())
+		return true;
+
+	s = getenv(erratum);
 
 	return s && (*s == '1' || *s == 'y' || *s == 'Y');
 }
 
 static inline bool errata_relaxed(const char *erratum)
 {
-	char *s = getenv(erratum);
+	char *s;
+
+	if (errata_force())
+		return true;
+
+	s = getenv(erratum);
 
 	return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
 }
diff --git a/run_tests.sh b/run_tests.sh
index c7972cbd198b..aa2e65f622ce 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -19,6 +19,7 @@ Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS]
     -h: Output this help text
     -v: Enables verbose mode
     -a: Run all tests, including those flagged as 'nodefault'
+        and those guarded by errata.
     -g: Only execute tests in the given group
     -j: Execute tests in parallel
 
@@ -35,6 +36,7 @@ while getopts "ag:hj:v" opt; do
     case $opt in
         a)
             run_all_tests="yes"
+            export ERRATA_FORCE=y
             ;;
         g)
             only_group=$OPTARG
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 7/9] README: add section on guarding unsafe tests
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
                   ` (5 preceding siblings ...)
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 6/9] errata: add ERRATA_FORCE Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 8/9] AArch32: apply errata framework to unsafe pmccntr64 test Andrew Jones
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 9/9] arm/arm64: apply errata framework to unsafe cpu-on test Andrew Jones
  8 siblings, 0 replies; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 README.md | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/README.md b/README.md
index 49fbc9c50bce..fb257af1762b 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,40 @@ Additionally these self-explanatory variables are reserved
  QEMU_MAJOR, QEMU_MINOR, QEMU_MICRO, KERNEL_VERSION, KERNEL_PATCHLEVEL,
  KERNEL_SUBLEVEL, KERNEL_EXTRAVERSION
 
+# Guarding unsafe tests
+
+Some tests are not safe to run by default, as they may crash the
+host. kvm-unit-tests provides two ways to handle tests like those.
+
+ 1) Adding 'nodefault' to the groups field for the unit test in the
+    unittests.cfg file. When a unit test is in the nodefault group
+    it is only run when invoked
+
+    a) independently, arch-run arch/test
+    b) by specifying any other non-nodefault group it is in,
+       groups = nodefault,mygroup : ./run_tests.sh -g mygroup
+    c) by specifying all tests should be run, ./run_tests.sh -a
+
+ 2) Making the test conditional on errata in the code,
+    if (ERRATA(abcdef012345)) {
+        do_unsafe_test();
+    }
+
+    With the errata condition the unsafe unit test is only run
+    when
+
+    a) the ERRATA_abcdef012345 environ variable is provided and 'y'
+    b) the ERRATA_FORCE environ variable is provided and 'y'
+    c) by specifying all tests should be run, ./run_tests.sh -a
+       (The -a switch ensures the ERRATA_FORCE is provided and set
+        to 'y'.)
+
+The errata.txt file provides a mapping of the commits needed by errata
+conditionals to their respective minimum kernel versions. By default,
+when the user does not provide an environ, then an environ generated
+from the errata.txt file and the host's kernel version is provided to
+all unit tests.
+
 # Contributing
 
 ## Directory structure
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 8/9] AArch32: apply errata framework to unsafe pmccntr64 test
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
                   ` (6 preceding siblings ...)
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 7/9] README: add section on guarding unsafe tests Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 9/9] arm/arm64: apply errata framework to unsafe cpu-on test Andrew Jones
  8 siblings, 0 replies; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/pmu.c  | 26 ++++++++++++++++++--------
 errata.txt |  1 +
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/arm/pmu.c b/arm/pmu.c
index 74848988a678..1ac692023e5e 100644
--- a/arm/pmu.c
+++ b/arm/pmu.c
@@ -14,6 +14,7 @@
  * for more details.
  */
 #include "libcflat.h"
+#include "errata.h"
 #include "asm/barrier.h"
 #include "asm/sysreg.h"
 #include "asm/processor.h"
@@ -57,18 +58,12 @@ static inline uint8_t get_pmu_version(void)
 
 static inline uint64_t get_pmccntr(void)
 {
-	if (pmu_version == 0x3)
-		return read_sysreg(PMCCNTR64);
-	else
-		return read_sysreg(PMCCNTR32);
+	return read_sysreg(PMCCNTR32);
 }
 
 static inline void set_pmccntr(uint64_t value)
 {
-	if (pmu_version == 0x3)
-		write_sysreg(value, PMCCNTR64);
-	else
-		write_sysreg(value & 0xffffffff, PMCCNTR32);
+	write_sysreg(value & 0xffffffff, PMCCNTR32);
 }
 
 /* PMCCFILTR is an obsolete name for PMXEVTYPER31 in ARMv7 */
@@ -267,6 +262,19 @@ static bool check_cpi(int cpi)
 	return true;
 }
 
+static void pmccntr64_test(void)
+{
+#ifdef __arm__
+	if (pmu_version == 0x3) {
+		if (ERRATA(9e3f7a296940)) {
+			write_sysreg(0xdead, PMCCNTR64);
+			report("pmccntr64", read_sysreg(PMCCNTR64) == 0xdead);
+		} else
+			report_skip("Skipping unsafe pmccntr64 test. Set ERRATA_9e3f7a296940=y to enable.");
+	}
+#endif
+}
+
 /* Return FALSE if no PMU found, otherwise return TRUE */
 bool pmu_probe(void)
 {
@@ -293,5 +301,7 @@ int main(int argc, char *argv[])
 	report("Monotonically increasing cycle count", check_cycles_increase());
 	report("Cycle/instruction ratio", check_cpi(cpi));
 
+	pmccntr64_test();
+
 	return report_summary();
 }
diff --git a/errata.txt b/errata.txt
index 95b66c837c63..682d7aa067b9 100644
--- a/errata.txt
+++ b/errata.txt
@@ -2,4 +2,5 @@
 # commit	: minimum kernel	: summary
 # 12 hex digits	: version		:
 #---------------:-----------------------:--------------------------------------
+9e3f7a296940	: 4.9			: arm64: KVM: pmu: Fix AArch32 cycle counter access
 #---------------:-----------------------:--------------------------------------
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH kvm-unit-tests v2 9/9] arm/arm64: apply errata framework to unsafe cpu-on test
  2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
                   ` (7 preceding siblings ...)
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 8/9] AArch32: apply errata framework to unsafe pmccntr64 test Andrew Jones
@ 2017-06-06 18:22 ` Andrew Jones
  8 siblings, 0 replies; 19+ messages in thread
From: Andrew Jones @ 2017-06-06 18:22 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, rkrcmar, lvivier, thuth

With the unsafe subtest guarded by an erratum we no longer need
nodefault.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/psci.c        | 7 ++++++-
 arm/unittests.cfg | 2 +-
 errata.txt        | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arm/psci.c b/arm/psci.c
index 4e6bc58dbe42..5cb4d5c7c233 100644
--- a/arm/psci.c
+++ b/arm/psci.c
@@ -8,6 +8,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
+#include <errata.h>
 #include <asm/processor.h>
 #include <asm/smp.h>
 #include <asm/psci.h>
@@ -135,7 +136,11 @@ int main(void)
 	report("invalid-function", psci_invalid_function());
 	report("affinity-info-on", psci_affinity_info_on());
 	report("affinity-info-off", psci_affinity_info_off());
-	report("cpu-on", psci_cpu_on_test());
+
+	if (ERRATA(6c7a5dce22b3))
+		report("cpu-on", psci_cpu_on_test());
+	else
+		report_skip("Skipping unsafe cpu-on test. Set ERRATA_6c7a5dce22b3=y to enable.");
 
 done:
 #if 0
diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index 4fc90eef91db..73a2419fefe6 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -108,4 +108,4 @@ groups = gic
 [psci]
 file = psci.flat
 smp = $MAX_SMP
-groups = nodefault,psci
+groups = psci
diff --git a/errata.txt b/errata.txt
index 682d7aa067b9..5608a308ce7c 100644
--- a/errata.txt
+++ b/errata.txt
@@ -3,4 +3,5 @@
 # 12 hex digits	: version		:
 #---------------:-----------------------:--------------------------------------
 9e3f7a296940	: 4.9			: arm64: KVM: pmu: Fix AArch32 cycle counter access
+6c7a5dce22b3	: 4.12			: KVM: arm/arm64: fix races in kvm_psci_vcpu_on
 #---------------:-----------------------:--------------------------------------
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create Andrew Jones
@ 2017-06-08 10:04   ` Laurent Vivier
  2017-06-13  8:04     ` Andrew Jones
  0 siblings, 1 reply; 19+ messages in thread
From: Laurent Vivier @ 2017-06-08 10:04 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, thuth

On 06/06/2017 20:22, Andrew Jones wrote:
> Encapsulate the preparation of the optional initrd command line
> option.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  arm/run               | 5 +++--
>  powerpc/run           | 5 +++--
>  scripts/arch-run.bash | 5 +++++
>  x86/run               | 5 +++--
>  4 files changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/arm/run b/arm/run
> index f73593bc01af..1b1602c74970 100755
> --- a/arm/run
> +++ b/arm/run
> @@ -71,10 +71,11 @@ if $qemu $M -device '?' 2>&1 | grep pci-testdev > /dev/null; then
>  	pci_testdev="-device pci-testdev"
>  fi
>  
> +initrd_create
> +
>  M+=",accel=$ACCEL"
>  command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev"
> -[ -f "$ENV" ] && command+=" -initrd $ENV"
> -command+=" -display none -serial stdio -kernel"
> +command+=" -display none -serial stdio $INITRD -kernel"
>  command="$(timeout_cmd) $command"
>  echo $command "$@"
>  
> diff --git a/powerpc/run b/powerpc/run
> index d73f721680b5..7ccf1a36ff49 100755
> --- a/powerpc/run
> +++ b/powerpc/run
> @@ -35,11 +35,12 @@ if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then
>  	exit 2
>  fi
>  
> +initrd_create
> +
>  M='-machine pseries'
>  M+=",accel=$ACCEL"
>  command="$qemu -nodefaults $M -bios $FIRMWARE"
> -[ -f "$ENV" ] && command+=" -initrd $ENV"
> -command+=" -display none -serial stdio -kernel"
> +command+=" -display none -serial stdio $INITRD -kernel"
>  command="$(migration_cmd) $(timeout_cmd) $command"
>  echo $command "$@"
>  
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index 5c10828e30f9..fc95e263458f 100644
> --- a/scripts/arch-run.bash
> +++ b/scripts/arch-run.bash
> @@ -155,3 +155,8 @@ search_qemu_binary ()
>  	command -v $qemu
>  	export PATH=$save_path
>  }
> +
> +initrd_create ()
> +{
> +	[ -f "$ENV" ] && INITRD="-initrd $ENV"
> +}

Is this intentional to not clear INITRD and thus to allow it to be
imported from the environment?

Laurent

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 2/9] arch-run: provide errata from run env
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 2/9] arch-run: provide errata from run env Andrew Jones
@ 2017-06-08 10:25   ` Laurent Vivier
  0 siblings, 0 replies; 19+ messages in thread
From: Laurent Vivier @ 2017-06-08 10:25 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, thuth

On 06/06/2017 20:22, 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>

Reviewed-by: Laurent Vivier <lvivier@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 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
> +}
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 3/9] x86/run: source config.mak
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 3/9] x86/run: source config.mak Andrew Jones
@ 2017-06-08 10:25   ` Laurent Vivier
  0 siblings, 0 replies; 19+ messages in thread
From: Laurent Vivier @ 2017-06-08 10:25 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, thuth

On 06/06/2017 20:22, Andrew Jones wrote:
> x86/run will need to start looking at config vars with
> the next patch.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

> ---
>  x86/run | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/x86/run b/x86/run
> index 5b402a680cc7..88f5ff771140 100755
> --- a/x86/run
> +++ b/x86/run
> @@ -1,6 +1,13 @@
>  #!/usr/bin/env bash
>  
> -[ -z "$STANDALONE" ] && source scripts/arch-run.bash
> +if [ -z "$STANDALONE" ]; then
> +	if [ ! -f config.mak ]; then
> +		echo "run ./configure && make first. See ./configure -h"
> +		exit 2
> +	fi
> +	source config.mak
> +	source scripts/arch-run.bash
> +fi
>  
>  qemu=$(search_qemu_binary)
>  
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 4/9] arch-run: generate errata when no environ is provided
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 4/9] arch-run: generate errata when no environ is provided Andrew Jones
@ 2017-06-08 10:43   ` Laurent Vivier
  2017-06-13  8:12     ` Andrew Jones
  0 siblings, 1 reply; 19+ messages in thread
From: Laurent Vivier @ 2017-06-08 10:43 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, thuth

On 06/06/2017 20:22, Andrew Jones wrote:
> Provide a table mapping errata to minimum kernel versions and
> a function that will use the host's kernel version to determine
> the values for each errata variable. These errata variables, with
> values based on the host kernel, are now provided to all unit
> tests by default, if no environ is provided. Errata variables
> passed from the run script environment still take precedence.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  configure             | 11 +++++++++++
>  errata.txt            |  5 +++++
>  scripts/arch-run.bash | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 62 insertions(+)
>  create mode 100644 errata.txt
> 
> diff --git a/configure b/configure
> index 64722c9b263b..cde2cfe9db61 100755
> --- a/configure
> +++ b/configure
> @@ -14,6 +14,7 @@ host=$arch
>  cross_prefix=
>  endian=""
>  pretty_print_stacks=yes
> +environ_default=yes
>  u32_long=
>  
>  usage() {
> @@ -31,6 +32,9 @@ usage() {
>  	    --endian=ENDIAN        endianness to compile for (little or big, ppc64 only)
>  	    --[enable|disable]-pretty-print-stacks
>  	                           enable or disable pretty stack printing (enabled by default)
> +	    --[enable|disable]-default-environ
> +	                           enable or disable the generation of a default environ when
> +	                           no environ is provided by the user (enabled by default)
>  EOF
>      exit 1
>  }
> @@ -73,6 +77,12 @@ while [[ "$1" = -* ]]; do
>  	--disable-pretty-print-stacks)
>  	    pretty_print_stacks=no
>  	    ;;
> +	--enable-default-environ)
> +	    environ_default=yes
> +	    ;;
> +	--disable-default-environ)
> +	    environ_default=no
> +	    ;;
>  	--help)
>  	    usage
>  	    ;;
> @@ -183,5 +193,6 @@ TEST_DIR=$testdir
>  FIRMWARE=$firmware
>  ENDIAN=$endian
>  PRETTY_PRINT_STACKS=$pretty_print_stacks
> +ENVIRON_DEFAULT=$environ_default
>  U32_LONG_FMT=$u32_long
>  EOF
> diff --git a/errata.txt b/errata.txt
> new file mode 100644
> index 000000000000..95b66c837c63
> --- /dev/null
> +++ b/errata.txt
> @@ -0,0 +1,5 @@
> +#---------------:-----------------------:--------------------------------------
> +# commit	: minimum kernel	: summary
> +# 12 hex digits	: version		:
> +#---------------:-----------------------:--------------------------------------
> +#---------------:-----------------------:--------------------------------------
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index 09072ee46366..b4aa67f3c94c 100644
> --- a/scripts/arch-run.bash
> +++ b/scripts/arch-run.bash
> @@ -172,6 +172,8 @@ env_add_errata ()
>  			test -v $errata && continue
>  			eval export "$line"
>  		done
> +	elif [ ! -f "$ENV" ]; then
> +		env_generate_errata
>  	fi
>  
>  	if grep -q '^ERRATA_' <(env); then
> @@ -183,6 +185,50 @@ env_add_errata ()
>  	fi
>  }
>  
> +env_generate_errata ()
> +{
> +	local kernel_version_string=$(uname -r)
> +	local kernel_version kernel_patchlevel kernel_sublevel
> +	local line commit minver errata v p s have
> +
> +	IFS=. read kernel_version kernel_patchlevel kernel_sublevel <<<$kernel_version_string
> +	kernel_sublevel=${kernel_sublevel%%[!0-9]*}

I don't understand the pattern.

BASH(1)

${parameter%%word}
    The word is expanded to produce a pattern just as in pathname
    expansion

Pathname Expansion

    *      Matches any string
    [...]  Matches any one of the enclosed characters
           If  the  first character following the [ is a !  or a ^ then
           any character not enclosed is matched

So you need only "${kernel_sublevel%%-*}"

Laurent

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 6/9] errata: add ERRATA_FORCE
  2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 6/9] errata: add ERRATA_FORCE Andrew Jones
@ 2017-06-08 10:56   ` Laurent Vivier
  0 siblings, 0 replies; 19+ messages in thread
From: Laurent Vivier @ 2017-06-08 10:56 UTC (permalink / raw)
  To: Andrew Jones, kvm; +Cc: pbonzini, rkrcmar, thuth

On 06/06/2017 20:22, Andrew Jones wrote:
> Provide an easy way for test runners to run all tests, even those
> guarded by an erratum. Setting ERRATA_FORCE forces errata() and
> errata_relaxed() to always return true. ./run_tests.sh -a is
> also updated to set it.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

> ---
>  lib/errata.h | 21 +++++++++++++++++++--
>  run_tests.sh |  2 ++
>  2 files changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/errata.h b/lib/errata.h
> index 7b089c2578ad..f3ebca2d8a6c 100644
> --- a/lib/errata.h
> +++ b/lib/errata.h
> @@ -13,16 +13,33 @@
>  #define _ERRATA_RELAXED(erratum) errata_relaxed("ERRATA_" # erratum)
>  #define ERRATA_RELAXED(erratum) _ERRATA_RELAXED(erratum)
>  
> +static inline bool errata_force(void)
> +{
> +	char *s = getenv("ERRATA_FORCE");
> +
> +	return s && (*s == '1' || *s == 'y' || *s == 'Y');
> +}
> +
>  static inline bool errata(const char *erratum)
>  {
> -	char *s = getenv(erratum);
> +	char *s;
> +
> +	if (errata_force())
> +		return true;
> +
> +	s = getenv(erratum);
>  
>  	return s && (*s == '1' || *s == 'y' || *s == 'Y');
>  }
>  
>  static inline bool errata_relaxed(const char *erratum)
>  {
> -	char *s = getenv(erratum);
> +	char *s;
> +
> +	if (errata_force())
> +		return true;
> +
> +	s = getenv(erratum);
>  
>  	return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
>  }
> diff --git a/run_tests.sh b/run_tests.sh
> index c7972cbd198b..aa2e65f622ce 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -19,6 +19,7 @@ Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS]
>      -h: Output this help text
>      -v: Enables verbose mode
>      -a: Run all tests, including those flagged as 'nodefault'
> +        and those guarded by errata.
>      -g: Only execute tests in the given group
>      -j: Execute tests in parallel
>  
> @@ -35,6 +36,7 @@ while getopts "ag:hj:v" opt; do
>      case $opt in
>          a)
>              run_all_tests="yes"
> +            export ERRATA_FORCE=y
>              ;;
>          g)
>              only_group=$OPTARG
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create
  2017-06-08 10:04   ` Laurent Vivier
@ 2017-06-13  8:04     ` Andrew Jones
  2017-06-13  9:50       ` Laurent Vivier
  0 siblings, 1 reply; 19+ messages in thread
From: Andrew Jones @ 2017-06-13  8:04 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm, pbonzini, rkrcmar, thuth

On Thu, Jun 08, 2017 at 12:04:39PM +0200, Laurent Vivier wrote:
> On 06/06/2017 20:22, Andrew Jones wrote:
> > Encapsulate the preparation of the optional initrd command line
> > option.
> > 
> > Signed-off-by: Andrew Jones <drjones@redhat.com>
> > ---
> >  arm/run               | 5 +++--
> >  powerpc/run           | 5 +++--
> >  scripts/arch-run.bash | 5 +++++
> >  x86/run               | 5 +++--
> >  4 files changed, 14 insertions(+), 6 deletions(-)
> > 
> > diff --git a/arm/run b/arm/run
> > index f73593bc01af..1b1602c74970 100755
> > --- a/arm/run
> > +++ b/arm/run
> > @@ -71,10 +71,11 @@ if $qemu $M -device '?' 2>&1 | grep pci-testdev > /dev/null; then
> >  	pci_testdev="-device pci-testdev"
> >  fi
> >  
> > +initrd_create
> > +
> >  M+=",accel=$ACCEL"
> >  command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev"
> > -[ -f "$ENV" ] && command+=" -initrd $ENV"
> > -command+=" -display none -serial stdio -kernel"
> > +command+=" -display none -serial stdio $INITRD -kernel"
> >  command="$(timeout_cmd) $command"
> >  echo $command "$@"
> >  
> > diff --git a/powerpc/run b/powerpc/run
> > index d73f721680b5..7ccf1a36ff49 100755
> > --- a/powerpc/run
> > +++ b/powerpc/run
> > @@ -35,11 +35,12 @@ if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then
> >  	exit 2
> >  fi
> >  
> > +initrd_create
> > +
> >  M='-machine pseries'
> >  M+=",accel=$ACCEL"
> >  command="$qemu -nodefaults $M -bios $FIRMWARE"
> > -[ -f "$ENV" ] && command+=" -initrd $ENV"
> > -command+=" -display none -serial stdio -kernel"
> > +command+=" -display none -serial stdio $INITRD -kernel"
> >  command="$(migration_cmd) $(timeout_cmd) $command"
> >  echo $command "$@"
> >  
> > diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> > index 5c10828e30f9..fc95e263458f 100644
> > --- a/scripts/arch-run.bash
> > +++ b/scripts/arch-run.bash
> > @@ -155,3 +155,8 @@ search_qemu_binary ()
> >  	command -v $qemu
> >  	export PATH=$save_path
> >  }
> > +
> > +initrd_create ()
> > +{
> > +	[ -f "$ENV" ] && INITRD="-initrd $ENV"
> > +}
> 
> Is this intentional to not clear INITRD and thus to allow it to be
> imported from the environment?

Actually no, that wasn't intentional. I'm not sure I have much of a
preference, but I'm leaning towards wanting to clear it. What do you
think?

Thanks,
drew

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 4/9] arch-run: generate errata when no environ is provided
  2017-06-08 10:43   ` Laurent Vivier
@ 2017-06-13  8:12     ` Andrew Jones
  2017-06-13 10:01       ` Laurent Vivier
  0 siblings, 1 reply; 19+ messages in thread
From: Andrew Jones @ 2017-06-13  8:12 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm, pbonzini, rkrcmar, thuth

On Thu, Jun 08, 2017 at 12:43:20PM +0200, Laurent Vivier wrote:
> On 06/06/2017 20:22, Andrew Jones wrote:
> > Provide a table mapping errata to minimum kernel versions and
> > a function that will use the host's kernel version to determine
> > the values for each errata variable. These errata variables, with
> > values based on the host kernel, are now provided to all unit
> > tests by default, if no environ is provided. Errata variables
> > passed from the run script environment still take precedence.
> > 
> > Signed-off-by: Andrew Jones <drjones@redhat.com>
> > ---
> >  configure             | 11 +++++++++++
> >  errata.txt            |  5 +++++
> >  scripts/arch-run.bash | 46 ++++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 62 insertions(+)
> >  create mode 100644 errata.txt
> > 
> > diff --git a/configure b/configure
> > index 64722c9b263b..cde2cfe9db61 100755
> > --- a/configure
> > +++ b/configure
> > @@ -14,6 +14,7 @@ host=$arch
> >  cross_prefix=
> >  endian=""
> >  pretty_print_stacks=yes
> > +environ_default=yes
> >  u32_long=
> >  
> >  usage() {
> > @@ -31,6 +32,9 @@ usage() {
> >  	    --endian=ENDIAN        endianness to compile for (little or big, ppc64 only)
> >  	    --[enable|disable]-pretty-print-stacks
> >  	                           enable or disable pretty stack printing (enabled by default)
> > +	    --[enable|disable]-default-environ
> > +	                           enable or disable the generation of a default environ when
> > +	                           no environ is provided by the user (enabled by default)
> >  EOF
> >      exit 1
> >  }
> > @@ -73,6 +77,12 @@ while [[ "$1" = -* ]]; do
> >  	--disable-pretty-print-stacks)
> >  	    pretty_print_stacks=no
> >  	    ;;
> > +	--enable-default-environ)
> > +	    environ_default=yes
> > +	    ;;
> > +	--disable-default-environ)
> > +	    environ_default=no
> > +	    ;;
> >  	--help)
> >  	    usage
> >  	    ;;
> > @@ -183,5 +193,6 @@ TEST_DIR=$testdir
> >  FIRMWARE=$firmware
> >  ENDIAN=$endian
> >  PRETTY_PRINT_STACKS=$pretty_print_stacks
> > +ENVIRON_DEFAULT=$environ_default
> >  U32_LONG_FMT=$u32_long
> >  EOF
> > diff --git a/errata.txt b/errata.txt
> > new file mode 100644
> > index 000000000000..95b66c837c63
> > --- /dev/null
> > +++ b/errata.txt
> > @@ -0,0 +1,5 @@
> > +#---------------:-----------------------:--------------------------------------
> > +# commit	: minimum kernel	: summary
> > +# 12 hex digits	: version		:
> > +#---------------:-----------------------:--------------------------------------
> > +#---------------:-----------------------:--------------------------------------
> > diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> > index 09072ee46366..b4aa67f3c94c 100644
> > --- a/scripts/arch-run.bash
> > +++ b/scripts/arch-run.bash
> > @@ -172,6 +172,8 @@ env_add_errata ()
> >  			test -v $errata && continue
> >  			eval export "$line"
> >  		done
> > +	elif [ ! -f "$ENV" ]; then
> > +		env_generate_errata
> >  	fi
> >  
> >  	if grep -q '^ERRATA_' <(env); then
> > @@ -183,6 +185,50 @@ env_add_errata ()
> >  	fi
> >  }
> >  
> > +env_generate_errata ()
> > +{
> > +	local kernel_version_string=$(uname -r)
> > +	local kernel_version kernel_patchlevel kernel_sublevel
> > +	local line commit minver errata v p s have
> > +
> > +	IFS=. read kernel_version kernel_patchlevel kernel_sublevel <<<$kernel_version_string
> > +	kernel_sublevel=${kernel_sublevel%%[!0-9]*}
> 
> I don't understand the pattern.
> 
> BASH(1)
> 
> ${parameter%%word}
>     The word is expanded to produce a pattern just as in pathname
>     expansion
> 
> Pathname Expansion
> 
>     *      Matches any string
>     [...]  Matches any one of the enclosed characters
>            If  the  first character following the [ is a !  or a ^ then
>            any character not enclosed is matched
> 
> So you need only "${kernel_sublevel%%-*}"

This assumes the kernel's EXTRAVERSION starts with a '-', which is likely
a safe assumption, but the pattern I used ensures any non-digit will be
dropped, which is safer, because kernel_sublevel gets used in arithmetic
expressions.

Thanks,
drew

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create
  2017-06-13  8:04     ` Andrew Jones
@ 2017-06-13  9:50       ` Laurent Vivier
  0 siblings, 0 replies; 19+ messages in thread
From: Laurent Vivier @ 2017-06-13  9:50 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvm, pbonzini, rkrcmar, thuth

On 13/06/2017 10:04, Andrew Jones wrote:
> On Thu, Jun 08, 2017 at 12:04:39PM +0200, Laurent Vivier wrote:
>> On 06/06/2017 20:22, Andrew Jones wrote:
>>> Encapsulate the preparation of the optional initrd command line
>>> option.
>>>
>>> Signed-off-by: Andrew Jones <drjones@redhat.com>
>>> ---
>>>  arm/run               | 5 +++--
>>>  powerpc/run           | 5 +++--
>>>  scripts/arch-run.bash | 5 +++++
>>>  x86/run               | 5 +++--
>>>  4 files changed, 14 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/arm/run b/arm/run
>>> index f73593bc01af..1b1602c74970 100755
>>> --- a/arm/run
>>> +++ b/arm/run
>>> @@ -71,10 +71,11 @@ if $qemu $M -device '?' 2>&1 | grep pci-testdev > /dev/null; then
>>>  	pci_testdev="-device pci-testdev"
>>>  fi
>>>  
>>> +initrd_create
>>> +
>>>  M+=",accel=$ACCEL"
>>>  command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev"
>>> -[ -f "$ENV" ] && command+=" -initrd $ENV"
>>> -command+=" -display none -serial stdio -kernel"
>>> +command+=" -display none -serial stdio $INITRD -kernel"
>>>  command="$(timeout_cmd) $command"
>>>  echo $command "$@"
>>>  
>>> diff --git a/powerpc/run b/powerpc/run
>>> index d73f721680b5..7ccf1a36ff49 100755
>>> --- a/powerpc/run
>>> +++ b/powerpc/run
>>> @@ -35,11 +35,12 @@ if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then
>>>  	exit 2
>>>  fi
>>>  
>>> +initrd_create
>>> +
>>>  M='-machine pseries'
>>>  M+=",accel=$ACCEL"
>>>  command="$qemu -nodefaults $M -bios $FIRMWARE"
>>> -[ -f "$ENV" ] && command+=" -initrd $ENV"
>>> -command+=" -display none -serial stdio -kernel"
>>> +command+=" -display none -serial stdio $INITRD -kernel"
>>>  command="$(migration_cmd) $(timeout_cmd) $command"
>>>  echo $command "$@"
>>>  
>>> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
>>> index 5c10828e30f9..fc95e263458f 100644
>>> --- a/scripts/arch-run.bash
>>> +++ b/scripts/arch-run.bash
>>> @@ -155,3 +155,8 @@ search_qemu_binary ()
>>>  	command -v $qemu
>>>  	export PATH=$save_path
>>>  }
>>> +
>>> +initrd_create ()
>>> +{
>>> +	[ -f "$ENV" ] && INITRD="-initrd $ENV"
>>> +}
>>
>> Is this intentional to not clear INITRD and thus to allow it to be
>> imported from the environment?
> 
> Actually no, that wasn't intentional. I'm not sure I have much of a
> preference, but I'm leaning towards wanting to clear it. What do you
> think?

I think it's better to clear it to have a deterministic behavior of the
test (only influenced by ENV).

Laurent

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH kvm-unit-tests v2 4/9] arch-run: generate errata when no environ is provided
  2017-06-13  8:12     ` Andrew Jones
@ 2017-06-13 10:01       ` Laurent Vivier
  0 siblings, 0 replies; 19+ messages in thread
From: Laurent Vivier @ 2017-06-13 10:01 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvm, pbonzini, rkrcmar, thuth

On 13/06/2017 10:12, Andrew Jones wrote:
> On Thu, Jun 08, 2017 at 12:43:20PM +0200, Laurent Vivier wrote:
>> On 06/06/2017 20:22, Andrew Jones wrote:
>>> Provide a table mapping errata to minimum kernel versions and
>>> a function that will use the host's kernel version to determine
>>> the values for each errata variable. These errata variables, with
>>> values based on the host kernel, are now provided to all unit
>>> tests by default, if no environ is provided. Errata variables
>>> passed from the run script environment still take precedence.
>>>
>>> Signed-off-by: Andrew Jones <drjones@redhat.com>
>>> ---
>>>  configure             | 11 +++++++++++
>>>  errata.txt            |  5 +++++
>>>  scripts/arch-run.bash | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>>>  3 files changed, 62 insertions(+)
>>>  create mode 100644 errata.txt
>>>
>>> diff --git a/configure b/configure
>>> index 64722c9b263b..cde2cfe9db61 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -14,6 +14,7 @@ host=$arch
>>>  cross_prefix=
>>>  endian=""
>>>  pretty_print_stacks=yes
>>> +environ_default=yes
>>>  u32_long=
>>>  
>>>  usage() {
>>> @@ -31,6 +32,9 @@ usage() {
>>>  	    --endian=ENDIAN        endianness to compile for (little or big, ppc64 only)
>>>  	    --[enable|disable]-pretty-print-stacks
>>>  	                           enable or disable pretty stack printing (enabled by default)
>>> +	    --[enable|disable]-default-environ
>>> +	                           enable or disable the generation of a default environ when
>>> +	                           no environ is provided by the user (enabled by default)
>>>  EOF
>>>      exit 1
>>>  }
>>> @@ -73,6 +77,12 @@ while [[ "$1" = -* ]]; do
>>>  	--disable-pretty-print-stacks)
>>>  	    pretty_print_stacks=no
>>>  	    ;;
>>> +	--enable-default-environ)
>>> +	    environ_default=yes
>>> +	    ;;
>>> +	--disable-default-environ)
>>> +	    environ_default=no
>>> +	    ;;
>>>  	--help)
>>>  	    usage
>>>  	    ;;
>>> @@ -183,5 +193,6 @@ TEST_DIR=$testdir
>>>  FIRMWARE=$firmware
>>>  ENDIAN=$endian
>>>  PRETTY_PRINT_STACKS=$pretty_print_stacks
>>> +ENVIRON_DEFAULT=$environ_default
>>>  U32_LONG_FMT=$u32_long
>>>  EOF
>>> diff --git a/errata.txt b/errata.txt
>>> new file mode 100644
>>> index 000000000000..95b66c837c63
>>> --- /dev/null
>>> +++ b/errata.txt
>>> @@ -0,0 +1,5 @@
>>> +#---------------:-----------------------:--------------------------------------
>>> +# commit	: minimum kernel	: summary
>>> +# 12 hex digits	: version		:
>>> +#---------------:-----------------------:--------------------------------------
>>> +#---------------:-----------------------:--------------------------------------
>>> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
>>> index 09072ee46366..b4aa67f3c94c 100644
>>> --- a/scripts/arch-run.bash
>>> +++ b/scripts/arch-run.bash
>>> @@ -172,6 +172,8 @@ env_add_errata ()
>>>  			test -v $errata && continue
>>>  			eval export "$line"
>>>  		done
>>> +	elif [ ! -f "$ENV" ]; then
>>> +		env_generate_errata
>>>  	fi
>>>  
>>>  	if grep -q '^ERRATA_' <(env); then
>>> @@ -183,6 +185,50 @@ env_add_errata ()
>>>  	fi
>>>  }
>>>  
>>> +env_generate_errata ()
>>> +{
>>> +	local kernel_version_string=$(uname -r)
>>> +	local kernel_version kernel_patchlevel kernel_sublevel
>>> +	local line commit minver errata v p s have
>>> +
>>> +	IFS=. read kernel_version kernel_patchlevel kernel_sublevel <<<$kernel_version_string
>>> +	kernel_sublevel=${kernel_sublevel%%[!0-9]*}
>>
>> I don't understand the pattern.
>>
>> BASH(1)
>>
>> ${parameter%%word}
>>     The word is expanded to produce a pattern just as in pathname
>>     expansion
>>
>> Pathname Expansion
>>
>>     *      Matches any string
>>     [...]  Matches any one of the enclosed characters
>>            If  the  first character following the [ is a !  or a ^ then
>>            any character not enclosed is matched
>>
>> So you need only "${kernel_sublevel%%-*}"
> 
> This assumes the kernel's EXTRAVERSION starts with a '-', which is likely
> a safe assumption, but the pattern I used ensures any non-digit will be
> dropped, which is safer, because kernel_sublevel gets used in arithmetic
> expressions.

ok, thanks.

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

Laurent

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-06-13 10:01 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-06 18:22 [PATCH kvm-unit-tests v2 0/9] Extend and apply the errata framework Andrew Jones
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 1/9] arch-run: introduce initrd_create Andrew Jones
2017-06-08 10:04   ` Laurent Vivier
2017-06-13  8:04     ` Andrew Jones
2017-06-13  9:50       ` Laurent Vivier
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 2/9] arch-run: provide errata from run env Andrew Jones
2017-06-08 10:25   ` Laurent Vivier
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 3/9] x86/run: source config.mak Andrew Jones
2017-06-08 10:25   ` Laurent Vivier
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 4/9] arch-run: generate errata when no environ is provided Andrew Jones
2017-06-08 10:43   ` Laurent Vivier
2017-06-13  8:12     ` Andrew Jones
2017-06-13 10:01       ` Laurent Vivier
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 5/9] mkstandalone: provide errata to tests Andrew Jones
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 6/9] errata: add ERRATA_FORCE Andrew Jones
2017-06-08 10:56   ` Laurent Vivier
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 7/9] README: add section on guarding unsafe tests Andrew Jones
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 8/9] AArch32: apply errata framework to unsafe pmccntr64 test Andrew Jones
2017-06-06 18:22 ` [PATCH kvm-unit-tests v2 9/9] arm/arm64: apply errata framework to unsafe cpu-on test Andrew Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.