xref: /freebsd/sys/contrib/openzfs/.github/workflows/scripts/qemu-6-tests.sh (revision acd546f01e58354af049455472980c6c4a52e18b)
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
8######################################################################
9
10set -eu
11
12function prefix() {
13  ID="$1"
14  LINE="$2"
15  CURRENT=$(date +%s)
16  TSSTART=$(cat /tmp/tsstart)
17  DIFF=$((CURRENT-TSSTART))
18  H=$((DIFF/3600))
19  DIFF=$((DIFF-(H*3600)))
20  M=$((DIFF/60))
21  S=$((DIFF-(M*60)))
22
23  CTR=$(cat /tmp/ctr)
24  echo $LINE| grep -q '^\[.*] Test[: ]' && CTR=$((CTR+1)) && echo $CTR > /tmp/ctr
25
26  BASE="$HOME/work/zfs/zfs"
27  COLOR="$BASE/scripts/zfs-tests-color.sh"
28  CLINE=$(echo $LINE| grep '^\[.*] Test[: ]' \
29    | sed -e 's|^\[.*] Test|Test|g' \
30    | sed -e 's|/usr/local|/usr|g' \
31    | sed -e 's| /usr/share/zfs/zfs-tests/tests/| |g' | $COLOR)
32  if [ -z "$CLINE" ]; then
33    printf "vm${ID}: %s\n" "$LINE"
34  else
35    # [vm2: 00:15:54  256] Test: functional/checksum/setup (run as root) [00:00] [PASS]
36    printf "[vm${ID}: %02d:%02d:%02d %4d] %s\n" \
37      "$H" "$M" "$S" "$CTR" "$CLINE"
38  fi
39}
40
41# called directly on the runner
42if [ -z ${1:-} ]; then
43  cd "/var/tmp"
44  source env.txt
45  SSH=$(which ssh)
46  TESTS='$HOME/zfs/.github/workflows/scripts/qemu-6-tests.sh'
47  echo 0 > /tmp/ctr
48  date "+%s" > /tmp/tsstart
49
50  for ((i=1; i<=VMs; i++)); do
51    IP="192.168.122.1$i"
52    daemonize -c /var/tmp -p vm${i}.pid -o vm${i}log.txt -- \
53      $SSH zfs@$IP $TESTS $OS $i $VMs $CI_TYPE
54    # handly line by line and add info prefix
55    stdbuf -oL tail -fq vm${i}log.txt \
56      | while read -r line; do prefix "$i" "$line"; done &
57    echo $! > vm${i}log.pid
58    # don't mix up the initial --- Configuration --- part
59    sleep 0.13
60  done
61
62  # wait for all vm's to finish
63  for ((i=1; i<=VMs; i++)); do
64    tail --pid=$(cat vm${i}.pid) -f /dev/null
65    pid=$(cat vm${i}log.pid)
66    rm -f vm${i}log.pid
67    kill $pid
68  done
69
70  exit 0
71fi
72
73# this part runs inside qemu vm
74export PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin"
75case "$1" in
76  freebsd*)
77    TDIR="/usr/local/share/zfs"
78    sudo kldstat -n zfs 2>/dev/null && sudo kldunload zfs
79    sudo -E ./zfs/scripts/zfs.sh
80    sudo mv -f /var/tmp/*.txt /tmp
81    sudo newfs -U -t -L tmp /dev/vtbd1 >/dev/null
82    sudo mount -o noatime /dev/vtbd1 /var/tmp
83    sudo chmod 1777 /var/tmp
84    sudo mv -f /tmp/*.txt /var/tmp
85    ;;
86  *)
87    # use xfs @ /var/tmp for all distros
88    TDIR="/usr/share/zfs"
89    sudo -E modprobe zfs
90    sudo mv -f /var/tmp/*.txt /tmp
91    sudo mkfs.xfs -fq /dev/vdb
92    sudo mount -o noatime /dev/vdb /var/tmp
93    sudo chmod 1777 /var/tmp
94    sudo mv -f /tmp/*.txt /var/tmp
95    ;;
96esac
97
98# enable io_uring on el9/el10
99case "$1" in
100  almalinux9|almalinux10|centos-stream*)
101    sudo sysctl kernel.io_uring_disabled=0 > /dev/null
102    ;;
103esac
104
105# run functional testings and save exitcode
106cd /var/tmp
107TAGS=$2/$3
108if [ "$4" == "quick" ]; then
109  export RUNFILES="sanity.run"
110fi
111sudo dmesg -c > dmesg-prerun.txt
112mount > mount.txt
113df -h > df-prerun.txt
114$TDIR/zfs-tests.sh -vK -s 3GB -T $TAGS
115RV=$?
116df -h > df-postrun.txt
117echo $RV > tests-exitcode.txt
118sync
119exit 0
120