File: sanitizer.sh

package info (click to toggle)
libreswan 5.2-2.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 81,632 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (186 lines) | stat: -rwxr-xr-x 3,913 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
set -eu

utilsdir=$(dirname $(readlink -f $0))
testingdir=$(dirname $utilsdir)
fixupdir=$testingdir/sanitizers

# cleanup the given console output

if test $# -lt 1; then
    cat <<EOF 1>&2
Usage:

    $0 <all.console.verbose.txt> [ <test-directory> [ <fixup-directory> ... ] ]

Sanitizes the file <all.console.verbose.txt> using fixup scripts
specified by testparams.sh (or default-testparams.sh).  The result is
written to STDOUT.

<test-directory>

	The directory containing testparams.sh

	Only required when when the unsanitized file
	<all.console.verbose.txt> is not under OUTPUT/ in the build
	tree.

	By default, the test under directory:
		${testingdir}
	from this source tree is used.

<fixup.directory> ...

	A list of directories containing the fixup scripts.

	By default, the directory:
		${fixupdir}
	from this source tree is used.

EOF
    exit 1
fi


# *.console.verbose.txt

if test "x$1" = "x-"; then
    input=- ; shift
else
    input=$(readlink -f $1) ; shift
    if test ! -r "$input"; then
	echo "unsanitized file not found: $input" 1>&2
	exit 1
    fi
    case "$input" in
	*.console.verbose.txt )
	    :
	    ;;
	* )
	    echo "expecting an unsanitized .console.verbose.txt file: $input" 1>&2
	    exit 1
	    ;;
    esac
fi

# <test-directory>

if test $# -gt 0; then
    testdir=$(readlink -f $1) ; shift
elif test "x$input" != "x-" ; then
    testdir=$(dirname $(dirname $input))
else
    echo "No <test-directory> specified (and console is '-')" 1>&2
    exit 1
fi


# <fixups-dir> ...
if test $# -gt 0; then
    fixupdirs="$@"
else
    fixupdirs="${fixupdir}"
fi


# Load REF_CONSOLE_FIXUPS et.al.
if [ -f $testdir/testparams.sh ]; then
    # testparams.sh expects to be sourced from its directory,
    # expecting to be able to include the relative pathed
    # ../../default-testparams.sh
    pushd $testdir > /dev/null
    . ./testparams.sh
    popd > /dev/null
else
    . $testingdir/default-testparams.sh
fi


# The per-host fixup.  Get hostname from the INPUT file name,
# stripping of what is probably .console.verbose.txt
host_fixups=$(basename ${input} | sed -e 's;\..*;;' | tr '[a-z]' '[A-Z]')_CONSOLE_FIXUPS
REF_CONSOLE_FIXUPS=${!host_fixups:-${REF_CONSOLE_FIXUPS}}

if test -z "$REF_CONSOLE_FIXUPS"; then
    echo "\$REF_CONSOLE_FIXUPS empty" 1>&2
    exit 1
fi


cleanups=
sedups=
cleanup=

find_cleanup()
{
    local fixup=$1
    # Parameter list contains fixup directories; find the one
    # containing the sanitizer script ${fixup}
    cleanup=
    for fixupdir in "${fixupdirs}" ; do
	if test -f ${fixupdir}/${fixup} ; then
	    cleanup=$(realpath --relative-to=$PWD ${fixupdir}/${fixup})
	    return
	fi
    done
    echo "fixup '${fixup}' not found in $@" 1>&2
    exit 1
}

cleanup() {
    local fixup=$1 ; shift
    local op="$*" ; shift
    find_cleanup ${fixup}
    if test -z "${cleanups}" -a -z "${sedups}" ; then
	cleanups="${op} < ${input} -f ${cleanup}"
    else
	cleanups="${cleanups}${sedups} | ${op} -f ${cleanup}"
	sedups=
    fi
}

sedup() {
    local fixup=$(basename $1 .sed-f).sed ; shift
    find_cleanup ${fixup}
    if test -z "${cleanups}" -a -z "${sedups}" ; then
	sedups="sed < ${input} -f ${cleanup}"
    elif test -z "${sedups}" ; then
	sedups=" | sed -f ${cleanup}"
    else
	sedups="${sedups} -f ${cleanup}"
    fi
}

for fixup in ${REF_CONSOLE_FIXUPS}; do
    # now add the fixup to the pipeline
    case $fixup in
	*.sed-n) # -n sanitizers suppress output
	    cleanup ${fixup} sed -n
	    ;;
	*.sed)
	    cleanup ${fixup} sed
	    ;;
	*.awk)
	    cleanup ${fixup} awk
	    ;;
	*.sed-f) # -f sanitizers can be merged
	    sedup ${fixup}
	    ;;
	*)
	    echo "unknown fixup type: $fixup" 1>&2
	    exit 1
	    ;;
    esac
done

# close
cleanups="${cleanups}${sedups}"
# echo "${cleanups}" 1>&2

eval $cleanups
status=$?

# The "known-good" output contains an extra trailing blank line so add
# one here.
echo
exit $status