Skip to contentSkip to conversation

Extend and apply the errata framework

PATCH Applied Andrew Jones 3 participants 14 messages Jun 13, 2017 – Jun 14, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Extend and apply the errata framework

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

v3:
- clear INITRD to be sure it's not used unless derived from ENV [Laurent]
- add some Laurent r-b's

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   | 80 +++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/mkstandalone.sh |  6 ++++
 x86/run                 | 14 +++++++--
 13 files changed, 202 insertions(+), 19 deletions(-)
 create mode 100644 errata.txt
Signature · 1 line
2.9.4
#1 lore raw

PATCH v3 1/9 arch-run: introduce initrd_create

Encapsulate the preparation of the optional initrd command line option.

---
 arm/run               | 5 +++--
 powerpc/run           | 5 +++--
 scripts/arch-run.bash | 6 ++++++
 x86/run               | 5 +++--
 4 files changed, 15 insertions(+), 6 deletions(-)
arm/run +3 -2
index f73593bc01af..1b1602c74970 100755
@@ -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 "$@"
 
powerpc/run +3 -2
index d73f721680b5..7ccf1a36ff49 100755
@@ -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 "$@"
 
scripts/arch-run.bash +6 -0
index 5c10828e30f9..9efa76d6ae33 100644
@@ -155,3 +155,9 @@ search_qemu_binary ()
 	command -v $qemu
 	export PATH=$save_path
 }
+
+initrd_create ()
+{
+	unset INITRD
+	[ -f "$ENV" ] && INITRD="-initrd $ENV"
+}
x86/run +3 -2
index c0502c7c3fcb..5b402a680cc7 100755
@@ -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} "$@"
 
Signature · 1 line
2.9.4
#3 lore raw

PATCH v3 2/9 arch-run: provide errata from run env

In reply to Andrew Jones

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.

---
 scripts/arch-run.bash | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
scripts/arch-run.bash +28 -0
index 9efa76d6ae33..135342ef48f2 100644
@@ -158,6 +158,34 @@ search_qemu_binary ()
 
 initrd_create ()
 {
+	env_add_errata
 	unset INITRD
 	[ -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
+}
Signature · 1 line
2.9.4
#4 lore raw

PATCH v3 3/9 x86/run: source config.mak

In reply to Andrew Jones

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

---
 x86/run | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
x86/run +8 -1
index 5b402a680cc7..88f5ff771140 100755
@@ -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)
 
Signature · 1 line
2.9.4
#5 lore raw

PATCH v3 4/9 arch-run: generate errata when no environ is provided

In reply to Andrew Jones

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.

---
 configure             | 11 +++++++++++
 errata.txt            |  5 +++++
 scripts/arch-run.bash | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 errata.txt
configure +11 -0
index 64722c9b263b..cde2cfe9db61 100755
@@ -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
errata.txt new file +5 -0
new file mode 100644
index 000000000000..95b66c837c63
@@ -0,0 +1,5 @@
+#---------------:-----------------------:--------------------------------------
+# commit	: minimum kernel	: summary
+# 12 hex digits	: version		:
+#---------------:-----------------------:--------------------------------------
+#---------------:-----------------------:--------------------------------------
scripts/arch-run.bash +46 -0

58 lines not on this page · raw message

Signature · 1 line
2.9.4
#6 lore raw

PATCH v3 5/9 mkstandalone: provide errata to tests

In reply to Andrew Jones
---
 configure               | 1 +
 scripts/arch-run.bash   | 4 ++--
 scripts/mkstandalone.sh | 6 ++++++
 3 files changed, 9 insertions(+), 2 deletions(-)
configure +1 -0
index cde2cfe9db61..e1efb3ca0cca 100755
@@ -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
scripts/arch-run.bash +2 -2
index 27b8531fcfcf..7c6c79ad3a9d 100644
@@ -196,9 +196,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#*:}
 
scripts/mkstandalone.sh +6 -0
index 55cfc4ef8c00..a15941f75375 100755
@@ -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'
 
Signature · 1 line
2.9.4
#9 lore raw

PATCH v3 7/9 README: add section on guarding unsafe tests

In reply to Andrew Jones
---
 README.md | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
README.md +34 -0
index 576584b752eb..453eb85bd7c4 100644
@@ -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
Signature · 1 line
2.9.4
#11 lore raw

PATCH v3 8/9 AArch32: apply errata framework to unsafe pmccntr64 test

In reply to Andrew Jones
---
 arm/pmu.c  | 26 ++++++++++++++++++--------
 errata.txt |  1 +
 2 files changed, 19 insertions(+), 8 deletions(-)
