blob: 3844e57d334a34337ab64cfd200aead8c8f7e34c [file] [log] [blame]
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2021 Oracle. All Rights Reserved.
#
# Generate a group file from the _begin_fstest call in each test.
if [ "$1" = "--help" ]; then
echo "Usage: (cd tests/XXX/ ; ../../tools/mkgroupfile [output])"
exit 1
fi
test_dir="$PWD"
groupfile="$1"
GROUPNAME_DOC_FILE="$(readlink -m ../../doc/group-names.txt)"
export GROUPNAME_DOC_FILE
if [ ! -x ../../check ]; then
echo "$0: Run this from tests/XXX/."
exit 1
fi
cleanup() {
test -z "$groupfile" && return
test -z "$ngroupfile" && return
if [ $ret -eq 0 ]; then
mv -f "$ngroupfile" "$groupfile"
else
rm -f "$ngroupfile"
fi
}
ret=1 # trigger cleanup of temporary files unless we succeed
trap 'cleanup; exit $ret' EXIT INT TERM QUIT
generate_groupfile() {
cat << ENDL
# QA groups control file, automatically generated.
# See _begin_fstest in each test for details.
ENDL
cd ../../
export GENERATE_GROUPS=yes
grep -R -l "^_begin_fstest" "$test_dir/" 2>/dev/null | while read testfile; do
test -x "$testfile" && "$testfile" || return 1
done | sort -g
ret="${PIPESTATUS[1]}"
cd "$test_dir"
}
if [ -z "$groupfile" ] || [ "$groupfile" = "-" ]; then
# Dump the group file to stdout and exit
unset groupfile
generate_groupfile
else
# Otherwise, write the group file to disk somewhere.
ngroupfile="${groupfile}.new"
rm -f "$ngroupfile"
generate_groupfile >> "$ngroupfile"
# let cleanup rename or delete ngroupfile
fi