From e6b2c7f35d82b1429b3dcd8b57edde119c262b2e Mon Sep 17 00:00:00 2001 From: Marcelo Bandeira Condotta Date: Wed, 5 Jun 2019 10:09:51 -0300 Subject: [PATCH] KVM Kernel Self Tests Make Kernel Self Tests run with the current running Kernel. Remove patch since the code has been added on RHEL8 (4.18.0-97) and ARK (5.2). Fix KVM Kernel Selftests to run for the correct kernel version (currently running). Run indiviual tests separately to be able to disable them if there are bugs. Fix the script to detect failures. Fix python for RHEL8.1. Fix downloading of the SRC RPM for CKI builds. --- vm/kvm-self-tests/Makefile | 1 + vm/kvm-self-tests/patches/bitmap.h.patch | 27 ----- vm/kvm-self-tests/runtest.sh | 127 ++++++++++++++++++++--- 3 files changed, 113 insertions(+), 42 deletions(-) delete mode 100644 vm/kvm-self-tests/patches/bitmap.h.patch diff --git a/vm/kvm-self-tests/Makefile b/vm/kvm-self-tests/Makefile index 6c21a9ca..aca4bfd2 100644 --- a/vm/kvm-self-tests/Makefile +++ b/vm/kvm-self-tests/Makefile @@ -55,6 +55,7 @@ $(METADATA): Makefile @echo "Requires: patch" >> $(METADATA) @echo "Requires: python2-lxml" >> $(METADATA) @echo "Requires: python3-lxml" >> $(METADATA) + @echo "Requires: bc" >> $(METADATA) @echo "Priority: Normal" >> $(METADATA) @echo "License: GPLv3" >> $(METADATA) @echo "Confidential: no" >> $(METADATA) diff --git a/vm/kvm-self-tests/patches/bitmap.h.patch b/vm/kvm-self-tests/patches/bitmap.h.patch deleted file mode 100644 index ec0516bb..00000000 --- a/vm/kvm-self-tests/patches/bitmap.h.patch +++ /dev/null @@ -1,27 +0,0 @@ ---- a/tools/include/linux/bitmap.h 2019-03-28 23:18:27.245070526 -0400 -+++ b/tools/include/linux/bitmap.h 2019-03-28 23:20:26.958597334 -0400 -@@ -97,6 +97,24 @@ - } - - /** -+ * test_and_clear_bit - Clear a bit and return its old value -+ * @nr: Bit to clear -+ * @addr: Address to count from -+ */ -+static inline int test_and_clear_bit(int nr, volatile unsigned long *addr) -+{ -+ unsigned long mask = BIT_MASK(nr); -+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); -+ unsigned long old; -+ unsigned long flags; -+ -+ old = *p; -+ *p = old & ~mask; -+ -+ return (old & mask) != 0; -+} -+ -+/** - * bitmap_alloc - Allocate bitmap - * @nbits: Number of bits - */ diff --git a/vm/kvm-self-tests/runtest.sh b/vm/kvm-self-tests/runtest.sh index 53754240..4afaab2e 100644 --- a/vm/kvm-self-tests/runtest.sh +++ b/vm/kvm-self-tests/runtest.sh @@ -20,8 +20,78 @@ NAME=$(basename $0) CDIR=$(dirname $0) TEST=${TEST:-"$0"} -PACKAGE="kernel" +RELEASE=$(uname -r | sed s/\.`arch`//) +PACKAGE="kernel-${RELEASE}" TMPDIR=/var/tmp/$(date +"%Y%m%d%H%M%S") +BINDIR=${TMPDIR}-bin + +function getTests +{ + # List of tests to run on all architectures + ALLARCH_TESTS=() + while IFS= read -r -d $'\0'; do + ALLARCH_TESTS+=("$REPLY") + done < <(find ${BINDIR} -maxdepth 1 -type f -executable -printf "%f\0") + + # List of tests to run on x86_64 architecture + X86_64_TESTS=() + while IFS= read -r -d $'\0'; do + X86_64_TESTS+=("$REPLY") + done < <(find ${BINDIR}/x86_64 -maxdepth 1 -type f -executable -printf "x86_64/%f\0") + + # List of tests to run on aarch64 architecture + AARCH64_TESTS=() + + # List of tests to run on ppc64 architecture + PPC64_TESTS=() + + # List of tests to run on s390x architecture + S390X_TESTS=() +} + +function disableTests +{ + # Disable tests for RHEL8 Kernel (4.18.X) + if uname -r | grep --quiet '^4'; then + # Disable test clear_dirty_log_test + # due to https://bugzilla.redhat.com/show_bug.cgi?id=1718479 + mapfile -d $'\0' -t ALLARCH_TESTS < <(printf '%s\0' "${ALLARCH_TESTS[@]}" | grep -Pzv "clear_dirty_log_test") + + # Disabled x86_64 tests for AMD machines due to bugs + if lsmod | grep --quiet kvm_amd; then + # Disable test x86_64/platform_info_test + # due to https://bugzilla.redhat.com/show_bug.cgi?id=1718499 + mapfile -d $'\0' -t X86_64_TESTS < <(printf '%s\0' "${X86_64_TESTS[@]}" | grep -Pzv "x86_64/platform_info_test") + fi + fi + + # Disable tests for ARK Kernel (5.X) + if uname -r | grep --quiet '^5'; then + # Disable x86_64/sync_regs_test + # due to https://bugzilla.redhat.com/show_bug.cgi?id=1719397 + mapfile -d $'\0' -t X86_64_TESTS < <(printf '%s\0' "${X86_64_TESTS[@]}" | grep -Pzv "x86_64/sync_regs_test") + + # Disabled x86_64 tests for AMD machines due to bugs + if lsmod | grep --quiet kvm_amd; then + # Disable test x86_64/platform_info_test + # due to https://bugzilla.redhat.com/show_bug.cgi?id=1719387 + mapfile -d $'\0' -t X86_64_TESTS < <(printf '%s\0' "${X86_64_TESTS[@]}" | grep -Pzv "x86_64/platform_info_test") + # Disable x86_64/state_test + # due to https://bugzilla.redhat.com/show_bug.cgi?id=1719401 + mapfile -d $'\0' -t X86_64_TESTS < <(printf '%s\0' "${X86_64_TESTS[@]}" | grep -Pzv "x86_64/state_test") + # Disable x86_64/smm_test + # due to https://bugzilla.redhat.com/show_bug.cgi?id=1719402 + mapfile -d $'\0' -t X86_64_TESTS < <(printf '%s\0' "${X86_64_TESTS[@]}" | grep -Pzv "x86_64/smm_test") + fi + + # Disabled x86_64 tests for Intel machines due to bugs + if lsmod | grep --quiet kvm_intel; then + # Disable x86_64/evmcs_test + # due to https://bugzilla.redhat.com/show_bug.cgi?id=1719400 + mapfile -d $'\0' -t X86_64_TESTS < <(printf '%s\0' "${X86_64_TESTS[@]}" | grep -Pzv "x86_64/evmcs_test") + fi + fi +} source /usr/share/beakerlib/beakerlib.sh @@ -112,21 +182,27 @@ function runtest typeset linux_srcdir=$(find $TMPDIR -type d -a -name "linux-*") typeset tests_srcdir="$linux_srcdir/tools/testing/selftests/kvm" - rlAssertExists $tests_srcdir + typeset outputdir="${BINDIR}" + typeset hwpf=$(uname -i) - # - # XXX: Apply a patch because case 'dirty_log_test' fails to be built, which - # is because patch [1] is missed when backporting to RHEL8 repo. Note - # we should remove the workaround if the case is fixed. - # [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=07a262cc - # - rlRun "patch -d $linux_srcdir -p1 < patches/bitmap.h.patch" 0 \ - "Patching via patches/bitmap.h.patch" + rlAssertExists $tests_srcdir + rlAssertExists ${outputdir} rlRun "pushd '.'" - rlRun "cd $tests_srcdir && make TARGETS=kvm run_tests" 0 \ - "Running kvm selftests" - (( $? == 0 )) && rlPass $TEST || rlFail $TEST + + # Build tests + rlRun "make -C ${tests_srcdir} OUTPUT=${outputdir} TARGETS=kvm" + + # Prepare lists of tests to run + getTests + disableTests + + # Run tests + for test in ${ALLARCH_TESTS[*]}; do rlRun "${outputdir}/${test}" 0,4; done + [[ $hwpf == "x86_64" ]] && for test in ${X86_64_TESTS[*]}; do rlRun "${outputdir}/${test}" 0,4; done + [[ $hwpf == "aarch64" ]] && for test in ${AARCH64_TESTS[*]}; do rlRun "${outputdir}/${test}" 0,4; done + [[ $hwpf == "ppc64" || $hwpf == "ppc64le" ]] && for test in ${PPC64_TESTS[*]}; do rlRun "${outputdir}/${test}" 0,4; done + [[ $hwpf == "s390x" ]] && for test in ${S390X_TESTS[*]}; do rlRun "${outputdir}/${test}" 0,4; done rlRun "popd" @@ -141,13 +217,33 @@ function setup check + if lsmod | grep --quiet kvm_intel; then + rmmod kvm_intel; rmmod kvm + modprobe kvm; modprobe kvm_intel + elif lsmod | grep --quiet kvm_amd; then + rmmod kvm_amd; rmmod kvm + modprobe kvm; modprobe kvm_amd + fi rlRun "rm -rf $TMPDIR && mkdir $TMPDIR" + rlRun "rm -rf ${BINDIR} && mkdir -p ${BINDIR}/x86_64" rlRun "pushd '.'" + # if running on rhel8, use python3 + if grep --quiet "release 8." /etc/redhat-release && [ ! -x /usr/bin/python ];then + ln -s /usr/libexec/platform-python /usr/bin/python + fi + rlRun "cd $TMPDIR" - rlFetchSrcForInstalled $pkg - typeset rpmfile=$(ls -1 $TMPDIR/${pkg}*.src.rpm) + if [ -x /usr/bin/dnf ]; then + dnf download ${pkg} --source + elif [ -x /usr/bin/yum ]; then + yum download ${pkg} --source + fi + if [ ! -f $TMPDIR/${pkg}.src.rpm ]; then + rlFetchSrcForInstalled $pkg + fi + typeset rpmfile=$(ls -1 $TMPDIR/${pkg}.src.rpm) rlAssertExists $rpmfile rlRun "ls -l $rpmfile" @@ -171,6 +267,7 @@ function cleanup rlPhaseStartCleanup rlRun "rm -rf $TMPDIR" + rlRun "rm -rf ${BINDIR}" rlPhaseEnd }