From 76846ae7d4bb7744d7e86fd29d619ddfac6e5dd7 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 9 Dec 2021 14:13:00 -0500 Subject: [PATCH] Implement xfstests using zsh This includes our main xfstests.zsh file, and some support scripts for setting up and running tests on the client Signed-off-by: Anna Schumaker --- colors/xfstests.py | 55 ++++++++++++++++++++++++++++++++++ completions/_xfstests.zsh | 17 +++++++++++ install-scripts.zsh | 3 +- run-xfstests.zsh | 23 ++++++++++++++ setup-xfstests.zsh | 31 +++++++++++++++++++ xfstests.zsh | 63 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 colors/xfstests.py create mode 100644 completions/_xfstests.zsh create mode 100755 run-xfstests.zsh create mode 100755 setup-xfstests.zsh create mode 100755 xfstests.zsh diff --git a/colors/xfstests.py b/colors/xfstests.py new file mode 100644 index 0000000..d0d98b3 --- /dev/null +++ b/colors/xfstests.py @@ -0,0 +1,55 @@ +import sys +import re +import termcolor + +prefix = termcolor.colored("[", "white", attrs=["bold"]) +prefix += termcolor.colored(sys.argv[1].rjust(4), "red", attrs=["bold"]) +prefix += "," +prefix += termcolor.colored(f"v{sys.argv[2]}".ljust(4), "magenta") +prefix += termcolor.colored("] ", "white", attrs=["bold"]) + +#proto = sys.argv[1].rjust(4) +#vers = sys.argv[2].ljust(3) +def print_prefix(): + print(prefix, end="") + # termcolor.cprint("[", "white", attrs=["bold"], end="") + #termcolor.cprint(proto, "red", attrs=["bold"], end="") + #termcolor.cprint(",", "white", end="") + #termcolor.cprint(f"v{vers}", "magenta", end="") + #termcolor.cprint("] ", "white", attrs=["bold"], end="") + +text = "" +def print_text(color, attr=None): + global text + termcolor.cprint(text, color=color, attrs=[attr] if attr else None, end="") + text = "" + +def print_config(): + global text + key, val = re.split("--", text) + if key != "MKFS_OPTIONS " and val[:3] != " -o": + print_prefix() + termcolor.cprint(key, "cyan", attrs=["bold"], end="") + termcolor.cprint("--", "white", end="") + termcolor.cprint(val, "white", attrs=["bold"], end="") + text = "" + +while c := sys.stdin.read(1): + text += c + if re.match("^PLATFORM.*PREEMPT", text): + text += "\n" + print_config() + text = "COMPILED --" + elif re.match("^[A-Z_]+[ ]+-- .*?\n", text): + print_config() + elif re.match("[a-z]+/[\d]+[ ]", text): + print_prefix() + print_text("blue") + elif re.match("[ ]?[\d]+s", text): + print_text("green") + elif re.match(" ... ", text): + print_text("white") + elif re.match("\[not run\]", text): + print_text("yellow", "bold") + elif c == "\n": + print_text("white", "bold") diff --git a/completions/_xfstests.zsh b/completions/_xfstests.zsh new file mode 100644 index 0000000..4365652 --- /dev/null +++ b/completions/_xfstests.zsh @@ -0,0 +1,17 @@ +#compdef xfstests.zsh + +function _xfstests.zsh() { + _arguments \ + {-c,--client}'[the client to test]: : _alternative + "hosts\:hosts\: _ssh_hosts" + "domains\:domains\:($(virsh list --all --name))"' \ + {-k,--scratch}'[the exported scratch directory on the server]: : _files -/' \ + {-p,--mountpoint}'[the directory to mount the server]: : _files -/' \ + {-r,--rdma}'[test using rdma]: :(rxe siw)' \ + {-q,--scratchmnt}'[the directory to mount the scratch export]: : _files -/' \ + {-s,--server}'[the server to test against]: : _alternative + "hosts\:hosts\: _ssh_hosts" + "domains\:domains\:($(virsh list --all --name))"' \ + \*{-v,--version}+'[the nfs version to test (default=all)]: :(3 4.0 4.1 4.2)' \ + {-x,--export}'[the exported directory on the server]: : _files -/' +} diff --git a/install-scripts.zsh b/install-scripts.zsh index 10475d9..93e922e 100755 --- a/install-scripts.zsh +++ b/install-scripts.zsh @@ -1,7 +1,8 @@ #!/bin/zsh BIN=$HOME/bin -SCRIPTS=(grub-list.zsh setup-testdirs.zsh setup-cthon.zsh) +SCRIPTS=(grub-list.zsh setup-testdirs.zsh setup-cthon.zsh \ + setup-xfstests.zsh run-xfstests.zsh) function install_script() { ssh $1 mkdir -p bin/ diff --git a/run-xfstests.zsh b/run-xfstests.zsh new file mode 100755 index 0000000..d634cd4 --- /dev/null +++ b/run-xfstests.zsh @@ -0,0 +1,23 @@ +#!/bin/zsh + +zparseopts -D -K -server:=SERVER -opts:=OPTS -user:=USER \ + -export:=EXPORT -mountpoint:=MOUNTPOINT \ + -scratch:=SCRATCH -scratchmnt:=SCRATCHMNT + +cd /home/${USER[-1]}/xfstests-dev +export TEST_DEV=${SERVER[-1]}:${EXPORT[-1]}/${USER[-1]}/xfstests +export TEST_DIR=${MOUNTPOINT[-1]} +export SCRATCH_DEV=${SERVER[-1]}:${SCRATCH[-1]}/${USER[-1]}/xfstests +export SCRATCH_MNT=${SCRATCHMNT[-1]} +export NFS_MOUNT_OPTIONS="-o ${OPTS[-1]}" + +echo "TIME -- $(date)" +echo "TEST_DEV -- $TEST_DEV" +echo "TEST_DIR -- $TEST_DIR" +echo "SCRATCH_DEV -- $SCRATCH_DEV" +echo "SCRATCH_MNT -- $SCRATCH_MNT" +echo "MOUNT_OPTIONS -- ${OPTS[-1]}" +if [ ! -z "$*" ]; then + echo "XFSTESTS_ARGS -- $*" +fi +./check -nfs $* diff --git a/setup-xfstests.zsh b/setup-xfstests.zsh new file mode 100755 index 0000000..ab964ee --- /dev/null +++ b/setup-xfstests.zsh @@ -0,0 +1,31 @@ +#!/bin/zsh +SERVER=$1 +EXPORT=$2 +MOUNTPOINT=$3 +SCRATCH=$4 +SCRATCHMNT=$5 +USER=$6 + +if [ "$#" -ne 6 ]; then + echo "Usage: $0 {server} {export} {mountpoint} {scratch} {scratchmnt} {user}" + exit 1 +fi + +useradd -m fsgqa 2>/dev/null +groupadd fsgqa 2>/dev/null +useradd --badnames 123456-fsgqa 2>/dev/null +useradd fsgqa2 2>/dev/null + +TRAPEXIT() { + umount $MOUNTPOINT + umount $SCRATCHMNT +} + +mkdir -p $MOUNTPOINT +mkdir -p $SCRATCHMNT + +mount -o sec=sys $SERVER:$EXPORT $MOUNTPOINT +mount -o sec=sys $SERVER:$SCRATCH $SCRATCHMNT + +mkdir -p -m 777 $MOUNTPOINT/$USER/xfstests +mkdir -p -m 777 $SCRATCHMNT/$USER/xfstests diff --git a/xfstests.zsh b/xfstests.zsh new file mode 100755 index 0000000..b517c53 --- /dev/null +++ b/xfstests.zsh @@ -0,0 +1,63 @@ +#!/bin/zsh -e +CLIENT=(client) +SERVER=(server) +EXPORT=(/srv/test) +SCRATCH=(/srv/scratch) +MOUNTPOINT=(/mnt/test) +SCRATCHMNT=(/mnt/scratch) +VERSION=(3 4.0 4.1 4.2) +PROTO=(tcp) + +zparseopts -D -K \ + c:=CLIENT -client:=CLIENT \ + k:=SCRATCH -scratch:=SCRATCH \ + p:=MOUNTPOINT -mountpoint:=MOUNTPOINT \ + q:=SCRATCHMNT -scratchmnt:=SCRATCHMNT \ + r:=RDMA -rdma:=RDMA \ + s:=SERVER -server:=SERVER \ + x:=EXPORT -export:=EXPORT \ + v+:=VERSION -version+:=VERSION + +BIN=$HOME/bin +COLOR=$BIN/colors/xfstests.py +RUN_XFSTESTS="sudo run-xfstests.zsh" +USER=$(whoami) + +# +# Prepare to test +# +$BIN/vm.zsh boot ${CLIENT[-1]} ${SERVER[-1]} +$BIN/install-scripts.zsh ${CLIENT[-1]} +if [ ${#RDMA} -gt 0 ]; then + PROTO+=(rdma) + $BIN/rdma.zsh ${RDMA[-1]} ${CLIENT[-1]} ${SERVER[-1]} +fi + +ssh ${CLIENT[-1]} "sudo setup-xfstests.zsh ${SERVER[-1]} ${EXPORT[-1]} ${MOUNTPOINT[-1]} \ + ${SCRATCH[-1]} ${SCRATCHMNT[-1]} $USER" +echo + +testargs=() +for arg in $*; do + testargs+=($(printf '%q' "$arg")) +done + +# +# Run tests +# +for proto in $PROTO; do + for vers in $VERSION; do + case $vers in + "-v" | "--version") continue ;; + *) opts="$proto,vers=$vers" ;; + esac + + ssh ${CLIENT[-1]} "$RUN_XFSTESTS --server ${SERVER[-1]} \ + --export ${EXPORT[-1]} \ + --mountpoint ${MOUNTPOINT[-1]} \ + --scratch ${SCRATCH[-1]} \ + --scratchmnt ${SCRATCHMNT[-1]} \ + --opts $opts \ + --user $USER $testargs" | python -u $COLOR $proto $vers + done +done