Debian Codegraph @

libstdc++-v3/testsuite/experimental/simd/generate_makefile.sh

raw
1 #!/bin/sh
2
3 srcdir="$(cd "${0%/*}" && pwd)"
4 driver="$srcdir/driver.sh"
5 srcdir="$srcdir/tests"
6 sim=
7 rm_logs=true
8 dst=.
9 testflags=
10
11 usage() {
12 cat <<EOF
13 Usage: $0 [Options] <g++ invocation>
14
15 Options:
16 -h, --help Print this message and exit.
17 --srcdir <path> The source directory of the tests (default: $srcdir).
18 --sim <executable> Path to an executable that is prepended to the test
19 execution binary (default: none).
20 --keep-intermediate-logs
21 Keep intermediate logs.
22 --testflags <flags> Force initial TESTFLAGS contents.
23 -d <path>, --destination <path>
24 Destination for the generated Makefile. If the directory
25 does not exist it is created (default: $dst).
26 EOF
27 }
28
29 while [ $# -gt 0 ]; do
30 case "$1" in
31 -h|--help)
32 usage
33 exit
34 ;;
35 --testflags)
36 testflags="$2"
37 shift
38 ;;
39 --testflags=*)
40 testflags="${1#--testflags=}"
41 ;;
42 -d|--destination)
43 dst="$2"
44 shift
45 ;;
46 --destination=*)
47 dst="${1#--destination=}"
48 ;;
49 --keep-intermediate-logs)
50 rm_logs=false
51 ;;
52 --srcdir)
53 srcdir="$2"
54 shift
55 ;;
56 --srcdir=*)
57 srcdir="${1#--srcdir=}"
58 ;;
59 --sim)
60 sim="$2"
61 shift
62 ;;
63 --sim=*)
64 sim="${1#--sim=}"
65 ;;
66 --)
67 shift
68 break
69 ;;
70 *)
71 break
72 ;;
73 esac
74 shift
75 done
76
77 mkdir -p "$dst"
78 pch="$dst/pch.h"
79 dst="$dst/Makefile"
80 if [ -f "$dst" ]; then
81 echo "Error: $dst already exists. Aborting." 1>&2
82 exit 1
83 fi
84
85 CXX="$1"
86 shift
87
88 cat >> "$pch" <<EOF
89 #ifndef SIMD_PCH_
90 #define SIMD_PCH_
91 #include "${srcdir}/bits/verify.h"
92 #include "${srcdir}/bits/make_vec.h"
93 #include "${srcdir}/bits/mathreference.h"
94 #include "${srcdir}/bits/metahelpers.h"
95 #include "${srcdir}/bits/simd_view.h"
96 #include "${srcdir}/bits/test_values.h"
97 #include "${srcdir}/bits/ulp.h"
98 #include "${srcdir}/bits/conversions.h"
99 #endif // SIMD_PCH_
100 EOF
101
102 echo "TESTFLAGS ?=" > "$dst"
103 echo "test_flags := $testflags \$(TESTFLAGS)" >> "$dst"
104 echo CXXFLAGS = "$@" -include pch.h "\$(test_flags)" >> "$dst"
105 [ -n "$sim" ] && echo "export GCC_TEST_SIMULATOR = $sim" >> "$dst"
106 cat >> "$dst" <<EOF
107 srcdir = ${srcdir}
108 CXX = ${CXX}
109 DRIVER = ${driver}
110 DRIVEROPTS ?=
111 driveroptions := \$(DRIVEROPTS)
112 PCH_DEPS := \$(shell \$(CXX) \$(CXXFLAGS) -M pch.h | sed -e 's/^.*://' -e 's/\\\\//g')
113
114 all: simd_testsuite.sum
115
116 pch.h.gch: \$(PCH_DEPS)
117 @echo "Preparing pre-compiled header"
118 @\$(CXX) \$(CXXFLAGS) -c \$< -o \$@
119
120 simd_testsuite.sum: .progress .progress_total simd_testsuite.log
121 @printf "\n\t\t=== simd_testsuite \$(test_flags) Summary ===\n\n"\\
122 "# of expected passes:\t\t\$(shell grep -c '^PASS:' \$@)\n"\\
123 "# of unexpected passes:\t\t\$(shell grep -c '^XPASS:' \$@)\n"\\
124 "# of unexpected failures:\t\$(shell grep -c '^FAIL:' \$@)\n"\\
125 "# of expected failures:\t\t\$(shell grep -c '^XFAIL:' \$@)\n"\\
126 "# of unsupported tests:\t\t\$(shell grep -c '^UNSUPPORTED:' \$@)\n"\\
127 | tee -a \$@
128
129 EOF
130
131 matches() {
132 eval "case '$1' in
133 $2) return 0;; esac"
134 return 1
135 }
136
137 cxx_type() {
138 case "$1" in
139 ldouble) echo "long double";;
140 ullong) echo "unsigned long long";;
141 ulong) echo "unsigned long";;
142 llong) echo "long long";;
143 uint) echo "unsigned int";;
144 ushort) echo "unsigned short";;
145 uchar) echo "unsigned char";;
146 schar) echo "signed char";;
147 *) echo "$1";;
148 esac
149 }
150
151 filter_types() {
152 only="$1"
153 skip="$2"
154 shift 2
155 if [ -z "$only" -a -z "$skip" ]; then
156 for x in "$@"; do
157 cxx_type "$x"
158 echo "$x"
159 done
160 elif [ -z "$skip" ]; then
161 for x in "$@"; do
162 if matches "$x" "$only"; then
163 cxx_type "$x"
164 echo "$x"
165 fi
166 done
167 elif [ -z "$only" ]; then
168 for x in "$@"; do
169 matches "$x" "$skip" && continue
170 cxx_type "$x"
171 echo "$x"
172 done
173 else
174 for x in "$@"; do
175 matches "$x" "$skip" && continue
176 if matches "$x" "$only"; then
177 cxx_type "$x"
178 echo "$x"
179 fi
180 done
181 fi
182 }
183
184 all_types() {
185 src="$1"
186 only=
187 skip=
188 if [ -n "$src" ]; then
189 only="$(head -n25 "$src"| grep '^//\s*only: [^ ]* \* \* \*')"
190 only="${only#*: }"
191 only="${only%% *}"
192 skip="$(head -n25 "$src"| grep '^//\s*skip: [^ ]* \* \* \*')"
193 skip="${skip#*: }"
194 skip="${skip%% *}"
195 fi
196 filter_types "$only" "$skip" \
197 "ldouble" \
198 "double" \
199 "float" \
200 "llong" \
201 "ullong" \
202 "ulong" \
203 "long" \
204 "int" \
205 "uint" \
206 "short" \
207 "ushort" \
208 "char" \
209 "schar" \
210 "uchar" \
211 "char32_t" \
212 "char16_t" \
213 "wchar_t"
214 }
215
216 all_tests() {
217 if [ -f testsuite_files_simd ]; then
218 sed 's,^experimental/simd/tests/,,' testsuite_files_simd | while read file; do
219 echo "$srcdir/$file"
220 echo "${file%.cc}"
221 done
222 else
223 for file in ${srcdir}/*.cc; do
224 echo "$file"
225 name="${file%.cc}"
226 echo "${name##*/}"
227 done
228 fi
229 }
230
231 {
232 rmline=""
233 if $rm_logs; then
234 rmline="
235 @rm \$^ \$(^:log=sum)"
236 fi
237 echo -n "simd_testsuite.log:"
238 all_tests | while read file && read name; do
239 echo -n " $name.log"
240 done
241 cat <<EOF
242
243 @cat $^ > \$@
244 @cat \$(^:log=sum) > \$(@:log=sum)${rmline}
245
246 EOF
247 all_tests | while read file && read name; do
248 echo -n "$name.log:"
249 all_types "$file" | while read t && read type; do
250 echo -n " $name-$type.log"
251 done
252 cat <<EOF
253
254 @cat $^ > \$@
255 @cat \$(^:log=sum) > \$(@:log=sum)${rmline}
256
257 EOF
258 done
259 all_types | while read t && read type; do
260 cat <<EOF
261 %-$type.log: %-$type-0.log %-$type-1.log %-$type-2.log %-$type-3.log \
262 %-$type-4.log %-$type-5.log %-$type-6.log %-$type-7.log \
263 %-$type-8.log %-$type-9.log
264 @cat \$^ > \$@
265 @cat \$(^:log=sum) > \$(@:log=sum)${rmline}
266
267 EOF
268 for i in $(seq 0 9); do
269 cat <<EOF
270 %-$type-$i.log: pch.h.gch \$(srcdir)/%.cc
271 @\$(DRIVER) \$(driveroptions) -t "$t" -a $i -n \$* \$(CXX) \$(CXXFLAGS)
272
273 EOF
274 done
275 done
276 cat <<EOF
277 run-%: export GCC_TEST_RUN_EXPENSIVE=yes
278 run-%: driveroptions += -vv
279 run-%: %.log
280 @rm \$^ \$(^:log=sum)
281
282 help: .make_help.txt
283 @cat \$<
284
285 EOF
286 dsthelp="${dst%Makefile}.make_help.txt"
287 cat <<EOF > "$dsthelp"
288 use DRIVEROPTS=<options> to pass the following options:
289 -q, --quiet Disable same-line progress output (default if stdout is
290 not a tty).
291 -p, --percentage Add percentage to default same-line progress output.
292 -v, --verbose Print one line per test and minimal extra information on
293 failure.
294 -vv Print all compiler and test output.
295 -k, --keep-failed Keep executables of failed tests.
296 --sim <executable> Path to an executable that is prepended to the test
297 execution binary (default: the value of
298 GCC_TEST_SIMULATOR).
299 --timeout-factor <x>
300 Multiply the default timeout with x.
301 -x, --run-expensive Compile and run tests marked as expensive (default:
302 true if GCC_TEST_RUN_EXPENSIVE is set, false otherwise).
303 -o <pattern>, --only <pattern>
304 Compile and run only tests matching the given pattern.
305
306 use TESTFLAGS=<flags> to pass additional compiler flags
307
308 The following are some of the valid targets for this Makefile:
309 ... all
310 ... clean
311 ... help"
312 EOF
313 N=$(((0$(
314 all_tests | while read file && read name; do
315 all_types "$file" | printf " + %d" $(wc -l)
316 done) ) * 5))
317 all_tests | while read file && read name; do
318 echo "... run-${name}"
319 all_types "$file" | while read t && read type; do
320 echo "... run-${name}-${type}"
321 for i in $(seq 0 9); do
322 echo "... run-${name}-${type}-$i"
323 done
324 done
325 done >> "$dsthelp"
326 cat <<EOF
327
328 .progress:
329 @echo 0 > .progress
330
331 .progress_total:
332 @echo $N > .progress_total
333
334 clean:
335 rm -f -- *.sum *.log *.exe .progress .progress_total
336
337 .PHONY: all clean help .progress .progress_total
338
339 .PRECIOUS: %.log %.sum
340 EOF
341 } >> "$dst"
342