0681e5d29d55635dbec1f1ca5c69bf545ffbb077
[xfstests-dev.git] / tools / mkgroupfile
1 #!/bin/bash
2
3 # Generate a group file from the _begin_fstest call in each test.
4
5 if [ "$1" = "--help" ]; then
6         echo "Usage: (cd tests/XXX/ ; ../../tools/mkgroupfile [output])"
7         exit 1
8 fi
9
10 test_dir="$PWD"
11 groupfile="$1"
12
13 if [ ! -x ../../check ]; then
14         echo "$0: Run this from tests/XXX/."
15         exit 1
16 fi
17
18 generate_groupfile() {
19         cat << ENDL
20 # QA groups control file, automatically generated.
21 # See _begin_fstest in each test for details.
22
23 ENDL
24         cd ../../
25         export GENERATE_GROUPS=yes
26         grep -R -l "^_begin_fstest" "$test_dir/" 2>/dev/null | while read testfile; do
27                 test -x "$testfile" && "$testfile"
28         done | sort -g
29         cd "$test_dir"
30 }
31
32 if [ -z "$groupfile" ] || [ "$groupfile" = "-" ]; then
33         # Dump the group file to stdout and exit
34         generate_groupfile
35         exit 0
36 fi
37
38 # Otherwise, write the group file to disk somewhere.
39 ngroupfile="${groupfile}.new"
40 rm -f "$ngroupfile"
41 generate_groupfile >> "$ngroupfile"
42 mv "$ngroupfile" "$groupfile"