diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-04-09 21:19:09 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2022-04-09 21:19:09 -0400 |
commit | 090f958472fdb915c5af80192ba74ae01e85008a (patch) | |
tree | aecbc081aef78c905ee9b4dd5b30c6c03bd1ed9d | |
parent | b4fb62df7b0a70f671486900653b6f6589d457ee (diff) |
Consolidate various paths and directories
Now, everything that ktest produces goes under ktest-out, and we have
only one input path and one output path to (potentially) specify on the
commandline - the kernel source tree, and the ktest-out directory.
The kernel build directory and kernel binary directory now go under
ktest-out.
Also deleted a bunch of old unused options.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rwxr-xr-x | build-test-kernel | 79 | ||||
-rwxr-xr-x | ktest | 6 | ||||
-rw-r--r-- | lib/libktest.sh | 69 | ||||
-rwxr-xr-x | lib/testrunner | 4 |
4 files changed, 56 insertions, 102 deletions
diff --git a/build-test-kernel b/build-test-kernel index 8084bbe..2c9b008 100755 --- a/build-test-kernel +++ b/build-test-kernel @@ -15,21 +15,9 @@ checkdep make ktest_kernel_source="." # dir of kernel source # set with: -k <path> # defaults: current directory -ktest_kernel_build="" # kernel build dir - # defaults to - # $ktest_kernel_source/.build-test-kernel-$ktest_arch -ktest_kernel_binary="" # kernel output dir - # defaults to $ktest_kernel_build/kpkg - -BUILD=1 # if set to 1, kernel will build -DEPS=1 + COVERAGE="" # doing code coverage? MAKEARGS=() -ktest_njobs=$(($(grep -c '^processor' /proc/cpuinfo) * 2)) - # number of jobs to passed to make during kernel compile - # sets with: -j - # defaults to 2 * number of processor - usage() { @@ -45,13 +33,7 @@ usage() echo " options for build-test-kernel run:" ktest_usage_run_opts echo " -k <dir> kernel source dir" - echo " -b <dir> build directory for kernel (default: kernel_source/.build-test-kernel)" - echo " -o <dir> output directory for kernel binary (default: kernel_build/kpkg" - echo " -K don't rebuild kernel" - echo " -D don't modify kernel .config" echo " -c <dir> enable coverage for this dir (only valid without -K)" - echo " -j <num> j option to make" - echo " -K don't rebuild kernel" echo ktest_usage_post } @@ -65,23 +47,11 @@ fi CMD="$1" shift -while getopts "k:b:o:KDc:j:h${ktest_args}" arg; do +while getopts "k:c:h${ktest_args}" arg; do case $arg in k) ktest_kernel_source="$OPTARG" ;; - b) - ktest_kernel_build="$OPTARG" - ;; - o) - ktest_kernel_binary="$OPTARG" - ;; - K) - BUILD="" - ;; - D) - DEPS="" - ;; c) if [[ ! -d $OPTARG ]]; then echo "$OPTARG must be a directory" @@ -95,10 +65,6 @@ while getopts "k:b:o:KDc:j:h${ktest_args}" arg; do MAKEARGS+=("GCOV_PROFILE_$OPTARG=y") COVERAGE=1 ;; - j) - ktest_njobs=$OPTARG - ;; - h) usage exit 0 @@ -108,10 +74,10 @@ while getopts "k:b:o:KDc:j:h${ktest_args}" arg; do done shift $(( OPTIND - 1 )) +parse_args_post + # default parameters [[ -z $ktest_kernel_source ]] && ktest_kernel_source="." -[[ -z $ktest_kernel_build ]] && ktest_kernel_build="$ktest_kernel_source/.build_test_kernel-$ktest_arch" -[[ -z $ktest_kernel_binary ]] && ktest_kernel_binary="$ktest_kernel_build/kpgk" if [[ ! -d $ktest_kernel_source ]]; then echo "kernel source directory $ktest_kernel_source does not exist" @@ -120,13 +86,9 @@ fi ktest_kernel_source=$(readlink -e "$ktest_kernel_source") +ktest_kernel_build="$ktest_out/kernel_build.$ktest_arch" mkdir -p "$ktest_kernel_build" -ktest_kernel_build=$(readlink -e "$ktest_kernel_build") -ktest_kernel_binary=$(readlink -f "$ktest_kernel_binary") - -parse_args_post - if [[ -n $CROSS_COMPILE ]]; then checkdep "$ARCH_TRIPLE-gcc" "gcc-$ARCH_TRIPLE" fi @@ -136,7 +98,7 @@ run_ktest() arg=$1 shift - "$KTEST" "$arg" $KTESTARGS -k "$ktest_kernel_binary" "$@" + "$KTEST" "$arg" $KTESTARGS "$@" } do_make() @@ -146,12 +108,7 @@ do_make() export CROSS_COMPILE="$ARCH_TRIPLE-" fi - # work around a bug in make - maybe not needed anymore? -# if [[ $# = 0 || $1 != nconfig ]]; then -# MAKEARGS+=("--output-sync=target") -# fi - - make --jobs="$ktest_njobs" \ + make -j \ --directory="$ktest_kernel_source" \ O="$ktest_kernel_build" \ INSTALL_MOD_PATH="$ktest_kernel_binary" \ @@ -224,19 +181,17 @@ build_kernel() mkdir -p "$ktest_kernel_binary" touch "$magic" - if [[ -n $DEPS ]]; then - new_config + new_config - for opt in "${ktest_kernel_config_require[@]}"; do - [[ -n $opt ]] && kernel_opt set "$opt" - done + for opt in "${ktest_kernel_config_require[@]}"; do + [[ -n $opt ]] && kernel_opt set "$opt" + done - do_make olddefconfig + do_make olddefconfig - for opt in "${ktest_kernel_config_require[@]}"; do - [[ -n $opt ]] && kernel_opt check "$opt" - done - fi + for opt in "${ktest_kernel_config_require[@]}"; do + [[ -n $opt ]] && kernel_opt check "$opt" + done case $KERNEL_ARCH in mips) @@ -286,9 +241,7 @@ cmd_run() ktest_kernel_config_require+=(GCOV_KERNEL) fi - if [[ -n $BUILD ]]; then - run_quiet "building kernel" build_kernel - fi + run_quiet "building kernel" build_kernel start_vm } @@ -26,7 +26,6 @@ usage() ktest_usage_opts echo echo " options for ktest run:" - echo " -k <dir> kernel to run" ktest_usage_run_opts echo ktest_usage_post @@ -67,11 +66,8 @@ else exit 1 fi -while getopts "k:h${ktest_args}" arg; do +while getopts "h${ktest_args}" arg; do case $arg in - k) - ktest_kernel_binary=$OPTARG - ;; h) usage exit 0 diff --git a/lib/libktest.sh b/lib/libktest.sh index f5171ee..43e0349 100644 --- a/lib/libktest.sh +++ b/lib/libktest.sh @@ -11,9 +11,7 @@ ktest_root_image="" # virtual machine root filesystem # set with: -i <path> # defaults: /var/lib/ktest/root # auto-override: $HOME/.ktest/root -ktest_kernel_binary="" # dir that has the kernel to run - # set with: -k <path> -ktest_out="./ktest_out" # dir for test output (logs, code coverage, etc.) +ktest_out="./ktest-out" # dir for test output (logs, code coverage, etc.) ktest_priority=0 # hint for how long test should run ktest_interactive=0 # if set to 1, timeout is ignored completely @@ -41,23 +39,15 @@ checkdep qemu-system-x86_64 qemu-system-x86 # defaults: [[ -f $HOME/.ktestrc ]] && . "$HOME/.ktestrc" -[[ -f $HOME/.ktest/root ]] && ktest_root_image="$HOME/.ktest/root" # args: -ktest_args="i:s:a:p:ISFLvxn:N:" +ktest_args="a:p:ISFLvxn:N:" parse_ktest_arg() { local arg=$1 case $arg in - i) - ktest_root_image=$OPTARG - ;; - s) - ktest_tmp=$OPTARG - ktest_no_cleanup_tmpdir=1 - ;; a) ktest_arch=$OPTARG ;; @@ -98,10 +88,19 @@ parse_args_post() checkdep $QEMU_BIN $QEMU_PACKAGE if [[ -z $ktest_root_image ]]; then - ktest_root_image=/var/lib/ktest/root.$DEBIAN_ARCH + if [[ -f $HOME/.ktest/root.$DEBIAN_ARCH ]]; then + ktest_root_image="$HOME/.ktest/root.DEBIAN_ARCH" + elif [[ -f /var/lib/ktest/root.$DEBIAN_ARCH ]]; then + ktest_root_image=/var/lib/ktest/root.$DEBIAN_ARCH + else + echo "Root image not found in $HOME/.ktest or /var/lib/ktest" + echo "Use $ktest_dir/root_image create" + exit 1 + fi fi ktest_out=$(readlink -f "$ktest_out") + ktest_kernel_binary="$ktest_out/kernel.$ktest_arch" if [[ $ktest_interactive = 1 ]]; then ktest_kgdb=1 @@ -116,6 +115,9 @@ parse_args_post() ktest_usage_opts() { + echo " -a <arch> architecture" + echo " -o <dir> output directory; defaults to ./ktest-out" + echo " -n (user|vde) Networking type to use" echo " -x bash debug statements" echo " -h display this help and exit" } @@ -123,16 +125,11 @@ ktest_usage_opts() ktest_usage_run_opts() { echo " -p <num> hint for test duration (higher is longer, default is 0)" - echo " -a <arch> architecture" - echo " -i <image> ktest root image" - echo " -s <dir> directory for scratch drives" - echo " -o <dir> test output directory; defaults to ktest-out" echo " -I interactive mode - don't shut down VM automatically" echo " -S exit on test success" echo " -F failfast - stop after first test failure" echo " -L run all tests in infinite loop until failure" echo " -v verbose mode" - echo " -n (user|vde) Networking type to use" echo " -N <val> Nice value for kernel build and VM" } @@ -295,7 +292,7 @@ start_vm() kernelargs+=(console=hvc0) kernelargs+=(root=/dev/sda rw log_buf_len=8M) kernelargs+=("ktest.dir=$ktest_dir") - kernelargs+=("ktest.env=$ktest_tmp/env") + kernelargs+=(ktest.env=$(readlink -f "$ktest_out/vm/env")) [[ $ktest_kgdb = 1 ]] && kernelargs+=(kgdboc=ttyS0,115200 nokaslr) [[ $ktest_verbose = 0 ]] && kernelargs+=(quiet systemd.show_status=0 systemd.log-target=journal) [[ $ktest_crashdump = 1 ]] && kernelargs+=(crashkernel=128M) @@ -324,30 +321,34 @@ start_vm() -device virtio-serial \ -chardev stdio,id=console \ -device virtconsole,chardev=console \ - -serial "unix:$ktest_tmp/vm-kgdb,server,nowait" \ - -monitor "unix:$ktest_tmp/vm-mon,server,nowait" \ - -gdb "unix:$ktest_tmp/vm-gdb,server,nowait" \ + -serial "unix:$ktest_out/vm/kgdb,server,nowait" \ + -monitor "unix:$ktest_out/vm/mon,server,nowait" \ + -gdb "unix:$ktest_out/vm/gdb,server,nowait" \ -device virtio-rng-pci \ -virtfs local,path=/,mount_tag=host,security_model=none \ -device $ktest_storage_bus,id=hba \ ) + if [[ -f $ktest_kernel_binary/initramfs ]]; then + qemu_cmd+=(-initrd "$ktest_kernel_binary/initramfs") + fi + case $ktest_networking in user) ktest_ssh_port=$(get_unused_port) - echo $ktest_ssh_port > "$ktest_tmp/ssh_port" + echo $ktest_ssh_port > "$ktest_out/vm/ssh_port" qemu_cmd+=( \ -nic user,model=virtio,hostfwd=tcp:127.0.0.1:$ktest_ssh_port-:22 \ ) ;; vde) - local net="$ktest_tmp/net" + local net="$ktest_out/vm/net" checkdep vde_switch vde2 - [[ ! -p "$ktest_tmp/vde_input" ]] && mkfifo "$ktest_tmp/vde_input" - tail -f "$ktest_tmp/vde_input" |vde_switch -sock "$net" >& /dev/null & + [[ ! -p "$ktest_out/vm/vde_input" ]] && mkfifo "$ktest_out/vm/vde_input" + tail -f "$ktest_out/vm/vde_input" |vde_switch -sock "$net" >& /dev/null & while [[ ! -e "$net" ]]; do sleep 0.1 @@ -355,7 +356,7 @@ start_vm() slirpvde --sock "$net" --dhcp=10.0.2.2 --host 10.0.2.1/24 >& /dev/null & qemu_cmd+=( \ -net nic,model=virtio,macaddr=de:ad:be:ef:00:00 \ - -net vde,sock="$ktest_tmp/net" \ + -net vde,sock="$ktest_out/vm/net" \ ) ;; *) @@ -393,7 +394,7 @@ start_vm() done for size in "${ktest_scratch_devs[@]}"; do - local file="$ktest_tmp/dev-$disknr" + local file="$ktest_out/vm/dev-$disknr" truncate -s "$size" "$file" @@ -401,21 +402,21 @@ start_vm() done for size in "${ktest_pmem_devs[@]}"; do - local file="$ktest_tmp/dev-$disknr" + local file="$ktest_out/vm/dev-$disknr" fallocate -l "$size" "$file" qemu_pmem mem-path="$file",size=$size done - set |grep -v "^PATH=" > "$ktest_tmp/env_tmp" + set |grep -v "^PATH=" > "$ktest_out/vm/env_tmp" readonly_variables="$(readonly | cut -d= -f1 | cut -d' ' -f3)" for variable in ${readonly_variables} do - grep -v "${variable}" "$ktest_tmp/env_tmp" > "$ktest_tmp/env" - cp "$ktest_tmp/env" "$ktest_tmp/env_tmp" + grep -v "${variable}" "$ktest_out/vm/env_tmp" > "$ktest_out/vm/env" + cp "$ktest_out/vm/env" "$ktest_out/vm/env_tmp" done - sed -i "s/^ ;$//g" "$ktest_tmp/env" - rm -rf "$ktest_tmp/env_tmp" + sed -i "s/^ ;$//g" "$ktest_out/vm/env" + rm -rf "$ktest_out/vm/env_tmp" set +o errexit set -o pipefail diff --git a/lib/testrunner b/lib/testrunner index f9012a2..c64a617 100755 --- a/lib/testrunner +++ b/lib/testrunner @@ -266,12 +266,16 @@ cd /root set +e ret=0 +iterations=0 while [[ $ret = 0 ]]; do run_tests $tests ret=$? pkill -P $$ >/dev/null || true [[ $ret != 0 ]] && break [[ $ktest_loop = 1 ]] || break + + iterations=$((iterations + 1)) + echo "SUCCESSFUL ITERATIONS $iterations" done copy_to_host |