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