2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Oracle. All Rights Reserved.
5 # Move group tags from the groups file into the test files themselves.
7 if [ -z "$1" ] || [ "$1" = "--help" ]; then
8 echo "Usage: $0 test_dir [test_dirs...]"
12 obliterate_group_file() {
13 sed -e 's/^#.*$//g' < group | while read test groups; do
14 if [ -z "$test" ]; then
16 elif [ ! -e "$test" ]; then
17 echo "Ignoring unknown test file \"$test\"."
21 # Replace all the open-coded test preparation code with a
22 # single call to _begin_fstest.
23 sed -e '/^seqres=\$RESULT_DIR\/\$seq$/d' \
24 -e '/^seqres=\"\$RESULT_DIR\/\$seq\"$/d' \
25 -e '/^echo "QA output created by \$seq"$/d' \
26 -e '/^here=`pwd`$/d' \
27 -e '/^here=\$(pwd)$/d' \
28 -e '/^here=\$PWD$/d' \
29 -e '/^here=\"`pwd`\"$/d' \
30 -e '/^tmp=\/tmp\/\$\$$/d' \
31 -e '/^status=1.*failure.*is.*the.*default/d' \
32 -e '/^status=1.*FAILure.*is.*the.*default/d' \
33 -e '/^status=1.*success.*is.*the.*default/d' \
34 -e '/^status=1.*default.*failure/d' \
35 -e '/^echo.*QA output created by.*seq/d' \
36 -e '/^# remove previous \$seqres.full before test/d' \
37 -e '/^rm -f \$seqres.full/d' \
38 -e 's|^# get standard environment, filters and checks|# Import common functions.|g' \
39 -e '/^\. \.\/common\/rc/d' \
40 -e '/^\. common\/rc/d' \
41 -e 's|^seq=.*$|. ./common/preamble\n_begin_fstest '"$groups"'|g' \
44 # Replace the open-coded trap calls that register cleanup code
45 # with a call to _register_cleanup.
47 # For tests that registered empty-string cleanups or open-coded
48 # calls to remove $tmp files, remove the _register_cleanup
49 # calls entirely because the default _cleanup does that for us.
51 # For tests that now have a _register_cleanup call for the
52 # _cleanup function, remove the explicit call because
53 # _begin_fstest already registers that for us.
55 # For tests that override _cleanup, insert a comment noting
56 # that it is overriding the default, to match the ./new
58 sed -e 's|^trap "exit \\\$status" 0 1 2 3 15|_register_cleanup ""|g' \
59 -e 's|^trap "\(.*\)[[:space:]]*; exit \\\$status" 0 1 2 3 15|_register_cleanup "\1"|g' \
60 -e 's|^trap "\(.*\)[[:space:]]*; exit \\\$status" 1 2 3 15|_register_cleanup "\1"|g' \
61 -e 's|^trap '"'"'\(.*\)[[:space:]]*; exit \$status'"'"' 0 1 2 3 15|_register_cleanup "\1"|g' \
62 -e 's|^trap "\(.*\)[[:space:]]*; exit \\\$status" 0 1 2 3 7 15|_register_cleanup "\1" BUS|g' \
63 -e 's|^_register_cleanup "[[:space:]]*\([^[:space:]]*\)[[:space:]]*"|_register_cleanup "\1"|g' \
64 -e '/^_register_cleanup ""$/d' \
65 -e '/^_register_cleanup "rm -f \$tmp.*"$/d' \
66 -e '/^_register_cleanup "_cleanup"$/d' \
67 -e 's|^_cleanup()|# Override the default cleanup function.\n_cleanup()|g' \
70 # If the test doesn't import any common functionality,
71 # get rid of the pointless comment.
72 if ! grep -q '^\. .*common' "$test"; then
73 sed -e '/^# Import common functions.$/d' -i "$test"
76 # Replace the "status=1" lines that don't have the usual
77 # "failure is the default" message if there's no other code
78 # between _begin_fstest and status=1.
79 if grep -q '^status=1$' "$test"; then
85 if ($0 ~ /^_begin_fstest/) {
88 } else if ($0 ~ /^status=1$/) {
89 if (saw_groupinfo == 0) {
92 } else if ($0 == "") {
99 ' < "$test" > "$test.new"
100 cat "$test.new" > "$test"
104 # Get rid of _cleanup functions that match the standard one.
105 # Thanks to Eric Biggers for providing this.
107 -e 's/(#[^#\n]*\n)*_cleanup\(\)\n\{\n(\s+cd \/\n)?\s+rm -r?f "?\$tmp"?\.\*\n\}\n\n?//' \
108 -e 's/(#[^#\n]*\n)*_cleanup\(\)\n\{\n(\s+cd \/\n)?\s+rm -fr "?\$tmp"?\.\*\n\}\n\n?//' \
111 # Collapse sequences of blank lines to a single blank line.
118 if (saw_blank == 0) {
127 ' < "$test" > "$test.new"
128 cat "$test.new" > "$test"
136 obliterate_group_file