arm/pmu.c +18 -8
index 74848988a678..1ac692023e5e 100644
@@ -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();
 }
errata.txt +1 -0
index 95b66c837c63..682d7aa067b9 100644
@@ -2,4 +2,5 @@
 # commit	: minimum kernel	: summary
 # 12 hex digits	: version		:
 #---------------:-----------------------:--------------------------------------
+9e3f7a296940	: 4.9			: arm64: KVM: pmu: Fix AArch32 cycle counter access
 #---------------:-----------------------:--------------------------------------
Signature · 1 line
2.9.4
#8 lore raw

PATCH v3 6/9 errata: add ERRATA_FORCE

In reply to Andrew Jones

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.

---
 lib/errata.h | 21 +++++++++++++++++++--
 run_tests.sh |  2 ++
 2 files changed, 21 insertions(+), 2 deletions(-)
lib/errata.h +19 -2
index 7b089c2578ad..f3ebca2d8a6c 100644
@@ -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'));
 }
run_tests.sh +2 -0
index c7972cbd198b..aa2e65f622ce 100755
@@ -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
Signature · 1 line
2.9.4
#12 lore raw

PATCH v3 9/9 arm/arm64: apply errata framework to unsafe cpu-on test

In reply to Andrew Jones

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

---
 arm/psci.c        | 7 ++++++-
 arm/unittests.cfg | 2 +-
 errata.txt        | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)
arm/psci.c +6 -1
index 4e6bc58dbe42..5cb4d5c7c233 100644
@@ -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
arm/unittests.cfg +1 -1
index 4fc90eef91db..73a2419fefe6 100644
@@ -108,4 +108,4 @@ groups = gic
 [psci]
 file = psci.flat
 smp = $MAX_SMP
-groups = nodefault,psci
+groups = psci
errata.txt +1 -0
index 682d7aa067b9..5608a308ce7c 100644
@@ -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
 #---------------:-----------------------:--------------------------------------
Signature · 1 line
2.9.4
Reviewed-by on v3 1/9
#2 lore raw

Re: [PATCH kvm-unit-tests v3 1/9] arch-run: introduce initrd_create

In reply to Andrew Jones
Quoted 4 lines · Andrew Jones

Encapsulate the preparation of the optional initrd command line option.

Quoted 76 lines
---
 arm/run               | 5 +++--
 powerpc/run           | 5 +++--
 scripts/arch-run.bash | 6 ++++++
 x86/run               | 5 +++--
 4 files changed, 15 insertions(+), 6 deletions(-)
arm/run +3 -2
index f73593bc01af..1b1602c74970 100755
@@ -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 "$@"
 
powerpc/run +3 -2
index d73f721680b5..7ccf1a36ff49 100755
@@ -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 "$@"
 
scripts/arch-run.bash +6 -0
index 5c10828e30f9..9efa76d6ae33 100644
@@ -155,3 +155,9 @@ search_qemu_binary ()
 	command -v $qemu
 	export PATH=$save_path
 }
+
+initrd_create ()
+{
+	unset INITRD
+	[ -f "$ENV" ] && INITRD="-initrd $ENV"
+}
x86/run +3 -2
index c0502c7c3fcb..5b402a680cc7 100755
@@ -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} "$@"
 
Reviewed-by on v3 5/9
#7 lore raw

Re: [PATCH kvm-unit-tests v3 5/9] mkstandalone: provide errata to tests

In reply to Andrew Jones
Quoted 1 line · Andrew Jones
Quoted 58 lines
---
 configure               | 1 +
 scripts/arch-run.bash   | 4 ++--
 scripts/mkstandalone.sh | 6 ++++++
 3 files changed, 9 insertions(+), 2 deletions(-)
configure +1 -0
index cde2cfe9db61..e1efb3ca0cca 100755
@@ -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
scripts/arch-run.bash +2 -2
index 27b8531fcfcf..7c6c79ad3a9d 100644
@@ -196,9 +196,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#*:}
 
scripts/mkstandalone.sh +6 -0
index 55cfc4ef8c00..a15941f75375 100755
@@ -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'
 
Reviewed-by on v3 7/9
#10 lore raw

Re: [PATCH kvm-unit-tests v3 7/9] README: add section on guarding unsafe tests

In reply to Andrew Jones
Quoted 1 line · Andrew Jones
Quoted 50 lines
---
 README.md | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
README.md +34 -0
index 576584b752eb..453eb85bd7c4 100644
@@ -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
#13 lore raw
In reply to Andrew Jones

2017-06-13 13:54+0200, Andrew Jones:

Quoted 11 lines

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

Applied, thanks.