1#!/usr/bin/env bash 2 3###################################################################### 4# 6) load openzfs module and run the tests 5# 6# called on runner: qemu-6-tests.sh 7# called on qemu-vm: qemu-6-tests.sh $OS $2 $3 [--lustre|--builtin] [quick|default] 8# 9# --lustre: Test build lustre in addition to the normal tests 10# --builtin: Test build ZFS as a kernel built-in in addition to the normal tests 11###################################################################### 12 13set -eu 14 15function prefix() { 16 ID="$1" 17 LINE="$2" 18 CURRENT=$(date +%s) 19 TSSTART=$(cat /tmp/tsstart) 20 DIFF=$((CURRENT-TSSTART)) 21 H=$((DIFF/3600)) 22 DIFF=$((DIFF-(H*3600))) 23 M=$((DIFF/60)) 24 S=$((DIFF-(M*60))) 25 26 CTR=$(cat /tmp/ctr) 27 echo $LINE| grep -q '^\[.*] Test[: ]' && CTR=$((CTR+1)) && echo $CTR > /tmp/ctr 28 29 BASE="$HOME/work/zfs/zfs" 30 COLOR="$BASE/scripts/zfs-tests-color.sh" 31 CLINE=$(echo $LINE| grep '^\[.*] Test[: ]' \ 32 | sed -e 's|^\[.*] Test|Test|g' \ 33 | sed -e 's|/usr/local|/usr|g' \ 34 | sed -e 's| /usr/share/zfs/zfs-tests/tests/| |g' | $COLOR) 35 if [ -z "$CLINE" ]; then 36 printf "vm${ID}: %s\n" "$LINE" 37 else 38 # [vm2: 00:15:54 256] Test: functional/checksum/setup (run as root) [00:00] [PASS] 39 printf "[vm${ID}: %02d:%02d:%02d %4d] %s\n" \ 40 "$H" "$M" "$S" "$CTR" "$CLINE" 41 fi 42} 43 44function do_lustre_build() { 45 local rc=0 46 $HOME/zfs/.github/workflows/scripts/qemu-6-lustre-tests-vm.sh &> /var/tmp/lustre.txt || rc=$? 47 echo "$rc" > /var/tmp/lustre-exitcode.txt 48 if [ "$rc" != "0" ] ; then 49 echo "$rc" > /var/tmp/tests-exitcode.txt 50 fi 51} 52export -f do_lustre_build 53 54# Test build ZFS into the kernel directly 55function do_builtin_build() { 56 local rc=0 57 # Get currently full kernel version (like '6.18.8') 58 fullver=$(uname -r | grep -Eo '^[0-9]+\.[0-9]+\.[0-9]+') 59 60 # Get just the major ('6') 61 major=$(echo $fullver | grep -Eo '^[0-9]+') 62 ( 63 set -e 64 65 wget https://cdn.kernel.org/pub/linux/kernel/v${major}.x/linux-$fullver.tar.xz 66 tar -xf $HOME/linux-$fullver.tar.xz 67 cd $HOME/linux-$fullver 68 make tinyconfig 69 ./scripts/config --enable EFI_PARTITON 70 ./scripts/config --enable BLOCK 71 # BTRFS_FS is easiest config option to enable CONFIG_ZLIB_INFLATE|DEFLATE 72 ./scripts/config --enable BTRFS_FS 73 yes "" | make oldconfig 74 make prepare 75 76 cd $HOME/zfs 77 ./configure --with-linux=$HOME/linux-$fullver --enable-linux-builtin --enable-debug 78 ./copy-builtin $HOME/linux-$fullver 79 80 cd $HOME/linux-$fullver 81 ./scripts/config --enable ZFS 82 ./scripts/config --enable ZFS_DEBUG 83 yes "" | make oldconfig 84 make -j `nproc` 85 ) &> /var/tmp/builtin.txt || rc=$? 86 echo "$rc" > /var/tmp/builtin-exitcode.txt 87 if [ "$rc" != "0" ] ; then 88 echo "$rc" > /var/tmp/tests-exitcode.txt 89 fi 90} 91export -f do_builtin_build 92 93# called directly on the runner 94if [ -z ${1:-} ]; then 95 cd "/var/tmp" 96 source env.txt 97 SSH=$(which ssh) 98 TESTS='$HOME/zfs/.github/workflows/scripts/qemu-6-tests.sh' 99 echo 0 > /tmp/ctr 100 date "+%s" > /tmp/tsstart 101 102 for ((i=1; i<=VMs; i++)); do 103 IP="192.168.122.1$i" 104 105 # We do an additional test build of Lustre against ZFS if we're vm2 106 # on almalinux*. At the time of writing, the vm2 tests were 107 # completing roughly 15min before the vm1 tests, so it makes sense 108 # to have vm2 do the build. 109 # 110 # In addition, we do an additional test build of ZFS as a Linux 111 # kernel built-in on Fedora. Again, we do it on vm2 to exploit vm2's 112 # early finish time. 113 extra="" 114 if [[ "$OS" == almalinux* ]] && [[ "$i" == "2" ]] ; then 115 extra="--lustre" 116 elif [[ "$OS" == fedora* ]] && [[ "$i" == "2" ]] ; then 117 extra="--builtin" 118 fi 119 120 daemonize -c /var/tmp -p vm${i}.pid -o vm${i}log.txt -- \ 121 $SSH zfs@$IP $TESTS $OS $i $VMs $extra $CI_TYPE 122 # handly line by line and add info prefix 123 stdbuf -oL tail -fq vm${i}log.txt \ 124 | while read -r line; do prefix "$i" "$line"; done & 125 echo $! > vm${i}log.pid 126 # don't mix up the initial --- Configuration --- part 127 sleep 0.13 128 done 129 130 # wait for all vm's to finish 131 for ((i=1; i<=VMs; i++)); do 132 tail --pid=$(cat vm${i}.pid) -f /dev/null 133 pid=$(cat vm${i}log.pid) 134 rm -f vm${i}log.pid 135 kill $pid 136 done 137 138 exit 0 139fi 140 141 142############################################# 143# Everything from here on runs inside qemu vm 144############################################# 145 146# Process cmd line args 147OS="$1" 148shift 149NUM="$1" 150shift 151DEN="$1" 152shift 153 154BUILD_LUSTRE=0 155BUILD_BUILTIN=0 156if [ "$1" == "--lustre" ] ; then 157 BUILD_LUSTRE=1 158 shift 159elif [ "$1" == "--builtin" ] ; then 160 BUILD_BUILTIN=1 161 shift 162fi 163 164if [ "$1" == "quick" ] ; then 165 export RUNFILES="sanity.run" 166fi 167 168export PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin" 169case "$OS" in 170 freebsd*) 171 TDIR="/usr/local/share/zfs" 172 sudo kldstat -n zfs 2>/dev/null && sudo kldunload zfs 173 sudo -E ./zfs/scripts/zfs.sh 174 sudo mv -f /var/tmp/*.txt /tmp 175 sudo newfs -U -t -L tmp /dev/vtbd1 >/dev/null 176 sudo mount -o noatime /dev/vtbd1 /var/tmp 177 sudo chmod 1777 /var/tmp 178 sudo mv -f /tmp/*.txt /var/tmp 179 ;; 180 *) 181 # use xfs @ /var/tmp for all distros 182 TDIR="/usr/share/zfs" 183 sudo -E modprobe zfs 184 sudo mv -f /var/tmp/*.txt /tmp 185 sudo mkfs.xfs -fq /dev/vdb 186 sudo mount -o noatime /dev/vdb /var/tmp 187 sudo chmod 1777 /var/tmp 188 sudo mv -f /tmp/*.txt /var/tmp 189 190 # Allow for longer RCU timeouts due to the heavily virtualized and 191 # potentially oversubscribed nature of the CI environment. 192 rcu_cpu_stall_timeout="/sys/module/rcupdate/parameters/rcu_cpu_stall_timeout" 193 if test -f $rcu_cpu_stall_timeout; then 194 echo 120 | sudo sh -c "cat > '$rcu_cpu_stall_timeout'" 195 fi 196 ;; 197esac 198 199# Distribution-specific settings. 200case "$OS" in 201 almalinux9|almalinux10|centos-stream*) 202 # Enable io_uring on Enterprise Linux 9 and 10. 203 sudo sysctl kernel.io_uring_disabled=0 > /dev/null 204 ;; 205 alpine*) 206 # Ensure `/etc/zfs/zpool.cache` exists. 207 sudo mkdir -p /etc/zfs 208 sudo touch /etc/zfs/zpool.cache 209 sudo chmod 644 /etc/zfs/zpool.cache 210 ;; 211esac 212 213# Lustre calls a number of exported ZFS module symbols. To make sure we don't 214# change the symbols and break Lustre, do a quick Lustre build of the latest 215# released Lustre against ZFS. 216# 217# Note that we do the Lustre test build in parallel with ZTS. ZTS isn't very 218# CPU intensive, so we can use idle CPU cycles "guilt free" for the build. 219# The Lustre build on its own takes ~15min. 220if [ "$BUILD_LUSTRE" == "1" ] ; then 221 do_lustre_build & 222elif [ "$BUILD_BUILTIN" == "1" ] ; then 223 # Try building ZFS directly into the Linux kernel (not as a module) 224 do_builtin_build & 225fi 226 227# run functional testings and save exitcode 228cd /var/tmp 229TAGS=$NUM/$DEN 230sudo dmesg -c > dmesg-prerun.txt 231mount > mount.txt 232df -h > df-prerun.txt 233RV=0 234$TDIR/zfs-tests.sh -vKO -s 3GB -T $TAGS || RV=$? 235 236df -h > df-postrun.txt 237echo $RV > tests-exitcode.txt 238sync 239exit 0 240