| #!/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" |
| new_groups="/tmp/groups.$$" |
| GROUPNAME_DOC_FILE="$(readlink -m ../../doc/group-names.txt)" |
| |
| if [ ! -x ../../check ]; then |
| echo "$0: Run this from tests/XXX/." |
| exit 1 |
| fi |
| |
| . ../../common/test_names |
| |
| cleanup() |
| { |
| rm -f $new_groups.check |
| rm -f $new_groups |
| } |
| |
| ret=1 # trigger cleanup of temporary files unless we succeed |
| trap 'cleanup; exit $ret' EXIT INT TERM QUIT |
| |
| # Make sure each group is in the documentation file. |
| _check_groups() { |
| test -n "$GROUPNAME_DOC_FILE" || return 0 |
| |
| local groups="$1" |
| declare -a missing=() |
| |
| for group in `grep -v '#' $groups`; do |
| if ! grep -q "^${group}[[:space:]]" "$GROUPNAME_DOC_FILE"; then |
| missing+=("\"${group}\"") |
| fi |
| done |
| test "${#missing}" -eq 0 && return 0 |
| |
| local suffix= |
| test "${#missing}" -gt 1 && suffix="s" |
| echo "group$suffix ${missing[@]} not mentioned in documentation." 1>&2 |
| ret=1 |
| exit 1 |
| } |
| |
| generate_groupfile() { |
| cat << ENDL > $new_groups |
| # QA groups control file, automatically generated. |
| # See _begin_fstest in each test for details. |
| |
| ENDL |
| |
| cd ../../ |
| |
| # Aggregate the groups each test belongs to for the group file |
| grep -I -R "^_begin_fstest" $test_dir/ | \ |
| sed -e "s/^.*\/\($VALID_TEST_NAME\):_begin_fstest/\1/" | \ |
| sort -ug >> $new_groups |
| |
| # Create the list of unique groups for existence checking |
| grep -I -R "^_begin_fstest" $test_dir/ | \ |
| sed -e 's/^.*_begin_fstest //' -e 's/ /\n/g' | \ |
| sort -u > $new_groups.check |
| |
| _check_groups $new_groups.check |
| |
| cd "$test_dir" |
| } |
| |
| if [ -z "$groupfile" ] || [ "$groupfile" = "-" ]; then |
| # Dump the group file to stdout and exit |
| unset groupfile |
| generate_groupfile |
| cat $new_groups |
| else |
| # Otherwise, write the group file to disk somewhere. |
| generate_groupfile |
| mv -f "$new_groups" "$groupfile" |
| fi |
| |
| # Success! |
| ret=0 |