RESEND staging branch
Subsystems (3)
cover RESEND staging branch
This series is just a reposting of the patches on
https://github.com/rhdrjones/kvm-unit-tests/commits/staging
I believe all patches have been posted before, well except 07/11.
Thanks,
drew
Alex Bennée (5):
README: add some CONTRIBUTING notes
configure: emit HOST=$host to config.mak
lib/printf: support the %u unsigned fmt field
lib: add isaac prng library from CCAN
lib/arm: add flush_tlb_page mmu function
Andrew Jones (6):
arm/arm64: uart0_init: check /chosen/stdout-path arm/arm64: allow building a single test
run_tests: pass test name to run script arm/run: use ACCEL to choose between kvm and tcg
run_tests: probe for max-smp
makefiles: use bash
Makefile | 2 + README | 26 +++++++ arm/run | 43 ++++++++++-- arm/unittests.cfg | 7 +- config/config-arm-common.mak | 7 ++ configure | 2 + lib/arm/asm/mmu.h | 11 +++ lib/arm/io.c | 36 +++++++--- lib/arm64/asm/mmu.h | 8 +++ lib/printf.c | 13 ++++ lib/prng.c | 162 +++++++++++++++++++++++++++++++++++++++++++ lib/prng.h | 82 ++++++++++++++++++++++ run_tests.sh | 12 +++- scripts/functions.bash | 8 ++- scripts/mkstandalone.sh | 22 ++++-- x86/unittests.cfg | 1 + 16 files changed, 418 insertions(+), 24 deletions(-) create mode 100644 lib/prng.c create mode 100644 lib/prng.h
Signature · 1 line
2.4.3
PATCH 1/11 arm/arm64: uart0_init: check /chosen/stdout-path
Arguably all of uart0_init() is unnecessary, as we're pretty sure that the address we initialize uart0_base to is correct. We go through the motions of finding the uart anyway though, because it's easy. It's also easy to check chosen/stdout-path first, so let's do that too. But, just to make all this stuff a little less unnecessary, let's add a warning when we do actually find an address that doesn't match our initializer.
--- lib/arm/io.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-)
lib/arm/io.c +27 -9
@@ -19,12 +19,14 @@ extern void halt(int code);/* * Use this guess for the pl011 base in order to make an attempt at * having earlier printf support. We'll overwrite it with the real -* base address that we read from the device tree later. +* base address that we read from the device tree later. This is +* the address we expect QEMU's mach-virt machine type to put in +* its generated device tree. */ -#define QEMU_MACH_VIRT_PL011_BASE 0x09000000UL +#define UART_EARLY_BASE 0x09000000ULstatic struct spinlock uart_lock; -static volatile u8 *uart0_base = (u8 *)QEMU_MACH_VIRT_PL011_BASE ; +static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE ;static void uart0_init (void ) {
@@ -32,16 +34,32 @@ static void uart0_init(void)struct dt_pbus_reg base;int ret; - ret =dt_pbus_get_base_compatible (compatible, &base); -assert (ret ==0 || ret == -FDT_ERR_NOTFOUND ); + ret =dt_get_default_console_node (); +assert (ret >=0 || ret == -FDT_ERR_NOTFOUND ); -if (ret) { -printf ("%s: %s not found in the device tree, aborting...\n" , - __func__, compatible); -abort (); +if (ret == -FDT_ERR_NOTFOUND ) { + + ret =dt_pbus_get_base_compatible (compatible, &base); +assert (ret ==0 || ret == -FDT_ERR_NOTFOUND ); + +if (ret) { +printf ("%s: %s not found in the device tree, " +"aborting...\n" , + __func__, compatible); +abort (); + } + + }else { +assert (dt_pbus_translate_node (ret,0 , &base) ==0 ); } uart0_base =ioremap (base.addr, base.size); + +if (uart0_base != (u8 *)UART_EARLY_BASE ) { +printf ("WARNING: early print support may not work. " +"Found uart at %p, but early base is %p.\n" , + uart0_base, (u8 *)UART_EARLY_BASE ); + } }void io_init (void )
Signature · 1 line
2.4.3
PATCH 2/11 arm/arm64: allow building a single test
In reply to Andrew JonesThis is mostly useful for building new tests that don't yet (and may never) have entries in the makefiles (config-arm*.mak). Of course it can be used to build tests that do have entries as well, in order to avoid building all tests, if the plan is to run just the one.
Just do 'make TEST=some-test' to use it, where "some-test" matches the name of the source file, i.e. arm/some-test.c
--- config/config-arm-common.mak | 6 ++++++ 1 file changed, 6 insertions(+)
config/config-arm-common.mak +6 -0
@@ -13,6 +13,11 @@ tests-common = \ $(TEST_DIR)/selftest.flat \ $(TEST_DIR)/spinlock-test.flat +ifneq ($(TEST),) + tests = $(TEST_DIR)/$(TEST).flat + tests-common = +endif + all: test_cases ##################################################################
@@ -68,5 +73,6 @@ generated_files = $(asm-offsets) test_cases: $(generated_files) $(tests-common) $(tests) +$(TEST_DIR)/$(TEST).elf: $(cstart.o) $(TEST_DIR)/$(TEST).o $(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o $(TEST_DIR)/spinlock-test.elf: $(cstart.o) $(TEST_DIR)/spinlock-test.o
Signature · 1 line
2.4.3
PATCH 3/11 README: add some CONTRIBUTING notes
In reply to Andrew JonesFrom: Alex Bennée <[email protected]>
--- README | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
README +26 -0
@@ -35,3 +35,29 @@ Directory structure: ./<ARCH>: the sources of the tests and the created objects/images See <ARCH>/README for architecture specific documentation. + +CONTRIBUTING: +============= + +Style +----- + +Currently there is a mix of indentation styles so any changes to +existing files should be consistent with the existing style. For new +files: + + - C: please use standard linux-with-tabs + - Shell: use TABs for indentation + +Patches +------- + +Patches are welcome at the KVM mailing list <[email protected]>. + +Please prefix messages with: [kvm-unit-tests PATCH] + +You can add the following to .git/config to do this automatically for you: + +[format] + subjectprefix = kvm-unit-tests PATCH +
Signature · 1 line
2.4.3
PATCH 4/11 configure: emit HOST=$host to config.mak
In reply to Andrew JonesFrom: Alex Bennée <[email protected]>
This is useful information for the run scripts to know, especially if they want to drop to using TCG.
--- configure | 2 ++ 1 file changed, 2 insertions(+)
configure +2 -0
@@ -7,6 +7,7 @@ ld=ld objcopy=objcopy ar=ar arch=`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'` +host=$arch cross_prefix= usage() {
@@ -122,6 +123,7 @@ ln -s $asm lib/asm cat <<EOF > config.mak PREFIX=$prefix KERNELDIR=$(readlink -f $kerneldir) +HOST=$host ARCH=$arch ARCH_NAME=$arch_name PROCESSOR=$processor
Signature · 1 line
2.4.3
PATCH 5/11 run_tests: pass test name to run script
In reply to Andrew JonesWith this $TEST_DIR/run can output test specific error messages.
--- run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
run_tests.sh +1 -1
@@ -46,7 +46,7 @@ function run() fi done - cmdline="./$TEST_DIR-run $kernel -smp $smp $opts" + cmdline="TESTNAME=$testname ./$TEST_DIR-run $kernel -smp $smp $opts" if [ $verbose != 0 ]; then echo $cmdline fi
Signature · 1 line
2.4.3
PATCH 6/11 arm/run: use ACCEL to choose between kvm and tcg
In reply to Andrew JonesInspired by a patch by Alex Bennée. This version uses a new unittests.cfg variable and includes support for DRYRUN.
--- arm/run | 43 +++++++++++++++++++++++++++++++++++++------ arm/unittests.cfg | 4 +++- run_tests.sh | 3 ++- scripts/functions.bash | 8 ++++++-- scripts/mkstandalone.sh | 15 +++++++++++---- 5 files changed, 59 insertions(+), 14 deletions(-)
arm/run +37 -6
@@ -7,6 +7,42 @@ fi source config.mak processor="$PROCESSOR" +if [ -c /dev/kvm ]; then + if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then + kvm_available=yes + elif [ "$HOST" = "aarch64" ]; then + kvm_available=yes + fi +fi + +if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ] && + [ "$DRYRUN" != "yes" ]; then + printf "skip $TESTNAME (kvm only)\n\n" + exit 2 +fi + +if [ -z "$ACCEL" ]; then + if [ "$DRYRUN" = "yes" ]; then + # Output kvm with tcg fallback for dryrun (when both are + # allowed), since the command line we output may get used + # elsewhere. + ACCEL="kvm:tcg" + elif [ "$kvm_available" = "yes" ]; then + ACCEL="kvm" + else + ACCEL="tcg" + fi +fi + +if [ "$ARCH" = "arm64" ]; then + if [[ $ACCEL =~ kvm ]]; then + # arm64 must use '-cpu host' with kvm, and we can't use + # '-cpu host' with tcg, so we force kvm-only (no fallback) + ACCEL="kvm" + processor="host" + fi +fi + qemu="${QEMU:-qemu-system-$ARCH_NAME}" qpath=$(which $qemu 2>/dev/null)
@@ -33,15 +69,10 @@ if $qemu $M -chardev testdev,id=id -initrd . 2>&1 \ exit 2 fi -M='-machine virt,accel=kvm:tcg' chr_testdev='-device virtio-serial-device' chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd' -# arm64 must use '-cpu host' with kvm -if [ "$(arch)" = "aarch64" ] && [ "$ARCH" = "arm64" ] && [ -c /dev/kvm ]; then - processor="host" -fi - +M+=",accel=$ACCEL" command="$qemu $M -cpu $processor $chr_testdev" command+=" -display none -serial stdio -kernel" echo $command "$@"
arm/unittests.cfg +3 -1
@@ -3,8 +3,10 @@ # file = foo.flat # Name of the flat file to be used # smp = 2 # Number of processors the VM will use during this test # extra_params = -append <params...> # Additional parameters used -# arch = arm/arm64 # Only if test case is specific to one +# arch = arm|arm64 # Only if test case is specific to one # groups = group1 group2 # Used to identify test cases with run_tests -g ... +# accel = kvm|tcg # Optionally specify if test must run with kvm or tcg. +# # If not specified, then kvm will be used when available. # # Test that the configured number of processors (smp = <num>), and
run_tests.sh +2 -1
@@ -20,6 +20,7 @@ function run() local opts="$5" local arch="$6" local check="$7" + local accel="$8" if [ -z "$testname" ]; then return
@@ -46,7 +47,7 @@ function run() fi done - cmdline="TESTNAME=$testname ./$TEST_DIR-run $kernel -smp $smp $opts" + cmdline="TESTNAME=$testname ACCEL=$accel ./$TEST_DIR-run $kernel -smp $smp $opts" if [ $verbose != 0 ]; then echo $cmdline fi
scripts/functions.bash +6 -2
@@ -10,12 +10,13 @@ function for_each_unittest() local groups local arch local check + local accel exec {fd}<"$unittests" while read -u $fd line; do if [[ "$line" =~ ^\[(.*)\]$ ]]; then - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" + "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" testname=${BASH_REMATCH[1]} smp=1 kernel=""
@@ -23,6 +24,7 @@ function for_each_unittest() groups="" arch="" check="" + accel="" elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then kernel=$TEST_DIR/${BASH_REMATCH[1]} elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
@@ -35,8 +37,10 @@ function for_each_unittest() arch=${BASH_REMATCH[1]} elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then check=${BASH_REMATCH[1]} + elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then + accel=${BASH_REMATCH[1]} fi done - "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" + "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" exec {fd}<&- }
scripts/mkstandalone.sh +11 -4
@@ -29,6 +29,7 @@ function mkstandalone() local opts="$5" local arch="$6" local check="$7" + local accel="$8" if [ -z "$testname" ]; then return 1
@@ -39,7 +40,7 @@ function mkstandalone() fi standalone=tests/$testname - cmdline=$(DRYRUN=yes ./$TEST_DIR-run $kernel) + cmdline=$(DRYRUN=yes ACCEL=$accel ./$TEST_DIR-run $kernel) if [ $? -ne 0 ]; then echo $cmdline exit 1
@@ -94,10 +95,16 @@ qemu="$qemu" if [ "\$QEMU" ]; then qemu="\$QEMU" fi -cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`" echo \$qemu $cmdline -smp $smp $opts -\$qemu \$cmdline -smp $smp $opts -ret=\$? + +cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`" +if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then + ret=2 +else + cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`" + \$qemu \$cmdline -smp $smp $opts + ret=\$? +fi echo Return value from qemu: \$ret if [ \$ret -le 1 ]; then echo PASS $testname 1>&2
Signature · 1 line
2.4.3
PATCH 7/11 run_tests: probe for max-smp
In reply to Andrew JonesKVM can be configured to only support a few vcpus. ARM and AArch64 currently have a default config of only 4. While it's nice to be able to write tests that use the maximum recommended, nr-host-cpus, we can't assume that nr-host-cpus == kvm-max-vcpus. This patch allows one to put $MAX_SMP in the smp = <num> line of a unittests.cfg file. That variable will then expand to the number of host cpus, or to the maximum vcpus allowed by KVM.
[Inspired by a patch from Alex Bennée solving the same issue.]
--- arm/unittests.cfg | 3 ++- run_tests.sh | 9 +++++++++ scripts/mkstandalone.sh | 9 ++++++++- x86/unittests.cfg | 1 + 4 files changed, 20 insertions(+), 2 deletions(-)
arm/unittests.cfg +2 -1
@@ -2,6 +2,7 @@ # [unittest_name] # file = foo.flat # Name of the flat file to be used # smp = 2 # Number of processors the VM will use during this test +# # Use $MAX_SMP to use the maximum the host supports. # extra_params = -append <params...> # Additional parameters used # arch = arm|arm64 # Only if test case is specific to one # groups = group1 group2 # Used to identify test cases with run_tests -g ...
@@ -34,6 +35,6 @@ groups = selftest # Test SMP support [selftest-smp] file = selftest.flat -smp = `getconf _NPROCESSORS_CONF` +smp = $MAX_SMP extra_params = -append 'smp' groups = selftest
run_tests.sh +9 -0
@@ -98,4 +98,13 @@ while getopts "g:hv" opt; do esac done +# +# Probe for MAX_SMP +# +MAX_SMP=$(getconf _NPROCESSORS_CONF) +while ./$TEST_DIR-run _NO_FILE_4Uhere_ -smp $MAX_SMP \ + |& grep -q 'exceeds max cpus'; do + ((--MAX_SMP)) +done + for_each_unittest $config run
scripts/mkstandalone.sh +8 -1
@@ -95,12 +95,19 @@ qemu="$qemu" if [ "\$QEMU" ]; then qemu="\$QEMU" fi + +MAX_SMP="MAX_SMP" echo \$qemu $cmdline -smp $smp $opts cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`" if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then - ret=2 + ret=2 else + MAX_SMP=\`getconf _NPROCESSORS_CONF\` + while \$qemu \$cmdline -smp \$MAX_SMP 2>&1 | grep 'exceeds max cpus' > /dev/null; do + MAX_SMP=\`expr \$MAX_SMP - 1\` + done + cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`" \$qemu \$cmdline -smp $smp $opts ret=\$?
x86/unittests.cfg +1 -0
@@ -2,6 +2,7 @@ # [unittest_name] # file = foo.flat # Name of the flat file to be used # smp = 2 # Number of processors the VM will use during this test +# # Use $MAX_SMP to use the maximum the host supports. # extra_params = -cpu qemu64,+x2apic # Additional parameters used # arch = i386/x86_64 # Only if the test case works only on one of them # groups = group1 group2 # Used to identify test cases with run_tests -g ...
Signature · 1 line
2.4.3
PATCH 8/11 lib/printf: support the %u unsigned fmt field
In reply to Andrew JonesFrom: Alex Bennée <[email protected]>
--- lib/printf.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
lib/printf.c +13 -0
@@ -180,6 +180,19 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)break ; }break ; +case 'u' : +switch (nlong) { +case 0 : +print_unsigned (&s,va_arg (va, unsigned),10 , props); +break ; +case 1 : + print_unsigned(&s, va_arg(va, unsigned long), 10, props); +break ; +default : + print_unsigned(&s, va_arg(va, unsigned long long), 10, props); +break ; + } +break ;case 'x' :switch (nlong) {case 0 :
Signature · 1 line
2.4.3
PATCH 9/11 lib: add isaac prng library from CCAN
In reply to Andrew JonesFrom: Alex Bennée <[email protected]>
It's often useful to introduce some sort of random variation when testing several racing CPU conditions. Instead of each test implementing some half-arsed PRNG bring in a a decent one which has good statistical randomness. Obviously it is deterministic for a given seed value which is likely the behaviour you want.
I've pulled in the ISAAC library from CCAN:
http://ccodearchive.net/info/isaac.html
I shaved off the float related stuff which is less useful for unit testing and re-indented to fit the style. The original license was CC0 (Public Domain) which is compatible with the LGPL v2 of kvm-unit-tests.
--- config/config-arm-common.mak | 1 + lib/prng.c | 162 +++++++++++++++++++++++++++++++++++++++++++ lib/prng.h | 82 ++++++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 lib/prng.c create mode 100644 lib/prng.h
config/config-arm-common.mak +1 -0
@@ -37,6 +37,7 @@ cflatobjs += lib/devicetree.o cflatobjs += lib/virtio.o cflatobjs += lib/virtio-mmio.o cflatobjs += lib/chr-testdev.o +cflatobjs += lib/prng.o cflatobjs += lib/arm/io.o cflatobjs += lib/arm/setup.o cflatobjs += lib/arm/mmu.o
lib/prng.c new file +162 -0
162 lines not on this page · raw message
lib/prng.h new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH 10/11 lib/arm: add flush_tlb_page mmu function
In reply to Andrew JonesFrom: Alex Bennée <[email protected]>
This introduces a new flush_tlb_page function which does exactly what you expect. It's going to be useful for the future TLB torture test.
--- lib/arm/asm/mmu.h | 11 +++++++++++ lib/arm64/asm/mmu.h | 8 ++++++++ 2 files changed, 19 insertions(+)
lib/arm/asm/mmu.h +11 -0
@@ -14,8 +14,11 @@#define PTE_AF PTE_EXT_AF#define PTE_WBWA L_PTE_MT_WRITEALLOC +/* See B3.18.7 TLB maintenance operations */ +static inline void local_flush_tlb_all (void ) { +/* TLBIALL */ asmvolatile ("mcr p15, 0, %0, c8, c7, 0" ::"r" (0 ));dsb ();isb ();
@@ -27,6 +30,14 @@ static inline void flush_tlb_all(void) local_flush_tlb_all(); } +static inline void flush_tlb_page (unsigned long vaddr) +{ +/* TLBIMVAA */ + asmvolatile ("mcr p15, 0, %0, c8, c7, 3" ::"r" (vaddr)); +dsb (); +isb (); +} +#include <asm/mmu-api.h> #endif /* __ASMARM_MMU_H_ */
lib/arm64/asm/mmu.h +8 -0
@@ -19,6 +19,14 @@ static inline void flush_tlb_all(void) isb(); } +static inline void flush_tlb_page (unsigned long vaddr) +{ +unsigned long page = vaddr >>12 ; +dsb (ishst); + asm("tlbi vaae1is, %0" ::"r" (page)); +dsb (ish); +} +#include <asm/mmu-api.h> #endif /* __ASMARM64_MMU_H_ */
Signature · 1 line
2.4.3
PATCH 11/11 makefiles: use bash
In reply to Andrew JonesUse bash in the makefiles, like we do in the scripts.
--- Makefile | 2 ++ 1 file changed, 2 insertions(+)
Makefile +2 -0
@@ -1,4 +1,6 @@ +SHELL := /bin/bash + ifeq ($(wildcard config.mak),) $(error run ./configure first. See ./configure -h) endif
Signature · 1 line
2.4.3