1#!/usr/bin/env bash
2
3# cryptest.sh - written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
4#               Copyright assigned to Crypto++ project.
5
6# This is a test script that can be used on some Linux/Unix/Apple machines to automate building the
7# library and running the self test with various combinations of flags, options, and conditions.
8# For more details, see http://cryptopp.com/wiki/cryptest.sh.
9
10# To run the script, simply perform the following:
11#     ./cryptest.sh
12
13# If you want to test a particular compiler, like clang++ or icpc, issue:
14#     CXX=clang++ ./cryptest.sh
15#     CXX=/opt/intel/bin/icpc ./cryptest.sh
16#     CXX=/opt/solstudio12.2/bin/CC ./cryptest.sh
17
18# The script ignores CXXFLAGS. You can add CXXFLAGS, like -mcpu or -mtune, through USER_CXXFLAGS:
19#     USER_CXXFLAGS=-Wall ./cryptest.sh
20#     USER_CXXFLAGS="-Wall -Wextra" ./cryptest.sh
21
22# The fastest results (in running time) will most likely omit Valgrind and Benchmarks because
23# significantly increase execution time:
24#     HAVE_VALGRIND=0 WANT_BENCHMARKS=0 ./cryptest.sh
25
26# Using 'fast' is shorthand for HAVE_VALGRIND=0 WANT_BENCHMARKS=0:
27#     ./cryptest.sh fast
28
29# You can reduce CPU load with the following. It will use half the number of CPU cores
30# rather than all of them. Its useful at places like the GCC Compile Farm, where being nice is policy.
31#     ./cryptest.sh nice
32
33############################################
34# Set to suite your taste
35
36if [[ (-z "$TEST_RESULTS") ]]; then
37	TEST_RESULTS=cryptest-result.txt
38fi
39if [[ (-z "$BENCHMARK_RESULTS") ]]; then
40	BENCHMARK_RESULTS=cryptest-bench.txt
41fi
42if [[ (-z "$WARN_RESULTS") ]]; then
43	WARN_RESULTS=cryptest-warn.txt
44fi
45if [[ (-z "$INSTALL_RESULTS") ]]; then
46	INSTALL_RESULTS=cryptest-install.txt
47fi
48
49# Remove previous test results
50rm -f "$TEST_RESULTS" > /dev/null 2>&1
51touch "$TEST_RESULTS"
52
53rm -f "$BENCHMARK_RESULTS" > /dev/null 2>&1
54touch "$BENCHMARK_RESULTS"
55
56rm -f "$WARN_RESULTS" > /dev/null 2>&1
57touch "$WARN_RESULTS"
58
59rm -f "$INSTALL_RESULTS" > /dev/null 2>&1
60touch "$INSTALL_RESULTS"
61
62# Avoid CRYPTOPP_DATA_DIR in this shell (it is tested below)
63unset CRYPTOPP_DATA_DIR
64
65# Avoid Malloc and Scribble guards on OS X (they are tested below)
66unset MallocScribble MallocPreScribble MallocGuardEdges
67
68############################################
69# Setup tools and platforms
70
71GREP=grep
72EGREP=egrep
73SED=sed
74AWK=awk
75
76# Code generation tests
77DISASS=objdump
78DISASSARGS=("--disassemble")
79
80THIS_SYSTEM=$(uname -s 2>&1)
81IS_DARWIN=$(echo -n "$THIS_SYSTEM" | "$GREP" -i -c darwin)
82IS_LINUX=$(echo -n "$THIS_SYSTEM" | "$GREP" -i -c linux)
83IS_CYGWIN=$(echo -n "$THIS_SYSTEM" | "$GREP" -i -c cygwin)
84IS_MINGW=$(echo -n "$THIS_SYSTEM" | "$GREP" -i -c mingw)
85IS_OPENBSD=$(echo -n "$THIS_SYSTEM" | "$GREP" -i -c openbsd)
86IS_FREEBSD=$(echo -n "$THIS_SYSTEM" | "$GREP" -i -c freebsd)
87IS_NETBSD=$(echo -n "$THIS_SYSTEM" | "$GREP" -i -c netbsd)
88IS_SOLARIS=$(echo -n "$THIS_SYSTEM" | "$GREP" -i -c sunos)
89
90THIS_MACHINE=$(uname -m 2>&1)
91IS_X86=$(echo -n "$THIS_MACHINE" | "$EGREP" -i -c "(i386|i486|i586|i686)")
92IS_X64=$(echo -n "$THIS_MACHINE" | "$EGREP" -i -c "(amd64|x86_64)")
93IS_PPC=$(echo -n "$THIS_MACHINE" | "$EGREP" -i -c "(Power|PPC)")
94IS_ARM32=$(echo -n "$THIS_MACHINE" | "$GREP" -v "64" | "$EGREP" -i -c "(arm|aarch32)")
95IS_ARM64=$(echo -n "$THIS_MACHINE" | "$EGREP" -i -c "(arm64|aarch64)")
96IS_S390=$(echo -n "$THIS_MACHINE" | "$EGREP" -i -c "s390")
97IS_X32=0
98
99# Fixup
100if [[ "$IS_SOLARIS" -ne "0" ]]; then
101	IS_X64=$(isainfo 2>/dev/null | "$GREP" -i -c "amd64")
102	if [[ "$IS_X64" -ne "0" ]]; then
103		IS_X86=0
104	fi
105
106	# Need something more powerful than the Posix versions
107	if [[ (-e "/usr/gnu/bin/grep") ]]; then
108		GREP=/usr/gnu/bin/grep;
109	fi
110	if [[ (-e "/usr/gnu/bin/egrep") ]]; then
111		EGREP=/usr/gnu/bin/egrep;
112	fi
113	if [[ (-e "/usr/gnu/bin/sed") ]]; then
114		SED=/usr/gnu/bin/sed;
115	fi
116	if [[ (-e "/usr/gnu/bin/awk") ]]; then
117		AWK=/usr/gnu/bin/awk;
118	else
119		AWK=nawk;
120	fi
121
122	DISASS=dis
123	DISASSARGS=()
124fi
125
126# Fixup
127if [[ "$IS_DARWIN" -ne 0 ]]; then
128	DISASS=otool
129	DISASSARGS=("-tV")
130fi
131
132# Fixup
133if [[ ("$IS_FREEBSD" -ne "0" || "$IS_OPENBSD" -ne "0" || "$IS_NETBSD" -ne "0") ]]; then
134	MAKE=gmake
135elif [[ ("$IS_SOLARIS" -ne "0") ]]; then
136	MAKE=$(which gmake 2>/dev/null | "$GREP" -v "no gmake" | head -1)
137	if [[ (-z "$MAKE") && (-e "/usr/sfw/bin/gmake") ]]; then
138		MAKE=/usr/sfw/bin/gmake
139	fi
140else
141	MAKE=make
142fi
143
144# CPU features and flags
145if [[ ("$IS_X86" -ne "0" || "$IS_X64" -ne "0") ]]; then
146	if [[ ("$IS_DARWIN" -ne "0") ]]; then
147		X86_CPU_FLAGS=$(sysctl machdep.cpu.features 2>&1 | cut -f 2 -d ':')
148	elif [[ ("$IS_SOLARIS" -ne "0") ]]; then
149		X86_CPU_FLAGS=$(isainfo -v 2>/dev/null)
150	elif [[ ("$IS_FREEBSD" -ne "0") ]]; then
151		X86_CPU_FLAGS=$(grep Features /var/run/dmesg.boot)
152	else
153		X86_CPU_FLAGS=$(cat /proc/cpuinfo 2>&1 | "$AWK" '{IGNORECASE=1}{if ($1 == "flags"){print;exit}}' | cut -f 2 -d ':')
154	fi
155elif [[ ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0") ]]; then
156	if [[ ("$IS_DARWIN" -ne "0") ]]; then
157		ARM_CPU_FLAGS=$(sysctl machdep.cpu.features 2>&1 | cut -f 2 -d ':')
158	else
159		ARM_CPU_FLAGS=$(cat /proc/cpuinfo 2>&1 | "$AWK" '{IGNORECASE=1}{if ($1 == "Features"){print;exit}}' | cut -f 2 -d ':')
160	fi
161fi
162
163for ARG in "$@"
164do
165	# Recognize "fast" and "quick", which does not perform tests that take more time to execute
166    if [[ ($("$EGREP" -ix "fast" <<< "$ARG") || $("$EGREP" -ix "quick" <<< "$ARG")) ]]; then
167		HAVE_VALGRIND=0
168		WANT_BENCHMARKS=0
169	# Recognize "farm" and "nice", which uses 1/2 the CPU cores in accordance with GCC Compile Farm policy
170	elif [[ ($("$EGREP" -ix "farm" <<< "$ARG") || $("$EGREP" -ix "nice" <<< "$ARG")) ]]; then
171		WANT_NICE=1
172	elif [[ ($("$EGREP" -ix "orig" <<< "$ARG") || $("$EGREP" -ix "original" <<< "$ARG") || $("$EGREP" -ix "config.h" <<< "$ARG")) ]]; then
173		git checkout config.h > /dev/null 2>&1
174	else
175		echo "Unknown option $ARG"
176	fi
177done
178
179# We need to use the C++ compiler to determine feature availablility. Otherwise
180#   mis-detections occur on a number of platforms.
181if [[ ((-z "$CXX") || ("$CXX" == "gcc")) ]]; then
182	if [[ ("$CXX" == "gcc") ]]; then
183		CXX=g++
184	elif [[ "$IS_DARWIN" -ne "0" ]]; then
185		CXX=c++
186	elif [[ "$IS_SOLARIS" -ne "0" ]]; then
187		if [[ (-e "/opt/developerstudio12.5/bin/CC") ]]; then
188			CXX=/opt/developerstudio12.5/bin/CC
189		elif [[ (-e "/opt/solarisstudio12.4/bin/CC") ]]; then
190			CXX=/opt/solarisstudio12.4/bin/CC
191		elif [[ (-e "/opt/solarisstudio12.3/bin/CC") ]]; then
192			CXX=/opt/solarisstudio12.3/bin/CC
193		elif [[ (-e "/opt/solstudio12.2/bin/CC") ]]; then
194			CXX=/opt/solstudio12.2/bin/CC
195		elif [[ (-e "/opt/solstudio12.1/bin/CC") ]]; then
196			CXX=/opt/solstudio12.1/bin/CC
197		elif [[ (-e "/opt/solstudio12.0/bin/CC") ]]; then
198			CXX=/opt/solstudio12.0/bin/CC
199		elif [[ (! -z $(which CC 2>/dev/null | "$GREP" -v "no CC" | head -1)) ]]; then
200			CXX=$(which CC | head -1)
201		elif [[ (! -z $(which g++ 2>/dev/null | "$GREP" -v "no g++" | head -1)) ]]; then
202			CXX=$(which g++ | head -1)
203		else
204			CXX=CC
205		fi
206	elif [[ ($(which g++ 2>&1 | "$GREP" -v "no g++" | "$GREP" -i -c g++) -ne "0") ]]; then
207		CXX=g++
208	else
209		CXX=c++
210	fi
211fi
212
213SUN_COMPILER=$("$CXX" -V 2>&1 | "$EGREP" -i -c "CC: (Sun|Studio)")
214GCC_COMPILER=$("$CXX" --version 2>&1 | "$GREP" -i -v "clang" | "$EGREP" -i -c "(gcc|g\+\+)")
215INTEL_COMPILER=$("$CXX" --version 2>&1 | "$EGREP" -i -c "\(icc\)")
216MACPORTS_COMPILER=$("$CXX" --version 2>&1 | "$EGREP" -i -c "MacPorts")
217CLANG_COMPILER=$("$CXX" --version 2>&1 | "$EGREP" -i -c "clang")
218
219if [[ ("$SUN_COMPILER" -eq "0") ]]; then
220	AMD64=$("$CXX" -dM -E - </dev/null 2>/dev/null | "$EGREP" -c "(__x64_64__|__amd64__)")
221	ILP32=$("$CXX" -dM -E - </dev/null 2>/dev/null | "$EGREP" -c "(__ILP32__|__ILP32)")
222	if [[ ("$AMD64" -ne "0") && ("$ILP32" -ne "0") ]]; then
223		IS_X32=1
224	fi
225fi
226
227# Now that the compiler is fixed, determine the compiler version for fixups
228CLANG_37_OR_ABOVE=$("$CXX" -v 2>&1 | "$EGREP" -i -c 'clang version (3\.[7-9]|[4-9]\.[0-9])')
229GCC_60_OR_ABOVE=$("$CXX" -v 2>&1 | "$EGREP" -i -c 'gcc version (6\.[0-9]|[7-9])')
230GCC_51_OR_ABOVE=$("$CXX" -v 2>&1 | "$EGREP" -i -c 'gcc version (5\.[1-9]|[6-9])')
231GCC_48_COMPILER=$("$CXX" -v 2>&1 | "$EGREP" -i -c 'gcc version 4\.8')
232GCC_49_COMPILER=$("$CXX" -v 2>&1 | "$EGREP" -i -c 'gcc version 4\.9')
233GCC_49_OR_ABOVE=$("$CXX" -v 2>&1 | "$EGREP" -i -c 'gcc version (4\.9|[5-9]\.[0-9])')
234SUNCC_510_OR_ABOVE=$("$CXX" -V 2>&1 | "$EGREP" -c "CC: (Sun|Studio) .* (5\.1[0-9]|5\.[2-9]|[6-9]\.)")
235SUNCC_511_OR_ABOVE=$("$CXX" -V 2>&1 | "$EGREP" -c "CC: (Sun|Studio) .* (5\.1[1-9]|5\.[2-9]|[6-9]\.)")
236SUNCC_512_OR_ABOVE=$("$CXX" -V 2>&1 | "$EGREP" -c "CC: (Sun|Studio) .* (5\.1[2-9]|5\.[2-9]|[6-9]\.)")
237SUNCC_513_OR_ABOVE=$("$CXX" -V 2>&1 | "$EGREP" -c "CC: (Sun|Studio) .* (5\.1[3-9]|5\.[2-9]|[6-9]\.)")
238
239# Fixup, bad code generation
240if [[ ("$SUNCC_510_OR_ABOVE" -ne "0") ]]; then
241	HAVE_O5=0
242	HAVE_OFAST=0
243fi
244
245if [[ (-z "$TMP") ]]; then
246	if [[ (-d "/tmp") ]]; then
247		TMP=/tmp
248	elif [[ (-d "/temp") ]]; then
249		TMP=/temp
250	elif [[ (-d "$HOME/tmp") ]]; then
251		TMP="$HOME/tmp"
252	else
253		echo "Please set TMP to a valid directory"
254		[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
255	fi
256fi
257
258# Sun Studio does not allow '-x c++'. Copy it here...
259rm -f adhoc.cpp > /dev/null 2>&1
260cp adhoc.cpp.proto adhoc.cpp
261
262rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
263if [[ (-z "$HAVE_CXX17") ]]; then
264	HAVE_CXX17=0
265	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
266	"$CXX" -DCRYPTOPP_ADHOC_MAIN -std=c++17 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
267	if [[ "$?" -eq "0" ]]; then
268		HAVE_CXX17=1
269	fi
270fi
271
272rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
273if [[ (-z "$HAVE_GNU17") ]]; then
274	HAVE_GNU17=0
275	"$CXX" -DCRYPTOPP_ADHOC_MAIN -std=gnu++17 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
276	if [[ "$?" -eq "0" ]]; then
277		HAVE_GNU17=1
278	fi
279fi
280
281rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
282if [[ (-z "$HAVE_CXX14") ]]; then
283	HAVE_CXX14=0
284	"$CXX" -DCRYPTOPP_ADHOC_MAIN -std=c++14 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
285	if [[ "$?" -eq "0" ]]; then
286		HAVE_CXX14=1
287	fi
288fi
289
290rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
291if [[ (-z "$HAVE_GNU14") ]]; then
292	HAVE_GNU14=0
293	"$CXX" -DCRYPTOPP_ADHOC_MAIN -std=gnu++14 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
294	if [[ "$?" -eq "0" ]]; then
295		HAVE_GNU14=1
296	fi
297fi
298
299rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
300if [[ (-z "$HAVE_CXX11") ]]; then
301	HAVE_CXX11=0
302	"$CXX" -DCRYPTOPP_ADHOC_MAIN -std=c++11 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
303	if [[ "$?" -eq "0" ]]; then
304		HAVE_CXX11=1
305	fi
306fi
307
308rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
309if [[ (-z "$HAVE_GNU11") ]]; then
310	HAVE_GNU11=0
311	"$CXX" -DCRYPTOPP_ADHOC_MAIN -std=gnu++11 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
312	if [[ "$?" -eq "0" ]]; then
313		HAVE_GNU11=1
314	fi
315fi
316
317rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
318if [[ (-z "$HAVE_CXX03") ]]; then
319	HAVE_CXX03=0
320	"$CXX" -DCRYPTOPP_ADHOC_MAIN -std=c++03 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
321	if [[ "$?" -eq "0" ]]; then
322		HAVE_CXX03=1
323	fi
324fi
325
326rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
327if [[ (-z "$HAVE_GNU03") ]]; then
328	HAVE_GNU03=0
329	"$CXX" -DCRYPTOPP_ADHOC_MAIN -std=gnu++03 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
330	if [[ "$?" -eq "0" ]]; then
331		HAVE_GNU03=1
332	fi
333fi
334
335# Use a fallback strategy so OPT_O0 can be used with DEBUG_CXXFLAGS
336OPT_O0=
337rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
338"$CXX" -DCRYPTOPP_ADHOC_MAIN -O0 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
339if [[ ("$?" -eq "0") ]]; then
340	OPT_O0=-O0
341else
342	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
343	"$CXX" -DCRYPTOPP_ADHOC_MAIN -xO0 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
344	if [[ ("$?" -eq "0") ]]; then
345		OPT_O0=-xO0
346	fi
347fi
348
349# Use a fallback strategy so OPT_O1 can be used with VALGRIND_CXXFLAGS
350OPT_O1=
351rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
352"$CXX" -DCRYPTOPP_ADHOC_MAIN -O1 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
353if [[ ("$?" -eq "0") ]]; then
354	OPT_O1=-O1
355else
356	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
357	"$CXX" -DCRYPTOPP_ADHOC_MAIN -xO1 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
358	if [[ ("$?" -eq "0") ]]; then
359		OPT_O1=-xO1
360	fi
361fi
362
363# Use a fallback strategy so OPT_O2 can be used with RELEASE_CXXFLAGS
364OPT_O2=
365rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
366"$CXX" -DCRYPTOPP_ADHOC_MAIN -O2 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
367if [[ ("$?" -eq "0") ]]; then
368	OPT_O2=-O2
369else
370	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
371	"$CXX" -DCRYPTOPP_ADHOC_MAIN -xO2 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
372	if [[ ("$?" -eq "0") ]]; then
373		OPT_O2=-xO2
374	fi
375fi
376
377if [[ (-z "$HAVE_O3") ]]; then
378	HAVE_O3=0
379	OPT_O3=
380	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
381	"$CXX" -DCRYPTOPP_ADHOC_MAIN -O3 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
382	if [[ ("$?" -eq "0") ]]; then
383		HAVE_O3=1
384		OPT_O3=-O3
385	else
386		rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
387		"$CXX" -DCRYPTOPP_ADHOC_MAIN -xO3 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
388		if [[ ("$?" -eq "0") ]]; then
389			HAVE_O3=1
390			OPT_O3=-xO3
391		fi
392	fi
393fi
394
395# Hit or miss, mostly hit
396if [[ (-z "$HAVE_O5") ]]; then
397	HAVE_O5=0
398	OPT_O5=
399	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
400	"$CXX" -DCRYPTOPP_ADHOC_MAIN -O5 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
401	if [[ ("$?" -eq "0") ]]; then
402		HAVE_O5=1
403		OPT_O5=-O5
404	else
405		rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
406		"$CXX" -DCRYPTOPP_ADHOC_MAIN -xO5 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
407		if [[ ("$?" -eq "0") ]]; then
408			HAVE_O5=1
409			OPT_O5=-xO5
410		fi
411	fi
412fi
413
414# Hit or miss, mostly hit
415if [[ (-z "$HAVE_OS") ]]; then
416	HAVE_OS=0
417	OPT_OS=
418	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
419	"$CXX" -DCRYPTOPP_ADHOC_MAIN -Os adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
420	if [[ ("$?" -eq "0") ]]; then
421		HAVE_OS=1
422		OPT_OS=-Os
423	fi
424fi
425
426# Hit or miss, mostly hit
427if [[ (-z "$HAVE_OFAST") ]]; then
428	HAVE_OFAST=0
429	OPT_OFAST=
430	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
431	"$CXX" -DCRYPTOPP_ADHOC_MAIN -Ofast adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
432	if [[ ("$?" -eq "0") ]]; then
433		HAVE_OFAST=1
434		OPT_OFAST=-Ofast
435	fi
436fi
437
438# Use a fallback strategy so OPT_G2 can be used with RELEASE_CXXFLAGS
439OPT_G2=
440rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
441"$CXX" -DCRYPTOPP_ADHOC_MAIN -g2 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
442if [[ ("$?" -eq "0") ]]; then
443	OPT_G2=-g2
444else
445	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
446	"$CXX" -DCRYPTOPP_ADHOC_MAIN -g adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
447	if [[ ("$?" -eq "0") ]]; then
448		OPT_G2=-g
449	fi
450fi
451
452# Use a fallback strategy so OPT_G3 can be used with DEBUG_CXXFLAGS
453OPT_G3=
454rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
455"$CXX" -DCRYPTOPP_ADHOC_MAIN -g3 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
456if [[ ("$?" -eq "0") ]]; then
457	OPT_G3=-g3
458else
459	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
460	"$CXX" -DCRYPTOPP_ADHOC_MAIN -g adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
461	if [[ ("$?" -eq "0") ]]; then
462		OPT_G3=-g
463	fi
464fi
465
466# Cygwin and noisy compiles
467OPT_PIC=
468rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
469if [[ (-z "$HAVE_PIC") ]]; then
470	HAVE_PIC=0
471	PIC_PROBLEMS=$("$CXX" -DCRYPTOPP_ADHOC_MAIN -fPIC adhoc.cpp -o "$TMP/adhoc.exe" 2>&1 | "$EGREP" -ic '(warning|error)')
472	if [[ "$PIC_PROBLEMS" -eq "0" ]]; then
473		HAVE_PIC=1
474		OPT_PIC=-fPIC
475	fi
476fi
477
478# GCC 4.8; Clang 3.4
479rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
480if [[ (-z "$HAVE_UBSAN") ]]; then
481	HAVE_UBSAN=0
482	"$CXX" -DCRYPTOPP_ADHOC_MAIN -fsanitize=undefined adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
483	if [[ ("$?" -eq "0") ]]; then
484		"$TMP/adhoc.exe" > /dev/null 2>&1
485		if [[ ("$?" -eq "0") ]]; then
486			HAVE_UBSAN=1
487		fi
488	fi
489fi
490
491# GCC 4.8; Clang 3.4
492rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
493if [[ (-z "$HAVE_ASAN") ]]; then
494	HAVE_ASAN=0
495	"$CXX" -DCRYPTOPP_ADHOC_MAIN -fsanitize=address adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
496	if [[ ("$?" -eq "0") ]]; then
497		"$TMP/adhoc.exe" > /dev/null 2>&1
498		if [[ ("$?" -eq "0") ]]; then
499			HAVE_ASAN=1
500		fi
501	fi
502fi
503
504# GCC 6.0; maybe Clang
505rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
506if [[ (-z "$HAVE_BOUNDS_SAN") ]]; then
507	HAVE_BOUNDS_SAN=0
508	"$CXX" -DCRYPTOPP_ADHOC_MAIN -fsanitize=bounds-strict adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
509	if [[ ("$?" -eq "0") ]]; then
510		"$TMP/adhoc.exe" > /dev/null 2>&1
511		if [[ ("$?" -eq "0") ]]; then
512			HAVE_BOUNDS_SAN=1
513		fi
514	fi
515fi
516
517rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
518if [[ (-z "$HAVE_OMP") ]]; then
519	HAVE_OMP=0
520	if [[ "$GCC_COMPILER" -ne "0" ]]; then
521		"$CXX" -DCRYPTOPP_ADHOC_MAIN -fopenmp -O3 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
522		if [[ "$?" -eq "0" ]]; then
523			HAVE_OMP=1
524			OMP_FLAGS=(-fopenmp -O3)
525		fi
526	elif [[ "$INTEL_COMPILER" -ne "0" ]]; then
527		"$CXX" -DCRYPTOPP_ADHOC_MAIN -openmp -O3 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
528		if [[ "$?" -eq "0" ]]; then
529			HAVE_OMP=1
530			OMP_FLAGS=(-openmp -O3)
531		fi
532	elif [[ "$CLANG_COMPILER" -ne "0" ]]; then
533		"$CXX" -DCRYPTOPP_ADHOC_MAIN -fopenmp=libomp -O3 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
534		if [[ "$?" -eq "0" ]]; then
535			HAVE_OMP=1
536			OMP_FLAGS=(-fopenmp=libomp -O3)
537		fi
538	elif [[ "$SUN_COMPILER" -ne "0" ]]; then
539		"$CXX" -DCRYPTOPP_ADHOC_MAIN -xopenmp=parallel -xO3 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
540		if [[ "$?" -eq "0" ]]; then
541			HAVE_OMP=1
542			OMP_FLAGS=(-xopenmp=parallel -xO3)
543		fi
544	fi
545fi
546
547rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
548if [[ (-z "$HAVE_INTEL_MULTIARCH") ]]; then
549	HAVE_INTEL_MULTIARCH=0
550	if [[ ("$IS_DARWIN" -ne "0") && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0") ]]; then
551		"$CXX" -DCRYPTOPP_ADHOC_MAIN -arch i386 -arch x86_64 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
552		if [[ "$?" -eq "0" ]]; then
553			HAVE_INTEL_MULTIARCH=1
554		fi
555	fi
556fi
557
558rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
559if [[ (-z "$HAVE_PPC_MULTIARCH") ]]; then
560	HAVE_PPC_MULTIARCH=0
561	if [[ ("$IS_DARWIN" -ne "0") && ("$IS_PPC" -ne "0") ]]; then
562		"$CXX" -DCRYPTOPP_ADHOC_MAIN -arch ppc -arch ppc64 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
563		if [[ "$?" -eq "0" ]]; then
564			HAVE_PPC_MULTIARCH=1
565		fi
566	fi
567fi
568
569rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
570if [[ (-z "$HAVE_X32") ]]; then
571	HAVE_X32=0
572	if [[ "$IS_X32" -ne "0" ]]; then
573		"$CXX" -DCRYPTOPP_ADHOC_MAIN -mx32 adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
574		if [[ "$?" -eq "0" ]]; then
575			HAVE_X32=1
576		fi
577	fi
578fi
579
580# "Modern compiler, old hardware" combinations
581HAVE_X86_AES=0
582HAVE_X86_RDRAND=0
583HAVE_X86_RDSEED=0
584HAVE_X86_PCLMUL=0
585if [[ ("$IS_X86" -ne "0" || "$IS_X64" -ne "0") && ("$SUN_COMPILER" -eq "0") ]]; then
586	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
587	"$CXX" -DCRYPTOPP_ADHOC_MAIN -maes adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
588	if [[ "$?" -eq "0" ]]; then
589		HAVE_X86_AES=1
590	fi
591
592	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
593	"$CXX" -DCRYPTOPP_ADHOC_MAIN -mrdrnd adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
594	if [[ "$?" -eq "0" ]]; then
595		HAVE_X86_RDRAND=1
596	fi
597
598	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
599	"$CXX" -DCRYPTOPP_ADHOC_MAIN -mrdseed adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
600	if [[ "$?" -eq "0" ]]; then
601		HAVE_X86_RDSEED=1
602	fi
603
604	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
605	"$CXX" -DCRYPTOPP_ADHOC_MAIN -mpclmul adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
606	if [[ "$?" -eq "0" ]]; then
607		HAVE_X86_PCLMUL=1
608	fi
609fi
610
611# ld-gold linker testing
612if [[ (-z "$HAVE_LDGOLD") ]]; then
613	HAVE_LDGOLD=0
614	LD_GOLD=$(which ld.gold 2>&1 | "$GREP" -v "no ld.gold" | head -1)
615	ELF_FILE=$(which file 2>&1 | "$GREP" -v "no file" | head -1)
616	if [[ (! -z "$LD_GOLD") && (! -z "$ELF_FILE") ]]; then
617		LD_GOLD=$(file "$LD_GOLD" | cut -d":" -f 2 | "$EGREP" -i -c "elf")
618		if [[ ("$LD_GOLD" -ne "0") ]]; then
619			"$CXX" -DCRYPTOPP_ADHOC_MAIN -fuse-ld=gold adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
620			if [[ "$?" -eq "0" ]]; then
621				HAVE_LDGOLD=1
622			fi
623		fi
624	fi
625fi
626
627# GCC unified syntax for ASM. Divided syntax is being deprecated
628if [[ (-z "$HAVE_UNIFIED_ASM") ]]; then
629	HAVE_UNIFIED_ASM=0
630	rm -f "$TMP/adhoc.exe" > /dev/null 2>&1
631	"$CXX" -DCRYPTOPP_ADHOC_MAIN -masm-syntax-unified adhoc.cpp -o "$TMP/adhoc.exe" > /dev/null 2>&1
632	if [[ "$?" -eq "0" ]]; then
633		HAVE_UNIFIED_ASM=1
634	fi
635fi
636
637# ARMv7 and ARMv8, including NEON, CRC32 and Crypto extensions
638if [[ ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0") ]]; then
639
640	if [[ (-z "$HAVE_ARMV7A" && "$IS_ARM32" -ne "0") ]]; then
641		HAVE_ARMV7A=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c 'neon')
642		if [[ ("$HAVE_ARMV7A" -gt "0") ]]; then HAVE_ARMV7A=1; fi
643	fi
644
645	if [[ (-z "$HAVE_ARMV8A" && ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0")) ]]; then
646		HAVE_ARMV8A=$(echo -n "$ARM_CPU_FLAGS" | "$EGREP" -i -c '(asimd|crc|crypto)')
647		if [[ ("$HAVE_ARMV8A" -gt "0") ]]; then HAVE_ARMV8A=1; fi
648	fi
649
650	if [[ (-z "$HAVE_ARM_VFPV3") ]]; then
651		HAVE_ARM_VFPV3=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c 'vfpv3')
652		if [[ ("$HAVE_ARM_VFPV3" -gt "0") ]]; then HAVE_ARM_VFPV3=1; fi
653	fi
654
655	if [[ (-z "$HAVE_ARM_VFPV4") ]]; then
656		HAVE_ARM_VFPV4=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c 'vfpv4')
657		if [[ ("$HAVE_ARM_VFPV4" -gt "0") ]]; then HAVE_ARM_VFPV4=1; fi
658	fi
659
660	if [[ (-z "$HAVE_ARM_VFPV5") ]]; then
661		HAVE_ARM_VFPV5=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c 'fpv5')
662		if [[ ("$HAVE_ARM_VFPV5" -gt "0") ]]; then HAVE_ARM_VFPV5=1; fi
663	fi
664
665	if [[ (-z "$HAVE_ARM_VFPD32") ]]; then
666		HAVE_ARM_VFPD32=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c 'vfpd32')
667		if [[ ("$HAVE_ARM_VFPD32" -gt "0") ]]; then HAVE_ARM_VFPD32=1; fi
668	fi
669
670	if [[ (-z "$HAVE_ARM_NEON") ]]; then
671		HAVE_ARM_NEON=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c 'neon')
672		if [[ ("$HAVE_ARM_NEON" -gt "0") ]]; then HAVE_ARM_NEON=1; fi
673	fi
674
675	if [[ (-z "$HAVE_ARMV8A") ]]; then
676		HAVE_ARMV8="$IS_ARM64"
677	fi
678
679	if [[ (-z "$HAVE_ARM_CRYPTO") ]]; then
680		HAVE_ARM_CRYPTO=$(echo -n "$ARM_CPU_FLAGS" | "$EGREP" -i -c '(aes|pmull|sha1|sha2)')
681		if [[ ("$HAVE_ARM_CRYPTO" -gt "0") ]]; then HAVE_ARM_CRYPTO=1; fi
682	fi
683
684	if [[ (-z "$HAVE_ARM_CRC") ]]; then
685		HAVE_ARM_CRC=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c 'crc32')
686		if [[ ("$HAVE_ARM_CRC" -gt "0") ]]; then HAVE_ARM_CRC=1; fi
687	fi
688fi
689
690# Valgrind testing of C++03, C++11, C++14 and C++17 binaries. Valgrind tests take a long time...
691if [[ (-z "$HAVE_VALGRIND") ]]; then
692	HAVE_VALGRIND=$(which valgrind 2>&1 | "$GREP" -v "no valgrind" | "$GREP" -i -c valgrind)
693fi
694
695# Try to find a symbolizer for Asan
696if [[ (-z "$HAVE_SYMBOLIZE") && (! -z "$ASAN_SYMBOLIZER_PATH") ]]; then
697	# Sets default value
698	HAVE_SYMBOLIZE=$(which asan_symbolize 2>&1 | "$GREP" -v "no asan_symbolize" | "$GREP" -i -c "asan_symbolize")
699	if [[ (("$HAVE_SYMBOLIZE" -ne "0") && (-z "$ASAN_SYMBOLIZE")) ]]; then
700		ASAN_SYMBOLIZE=asan_symbolize
701	fi
702
703	# Clang implicitly uses ASAN_SYMBOLIZER_PATH; set it if its not set.
704	if [[ (-z "$ASAN_SYMBOLIZER_PATH") ]]; then
705		LLVM_SYMBOLIZER_FOUND=$(which llvm-symbolizer 2>&1 | "$GREP" -v "no llvm-symbolizer" | "$GREP" -i -c llvm-symbolizer)
706		if [[ ("$LLVM_SYMBOLIZER_FOUND" -ne "0") ]]; then
707			export ASAN_SYMBOLIZER_PATH=$(which llvm-symbolizer)
708		fi
709	fi
710fi
711
712# Used to disassemble object modules so we can verify some aspects of code generation
713if [[ (-z "$HAVE_DISASS") ]]; then
714	echo "int main(int argc, char* argv[]) {return 0;}" > "$TMP/test.cc"
715	"$CXX" "$TMP/test.cc" -o "$TMP/test.exe" > /dev/null 2>&1
716	if [[ "$?" -eq "0" ]]; then
717		"$DISASS" "${DISASSARGS[@]}" "$TMP/test.exe" > /dev/null 2>&1
718		if [[ "$?" -eq "0" ]]; then
719			HAVE_DISASS=1
720		else
721			HAVE_DISASS=0
722		fi
723	fi
724fi
725
726# Fixup... GCC 4.8 ASAN produces false positives under ARM
727if [[ ( ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0") && "$GCC_48_COMPILER" -ne "0") ]]; then
728	HAVE_ASAN=0
729fi
730
731# Benchmarks take a long time...
732if [[ (-z "$WANT_BENCHMARKS") ]]; then
733	WANT_BENCHMARKS=1
734fi
735
736############################################
737# System information
738
739echo | tee -a "$TEST_RESULTS"
740if [[ "$IS_LINUX" -ne "0" ]]; then
741	echo "IS_LINUX: $IS_LINUX" | tee -a "$TEST_RESULTS"
742elif [[ "$IS_CYGWIN" -ne "0" ]]; then
743	echo "IS_CYGWIN: $IS_CYGWIN" | tee -a "$TEST_RESULTS"
744elif [[ "$IS_MINGW" -ne "0" ]]; then
745	echo "IS_MINGW: $IS_MINGW" | tee -a "$TEST_RESULTS"
746elif [[ "$IS_SOLARIS" -ne "0" ]]; then
747	echo "IS_SOLARIS: $IS_SOLARIS" | tee -a "$TEST_RESULTS"
748elif [[ "$IS_DARWIN" -ne "0" ]]; then
749	echo "IS_DARWIN: $IS_DARWIN" | tee -a "$TEST_RESULTS"
750fi
751
752if [[ "$IS_PPC" -ne "0" ]]; then
753	echo "IS_PPC: $IS_PPC" | tee -a "$TEST_RESULTS"
754fi
755if [[ "$IS_ARM64" -ne "0" ]]; then
756	echo "IS_ARM64: $IS_ARM64" | tee -a "$TEST_RESULTS"
757elif [[ "$IS_ARM32" -ne "0" ]]; then
758	echo "IS_ARM32: $IS_ARM32" | tee -a "$TEST_RESULTS"
759fi
760if [[ "$HAVE_ARMV7A" -ne "0" ]]; then
761	echo "HAVE_ARMV7A: $HAVE_ARMV7A" | tee -a "$TEST_RESULTS"
762elif [[ "$HAVE_ARMV8A" -ne "0" ]]; then
763	echo "HAVE_ARMV8A: $HAVE_ARMV8A" | tee -a "$TEST_RESULTS"
764fi
765if [[ "$HAVE_ARM_NEON" -ne "0" ]]; then
766	echo "HAVE_ARM_NEON: $HAVE_ARM_NEON" | tee -a "$TEST_RESULTS"
767fi
768if [[ "$HAVE_ARM_VFPD32" -ne "0" ]]; then
769	echo "HAVE_ARM_VFPD32: $HAVE_ARM_VFPD32" | tee -a "$TEST_RESULTS"
770fi
771if [[ "$HAVE_ARM_VFPV3" -ne "0" ]]; then
772	echo "HAVE_ARM_VFPV3: $HAVE_ARM_VFPV3" | tee -a "$TEST_RESULTS"
773fi
774if [[ "$HAVE_ARM_VFPV4" -ne "0" ]]; then
775	echo "HAVE_ARM_VFPV4: $HAVE_ARM_VFPV4" | tee -a "$TEST_RESULTS"
776fi
777if [[ "$HAVE_ARM_CRC" -ne "0" ]]; then
778	echo "HAVE_ARM_CRC: $HAVE_ARM_CRC" | tee -a "$TEST_RESULTS"
779fi
780if [[ "$HAVE_ARM_CRYPTO" -ne "0" ]]; then
781	echo "HAVE_ARM_CRYPTO: $HAVE_ARM_CRYPTO" | tee -a "$TEST_RESULTS"
782fi
783
784if [[ "$IS_X32" -ne "0" ]]; then
785    echo "IS_X32: $IS_X32" | tee -a "$TEST_RESULTS"
786elif [[ "$IS_X64" -ne "0" ]]; then
787	echo "IS_X64: $IS_X64" | tee -a "$TEST_RESULTS"
788elif [[ "$IS_X86" -ne "0" ]]; then
789	echo "IS_X86: $IS_X86" | tee -a "$TEST_RESULTS"
790fi
791
792if [[ "$IS_S390" -ne "0" ]]; then
793    echo "IS_S390: $IS_S390" | tee -a "$TEST_RESULTS"
794fi
795
796# C++03, C++11, C++14 and C++17
797echo | tee -a "$TEST_RESULTS"
798echo "HAVE_CXX03: $HAVE_CXX03" | tee -a "$TEST_RESULTS"
799echo "HAVE_GNU03: $HAVE_GNU03" | tee -a "$TEST_RESULTS"
800echo "HAVE_CXX11: $HAVE_CXX11" | tee -a "$TEST_RESULTS"
801echo "HAVE_GNU11: $HAVE_GNU11" | tee -a "$TEST_RESULTS"
802if [[ ("$HAVE_CXX14" -ne "0" || "$HAVE_CXX17" -ne "0" || "$HAVE_GNU14" -ne "0" || "$HAVE_GNU17" -ne "0") ]]; then
803	echo "HAVE_CXX14: $HAVE_CXX14" | tee -a "$TEST_RESULTS"
804	echo "HAVE_GNU14: $HAVE_GNU14" | tee -a "$TEST_RESULTS"
805	echo "HAVE_CXX17: $HAVE_CXX17" | tee -a "$TEST_RESULTS"
806	echo "HAVE_GNU17: $HAVE_GNU17" | tee -a "$TEST_RESULTS"
807fi
808if [[ "$HAVE_LDGOLD" -ne "0" ]]; then
809	echo "HAVE_LDGOLD: $HAVE_LDGOLD" | tee -a "$TEST_RESULTS"
810fi
811if [[ "$HAVE_UNIFIED_ASM" -ne "0" ]]; then
812	echo "HAVE_UNIFIED_ASM: $HAVE_UNIFIED_ASM" | tee -a "$TEST_RESULTS"
813fi
814
815# -O3, -O5 and -Os
816echo | tee -a "$TEST_RESULTS"
817echo "OPT_O3: $OPT_O3" | tee -a "$TEST_RESULTS"
818if [[ (! -z "$OPT_O5") || (! -z "$OPT_OS") || (! -z "$OPT_OFAST") ]]; then
819	echo "OPT_O5: $OPT_O5" | tee -a "$TEST_RESULTS"
820	echo "OPT_OS: $OPT_OS" | tee -a "$TEST_RESULTS"
821	echo "OPT_OFAST: $OPT_OFAST" | tee -a "$TEST_RESULTS"
822fi
823
824# Tools available for testing
825echo | tee -a "$TEST_RESULTS"
826if [[ ((! -z "$HAVE_OMP") && ("$HAVE_OMP" -ne "0")) ]]; then echo "HAVE_OMP: $HAVE_OMP" | tee -a "$TEST_RESULTS"; fi
827echo "HAVE_ASAN: $HAVE_ASAN" | tee -a "$TEST_RESULTS"
828if [[ ("$HAVE_ASAN" -ne "0") && (! -z "$ASAN_SYMBOLIZE") ]]; then echo "ASAN_SYMBOLIZE: $ASAN_SYMBOLIZE" | tee -a "$TEST_RESULTS"; fi
829echo "HAVE_UBSAN: $HAVE_UBSAN" | tee -a "$TEST_RESULTS"
830echo "HAVE_BOUNDS_SAN: $HAVE_BOUNDS_SAN" | tee -a "$TEST_RESULTS"
831echo "HAVE_VALGRIND: $HAVE_VALGRIND" | tee -a "$TEST_RESULTS"
832
833if [[ "$HAVE_INTEL_MULTIARCH" -ne "0" ]]; then
834	echo "HAVE_INTEL_MULTIARCH: $HAVE_INTEL_MULTIARCH" | tee -a "$TEST_RESULTS"
835fi
836if [[ "$HAVE_PPC_MULTIARCH" -ne "0" ]]; then
837	echo "HAVE_PPC_MULTIARCH: $HAVE_PPC_MULTIARCH" | tee -a "$TEST_RESULTS"
838fi
839
840############################################
841
842# CPU is logical count, memory is in MiB. Low resource boards have
843#   fewer than 4 cores and 1GB or less memory. We use this to
844#   determine if we can build in parallel without an OOM kill.
845CPU_COUNT=1
846MEM_SIZE=512
847
848if [[ (-e "/proc/cpuinfo") && (-e "/proc/meminfo") ]]; then
849	CPU_COUNT=$(cat /proc/cpuinfo | "$GREP" -c '^processor')
850	MEM_SIZE=$(cat /proc/meminfo | "$GREP" "MemTotal" | "$AWK" '{print $2}')
851	MEM_SIZE=$(($MEM_SIZE/1024))
852elif [[ "$IS_DARWIN" -ne "0" ]]; then
853	CPU_COUNT=$(sysctl -a 2>&1 | "$GREP" 'hw.availcpu' | "$AWK" '{print $3; exit}')
854	MEM_SIZE=$(sysctl -a 2>&1 | "$GREP" 'hw.memsize' | "$AWK" '{print $3; exit;}')
855	MEM_SIZE=$(($MEM_SIZE/1024/1024))
856elif [[ "$IS_SOLARIS" -ne "0" ]]; then
857	CPU_COUNT=$(psrinfo 2>/dev/null | wc -l | "$AWK" '{print $1}')
858	MEM_SIZE=$(prtconf 2>/dev/null | "$GREP" Memory | "$AWK" '{print $3}')
859fi
860
861# Benchmarks expect frequency in GiHz.
862CPU_FREQ=0.5
863if [[ (-e "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq") ]]; then
864	CPU_FREQ=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)
865	CPU_FREQ=$("$AWK" "BEGIN {print $CPU_FREQ/1024/1024}")
866elif [[ (-e "/proc/cpuinfo") ]]; then
867	CPU_FREQ=$(cat /proc/cpuinfo | "$GREP" 'MHz' | "$AWK" '{print $4; exit}')
868	if [[ -z "$CPU_FREQ" ]]; then CPU_FREQ=512; fi
869	CPU_FREQ=$("$AWK" "BEGIN {print $CPU_FREQ/1024}")
870elif [[ "$IS_DARWIN" -ne "0" ]]; then
871	CPU_FREQ=$(sysctl -a 2>&1 | "$GREP" 'hw.cpufrequency' | "$AWK" '{print $3; exit;}')
872	CPU_FREQ=$("$AWK" "BEGIN {print $CPU_FREQ/1024/1024/1024}")
873elif [[ "$IS_SOLARIS" -ne "0" ]]; then
874	CPU_FREQ=$(psrinfo -v 2>/dev/null | "$GREP" 'MHz' | "$AWK" '{print $6; exit;}')
875	CPU_FREQ=$("$AWK" "BEGIN {print $CPU_FREQ/1024}")
876fi
877
878# Some ARM devboards cannot use 'make -j N', even with multiple cores and RAM
879#  An 8-core Cubietruck Plus with 2GB RAM experiences OOM kills with '-j 2'.
880HAVE_SWAP=1
881if [[ "$IS_LINUX" -ne "0" ]]; then
882	if [[ (-e "/proc/meminfo") ]]; then
883		SWAP_SIZE=$(cat /proc/meminfo | "$GREP" "SwapTotal" | "$AWK" '{print $2}')
884		if [[ "$SWAP_SIZE" -eq "0" ]]; then
885			HAVE_SWAP=0
886		fi
887	else
888		HAVE_SWAP=0
889	fi
890fi
891
892echo | tee -a "$TEST_RESULTS"
893echo "CPU: $CPU_COUNT logical" | tee -a "$TEST_RESULTS"
894echo "FREQ: $CPU_FREQ GHz" | tee -a "$TEST_RESULTS"
895echo "MEM: $MEM_SIZE MB" | tee -a "$TEST_RESULTS"
896
897if [[ ("$CPU_COUNT" -ge "2" && "$MEM_SIZE" -ge "1280" && "$HAVE_SWAP" -ne "0") ]]; then
898	if [[ ("$WANT_NICE" -eq "1") ]]; then
899		CPU_COUNT=$(echo -n "$CPU_COUNT 2" | "$AWK" '{print int($1/$2)}')
900	fi
901	MAKEARGS=(-j "$CPU_COUNT")
902	echo "Using $MAKE -j $CPU_COUNT"
903fi
904
905############################################
906
907GIT_REPO=$(git branch 2>&1 | "$GREP" -v "fatal" | wc -l | "$AWK" '{print $1; exit;}')
908if [[ "$GIT_REPO" -ne "0" ]]; then
909	GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
910	GIT_HASH=$(git rev-parse HEAD 2>/dev/null | cut -c 1-16)
911fi
912
913echo | tee -a "$TEST_RESULTS"
914if [[ ! -z "$GIT_BRANCH" ]]; then
915	echo "Git branch: $GIT_BRANCH (commit $GIT_HASH)" | tee -a "$TEST_RESULTS"
916fi
917
918if [[ ("$SUN_COMPILER" -ne "0") ]]; then
919	echo $("$CXX" -V 2>&1 | "$SED" 's|CC:|Compiler:|g' | head -1) | tee -a "$TEST_RESULTS"
920else
921	echo "Compiler:" $("$CXX" --version | head -1) | tee -a "$TEST_RESULTS"
922fi
923
924CXX_PATH=$(which "$CXX")
925CXX_SYMLINK=$(ls -l "$CXX_PATH" 2>/dev/null | "$GREP" -c '\->' | "$AWK" '{print $1}')
926if [[ ("$CXX_SYMLINK" -ne "0") ]]; then CXX_PATH="$CXX_PATH (symlinked)"; fi
927echo "Pathname: $CXX_PATH" | tee -a "$TEST_RESULTS"
928
929############################################
930
931# Calculate these once. They handle Clang, GCC, ICC, etc
932DEBUG_CXXFLAGS="-DDEBUG $OPT_G3 $OPT_O0"
933RELEASE_CXXFLAGS="-DNDEBUG $OPT_G2 $OPT_O2"
934VALGRIND_CXXFLAGS="-DNDEBUG $OPT_G3 $OPT_O1"
935PLATFORM_CXXFLAGS=()
936ELEVATED_CXXFLAGS=()
937
938# Clang {3.4|3.5|3.6} only advertises SSE2, http://bugs.launchpad.net/ubuntu/+bug/1616723,
939#   http://bugs.launchpad.net/ubuntu/+bug/1616729 and http://bugs.launchpad.net/ubuntu/+bug/1616731
940if [[ (("$IS_X86" -ne "0" || "$IS_X64" -ne "0") && ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0")) ]]; then
941
942	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sse2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-msse2"); fi
943	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sse3") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-msse3"); fi
944	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "ssse3") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mssse3"); fi
945	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sse4.1") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-msse4.1"); fi
946	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sse4.2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-msse4.2"); fi
947	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "aes") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-maes"); fi
948	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "pclmulqdq") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mpclmul"); fi
949	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "rdrand") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mrdrnd"); fi
950	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "rdseed") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mrdseed"); fi
951	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "avx") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mavx"); fi
952	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "avx2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mavx2"); fi
953	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "bmi") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mbmi"); fi
954	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "bmi2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-mbmi2"); fi
955	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "adx") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-madx"); fi
956	if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sha_ni") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-msha"); fi
957fi
958
959# Solaris Studio 12.1/SunCC 5.10 (and above) compilers consume GCC inline assembly. However, the compiler does
960#   not declare the CPU features, even when using options like -native and -xarch=<feature>.
961if [[ ("$IS_X86" -ne "0" || "$IS_X64" -ne "0") && ("$IS_SOLARIS" -ne "0") && ("$SUNCC_510_OR_ABOVE" -ne "0") ]]; then
962	SUNCC_XARCH=
963	if [[ ("$SUNCC_511_OR_ABOVE" -ne "0") ]]; then
964		if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sse2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__SSE2__"); SUNCC_XARCH=sse2; fi
965		if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sse3") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__SSE3__"); SUNCC_XARCH=ssse3; fi
966		if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "ssse3") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__SSSE3__"); SUNCC_XARCH=ssse3; fi
967		if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sse4.1") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__SSE4_1__"); SUNCC_XARCH=sse4_1; fi
968		if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "sse4.2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__SSE4_2__"); SUNCC_XARCH=sse4_2; fi
969
970		# This should use SUNCC_512_OR_ABOVE, but SunCC 5.12 crashes with -xarch=aes.
971		if [[ ("$SUNCC_513_OR_ABOVE" -ne "0") ]]; then
972			if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "aes") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__AES__"); SUNCC_XARCH=aes; fi
973			if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "pclmulqdq") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__PCLMUL__"); SUNCC_XARCH=aes; fi
974
975			if [[ ("$SUNCC_513_OR_ABOVE" -ne "0") ]]; then
976				if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "rdrand") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__RDRND__"); SUNCC_XARCH=avx_i; fi
977				if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "rdseed") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__RDSEED__"); SUNCC_XARCH=avx_i; fi
978				if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "avx") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__AVX__"); SUNCC_XARCH=avx; fi
979				if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "avx2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__AVX2__"); SUNCC_XARCH=avx2; fi
980				if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "bmi") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__BMI__"); SUNCC_XARCH=avx2; fi
981				if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "bmi2") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__BMI2__"); SUNCC_XARCH=avx2; fi
982
983				# SunCC 5.13 and "illegal use of -xarch option, illegal value ignored: avx2_i"
984				if [[ ("$SUNCC_514_OR_ABOVE" -ne "0") ]]; then
985					if [[ ($(echo -n "$X86_CPU_FLAGS" | "$GREP" -c "adx") -ne "0") ]]; then PLATFORM_CXXFLAGS+=("-D__ADX__"); SUNCC_XARCH=avx2_i; fi
986				fi
987			fi
988		fi
989	fi
990	PLATFORM_CXXFLAGS+=("-xarch=$SUNCC_XARCH")
991fi
992
993# Please, someone put an end to the madness of determining Features, FPU, ABI, hard floats and soft floats...
994if [[ ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0") ]]; then
995
996	if [[ (("$HAVE_ARMV7A" -ne "0") && ("$IS_ARM32" -ne "0")) ]]; then
997
998		PLATFORM_CXXFLAGS+=("-march=armv7-a")
999
1000		# http://community.arm.com/groups/tools/blog/2013/04/15/arm-cortex-a-processors-and-gcc-command-lines
1001		#  These may need more tuning. If it was easy to get the CPU model, like Cortex-A9, then we could
1002		#  be fairly certain of the FPU and ABI flags. But we can't easily get a CPU name, so we suffer through it.
1003		#  Also see http://lists.linaro.org/pipermail/linaro-toolchain/2016-July/005821.html
1004		if [[ ("$HAVE_ARM_NEON" -ne "0" && "$CLANG_COMPILER" -ne "0") ]]; then
1005			PLATFORM_CXXFLAGS+=("-mfpu=neon")
1006		elif [[ ("$HAVE_ARM_NEON" -ne "0" && "$HAVE_ARM_VFPV4" -ne "0") ]]; then
1007			PLATFORM_CXXFLAGS+=("-mfpu=neon-vfpv4")
1008		elif [[ ("$HAVE_ARM_NEON" -ne "0") ]]; then
1009			PLATFORM_CXXFLAGS+=("-mfpu=neon")
1010		elif [[ ("$HAVE_ARM_VFPV3" -ne "0" || "$HAVE_ARM_VFPV4" -ne "0") && "$HAVE_ARM_VFPD32" -ne "0" ]]; then
1011			PLATFORM_CXXFLAGS+=("-mfpu=neon")
1012		elif [[ ("$HAVE_ARM_VFPV5" -ne "0" && "$HAVE_ARM_VFPD32" -ne "0") ]]; then
1013			PLATFORM_CXXFLAGS+=("-mfpu=fpv5")
1014		elif [[ ("$HAVE_ARM_VFPV4" -ne "0" && "$HAVE_ARM_VFPD32" -ne "0") ]]; then
1015			PLATFORM_CXXFLAGS+=("-mfpu=vfpv4")
1016		elif [[ ("$HAVE_ARM_VFPV3" -ne "0" && "$HAVE_ARM_VFPD32" -ne "0") ]]; then
1017			PLATFORM_CXXFLAGS+=("-mfpu=vfpv3")
1018		elif [[ ("$HAVE_ARM_VFPV5" -ne "0") ]]; then
1019			PLATFORM_CXXFLAGS+=("-mfpu=fpv5-d16")
1020		elif [[ ("$HAVE_ARM_VFPV4" -ne "0") ]]; then
1021			PLATFORM_CXXFLAGS+=("-mfpu=vfpv4-d16")
1022		elif [[ ("$HAVE_ARM_VFPV3" -ne "0") ]]; then
1023			PLATFORM_CXXFLAGS+=("-mfpu=vfpv3-d16")
1024		fi
1025
1026	elif [[ (("$HAVE_ARMV8A" -ne "0") && ("$IS_ARM64" -ne "0")) ]]; then
1027
1028		if [[ ("$HAVE_ARM_CRC" -ne "0" && "$HAVE_ARM_CRYPTO" -ne "0") ]]; then
1029			PLATFORM_CXXFLAGS+=("-march=armv8-a+crc+crypto")
1030		elif [[ ("$HAVE_ARM_CRC" -ne "0") ]]; then
1031			PLATFORM_CXXFLAGS+=("-march=armv8-a+crc")
1032		elif [[ ("$HAVE_ARM_CRYPTO" -ne "0") ]]; then
1033			PLATFORM_CXXFLAGS+=("-march=armv8-a+crypto")
1034		else
1035			PLATFORM_CXXFLAGS+=("-march=armv8-a")
1036		fi
1037
1038	elif [[ (("$HAVE_ARMV8A" -ne "0") && ("$IS_ARM32" -ne "0")) ]]; then
1039
1040		if [[ ("$HAVE_ARM_CRC" -ne "0") ]]; then
1041			PLATFORM_CXXFLAGS+=("-march=armv8-a+crc")
1042		else
1043			PLATFORM_CXXFLAGS+=("-march=armv8-a")
1044		fi
1045
1046		if [[ ("$CLANG_COMPILER" -ne "0") ]]; then
1047			PLATFORM_CXXFLAGS+=("-mfpu=neon")
1048		elif [[ ("$HAVE_ARM_CRYPTO" -ne "0") ]]; then
1049			PLATFORM_CXXFLAGS+=("-mfpu=crypto-neon-fp-armv8")
1050		else
1051			PLATFORM_CXXFLAGS+=("-mfpu=neon-fp-armv8")
1052		fi
1053	fi
1054
1055	# Soft/Hard floats only apply to 32-bit ARM
1056	# http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka16242.html
1057	if [[ ("$IS_ARM32" -ne "0") ]]; then
1058		ARM_HARD_FLOAT=$("$CXX" -v 2>&1 | "$GREP" 'Target' | "$EGREP" -i -c '(armhf|gnueabihf)')
1059		if [[ ("$ARM_HARD_FLOAT" -ne "0") ]]; then
1060			PLATFORM_CXXFLAGS+=("-mfloat-abi=hard")
1061		else
1062			PLATFORM_CXXFLAGS+=("-mfloat-abi=softfp")
1063		fi
1064	fi
1065fi
1066
1067if [[ ("$GCC_COMPILER" -ne "0") ]]; then
1068	ELEVATED_CXXFLAGS+=("-Wall" "-Wextra" "-Wno-unknown-pragmas" "-Wstrict-aliasing=3" "-Wstrict-overflow" "-Wcast-align"
1069                        "-Waggressive-loop-optimizations" "-Wwrite-strings" "-Wformat=2" "-Wformat-security" "-Wtrampolines")
1070
1071	if [[ ("$GCC_60_OR_ABOVE" -ne "0") ]]; then
1072		ELEVATED_CXXFLAGS+=("-Wshift-negative-value -Wshift-overflow=2 -Wnull-dereference -Wduplicated-cond -Wodr-type-mismatch")
1073	fi
1074	if [[ ("$GCC_51_OR_ABOVE" -ne "0") ]]; then
1075		ELEVATED_CXXFLAGS+=("-Wabi" "-Wodr")
1076	fi
1077fi
1078
1079if [[ ("$CLANG_COMPILER" -ne "0") ]]; then
1080	ELEVATED_CXXFLAGS+=("-Wall" "-Wextra" "-Wno-unknown-pragmas" "-Wstrict-overflow" "-Wcast-align" "-Wwrite-strings"
1081                        "-Wformat=2" "-Wformat-security")
1082fi
1083
1084echo | tee -a "$TEST_RESULTS"
1085echo "DEBUG_CXXFLAGS: $DEBUG_CXXFLAGS" | tee -a "$TEST_RESULTS"
1086echo "RELEASE_CXXFLAGS: $RELEASE_CXXFLAGS" | tee -a "$TEST_RESULTS"
1087echo "VALGRIND_CXXFLAGS: $VALGRIND_CXXFLAGS" | tee -a "$TEST_RESULTS"
1088if [[ (! -z "$USER_CXXFLAGS") ]]; then
1089	echo "USER_CXXFLAGS: $USER_CXXFLAGS" | tee -a "$TEST_RESULTS"
1090fi
1091if [[ ("${#PLATFORM_CXXFLAGS[@]}" -ne "0") ]]; then
1092	echo "PLATFORM_CXXFLAGS: ${PLATFORM_CXXFLAGS[@]}" | tee -a "$TEST_RESULTS"
1093fi
1094
1095#############################################
1096#############################################
1097############### BEGIN TESTING ###############
1098#############################################
1099#############################################
1100
1101TEST_BEGIN=$(date)
1102echo | tee -a "$TEST_RESULTS"
1103echo "Start time: $TEST_BEGIN" | tee -a "$TEST_RESULTS"
1104
1105############################################
1106# Posix NDEBUG and assert
1107if true; then
1108
1109	echo
1110	echo "************************************" | tee -a "$TEST_RESULTS"
1111	echo "Testing: No Posix NDEBUG or assert" | tee -a "$TEST_RESULTS"
1112	echo
1113
1114	FAILED=0
1115
1116	# Filter out C++ and Doxygen comments.
1117	COUNT=$(cat *.h *.cpp | "$GREP" -v '//' | "$GREP" -c '(assert.h|cassert)')
1118	if [[ "$COUNT" -ne "0" ]]; then
1119		FAILED=1
1120		echo "FAILED: found Posix assert headers" | tee -a "$TEST_RESULTS"
1121	fi
1122
1123	# Filter out C++ and Doxygen comments.
1124	COUNT=$(cat *.h *.cpp | "$GREP" -v '//' | "$EGREP" -c 'assert[[:space:]]*\(')
1125	if [[ "$COUNT" -ne "0" ]]; then
1126		FAILED=1
1127		echo "FAILED: found use of Posix assert" | tee -a "$TEST_RESULTS"
1128	fi
1129
1130	# Filter out C++ and Doxygen comments.
1131	COUNT=$(cat *.h *.cpp | "$GREP" -v '//' | "$GREP" -c 'NDEBUG')
1132	if [[ "$COUNT" -ne "0" ]]; then
1133		FAILED=1
1134		echo "FAILED: found use of Posix NDEBUG" | tee -a "$TEST_RESULTS"
1135	fi
1136
1137	if [[ ("$FAILED" -eq "0") ]]; then
1138		echo "Verified no Posix NDEBUG or assert" | tee -a "$TEST_RESULTS"
1139	fi
1140fi
1141
1142############################################
1143# C++ std::min and std::max
1144# This is due to Windows.h and NOMINMAX. Linux test fine, while Windows breaks.
1145if true; then
1146
1147	echo
1148	echo "************************************" | tee -a "$TEST_RESULTS"
1149	echo "Testing: C++ std::min and std::max" | tee -a "$TEST_RESULTS"
1150	echo
1151
1152	FAILED=0
1153
1154	# If this fires, then use the library's STDMIN(a,b) or (std::min)(a, b);
1155	COUNT=$(cat *.h *.cpp | "$GREP" -v '//' | "$EGREP" -c 'std::min[[:space:]]*\(')
1156	if [[ "$COUNT" -ne "0" ]]; then
1157		FAILED=1
1158		echo "FAILED: found std::min" | tee -a "$TEST_RESULTS"
1159	fi
1160
1161	# If this fires, then use the library's STDMAX(a,b) or (std::max)(a, b);
1162	COUNT=$(cat *.h *.cpp | "$GREP" -v '//' | "$EGREP" -c 'std::max[[:space:]]*\(')
1163	if [[ "$COUNT" -ne "0" ]]; then
1164		FAILED=1
1165		echo "FAILED: found std::max" | tee -a "$TEST_RESULTS"
1166	fi
1167
1168	if [[ ("$FAILED" -eq "0") ]]; then
1169		echo "Verified std::min and std::max" | tee -a "$TEST_RESULTS"
1170	fi
1171fi
1172
1173############################################
1174# X86 code generation tests
1175if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_X86" -ne "0" || "$IS_X64" -ne "0")) ]]; then
1176
1177	############################################
1178	# X86 rotate immediate code generation
1179
1180	X86_ROTATE_IMM=1
1181	if [[ ("$X86_ROTATE_IMM" -ne "0") ]]; then
1182		echo
1183		echo "************************************" | tee -a "$TEST_RESULTS"
1184		echo "Testing: X86 rotate immediate code generation" | tee -a "$TEST_RESULTS"
1185		echo
1186
1187		OBJFILE=sha.o; rm -f "$OBJFILE" 2>/dev/null
1188		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1189
1190		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1191
1192		X86_SSE2=$(echo -n "$X86_CPU_FLAGS" | "$GREP" -i -c sse2)
1193		X86_SHA256_HASH_BLOCKS=$(echo -n "$DISASS_TEXT" | "$EGREP" -c 'X86_SHA256_HashBlocks')
1194		if [[ ("$X86_SHA256_HASH_BLOCKS" -ne "0") ]]; then
1195			COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c '(rol.*0x|ror.*0x)')
1196			if [[ ("$COUNT" -le "600") ]]; then
1197				FAILED=1
1198				echo "ERROR: failed to generate rotate immediate instruction (X86_SHA256_HashBlocks)" | tee -a "$TEST_RESULTS"
1199			fi
1200		else
1201			COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c '(rol.*0x|ror.*0x)')
1202			if [[ ("$COUNT" -le "1000") ]]; then
1203				FAILED=1
1204				echo "ERROR: failed to generate rotate immediate instruction" | tee -a "$TEST_RESULTS"
1205			fi
1206		fi
1207
1208		if [[ ("$X86_SSE2" -ne "0" && "$X86_SHA256_HASH_BLOCKS" -eq "0") ]]; then
1209			echo "ERROR: failed to use X86_SHA256_HashBlocks" | tee -a "$TEST_RESULTS"
1210			if [[ ("$CLANG_COMPILER" -ne "0") ]]; then
1211				echo "This could be due to Clang and lack of expected support for Intel assembly syntax in some versions of the compiler"
1212			fi
1213		fi
1214
1215		if [[ ("$FAILED" -eq "0" && "$X86_SHA256_HASH_BLOCKS" -ne "0") ]]; then
1216			echo "Verified rotate immediate machine instructions (X86_SHA256_HashBlocks)" | tee -a "$TEST_RESULTS"
1217		elif [[ ("$FAILED" -eq "0") ]]; then
1218			echo "Verified rotate immediate machine instructions" | tee -a "$TEST_RESULTS"
1219		fi
1220	fi
1221
1222	############################################
1223	# Test AES-NI code generation
1224
1225	X86_AESNI=$(echo -n "$X86_CPU_FLAGS" | "$GREP" -i -c aes)
1226	if [[ ("$X86_AESNI" -ne "0") ]]; then
1227		echo
1228		echo "************************************" | tee -a "$TEST_RESULTS"
1229		echo "Testing: X86 AES-NI code generation" | tee -a "$TEST_RESULTS"
1230		echo
1231
1232		OBJFILE=rijndael.o; rm -f "$OBJFILE" 2>/dev/null
1233		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1234
1235		COUNT=0
1236		FAILED=0
1237		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1238
1239		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c aesenc)
1240		if [[ ("$COUNT" -eq "0") ]]; then
1241			FAILED=1
1242			echo "ERROR: failed to generate aesenc instruction" | tee -a "$TEST_RESULTS"
1243		fi
1244
1245		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c aesenclast)
1246		if [[ ("$COUNT" -eq "0") ]]; then
1247			FAILED=1
1248			echo "ERROR: failed to generate aesenclast instruction" | tee -a "$TEST_RESULTS"
1249		fi
1250
1251		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c aesdec)
1252		if [[ ("$COUNT" -eq "0") ]]; then
1253			FAILED=1
1254			echo "ERROR: failed to generate aesdec instruction" | tee -a "$TEST_RESULTS"
1255		fi
1256
1257		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c aesdeclast)
1258		if [[ ("$COUNT" -eq "0") ]]; then
1259			FAILED=1
1260			echo "ERROR: failed to generate aesdeclast instruction" | tee -a "$TEST_RESULTS"
1261		fi
1262
1263		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c aesimc)
1264		if [[ ("$COUNT" -eq "0") ]]; then
1265			FAILED=1
1266			echo "ERROR: failed to generate aesimc instruction" | tee -a "$TEST_RESULTS"
1267		fi
1268
1269		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c aeskeygenassist)
1270		if [[ ("$COUNT" -eq "0") ]]; then
1271			FAILED=1
1272			echo "ERROR: failed to generate aeskeygenassist instruction" | tee -a "$TEST_RESULTS"
1273		fi
1274
1275		if [[ ("$FAILED" -eq "0") ]]; then
1276			echo "Verified aesenc, aesenclast, aesdec, aesdeclast, aesimc, aeskeygenassist machine instructions" | tee -a "$TEST_RESULTS"
1277		else
1278			if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then
1279				echo "This could be due to Clang and lack of expected support for SSSE3 (and above) in some versions of the compiler. If so, try Clang 3.7 or above"
1280			fi
1281		fi
1282	fi
1283
1284	############################################
1285	# X86 carryless multiply code generation
1286
1287	X86_PCLMUL=$(echo -n "$X86_CPU_FLAGS" | "$GREP" -i -c pclmulq)
1288	if [[ ("$X86_PCLMUL" -ne "0") ]]; then
1289		echo
1290		echo "************************************" | tee -a "$TEST_RESULTS"
1291		echo "Testing: X86 carryless multiply code generation" | tee -a "$TEST_RESULTS"
1292		echo
1293
1294		OBJFILE=gcm.o; rm -f "$OBJFILE" 2>/dev/null
1295		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1296
1297		COUNT=0
1298		FAILED=0
1299		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1300
1301		COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c '(pclmullqhq|vpclmulqdq)')
1302		if [[ ("$COUNT" -eq "0") ]]; then
1303			FAILED=1
1304			echo "ERROR: failed to generate pclmullqhq instruction" | tee -a "$TEST_RESULTS"
1305		fi
1306
1307		COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c '(pclmullqlq|vpclmulqdq)')
1308		if [[ ("$COUNT" -eq "0") ]]; then
1309			FAILED=1
1310			echo "ERROR: failed to generate pclmullqlq instruction" | tee -a "$TEST_RESULTS"
1311		fi
1312
1313		if [[ ("$FAILED" -eq "0") ]]; then
1314			echo "Verified pclmullqhq and pclmullqlq machine instructions" | tee -a "$TEST_RESULTS"
1315		else
1316			if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then
1317				echo "This could be due to Clang and lack of expected support for SSSE3 (and above) in some versions of the compiler. If so, try Clang 3.7 or above"
1318			fi
1319		fi
1320	fi
1321
1322	############################################
1323	# Test RDRAND and RDSEED code generation
1324
1325	X86_RDRAND=$(echo -n "$X86_CPU_FLAGS" | "$GREP" -i -c rdrand)
1326	X86_RDSEED=$(echo -n "$X86_CPU_FLAGS" | "$GREP" -i -c rdseed)
1327	if [[ ("$X86_RDRAND" -ne "0" || "$X86_RDSEED" -ne "0") ]]; then
1328		echo
1329		echo "************************************" | tee -a "$TEST_RESULTS"
1330		echo "Testing: X86 RDRAND and RDSEED code generation" | tee -a "$TEST_RESULTS"
1331		echo
1332
1333		OBJFILE=rdrand.o; rm -f "$OBJFILE" 2>/dev/null
1334		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1335
1336		COUNT=0
1337		FAILED=0
1338		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1339
1340		if [[ "$X86_RDRAND" -ne "0" ]]; then
1341			COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c rdrand)
1342			if [[ ("$COUNT" -eq "0") ]]; then
1343				FAILED=1
1344				echo "ERROR: failed to generate rdrand instruction" | tee -a "$TEST_RESULTS"
1345			fi
1346		fi
1347
1348		if [[ "$X86_RDSEED" -ne "0" ]]; then
1349			COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c rdseed)
1350			if [[ ("$COUNT" -eq "0") ]]; then
1351				FAILED=1
1352				echo "ERROR: failed to generate rdseed instruction" | tee -a "$TEST_RESULTS"
1353			fi
1354		fi
1355
1356		if [[ ("$FAILED" -eq "0") ]]; then
1357			echo "Verified rdrand and rdseed machine instructions" | tee -a "$TEST_RESULTS"
1358		else
1359			if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then
1360				echo "This could be due to Clang and lack of expected support for SSSE3 (and above) in some versions of the compiler. If so, try Clang 3.7 or above"
1361			fi
1362		fi
1363	fi
1364
1365	############################################
1366	# X86 CRC32 code generation
1367
1368	X86_CRC32=$(echo -n "$X86_CPU_FLAGS" | "$EGREP" -i -c '(sse4.2|sse4_2)')
1369	if [[ ("$X86_CRC32" -ne "0") ]]; then
1370		echo
1371		echo "************************************" | tee -a "$TEST_RESULTS"
1372		echo "Testing: X86 CRC32 code generation" | tee -a "$TEST_RESULTS"
1373		echo
1374
1375		OBJFILE=crc.o; rm -f "$OBJFILE" 2>/dev/null
1376		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1377
1378		COUNT=0
1379		FAILED=0
1380		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1381
1382		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c crc32l)
1383		if [[ ("$COUNT" -eq "0") ]]; then
1384			FAILED=1
1385			echo "ERROR: failed to generate crc32l instruction" | tee -a "$TEST_RESULTS"
1386		fi
1387
1388		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c crc32b)
1389		if [[ ("$COUNT" -eq "0") ]]; then
1390			FAILED=1
1391			echo "ERROR: failed to generate crc32b instruction" | tee -a "$TEST_RESULTS"
1392		fi
1393
1394		if [[ ("$FAILED" -eq "0") ]]; then
1395			echo "Verified crc32l and crc32b machine instructions" | tee -a "$TEST_RESULTS"
1396		else
1397			if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then
1398				echo "This could be due to Clang and lack of expected support for SSSE3 (and above) in some versions of the compiler. If so, try Clang 3.7 or above"
1399			fi
1400		fi
1401	fi
1402
1403	############################################
1404	# X86 SHA code generation
1405
1406	X86_SHA=$(echo -n "$X86_CPU_FLAGS" | "$EGREP" -i -c '(sha_ni)')
1407	if [[ ("$X86_SHA" -ne "0") ]]; then
1408		echo
1409		echo "************************************" | tee -a "$TEST_RESULTS"
1410		echo "Testing: X86 SHA code generation" | tee -a "$TEST_RESULTS"
1411		echo
1412
1413		OBJFILE=sha.o; rm -f "$OBJFILE" 2>/dev/null
1414		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1415
1416		COUNT=0
1417		FAILED=0
1418		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1419
1420		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c sha1rnds4)
1421		if [[ ("$COUNT" -eq "0") ]]; then
1422			FAILED=1
1423			echo "ERROR: failed to generate sha1rnds4 instruction" | tee -a "$TEST_RESULTS"
1424		fi
1425
1426		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c sha1nexte)
1427		if [[ ("$COUNT" -eq "0") ]]; then
1428			FAILED=1
1429			echo "ERROR: failed to generate sha1nexte instruction" | tee -a "$TEST_RESULTS"
1430		fi
1431
1432		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c sha1msg1)
1433		if [[ ("$COUNT" -eq "0") ]]; then
1434			FAILED=1
1435			echo "ERROR: failed to generate sha1msg1 instruction" | tee -a "$TEST_RESULTS"
1436		fi
1437
1438		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c sha1msg2)
1439		if [[ ("$COUNT" -eq "0") ]]; then
1440			FAILED=1
1441			echo "ERROR: failed to generate sha1msg2 instruction" | tee -a "$TEST_RESULTS"
1442		fi
1443
1444		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c sha256rnds2)
1445		if [[ ("$COUNT" -eq "0") ]]; then
1446			FAILED=1
1447			echo "ERROR: failed to generate sha256rnds2 instruction" | tee -a "$TEST_RESULTS"
1448		fi
1449
1450		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c sha256msg1)
1451		if [[ ("$COUNT" -eq "0") ]]; then
1452			FAILED=1
1453			echo "ERROR: failed to generate sha256msg1 instruction" | tee -a "$TEST_RESULTS"
1454		fi
1455
1456		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c sha256msg2)
1457		if [[ ("$COUNT" -eq "0") ]]; then
1458			FAILED=1
1459			echo "ERROR: failed to generate sha256msg2 instruction" | tee -a "$TEST_RESULTS"
1460		fi
1461
1462		if [[ ("$FAILED" -eq "0") ]]; then
1463			echo "Verified sha1rnds4, sha1nexte, sha1msg1, sha1msg2, sha256rnds2, sha256msg1 and sha256msg2 machine instructions" | tee -a "$TEST_RESULTS"
1464		else
1465			if [[ ("$CLANG_COMPILER" -ne "0" && "$CLANG_37_OR_ABOVE" -eq "0") ]]; then
1466				echo "This could be due to Clang and lack of expected support for SSSE3 (and above) in some versions of the compiler. If so, try Clang 3.7 or above"
1467			fi
1468		fi
1469	fi
1470fi
1471
1472############################################
1473# ARM code generation tests
1474if [[ ("$HAVE_DISASS" -ne "0" && ("$IS_ARM32" -ne "0" || "$IS_ARM64" -ne "0")) ]]; then
1475
1476	############################################
1477	# ARM NEON code generation
1478
1479	ARM_NEON=$(echo -n "$ARM_CPU_FLAGS" | "$EGREP" -i -c '(neon|asimd)')
1480	if [[ ("$ARM_NEON" -ne "0" || "$HAVE_ARM_NEON" -ne "0") ]]; then
1481		echo
1482		echo "************************************" | tee -a "$TEST_RESULTS"
1483		echo "Testing: ARM NEON code generation" | tee -a "$TEST_RESULTS"
1484		echo
1485
1486		OBJFILE=blake2.o; rm -f "$OBJFILE" 2>/dev/null
1487		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1488
1489		COUNT=0
1490		FAILED=0
1491		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1492
1493		# BLAKE2_NEON_Compress32: 30 each vld1q_u8 and vld1q_u64
1494		# BLAKE2_NEON_Compress64: 22 each vld1q_u8 and vld1q_u64
1495		COUNT1=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c 'ldr.*q|vld.*128')
1496		COUNT2=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c 'ldp.*q')
1497		COUNT=$(($COUNT1 + $(($COUNT2 + $COUNT2))))
1498		if [[ ("$COUNT" -lt "25") ]]; then
1499			FAILED=1
1500			echo "ERROR: failed to generate expected vector load instructions" | tee -a "$TEST_RESULTS"
1501		fi
1502
1503		# BLAKE2_NEON_Compress{32|64}: 6 each vst1q_u32 and vst1q_u64
1504		COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c 'str.*q|vstr')
1505		if [[ ("$COUNT" -lt "6") ]]; then
1506			FAILED=1
1507			echo "ERROR: failed to generate expected vector store instructions" | tee -a "$TEST_RESULTS"
1508		fi
1509
1510		# BLAKE2_NEON_Compress{32|64}: 409 each vaddq_u32 and vaddq_u64
1511		COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c 'add.*v|vadd')
1512		if [[ ("$COUNT" -lt "400") ]]; then
1513			FAILED=1
1514			echo "ERROR: failed to generate expected vector add instructions" | tee -a "$TEST_RESULTS"
1515		fi
1516
1517		# BLAKE2_NEON_Compress{32|64}: 559 each veorq_u32 and veorq_u64
1518		COUNT=$(echo -n "$DISASS_TEXT" | "$EGREP" -i -c 'eor.*v|veor')
1519		if [[ ("$COUNT" -lt "550") ]]; then
1520			FAILED=1
1521			echo "ERROR: failed to generate expected vector xor instructions" | tee -a "$TEST_RESULTS"
1522		fi
1523
1524		if [[ ("$FAILED" -eq "0") ]]; then
1525			echo "Verified vector load, store, add, xor machine instructions" | tee -a "$TEST_RESULTS"
1526		fi
1527	fi
1528
1529	############################################
1530	# ARM carryless multiply code generation
1531
1532	ARM_PMULL=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c pmull)
1533	if [[ ("$ARM_PMULL" -ne "0" || "$HAVE_ARM_CRYPTO" -ne "0") ]]; then
1534		echo
1535		echo "************************************" | tee -a "$TEST_RESULTS"
1536		echo "Testing: ARM carryless multiply code generation" | tee -a "$TEST_RESULTS"
1537		echo
1538
1539		OBJFILE=gcm.o; rm -f "$OBJFILE" 2>/dev/null
1540		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1541
1542		COUNT=0
1543		FAILED=0
1544		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1545
1546		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -v pmull2 | "$GREP" -i -c pmull)
1547		if [[ ("$COUNT" -eq "0") ]]; then
1548			FAILED=1
1549			echo "ERROR: failed to generate pmull instruction" | tee -a "$TEST_RESULTS"
1550		fi
1551
1552		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c pmull2)
1553		if [[ ("$COUNT" -eq "0") ]]; then
1554			FAILED=1
1555			echo "ERROR: failed to generate pmull2 instruction" | tee -a "$TEST_RESULTS"
1556		fi
1557
1558		if [[ ("$FAILED" -eq "0") ]]; then
1559			echo "Verified pmull and pmull2 machine instructions" | tee -a "$TEST_RESULTS"
1560		fi
1561	fi
1562
1563	############################################
1564	# ARM CRC32 code generation
1565
1566	ARM_CRC32=$(echo -n "$ARM_CPU_FLAGS" | "$GREP" -i -c crc32)
1567	if [[ ("$ARM_CRC32" -ne "0") ]]; then
1568		echo
1569		echo "************************************" | tee -a "$TEST_RESULTS"
1570		echo "Testing: ARM CRC32 code generation" | tee -a "$TEST_RESULTS"
1571		echo
1572
1573		OBJFILE=crc.o; rm -f "$OBJFILE" 2>/dev/null
1574		CXX="$CXX" CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}" "$MAKE" "${MAKEARGS[@]}" $OBJFILE 2>&1 | tee -a "$TEST_RESULTS"
1575
1576		COUNT=0
1577		FAILED=0
1578		DISASS_TEXT=$("$DISASS" "${DISASSARGS[@]}" "$OBJFILE" 2>/dev/null)
1579
1580		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c crc32cb)
1581		if [[ ("$COUNT" -eq "0") ]]; then
1582			FAILED=1
1583			echo "ERROR: failed to generate crc32cb instruction" | tee -a "$TEST_RESULTS"
1584		fi
1585
1586		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c crc32cw)
1587		if [[ ("$COUNT" -eq "0") ]]; then
1588			FAILED=1
1589			echo "ERROR: failed to generate crc32cw instruction" | tee -a "$TEST_RESULTS"
1590		fi
1591
1592		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c crc32b)
1593		if [[ ("$COUNT" -eq "0") ]]; then
1594			FAILED=1
1595			echo "ERROR: failed to generate crc32b instruction" | tee -a "$TEST_RESULTS"
1596		fi
1597
1598		COUNT=$(echo -n "$DISASS_TEXT" | "$GREP" -i -c crc32w)
1599		if [[ ("$COUNT" -eq "0") ]]; then
1600			FAILED=1
1601			echo "ERROR: failed to generate crc32w instruction" | tee -a "$TEST_RESULTS"
1602		fi
1603
1604		if [[ ("$FAILED" -eq "0") ]]; then
1605			echo "Verified crc32cb, crc32cw, crc32b and crc32w machine instructions" | tee -a "$TEST_RESULTS"
1606		fi
1607	fi
1608fi
1609
1610############################################
1611# Default CXXFLAGS
1612if true; then
1613	############################################
1614	# Debug build
1615	echo
1616	echo "************************************" | tee -a "$TEST_RESULTS"
1617	echo "Testing: Debug, default CXXFLAGS" | tee -a "$TEST_RESULTS"
1618	echo
1619
1620	"$MAKE" clean > /dev/null 2>&1
1621	rm -f adhoc.cpp > /dev/null 2>&1
1622
1623	CXXFLAGS="$DEBUG_CXXFLAGS"
1624	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1625
1626	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1627		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1628	else
1629		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1630		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1631			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1632		fi
1633		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1634		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1635			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1636		fi
1637	fi
1638
1639	############################################
1640	# Release build
1641	echo
1642	echo "************************************" | tee -a "$TEST_RESULTS"
1643	echo "Testing: Release, default CXXFLAGS" | tee -a "$TEST_RESULTS"
1644	echo
1645
1646	"$MAKE" clean > /dev/null 2>&1
1647	rm -f adhoc.cpp > /dev/null 2>&1
1648
1649	CXXFLAGS="$RELEASE_CXXFLAGS"
1650	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1651
1652	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1653		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1654	else
1655		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1656		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1657			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1658		fi
1659		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1660		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1661			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1662		fi
1663		echo
1664	fi
1665fi
1666
1667############################################
1668# Platform CXXFLAGS
1669if [[ ("${#PLATFORM_CXXFLAGS[@]}" -ne "0") ]]; then
1670
1671	############################################
1672	# Debug build, platform defines
1673	echo
1674	echo "************************************" | tee -a "$TEST_RESULTS"
1675	echo "Testing: Debug, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
1676	echo
1677
1678	"$MAKE" clean > /dev/null 2>&1
1679	rm -f adhoc.cpp > /dev/null 2>&1
1680
1681	CXXFLAGS="$DEBUG_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}"
1682	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1683
1684	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1685		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1686	else
1687		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1688		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1689			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1690		fi
1691		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1692		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1693			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1694		fi
1695	fi
1696
1697	############################################
1698	# Release build, platform defines
1699	echo
1700	echo "************************************" | tee -a "$TEST_RESULTS"
1701	echo "Testing: Release, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
1702	echo
1703
1704	"$MAKE" clean > /dev/null 2>&1
1705	rm -f adhoc.cpp > /dev/null 2>&1
1706
1707	CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]}"
1708	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1709
1710	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1711		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1712	else
1713		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1714		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1715			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1716		fi
1717		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1718		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1719			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1720		fi
1721	fi
1722fi
1723
1724############################################
1725# Minimum platform
1726if [[ ("$GCC_COMPILER" -ne "0" || "$CLANG_COMPILER" -ne "0" || "$INTEL_COMPILER" -ne "0") ]]; then
1727
1728	# i586 (lacks MMX, SSE and SSE2)
1729	if [[ "$IS_X86" -ne "0" ]]; then
1730		############################################
1731		# Debug build
1732		echo
1733		echo "************************************" | tee -a "$TEST_RESULTS"
1734		echo "Testing: Debug, i586 minimum arch CXXFLAGS" | tee -a "$TEST_RESULTS"
1735		echo
1736
1737		"$MAKE" clean > /dev/null 2>&1
1738		rm -f adhoc.cpp > /dev/null 2>&1
1739
1740		CXXFLAGS="$DEBUG_CXXFLAGS -march=i586 $OPT_PIC"
1741		CXX="$CXX" "$MAKE" "${MAKEARGS[@]}" CXXFLAGS="$CXXFLAGS" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1742
1743		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1744			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1745		else
1746			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1747			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1748				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1749			fi
1750			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1751			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1752				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1753			fi
1754		fi
1755
1756		############################################
1757		# Release build
1758		echo
1759		echo "************************************" | tee -a "$TEST_RESULTS"
1760		echo "Testing: Release, i586 minimum arch CXXFLAGS" | tee -a "$TEST_RESULTS"
1761		echo
1762
1763		"$MAKE" clean > /dev/null 2>&1
1764		rm -f adhoc.cpp > /dev/null 2>&1
1765
1766		CXXFLAGS="$RELEASE_CXXFLAGS -march=i586 $OPT_PIC"
1767		CXX="$CXX" "$MAKE" "${MAKEARGS[@]}" CXXFLAGS="$CXXFLAGS" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1768
1769		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1770			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1771		else
1772			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1773			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1774				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1775			fi
1776			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1777			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1778				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1779			fi
1780		fi
1781	fi
1782
1783	# x86_64
1784	if [[ "$IS_X64" -ne "0" ]]; then
1785		############################################
1786		# Debug build
1787		echo
1788		echo "************************************" | tee -a "$TEST_RESULTS"
1789		echo "Testing: Debug, x86_64 minimum arch CXXFLAGS" | tee -a "$TEST_RESULTS"
1790		echo
1791
1792		"$MAKE" clean > /dev/null 2>&1
1793		rm -f adhoc.cpp > /dev/null 2>&1
1794
1795		CXXFLAGS="$DEBUG_CXXFLAGS -march=x86-64 $OPT_PIC"
1796		CXX="$CXX" "$MAKE" "${MAKEARGS[@]}" CXXFLAGS="$CXXFLAGS" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1797
1798		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1799			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1800		else
1801			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1802			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1803				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1804			fi
1805			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1806			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1807				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1808			fi
1809		fi
1810
1811		############################################
1812		# Release build
1813		echo
1814		echo "************************************" | tee -a "$TEST_RESULTS"
1815		echo "Testing: Release, x86_64 minimum arch CXXFLAGS" | tee -a "$TEST_RESULTS"
1816		echo
1817
1818		"$MAKE" clean > /dev/null 2>&1
1819		rm -f adhoc.cpp > /dev/null 2>&1
1820
1821		CXXFLAGS="$RELEASE_CXXFLAGS -march=x86-64 $OPT_PIC"
1822		CXX="$CXX" "$MAKE" "${MAKEARGS[@]}" CXXFLAGS="$CXXFLAGS" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1823
1824		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1825			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1826		else
1827			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1828			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1829				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1830			fi
1831			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1832			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1833				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1834			fi
1835		fi
1836	fi
1837fi
1838
1839############################################
1840# Minimum arch with AESNI, RDRAND and RDSEED
1841if [[ ("$GCC_COMPILER" -ne "0" || "$CLANG_COMPILER" -ne "0" || "$INTEL_COMPILER" -ne "0") ]]; then
1842
1843	X86_OPTS=()
1844	if [[ "$HAVE_X86_AES" -ne "0" ]]; then
1845		X86_OPTS+=("-maes")
1846	fi
1847	if [[ "$HAVE_X86_RDRAND" -ne "0" ]]; then
1848		X86_OPTS+=("-mrdrnd")
1849	fi
1850	if [[ "$HAVE_X86_RDSEED" -ne "0" ]]; then
1851		X86_OPTS+=("-mrdseed")
1852	fi
1853
1854	# i586 (lacks MMX, SSE and SSE2; enables X86 hardware)
1855	if [[ "$IS_X86" -ne "0" ]]; then
1856		############################################
1857		# Debug build
1858		echo
1859		echo "************************************" | tee -a "$TEST_RESULTS"
1860		echo "Testing: Debug, i586, AESNI, RDRAND and RDSEED" | tee -a "$TEST_RESULTS"
1861		echo
1862
1863		"$MAKE" clean > /dev/null 2>&1
1864		rm -f adhoc.cpp > /dev/null 2>&1
1865
1866		CXXFLAGS="$DEBUG_CXXFLAGS -march=i586 ${X86_OPTS[@]} $OPT_PIC"
1867		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1868
1869		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1870			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1871		else
1872			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1873			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1874				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1875			fi
1876			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1877			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1878				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1879			fi
1880		fi
1881
1882		############################################
1883		# Release build
1884		echo
1885		echo "************************************" | tee -a "$TEST_RESULTS"
1886		echo "Testing: Release, i586, AESNI, RDRAND and RDSEED" | tee -a "$TEST_RESULTS"
1887		echo
1888
1889		"$MAKE" clean > /dev/null 2>&1
1890		rm -f adhoc.cpp > /dev/null 2>&1
1891
1892		CXXFLAGS="$RELEASE_CXXFLAGS -march=i586 ${X86_OPTS[@]} $OPT_PIC"
1893		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1894
1895		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1896			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1897		else
1898			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1899			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1900				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1901			fi
1902			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1903			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1904				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1905			fi
1906		fi
1907	fi
1908
1909	# x86-64
1910	if [[ "$IS_X64" -ne "0" ]]; then
1911		############################################
1912		# Debug build
1913		echo
1914		echo "************************************" | tee -a "$TEST_RESULTS"
1915		echo "Testing: Debug, SSE2, AESNI, RDRAND and RDSEED" | tee -a "$TEST_RESULTS"
1916		echo
1917
1918		"$MAKE" clean > /dev/null 2>&1
1919		rm -f adhoc.cpp > /dev/null 2>&1
1920
1921		CXXFLAGS="$DEBUG_CXXFLAGS -march=x86-64 ${X86_OPTS[@]} $OPT_PIC"
1922		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1923
1924		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1925			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1926		else
1927			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1928			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1929				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1930			fi
1931			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1932			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1933				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1934			fi
1935		fi
1936
1937		############################################
1938		# Release build
1939		echo
1940		echo "************************************" | tee -a "$TEST_RESULTS"
1941		echo "Testing: Release, SSE2, AESNI, RDRAND and RDSEED" | tee -a "$TEST_RESULTS"
1942		echo
1943
1944		"$MAKE" clean > /dev/null 2>&1
1945		rm -f adhoc.cpp > /dev/null 2>&1
1946
1947		CXXFLAGS="$RELEASE_CXXFLAGS -march=x86-64 ${X86_OPTS[@]} $OPT_PIC"
1948		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1949
1950		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1951			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1952		else
1953			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1954			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1955				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1956			fi
1957			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1958			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1959				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1960			fi
1961		fi
1962	fi
1963fi
1964
1965############################################
1966# mismatched arch capabilities
1967if [[ ("$GCC_COMPILER" -ne "0" || "$CLANG_COMPILER" -ne "0" || "$INTEL_COMPILER" -ne "0") ]]; then
1968
1969	# i586 (lacks MMX, SSE and SSE2)
1970	if [[ "$IS_X86" -ne "0" ]]; then
1971		############################################
1972		# Debug build
1973		echo
1974		echo "************************************" | tee -a "$TEST_RESULTS"
1975		echo "Testing: Debug, mismatched arch capabilities" | tee -a "$TEST_RESULTS"
1976		echo
1977
1978		"$MAKE" clean > /dev/null 2>&1
1979		rm -f adhoc.cpp > /dev/null 2>&1
1980
1981		CXXFLAGS="$DEBUG_CXXFLAGS -march=i586 $OPT_PIC"
1982		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static 2>&1 | tee -a "$TEST_RESULTS"
1983
1984		CXXFLAGS="$DEBUG_CXXFLAGS -march=native $OPT_PIC"
1985		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
1986
1987		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1988			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
1989		else
1990			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
1991			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1992				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
1993			fi
1994			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
1995			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
1996				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
1997			fi
1998		fi
1999
2000		############################################
2001		# Release build
2002		echo
2003		echo "************************************" | tee -a "$TEST_RESULTS"
2004		echo "Testing: Release, mismatched arch capabilities" | tee -a "$TEST_RESULTS"
2005		echo
2006
2007		"$MAKE" clean > /dev/null 2>&1
2008		rm -f adhoc.cpp > /dev/null 2>&1
2009
2010		CXXFLAGS="$RELEASE_CXXFLAGS -march=i586 $OPT_PIC"
2011		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static 2>&1 | tee -a "$TEST_RESULTS"
2012
2013		CXXFLAGS="$RELEASE_CXXFLAGS -march=native $OPT_PIC"
2014		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2015
2016		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2017			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2018		else
2019			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2020			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2021				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2022			fi
2023			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2024			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2025				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2026			fi
2027		fi
2028	fi
2029
2030	# x86-64
2031	if [[ "$IS_X64" -ne "0" ]]; then
2032		############################################
2033		# Debug build
2034		echo
2035		echo "************************************" | tee -a "$TEST_RESULTS"
2036		echo "Testing: Debug, mismatched arch capabilities" | tee -a "$TEST_RESULTS"
2037		echo
2038
2039		"$MAKE" clean > /dev/null 2>&1
2040		rm -f adhoc.cpp > /dev/null 2>&1
2041
2042		CXXFLAGS="$DEBUG_CXXFLAGS -march=x86-64 $OPT_PIC"
2043		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static 2>&1 | tee -a "$TEST_RESULTS"
2044
2045		CXXFLAGS="$DEBUG_CXXFLAGS -march=native $OPT_PIC"
2046		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2047
2048		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2049			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2050		else
2051			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2052			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2053				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2054			fi
2055			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2056			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2057				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2058			fi
2059		fi
2060
2061		############################################
2062		# Release build
2063		echo
2064		echo "************************************" | tee -a "$TEST_RESULTS"
2065		echo "Testing: Release, mismatched arch capabilities" | tee -a "$TEST_RESULTS"
2066		echo
2067
2068		"$MAKE" clean > /dev/null 2>&1
2069		rm -f adhoc.cpp > /dev/null 2>&1
2070
2071		CXXFLAGS="$RELEASE_CXXFLAGS -march=x86-64 $OPT_PIC"
2072		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static 2>&1 | tee -a "$TEST_RESULTS"
2073
2074		CXXFLAGS="$RELEASE_CXXFLAGS -march=native $OPT_PIC"
2075		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2076
2077		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2078			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2079		else
2080			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2081			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2082				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2083			fi
2084			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2085			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2086				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2087			fi
2088		fi
2089	fi
2090fi
2091
2092############################################
2093# Debug build, DISABLE_ASM
2094if true; then
2095
2096	############################################
2097	# Debug build
2098	echo
2099	echo "************************************" | tee -a "$TEST_RESULTS"
2100	echo "Testing: Debug, DISABLE_ASM" | tee -a "$TEST_RESULTS"
2101	echo
2102
2103	"$MAKE" clean > /dev/null 2>&1
2104	rm -f adhoc.cpp > /dev/null 2>&1
2105
2106	CXXFLAGS="$DEBUG_CXXFLAGS -DCRYPTOPP_DISABLE_ASM"
2107	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2108
2109	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2110		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2111	else
2112		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2113		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2114			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2115		fi
2116		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2117		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2118			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2119		fi
2120	fi
2121
2122	############################################
2123	# Release build
2124	echo
2125	echo "************************************" | tee -a "$TEST_RESULTS"
2126	echo "Testing: Release, DISABLE_ASM" | tee -a "$TEST_RESULTS"
2127	echo
2128
2129	"$MAKE" clean > /dev/null 2>&1
2130	rm -f adhoc.cpp > /dev/null 2>&1
2131
2132	CXXFLAGS="$RELEASE_CXXFLAGS -DCRYPTOPP_DISABLE_ASM"
2133	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2134
2135	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2136		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2137	else
2138		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2139		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2140			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2141		fi
2142		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2143		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2144			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2145		fi
2146	fi
2147fi
2148
2149############################################
2150# c++03 debug and release build
2151if [[ "$HAVE_CXX03" -ne "0" ]]; then
2152
2153	############################################
2154	# Debug build
2155	echo
2156	echo "************************************" | tee -a "$TEST_RESULTS"
2157	echo "Testing: Debug, c++03" | tee -a "$TEST_RESULTS"
2158	echo
2159
2160	"$MAKE" clean > /dev/null 2>&1
2161	rm -f adhoc.cpp > /dev/null 2>&1
2162
2163	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2164	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2165
2166	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2167		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2168	else
2169		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2170		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2171			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2172		fi
2173		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2174		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2175			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2176		fi
2177	fi
2178
2179	############################################
2180	# Release build
2181	echo
2182	echo "************************************" | tee -a "$TEST_RESULTS"
2183	echo "Testing: Release, c++03" | tee -a "$TEST_RESULTS"
2184	echo
2185
2186	"$MAKE" clean > /dev/null 2>&1
2187	rm -f adhoc.cpp > /dev/null 2>&1
2188
2189	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2190	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2191
2192	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2193		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2194	else
2195		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2196		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2197			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2198		fi
2199		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2200		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2201			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2202		fi
2203	fi
2204fi
2205
2206############################################
2207# gnu++03 debug and release build
2208if [[ "$HAVE_GNU03" -ne "0" ]]; then
2209
2210	############################################
2211	# Debug build
2212	echo
2213	echo "************************************" | tee -a "$TEST_RESULTS"
2214	echo "Testing: Debug, gnu++03" | tee -a "$TEST_RESULTS"
2215	echo
2216
2217	"$MAKE" clean > /dev/null 2>&1
2218	rm -f adhoc.cpp > /dev/null 2>&1
2219
2220	CXXFLAGS="$DEBUG_CXXFLAGS -std=gnu++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2221	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2222
2223	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2224		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2225	else
2226		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2227		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2228			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2229		fi
2230		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2231		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2232			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2233		fi
2234	fi
2235
2236	############################################
2237	# Release build
2238	echo
2239	echo "************************************" | tee -a "$TEST_RESULTS"
2240	echo "Testing: Release, gnu++03" | tee -a "$TEST_RESULTS"
2241	echo
2242
2243	"$MAKE" clean > /dev/null 2>&1
2244	rm -f adhoc.cpp > /dev/null 2>&1
2245
2246	CXXFLAGS="$RELEASE_CXXFLAGS -std=gnu++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2247	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2248
2249	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2250		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2251	else
2252		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2253		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2254			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2255		fi
2256		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2257		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2258			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2259		fi
2260	fi
2261fi
2262
2263############################################
2264# c++11 debug and release build
2265if [[ "$HAVE_CXX11" -ne "0" ]]; then
2266
2267	############################################
2268	# Debug build
2269	echo
2270	echo "************************************" | tee -a "$TEST_RESULTS"
2271	echo "Testing: Debug, c++11" | tee -a "$TEST_RESULTS"
2272	echo
2273
2274	"$MAKE" clean > /dev/null 2>&1
2275	rm -f adhoc.cpp > /dev/null 2>&1
2276
2277	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2278	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2279
2280	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2281		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2282	else
2283		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2284		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2285			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2286		fi
2287		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2288		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2289			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2290		fi
2291	fi
2292
2293	############################################
2294	# Release build
2295	echo
2296	echo "************************************" | tee -a "$TEST_RESULTS"
2297	echo "Testing: Release, c++11" | tee -a "$TEST_RESULTS"
2298	echo
2299
2300	"$MAKE" clean > /dev/null 2>&1
2301	rm -f adhoc.cpp > /dev/null 2>&1
2302
2303	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2304	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2305
2306	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2307		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2308	else
2309		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2310		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2311			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2312		fi
2313		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2314		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2315			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2316		fi
2317	fi
2318fi
2319
2320############################################
2321# gnu++11 debug and release build
2322if [[ "$HAVE_GNU11" -ne "0" ]]; then
2323
2324	############################################
2325	# Debug build
2326	echo
2327	echo "************************************" | tee -a "$TEST_RESULTS"
2328	echo "Testing: Debug, gnu++11" | tee -a "$TEST_RESULTS"
2329	echo
2330
2331	"$MAKE" clean > /dev/null 2>&1
2332	rm -f adhoc.cpp > /dev/null 2>&1
2333
2334	CXXFLAGS="$DEBUG_CXXFLAGS -std=gnu++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2335	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2336
2337	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2338		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2339	else
2340		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2341		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2342			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2343		fi
2344		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2345		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2346			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2347		fi
2348	fi
2349
2350	############################################
2351	# Release build
2352	echo
2353	echo "************************************" | tee -a "$TEST_RESULTS"
2354	echo "Testing: Release, gnu++11" | tee -a "$TEST_RESULTS"
2355	echo
2356
2357	"$MAKE" clean > /dev/null 2>&1
2358	rm -f adhoc.cpp > /dev/null 2>&1
2359
2360	CXXFLAGS="$RELEASE_CXXFLAGS -std=gnu++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2361	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2362
2363	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2364		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2365	else
2366		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2367		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2368			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2369		fi
2370		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2371		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2372			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2373		fi
2374	fi
2375fi
2376
2377############################################
2378# c++14 debug and release build
2379if [[ "$HAVE_CXX14" -ne "0" ]]; then
2380
2381	############################################
2382	# Debug build
2383	echo
2384	echo "************************************" | tee -a "$TEST_RESULTS"
2385	echo "Testing: Debug, c++14" | tee -a "$TEST_RESULTS"
2386	echo
2387
2388	"$MAKE" clean > /dev/null 2>&1
2389	rm -f adhoc.cpp > /dev/null 2>&1
2390
2391	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2392	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2393
2394	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2395		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2396	else
2397		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2398		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2399			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2400		fi
2401		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2402		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2403			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2404		fi
2405	fi
2406
2407	############################################
2408	# Release build
2409	echo
2410	echo "************************************" | tee -a "$TEST_RESULTS"
2411	echo "Testing: Release, c++14" | tee -a "$TEST_RESULTS"
2412	echo
2413
2414	"$MAKE" clean > /dev/null 2>&1
2415	rm -f adhoc.cpp > /dev/null 2>&1
2416
2417	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2418	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2419
2420	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2421		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2422	else
2423		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2424		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2425			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2426		fi
2427		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2428		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2429			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2430		fi
2431	fi
2432fi
2433
2434############################################
2435# gnu++14 debug and release build
2436if [[ "$HAVE_GNU14" -ne "0" ]]; then
2437
2438	############################################
2439	# Debug build
2440	echo
2441	echo "************************************" | tee -a "$TEST_RESULTS"
2442	echo "Testing: Debug, gnu++14" | tee -a "$TEST_RESULTS"
2443	echo
2444
2445	"$MAKE" clean > /dev/null 2>&1
2446	rm -f adhoc.cpp > /dev/null 2>&1
2447
2448	CXXFLAGS="$DEBUG_CXXFLAGS -std=gnu++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2449	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2450
2451	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2452		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2453	else
2454		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2455		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2456			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2457		fi
2458		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2459		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2460			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2461		fi
2462	fi
2463
2464	############################################
2465	# Release build
2466	echo
2467	echo "************************************" | tee -a "$TEST_RESULTS"
2468	echo "Testing: Release, gnu++14" | tee -a "$TEST_RESULTS"
2469	echo
2470
2471	"$MAKE" clean > /dev/null 2>&1
2472	rm -f adhoc.cpp > /dev/null 2>&1
2473
2474	CXXFLAGS="$RELEASE_CXXFLAGS -std=gnu++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2475	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2476
2477	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2478		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2479	else
2480		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2481		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2482			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2483		fi
2484		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2485		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2486			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2487		fi
2488	fi
2489fi
2490
2491############################################
2492# c++17 debug and release build
2493if [[ "$HAVE_CXX17" -ne "0" ]]; then
2494
2495	############################################
2496	# Debug build
2497	echo
2498	echo "************************************" | tee -a "$TEST_RESULTS"
2499	echo "Testing: Debug, c++17" | tee -a "$TEST_RESULTS"
2500	echo
2501
2502	"$MAKE" clean > /dev/null 2>&1
2503	rm -f adhoc.cpp > /dev/null 2>&1
2504
2505	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2506	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2507
2508	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2509		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2510	else
2511		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2512		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2513			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2514		fi
2515		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2516		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2517			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2518		fi
2519	fi
2520
2521	############################################
2522	# Release build
2523	echo
2524	echo "************************************" | tee -a "$TEST_RESULTS"
2525	echo "Testing: Release, c++17" | tee -a "$TEST_RESULTS"
2526	echo
2527
2528	"$MAKE" clean > /dev/null 2>&1
2529	rm -f adhoc.cpp > /dev/null 2>&1
2530
2531	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2532	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2533
2534	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2535		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2536	else
2537		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2538		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2539			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2540		fi
2541		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2542		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2543			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2544		fi
2545	fi
2546fi
2547
2548############################################
2549# gnu++17 debug and release build
2550if [[ "$HAVE_GNU17" -ne "0" ]]; then
2551
2552	############################################
2553	# Debug build
2554	echo
2555	echo "************************************" | tee -a "$TEST_RESULTS"
2556	echo "Testing: Debug, gnu++17" | tee -a "$TEST_RESULTS"
2557	echo
2558
2559	"$MAKE" clean > /dev/null 2>&1
2560	rm -f adhoc.cpp > /dev/null 2>&1
2561
2562	CXXFLAGS="$DEBUG_CXXFLAGS -std=gnu++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2563	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2564
2565	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2566		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2567	else
2568		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2569		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2570			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2571		fi
2572		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2573		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2574			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2575		fi
2576	fi
2577
2578	############################################
2579	# Release build
2580	echo
2581	echo "************************************" | tee -a "$TEST_RESULTS"
2582	echo "Testing: Release, gnu++17" | tee -a "$TEST_RESULTS"
2583	echo
2584
2585	"$MAKE" clean > /dev/null 2>&1
2586	rm -f adhoc.cpp > /dev/null 2>&1
2587
2588	CXXFLAGS="$RELEASE_CXXFLAGS -std=gnu++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2589	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2590
2591	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2592		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2593	else
2594		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2595		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2596			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2597		fi
2598		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2599		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2600			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2601		fi
2602	fi
2603fi
2604
2605############################################
2606# X32 debug and release build
2607if [[ "$HAVE_X32" -ne "0" ]]; then
2608
2609	############################################
2610	# Debug build
2611	echo
2612	echo "************************************" | tee -a "$TEST_RESULTS"
2613	echo "Testing: Debug, X32" | tee -a "$TEST_RESULTS"
2614	echo
2615
2616	"$MAKE" clean > /dev/null 2>&1
2617	rm -f adhoc.cpp > /dev/null 2>&1
2618
2619	CXXFLAGS="$DEBUG_CXXFLAGS -mx32 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2620	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2621
2622	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2623		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2624	else
2625		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2626		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2627			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2628		fi
2629		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2630		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2631			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2632		fi
2633	fi
2634
2635	############################################
2636	# Release build
2637	echo
2638	echo "************************************" | tee -a "$TEST_RESULTS"
2639	echo "Testing: Release, X32" | tee -a "$TEST_RESULTS"
2640	echo
2641
2642	"$MAKE" clean > /dev/null 2>&1
2643	rm -f adhoc.cpp > /dev/null 2>&1
2644
2645	CXXFLAGS="$RELEASE_CXXFLAGS -mx32 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2646	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2647
2648	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2649		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2650	else
2651		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2652		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2653			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2654		fi
2655		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2656		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2657			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2658		fi
2659	fi
2660fi
2661
2662############################################
2663# init_priority
2664if true; then
2665
2666	############################################
2667	# Debug build
2668	echo
2669	echo "************************************" | tee -a "$TEST_RESULTS"
2670	echo "Testing: Debug, INIT_PRIORITY (0)" | tee -a "$TEST_RESULTS"
2671	echo
2672
2673	"$MAKE" clean > /dev/null 2>&1
2674	rm -f adhoc.cpp > /dev/null 2>&1
2675
2676	CXXFLAGS="$DEBUG_CXXFLAGS -DCRYPTOPP_INIT_PRIORITY=0 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2677	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2678
2679	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2680		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2681	else
2682		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2683		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2684			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2685		fi
2686		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2687		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2688			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2689		fi
2690	fi
2691
2692	############################################
2693	# Release build
2694	echo
2695	echo "************************************" | tee -a "$TEST_RESULTS"
2696	echo "Testing: Release, INIT_PRIORITY (0)" | tee -a "$TEST_RESULTS"
2697	echo
2698
2699	"$MAKE" clean > /dev/null 2>&1
2700	rm -f adhoc.cpp > /dev/null 2>&1
2701
2702	CXXFLAGS="$RELEASE_CXXFLAGS -DCRYPTOPP_INIT_PRIORITY=0 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2703	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2704
2705	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2706		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2707	else
2708		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2709		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2710			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2711		fi
2712		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2713		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2714			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2715		fi
2716	fi
2717fi
2718
2719############################################
2720# OS Independence
2721if true; then
2722
2723	############################################
2724	# Debug build
2725	echo
2726	echo "************************************" | tee -a "$TEST_RESULTS"
2727	echo "Testing: Debug, NO_OS_DEPENDENCE" | tee -a "$TEST_RESULTS"
2728	echo
2729
2730	"$MAKE" clean > /dev/null 2>&1
2731	rm -f adhoc.cpp > /dev/null 2>&1
2732
2733	CXXFLAGS="$DEBUG_CXXFLAGS -DNO_OS_DEPENDENCE ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2734	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2735
2736	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2737		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2738	else
2739		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2740		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2741			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2742		fi
2743		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2744		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2745			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2746		fi
2747	fi
2748
2749	############################################
2750	# Release build
2751	echo
2752	echo "************************************" | tee -a "$TEST_RESULTS"
2753	echo "Testing: Release, NO_OS_DEPENDENCE" | tee -a "$TEST_RESULTS"
2754	echo
2755
2756	"$MAKE" clean > /dev/null 2>&1
2757	rm -f adhoc.cpp > /dev/null 2>&1
2758
2759	CXXFLAGS="$RELEASE_CXXFLAGS -DNO_OS_DEPENDENCE ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2760	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2761
2762	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2763		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2764	else
2765		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2766		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2767			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2768		fi
2769		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2770		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2771			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2772		fi
2773	fi
2774fi
2775
2776############################################
2777# Build with LD-Gold
2778if [[ "$HAVE_LDGOLD" -ne "0" ]]; then
2779
2780	############################################
2781	# Debug build
2782	echo
2783	echo "************************************" | tee -a "$TEST_RESULTS"
2784	echo "Testing: Debug, ld-gold linker" | tee -a "$TEST_RESULTS"
2785	echo
2786
2787	"$MAKE" clean > /dev/null 2>&1
2788	rm -f adhoc.cpp > /dev/null 2>&1
2789
2790	CXXFLAGS="$DEBUG_CXXFLAGS ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2791	CXX="$CXX" CXXFLAGS="$CXXFLAGS" LD="ld.gold" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2792
2793	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2794		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2795	else
2796		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2797		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2798			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2799		fi
2800		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2801		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2802			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2803		fi
2804	fi
2805
2806	############################################
2807	# Release build
2808	echo
2809	echo "************************************" | tee -a "$TEST_RESULTS"
2810	echo "Testing: Release, ld-gold linker" | tee -a "$TEST_RESULTS"
2811	echo
2812
2813	"$MAKE" clean > /dev/null 2>&1
2814	rm -f adhoc.cpp > /dev/null 2>&1
2815
2816	CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2817	CXX="$CXX" CXXFLAGS="$CXXFLAGS" LD="ld.gold" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2818
2819	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2820		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2821	else
2822		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2823		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2824			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2825		fi
2826		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2827		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2828			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2829		fi
2830	fi
2831fi
2832
2833############################################
2834# Build with Unified ASM
2835if [[ "$HAVE_UNIFIED_ASM" -ne "0" ]]; then
2836
2837	############################################
2838	# Debug build
2839	echo
2840	echo "************************************" | tee -a "$TEST_RESULTS"
2841	echo "Testing: Debug, unified asm syntax" | tee -a "$TEST_RESULTS"
2842	echo
2843
2844	"$MAKE" clean > /dev/null 2>&1
2845	rm -f adhoc.cpp > /dev/null 2>&1
2846
2847	CXXFLAGS="$DEBUG_CXXFLAGS ${PLATFORM_CXXFLAGS[@]} -masm-syntax-unified $USER_CXXFLAGS"
2848	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2849
2850	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2851		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2852	else
2853		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2854		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2855			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2856		fi
2857		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2858		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2859			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2860		fi
2861	fi
2862
2863	############################################
2864	# Release build
2865	echo
2866	echo "************************************" | tee -a "$TEST_RESULTS"
2867	echo "Testing: Release, unified asm syntax" | tee -a "$TEST_RESULTS"
2868	echo
2869
2870	"$MAKE" clean > /dev/null 2>&1
2871	rm -f adhoc.cpp > /dev/null 2>&1
2872
2873	CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]} -masm-syntax-unified $USER_CXXFLAGS"
2874	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2875
2876	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2877		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2878	else
2879		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2880		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2881			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2882		fi
2883		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2884		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2885			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2886		fi
2887	fi
2888fi
2889
2890############################################
2891# Build at -O3
2892if [[ "$HAVE_O3" -ne "0" ]]; then
2893
2894	############################################
2895	# Debug build
2896	echo
2897	echo "************************************" | tee -a "$TEST_RESULTS"
2898	echo "Testing: Debug, -O3 optimizations" | tee -a "$TEST_RESULTS"
2899	echo
2900
2901	"$MAKE" clean > /dev/null 2>&1
2902	rm -f adhoc.cpp > /dev/null 2>&1
2903
2904	CXXFLAGS="-DDEBUG $OPT_O3 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2905	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2906
2907	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2908		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2909	else
2910		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2911		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2912			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2913		fi
2914		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2915		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2916			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2917		fi
2918	fi
2919
2920	############################################
2921	# Release build
2922	echo
2923	echo "************************************" | tee -a "$TEST_RESULTS"
2924	echo "Testing: Release, -O3 optimizations" | tee -a "$TEST_RESULTS"
2925	echo
2926
2927	"$MAKE" clean > /dev/null 2>&1
2928	rm -f adhoc.cpp > /dev/null 2>&1
2929
2930	CXXFLAGS="-DNDEBUG $OPT_O3 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2931	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2932
2933	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2934		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2935	else
2936		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2937		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2938			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2939		fi
2940		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2941		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2942			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2943		fi
2944	fi
2945fi
2946
2947############################################
2948# Build at -O5
2949if [[ "$HAVE_O5" -ne "0" ]]; then
2950
2951	############################################
2952	# Debug build
2953	echo
2954	echo "************************************" | tee -a "$TEST_RESULTS"
2955	echo "Testing: Debug, -O5 optimizations" | tee -a "$TEST_RESULTS"
2956	echo
2957
2958	"$MAKE" clean > /dev/null 2>&1
2959	rm -f adhoc.cpp > /dev/null 2>&1
2960
2961	CXXFLAGS="-DDEBUG $OPT_O5 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2962	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2963
2964	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2965		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2966	else
2967		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2968		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2969			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2970		fi
2971		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2972		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2973			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
2974		fi
2975	fi
2976
2977	############################################
2978	# Release build
2979	echo
2980	echo "************************************" | tee -a "$TEST_RESULTS"
2981	echo "Testing: Release, -O5 optimizations" | tee -a "$TEST_RESULTS"
2982	echo
2983
2984	"$MAKE" clean > /dev/null 2>&1
2985	rm -f adhoc.cpp > /dev/null 2>&1
2986
2987	CXXFLAGS="-DNDEBUG $OPT_O5 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
2988	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
2989
2990	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2991		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
2992	else
2993		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
2994		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2995			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
2996		fi
2997		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
2998		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
2999			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3000		fi
3001	fi
3002fi
3003
3004############################################
3005# Build at -Os
3006if [[ "$HAVE_OS" -ne "0" ]]; then
3007
3008	############################################
3009	# Debug build
3010	echo
3011	echo "************************************" | tee -a "$TEST_RESULTS"
3012	echo "Testing: Debug, -Os optimizations" | tee -a "$TEST_RESULTS"
3013	echo
3014
3015	"$MAKE" clean > /dev/null 2>&1
3016	rm -f adhoc.cpp > /dev/null 2>&1
3017
3018	CXXFLAGS="-DDEBUG $OPT_OS ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3019	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
3020
3021	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3022		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3023	else
3024		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3025		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3026			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3027		fi
3028		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3029		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3030			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3031		fi
3032	fi
3033
3034	############################################
3035	# Release build
3036	echo
3037	echo "************************************" | tee -a "$TEST_RESULTS"
3038	echo "Testing: Release, -Os optimizations" | tee -a "$TEST_RESULTS"
3039	echo
3040
3041	"$MAKE" clean > /dev/null 2>&1
3042	rm -f adhoc.cpp > /dev/null 2>&1
3043
3044	CXXFLAGS="-DNDEBUG $OPT_OS ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3045	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
3046
3047	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3048		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3049	else
3050		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3051		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3052			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3053		fi
3054		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3055		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3056			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3057		fi
3058	fi
3059fi
3060
3061############################################
3062# Build at -Ofast
3063if [[ "$HAVE_OFAST" -ne "0" ]]; then
3064
3065	############################################
3066	# Debug build
3067	echo
3068	echo "************************************" | tee -a "$TEST_RESULTS"
3069	echo "Testing: Debug, -Ofast optimizations" | tee -a "$TEST_RESULTS"
3070	echo
3071
3072	"$MAKE" clean > /dev/null 2>&1
3073	rm -f adhoc.cpp > /dev/null 2>&1
3074
3075	CXXFLAGS="-DDEBUG $OPT_OFAST ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3076	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
3077
3078	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3079		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3080	else
3081		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3082		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3083			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3084		fi
3085		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3086		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3087			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3088		fi
3089	fi
3090
3091	############################################
3092	# Release build
3093	echo
3094	echo "************************************" | tee -a "$TEST_RESULTS"
3095	echo "Testing: Release, -Ofast optimizations" | tee -a "$TEST_RESULTS"
3096	echo
3097
3098	"$MAKE" clean > /dev/null 2>&1
3099	rm -f adhoc.cpp > /dev/null 2>&1
3100
3101	CXXFLAGS="-DNDEBUG $OPT_OFAST ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3102	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
3103
3104	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3105		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3106	else
3107		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3108		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3109			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3110		fi
3111		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3112		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3113			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3114		fi
3115	fi
3116fi
3117
3118############################################
3119# Dead code stripping
3120if [[ ("$SUN_COMPILER" -eq "0") ]]; then
3121
3122	############################################
3123	# Debug build
3124	echo
3125	echo "************************************" | tee -a "$TEST_RESULTS"
3126	echo "Testing: Debug, dead code strip" | tee -a "$TEST_RESULTS"
3127	echo
3128
3129	"$MAKE" clean > /dev/null 2>&1
3130	rm -f adhoc.cpp > /dev/null 2>&1
3131
3132	CXXFLAGS="$DEBUG_CXXFLAGS ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3133	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" lean 2>&1 | tee -a "$TEST_RESULTS"
3134
3135	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3136		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3137	else
3138		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3139		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3140			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3141		fi
3142		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3143		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3144			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3145		fi
3146	fi
3147
3148	############################################
3149	# Release build
3150	echo
3151	echo "************************************" | tee -a "$TEST_RESULTS"
3152	echo "Testing: Release, dead code strip" | tee -a "$TEST_RESULTS"
3153	echo
3154
3155	"$MAKE" clean > /dev/null 2>&1
3156	rm -f adhoc.cpp > /dev/null 2>&1
3157
3158	CXXFLAGS="$RELEASE_CXXFLAGS ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3159	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" lean 2>&1 | tee -a "$TEST_RESULTS"
3160
3161	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3162		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3163	else
3164		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3165		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3166			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3167		fi
3168		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3169		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3170			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3171		fi
3172	fi
3173fi
3174
3175############################################
3176# OpenMP
3177if [[ ("$HAVE_OMP" -ne "0") ]]; then
3178	echo
3179	echo "************************************" | tee -a "$TEST_RESULTS"
3180	echo "Testing: Debug, OpenMP" | tee -a "$TEST_RESULTS"
3181	echo
3182
3183	"$MAKE" clean > /dev/null 2>&1
3184	rm -f adhoc.cpp > /dev/null 2>&1
3185
3186	CXXFLAGS="-DDEBUG ${OMP_FLAGS[@]} ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3187	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" | tee -a "$TEST_RESULTS"
3188
3189	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3190		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3191	else
3192		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3193		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3194			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3195		fi
3196		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3197		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3198			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3199		fi
3200	fi
3201
3202	echo
3203	echo "************************************" | tee -a "$TEST_RESULTS"
3204	echo "Testing: Release, OpenMP" | tee -a "$TEST_RESULTS"
3205	echo
3206
3207	"$MAKE" clean > /dev/null 2>&1
3208	rm -f adhoc.cpp > /dev/null 2>&1
3209
3210	CXXFLAGS="-DNDEBUG ${OMP_FLAGS[@]} ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3211	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" | tee -a "$TEST_RESULTS"
3212
3213	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3214		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3215	else
3216		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3217		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3218			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3219		fi
3220		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3221		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3222			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3223		fi
3224	fi
3225fi
3226
3227############################################
3228# UBSan, c++03
3229if [[ ("$HAVE_CXX03" -ne "0" && "$HAVE_UBSAN" -ne "0") ]]; then
3230
3231	############################################
3232	# Debug build, UBSan, c++03
3233	echo
3234	echo "************************************" | tee -a "$TEST_RESULTS"
3235	echo "Testing: Debug, c++03, UBsan" | tee -a "$TEST_RESULTS"
3236	echo
3237
3238	"$MAKE" clean > /dev/null 2>&1
3239	rm -f adhoc.cpp > /dev/null 2>&1
3240
3241	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3242	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" ubsan | tee -a "$TEST_RESULTS"
3243
3244	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3245		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3246	else
3247		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3248		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3249			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3250		fi
3251		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3252		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3253			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3254		fi
3255	fi
3256
3257	############################################
3258	# Release build, UBSan, c++03
3259	echo
3260	echo "************************************" | tee -a "$TEST_RESULTS"
3261	echo "Testing: Release, c++03, UBsan" | tee -a "$TEST_RESULTS"
3262	echo
3263
3264	"$MAKE" clean > /dev/null 2>&1
3265	rm -f adhoc.cpp > /dev/null 2>&1
3266
3267	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3268	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" ubsan | tee -a "$TEST_RESULTS"
3269
3270	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3271		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3272	else
3273		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3274		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3275			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3276		fi
3277		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3278		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3279			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3280		fi
3281	fi
3282fi
3283
3284############################################
3285# Asan, c++03
3286if [[ ("$HAVE_CXX03" -ne "0" && "$HAVE_ASAN" -ne "0") ]]; then
3287
3288	############################################
3289	# Debug build, Asan, c++03
3290	echo
3291	echo "************************************" | tee -a "$TEST_RESULTS"
3292	echo "Testing: Debug, c++03, Asan" | tee -a "$TEST_RESULTS"
3293	echo
3294
3295	"$MAKE" clean > /dev/null 2>&1
3296	rm -f adhoc.cpp > /dev/null 2>&1
3297
3298	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3299	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" asan | tee -a "$TEST_RESULTS"
3300
3301	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3302		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3303	else
3304		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3305			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3306			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3307				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3308			fi
3309			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3310			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3311				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3312			fi
3313		else
3314			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3315			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3316				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3317			fi
3318			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3319			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3320				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3321			fi
3322		fi
3323
3324	fi
3325
3326	############################################
3327	# Release build, Asan, c++03
3328	echo
3329	echo "************************************" | tee -a "$TEST_RESULTS"
3330	echo "Testing: Release, c++03, Asan" | tee -a "$TEST_RESULTS"
3331	echo
3332
3333	"$MAKE" clean > /dev/null 2>&1
3334	rm -f adhoc.cpp > /dev/null 2>&1
3335
3336	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3337	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" asan | tee -a "$TEST_RESULTS"
3338
3339	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3340		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3341	else
3342		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3343			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3344			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3345				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3346			fi
3347			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3348			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3349				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3350			fi
3351		else
3352			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3353			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3354				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3355			fi
3356			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3357			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3358				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3359			fi
3360		fi
3361	fi
3362fi
3363
3364############################################
3365# Bounds Sanitizer, c++03
3366if [[ ("$HAVE_CXX03" -ne "0" && "$HAVE_BOUNDS_SAN" -ne "0") ]]; then
3367
3368	############################################
3369	# Debug build, Bounds Sanitizer, c++03
3370	echo
3371	echo "************************************" | tee -a "$TEST_RESULTS"
3372	echo "Testing: Debug, c++03, Bounds Sanitizer" | tee -a "$TEST_RESULTS"
3373	echo
3374
3375	"$MAKE" clean > /dev/null 2>&1
3376	rm -f adhoc.cpp > /dev/null 2>&1
3377
3378	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++03 -fsanitize=bounds-strict ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3379	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" | tee -a "$TEST_RESULTS"
3380
3381	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3382		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3383	else
3384		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3385			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3386			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3387				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3388			fi
3389			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3390			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3391				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3392			fi
3393		else
3394			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3395			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3396				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3397			fi
3398			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3399			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3400				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3401			fi
3402		fi
3403
3404	fi
3405
3406	############################################
3407	# Release build, Bounds Sanitizer, c++03
3408	echo
3409	echo "************************************" | tee -a "$TEST_RESULTS"
3410	echo "Testing: Release, c++03, Bounds Sanitizer" | tee -a "$TEST_RESULTS"
3411	echo
3412
3413	"$MAKE" clean > /dev/null 2>&1
3414	rm -f adhoc.cpp > /dev/null 2>&1
3415
3416	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 -fsanitize=bounds-strict ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3417	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" | tee -a "$TEST_RESULTS"
3418
3419	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3420		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3421	else
3422		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3423			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3424			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3425				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3426			fi
3427			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3428			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3429				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3430			fi
3431		else
3432			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3433			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3434				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3435			fi
3436			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3437			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3438				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3439			fi
3440		fi
3441	fi
3442fi
3443
3444############################################
3445# UBSan, c++11
3446if [[ ("$HAVE_CXX11" -ne "0" && "$HAVE_UBSAN" -ne "0") ]]; then
3447
3448	############################################
3449	# Debug build, UBSan, c++11
3450	echo
3451	echo "************************************" | tee -a "$TEST_RESULTS"
3452	echo "Testing: Debug, c++11, UBsan" | tee -a "$TEST_RESULTS"
3453	echo
3454
3455	"$MAKE" clean > /dev/null 2>&1
3456	rm -f adhoc.cpp > /dev/null 2>&1
3457
3458	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3459	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" ubsan | tee -a "$TEST_RESULTS"
3460
3461	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3462		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3463	else
3464		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3465		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3466			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3467		fi
3468		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3469		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3470			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3471		fi
3472	fi
3473
3474	############################################
3475	# Release build, UBSan, c++11
3476	echo
3477	echo "************************************" | tee -a "$TEST_RESULTS"
3478	echo "Testing: Release, c++11, UBsan" | tee -a "$TEST_RESULTS"
3479	echo
3480
3481	"$MAKE" clean > /dev/null 2>&1
3482	rm -f adhoc.cpp > /dev/null 2>&1
3483
3484	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3485	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" ubsan | tee -a "$TEST_RESULTS"
3486
3487	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3488		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3489	else
3490		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3491		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3492			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3493		fi
3494		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3495		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3496			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3497		fi
3498	fi
3499fi
3500
3501############################################
3502# Asan, c++11
3503if [[ ("$HAVE_CXX11" -ne "0" && "$HAVE_ASAN" -ne "0") ]]; then
3504
3505	############################################
3506	# Debug build, Asan, c++11
3507	echo
3508	echo "************************************" | tee -a "$TEST_RESULTS"
3509	echo "Testing: Debug, c++11, Asan" | tee -a "$TEST_RESULTS"
3510	echo
3511
3512	"$MAKE" clean > /dev/null 2>&1
3513	rm -f adhoc.cpp > /dev/null 2>&1
3514
3515	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3516	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" asan | tee -a "$TEST_RESULTS"
3517
3518	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3519		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3520	else
3521		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3522			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3523			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3524				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3525			fi
3526			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3527			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3528				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3529			fi
3530		else
3531			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3532			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3533				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3534			fi
3535			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3536			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3537				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3538			fi
3539		fi
3540
3541	fi
3542
3543	############################################
3544	# Release build, Asan, c++11
3545	echo
3546	echo "************************************" | tee -a "$TEST_RESULTS"
3547	echo "Testing: Release, c++11, Asan" | tee -a "$TEST_RESULTS"
3548	echo
3549
3550	"$MAKE" clean > /dev/null 2>&1
3551	rm -f adhoc.cpp > /dev/null 2>&1
3552
3553	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3554	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" asan | tee -a "$TEST_RESULTS"
3555
3556	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3557		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3558	else
3559		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3560			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3561			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3562				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3563			fi
3564			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3565			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3566				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3567			fi
3568		else
3569			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3570			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3571				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3572			fi
3573			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3574			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3575				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3576			fi
3577		fi
3578	fi
3579fi
3580
3581############################################
3582# Bounds Sanitizer, c++11
3583if [[ ("$HAVE_CXX11" -ne "0" && "$HAVE_BOUNDS_SAN" -ne "0") ]]; then
3584
3585	############################################
3586	# Debug build, Bounds Sanitizer, c++11
3587	echo
3588	echo "************************************" | tee -a "$TEST_RESULTS"
3589	echo "Testing: Debug, c++11, Bounds Sanitizer" | tee -a "$TEST_RESULTS"
3590	echo
3591
3592	"$MAKE" clean > /dev/null 2>&1
3593	rm -f adhoc.cpp > /dev/null 2>&1
3594
3595	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++11 -fsanitize=bounds-strict ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3596	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" | tee -a "$TEST_RESULTS"
3597
3598	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3599		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3600	else
3601		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3602			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3603			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3604				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3605			fi
3606			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3607			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3608				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3609			fi
3610		else
3611			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3612			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3613				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3614			fi
3615			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3616			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3617				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3618			fi
3619		fi
3620
3621	fi
3622
3623	############################################
3624	# Release build, Bounds Sanitizer, c++11
3625	echo
3626	echo "************************************" | tee -a "$TEST_RESULTS"
3627	echo "Testing: Release, c++11, Bounds Sanitizer" | tee -a "$TEST_RESULTS"
3628	echo
3629
3630	"$MAKE" clean > /dev/null 2>&1
3631	rm -f adhoc.cpp > /dev/null 2>&1
3632
3633	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 -fsanitize=bounds-strict ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3634	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" | tee -a "$TEST_RESULTS"
3635
3636	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3637		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3638	else
3639		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3640			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3641			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3642				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3643			fi
3644			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3645			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3646				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3647			fi
3648		else
3649			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3650			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3651				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3652			fi
3653			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3654			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3655				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3656			fi
3657		fi
3658	fi
3659fi
3660
3661############################################
3662# Release build, UBSan, c++14
3663if [[ ("$HAVE_CXX14" -ne "0" && "$HAVE_UBSAN" -ne "0") ]]; then
3664	echo
3665	echo "************************************" | tee -a "$TEST_RESULTS"
3666	echo "Testing: Release, c++14, UBsan" | tee -a "$TEST_RESULTS"
3667	echo
3668
3669	"$MAKE" clean > /dev/null 2>&1
3670	rm -f adhoc.cpp > /dev/null 2>&1
3671
3672	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3673	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" ubsan | tee -a "$TEST_RESULTS"
3674
3675	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3676		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3677	else
3678		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3679		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3680			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3681		fi
3682		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3683		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3684			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3685		fi
3686	fi
3687fi
3688
3689############################################
3690# Release build, Asan, c++14
3691if [[ ("$HAVE_CXX14" -ne "0" && "$HAVE_ASAN" -ne "0") ]]; then
3692	echo
3693	echo "************************************" | tee -a "$TEST_RESULTS"
3694	echo "Testing: Release, c++14, Asan" | tee -a "$TEST_RESULTS"
3695	echo
3696
3697	"$MAKE" clean > /dev/null 2>&1
3698	rm -f adhoc.cpp > /dev/null 2>&1
3699
3700	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3701	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" asan | tee -a "$TEST_RESULTS"
3702
3703	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3704		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3705	else
3706		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3707			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3708			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3709				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3710			fi
3711			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3712			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3713				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3714			fi
3715		else
3716			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3717			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3718				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3719			fi
3720			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3721			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3722				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3723			fi
3724		fi
3725	fi
3726fi
3727
3728############################################
3729# Release build, Bounds Sanitizer, c++14
3730if [[ ("$HAVE_CXX14" -ne "0" && "$HAVE_BOUNDS_SAN" -ne "0") ]]; then
3731	echo
3732	echo "************************************" | tee -a "$TEST_RESULTS"
3733	echo "Testing: Release, c++14, Bounds Sanitizer" | tee -a "$TEST_RESULTS"
3734	echo
3735
3736	"$MAKE" clean > /dev/null 2>&1
3737	rm -f adhoc.cpp > /dev/null 2>&1
3738
3739	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 -fsanitize=bounds-strict ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3740	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" | tee -a "$TEST_RESULTS"
3741
3742	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3743		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3744	else
3745		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3746		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3747			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3748		fi
3749		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3750		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3751			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3752		fi
3753	fi
3754fi
3755
3756############################################
3757# Release build, UBSan, c++17
3758if [[ ("$HAVE_CXX17" -ne "0" && "$HAVE_UBSAN" -ne "0") ]]; then
3759	echo
3760	echo "************************************" | tee -a "$TEST_RESULTS"
3761	echo "Testing: Release, c++17, UBsan" | tee -a "$TEST_RESULTS"
3762	echo
3763
3764	"$MAKE" clean > /dev/null 2>&1
3765	rm -f adhoc.cpp > /dev/null 2>&1
3766
3767	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3768	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" ubsan | tee -a "$TEST_RESULTS"
3769
3770	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3771		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3772	else
3773		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3774		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3775			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3776		fi
3777		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3778		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3779			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3780		fi
3781	fi
3782fi
3783
3784############################################
3785# Release build, Asan, c++17
3786if [[ ("$HAVE_CXX17" -ne "0" && "$HAVE_ASAN" -ne "0") ]]; then
3787	echo
3788	echo "************************************" | tee -a "$TEST_RESULTS"
3789	echo "Testing: Release, c++17, Asan" | tee -a "$TEST_RESULTS"
3790	echo
3791
3792	"$MAKE" clean > /dev/null 2>&1
3793	rm -f adhoc.cpp > /dev/null 2>&1
3794
3795	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3796	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" asan | tee -a "$TEST_RESULTS"
3797
3798	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3799		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3800	else
3801		if [[ ("$HAVE_SYMBOLIZE" -ne "0") ]]; then
3802			./cryptest.exe v 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3803			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3804				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3805			fi
3806			./cryptest.exe tv all 2>&1 | "$ASAN_SYMBOLIZE" 2>&1 | tee -a "$TEST_RESULTS"
3807			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3808				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3809			fi
3810		else
3811			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3812			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3813				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3814			fi
3815			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3816			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3817				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3818			fi
3819		fi
3820	fi
3821fi
3822
3823############################################
3824# Release build, Bounds Sanitizer, c++17
3825if [[ ("$HAVE_CXX17" -ne "0" && "$HAVE_BOUNDS_SAN" -ne "0") ]]; then
3826	echo
3827	echo "************************************" | tee -a "$TEST_RESULTS"
3828	echo "Testing: Release, c++17, Bounds Sanitizer" | tee -a "$TEST_RESULTS"
3829	echo
3830
3831	"$MAKE" clean > /dev/null 2>&1
3832	rm -f adhoc.cpp > /dev/null 2>&1
3833
3834	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++17 -fsanitize=bounds-strict ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
3835	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" | tee -a "$TEST_RESULTS"
3836
3837	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3838		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3839	else
3840		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3841		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3842			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3843		fi
3844		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3845		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3846			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3847		fi
3848	fi
3849fi
3850
3851############################################
3852# For Solaris, test under Sun Studio 12.2 - 12.5
3853if [[ "$IS_SOLARIS" -ne "0" ]]; then
3854
3855	# If PLATFORM_CXXFLAGS is for SunCC, then use them
3856	if [[ ("$SUNCC_510_OR_ABOVE" -ne "0") ]]; then
3857		SUNCC_CXXFLAGS="${PLATFORM_CXXFLAGS[@]}"
3858	fi
3859
3860	############################################
3861	# Sun Studio 12.2/SunCC 5.11
3862	if [[ (-e "/opt/solstudio12.2/bin/CC") ]]; then
3863
3864		# More workarounds... SunCC 5.11 only does SSSE3, http://github.com/weidai11/cryptopp/issues/228
3865		SUNCC_SSE_CXXFLAGS=$(echo -n "${SUNCC_CXXFLAGS[@]}" | "$AWK" '/__(SSE2|SSE3|SSSE3)__/' ORS=' ' RS=' ')
3866
3867		if [[ $(echo -n "$SUNCC_SSE_CXXFLAGS" | "$GREP" -i -c "ssse3") != "0" ]]; then
3868			SUNCC_SSE_CXXFLAGS="$SUNCC_SSE_CXXFLAGS -xarch=ssse3";
3869		elif [[ $(echo -n "$SUNCC_SSE_CXXFLAGS" | "$GREP" -i -c "sse3") != "0" ]]; then
3870			SUNCC_SSE_CXXFLAGS="$SUNCC_SSE_CXXFLAGS -xarch=sse3";
3871		else
3872			SUNCC_SSE_CXXFLAGS="$SUNCC_SSE_CXXFLAGS -xarch=sse2";
3873		fi
3874
3875		############################################
3876		# Debug build
3877		echo
3878		echo "************************************" | tee -a "$TEST_RESULTS"
3879		echo "Testing: Sun Studio 12.2, debug, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
3880		echo
3881
3882		"$MAKE" clean > /dev/null 2>&1
3883		rm -f adhoc.cpp > /dev/null 2>&1
3884
3885		CXXFLAGS="-DDEBUG -g -xO0 $SUNCC_SSE_CXXFLAGS"
3886		CXX="/opt/solstudio12.2/bin/CC" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
3887
3888		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3889			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3890		else
3891			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3892			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3893				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3894			fi
3895			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3896			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3897				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3898			fi
3899		fi
3900
3901		############################################
3902		# Release build
3903		echo
3904		echo "************************************" | tee -a "$TEST_RESULTS"
3905		echo "Testing: Sun Studio 12.2, release, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
3906		echo
3907
3908		"$MAKE" clean > /dev/null 2>&1
3909		rm -f adhoc.cpp > /dev/null 2>&1
3910
3911		CXXFLAGS="-DNDEBUG -g -xO2 $SUNCC_SSE_CXXFLAGS"
3912		CXX="/opt/solstudio12.2/bin/CC" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
3913
3914		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3915			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3916		else
3917			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3918			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3919				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3920			fi
3921			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3922			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3923				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3924			fi
3925		fi
3926	fi
3927
3928	############################################
3929	# Sun Studio 12.3/SunCC 5.12
3930	if [[ (-e "/opt/solarisstudio12.3/bin/CC") ]]; then
3931
3932		# More workarounds... SunCC 5.12 only does SSE4, http://github.com/weidai11/cryptopp/issues/228
3933		SUNCC_SSE_CXXFLAGS=$(echo -n "${SUNCC_CXXFLAGS[@]}" | "$AWK" '/__(SSE2|SSE3|SSSE3|SSE4_1|SSE4_2)__/' ORS=' ' RS=' ')
3934
3935		if [[ $(echo -n "$SUNCC_SSE_CXXFLAGS" | "$GREP" -i -c "sse4_2") != "0" ]]; then
3936			SUNCC_SSE_CXXFLAGS="$SUNCC_SSE_CXXFLAGS -xarch=sse4_2";
3937		elif [[ $(echo -n "$SUNCC_SSE_CXXFLAGS" | "$GREP" -i -c "sse4_1") != "0" ]]; then
3938			SUNCC_SSE_CXXFLAGS="$SUNCC_SSE_CXXFLAGS -xarch=sse4_1";
3939		elif [[ $(echo -n "$SUNCC_SSE_CXXFLAGS" | "$GREP" -i -c "ssse3") != "0" ]]; then
3940			SUNCC_SSE_CXXFLAGS="$SUNCC_SSE_CXXFLAGS -xarch=ssse3";
3941		elif [[ $(echo -n "$SUNCC_SSE_CXXFLAGS" | "$GREP" -i -c "sse3") != "0" ]]; then
3942			SUNCC_SSE_CXXFLAGS="$SUNCC_SSE_CXXFLAGS -xarch=sse3";
3943		else
3944			SUNCC_SSE_CXXFLAGS="$SUNCC_SSE_CXXFLAGS -xarch=sse2";
3945		fi
3946
3947		############################################
3948		# Debug build
3949		echo
3950		echo "************************************" | tee -a "$TEST_RESULTS"
3951		echo "Testing: Sun Studio 12.3, debug, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
3952		echo
3953
3954		"$MAKE" clean > /dev/null 2>&1
3955		rm -f adhoc.cpp > /dev/null 2>&1
3956
3957		CXXFLAGS="-DDEBUG -g3 -xO0 $SUNCC_SSE_CXXFLAGS"
3958		CXX=/opt/solarisstudio12.3/bin/CC CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
3959
3960		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3961			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3962		else
3963			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3964			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3965				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3966			fi
3967			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3968			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3969				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3970			fi
3971		fi
3972
3973		############################################
3974		# Release build
3975		echo
3976		echo "************************************" | tee -a "$TEST_RESULTS"
3977		echo "Testing: Sun Studio 12.3, release, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
3978		echo
3979
3980		"$MAKE" clean > /dev/null 2>&1
3981		rm -f adhoc.cpp > /dev/null 2>&1
3982
3983		CXXFLAGS="-DNDEBUG -g3 -xO2 $SUNCC_SSE_CXXFLAGS"
3984		CXX=/opt/solarisstudio12.3/bin/CC CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
3985
3986		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3987			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
3988		else
3989			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
3990			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3991				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
3992			fi
3993			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
3994			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
3995				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
3996			fi
3997		fi
3998	fi
3999
4000	############################################
4001	# Sun Studio 12.4/SunCC 5.13
4002	if [[ (-e "/opt/solarisstudio12.4/bin/CC") ]]; then
4003
4004		############################################
4005		# Debug build
4006		echo
4007		echo "************************************" | tee -a "$TEST_RESULTS"
4008		echo "Testing: Sun Studio 12.4, debug, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
4009		echo
4010
4011		# No workarounds... SunCC 5.13 does AES, PCLMUL, RDRAND, AVX, BMI, ADX...
4012
4013		"$MAKE" clean > /dev/null 2>&1
4014		rm -f adhoc.cpp > /dev/null 2>&1
4015
4016		CXXFLAGS="-DDEBUG -g3 -xO0 $SUNCC_CXXFLAGS"
4017		CXX=/opt/solarisstudio12.4/bin/CC CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4018
4019		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4020			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4021		else
4022			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4023			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4024				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4025			fi
4026			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4027			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4028				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4029			fi
4030		fi
4031
4032		############################################
4033		# Release build
4034		echo
4035		echo "************************************" | tee -a "$TEST_RESULTS"
4036		echo "Testing: Sun Studio 12.4, release, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
4037		echo
4038
4039		"$MAKE" clean > /dev/null 2>&1
4040		rm -f adhoc.cpp > /dev/null 2>&1
4041
4042		CXXFLAGS="-DNDEBUG -g2 -xO2 $SUNCC_CXXFLAGS"
4043		CXX=/opt/solarisstudio12.4/bin/CC CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4044
4045		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4046			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4047		else
4048			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4049			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4050				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4051			fi
4052			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4053			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4054				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4055			fi
4056		fi
4057	fi
4058
4059	############################################
4060	# Sun Studio 12.5/SunCC 5.14
4061	if [[ (-e "/opt/developerstudio12.5/bin/CC") ]]; then
4062
4063		############################################
4064		# Debug build
4065		echo
4066		echo "************************************" | tee -a "$TEST_RESULTS"
4067		echo "Testing: Sun Studio 12.5, debug, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
4068		echo
4069
4070		# No workarounds... SunCC 5.14 does AES, PCLMUL, RDRAND, AVX, BMI, ADX...
4071
4072		"$MAKE" clean > /dev/null 2>&1
4073		rm -f adhoc.cpp > /dev/null 2>&1
4074
4075		CXXFLAGS="-DDEBUG -g3 -xO1 $SUNCC_CXXFLAGS"
4076		CXX=/opt/developerstudio12.5/bin/CC CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4077
4078		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4079			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4080		else
4081			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4082			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4083				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4084			fi
4085			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4086			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4087				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4088			fi
4089		fi
4090
4091		############################################
4092		# Release build
4093		echo
4094		echo "************************************" | tee -a "$TEST_RESULTS"
4095		echo "Testing: Sun Studio 12.5, release, platform CXXFLAGS" | tee -a "$TEST_RESULTS"
4096		echo
4097
4098		"$MAKE" clean > /dev/null 2>&1
4099		rm -f adhoc.cpp > /dev/null 2>&1
4100
4101		CXXFLAGS="-DNDEBUG -g2 -xO2 $SUNCC_CXXFLAGS"
4102		CXX=/opt/developerstudio12.5/bin/CC CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4103
4104		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4105			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4106		else
4107			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4108			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4109				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4110			fi
4111			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4112			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4113				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4114			fi
4115		fi
4116	fi
4117
4118	############################################
4119	# GCC on Solaris
4120	if [[ (-e "/bin/g++") ]]; then
4121
4122		############################################
4123		# Debug build
4124		echo
4125		echo "************************************" | tee -a "$TEST_RESULTS"
4126		echo "Testing: Solaris GCC, debug, default CXXFLAGS" | tee -a "$TEST_RESULTS"
4127		echo
4128
4129		"$MAKE" clean > /dev/null 2>&1
4130		rm -f adhoc.cpp > /dev/null 2>&1
4131
4132		CXXFLAGS="-DDEBUG -g3 -O0"
4133		CXX="/bin/g++" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4134
4135		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4136			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4137		else
4138			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4139			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4140				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4141			fi
4142			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4143			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4144				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4145			fi
4146		fi
4147
4148		############################################
4149		# Release build
4150		echo
4151		echo "************************************" | tee -a "$TEST_RESULTS"
4152		echo "Testing: Soalris GCC, release, default CXXFLAGS" | tee -a "$TEST_RESULTS"
4153		echo
4154
4155		"$MAKE" clean > /dev/null 2>&1
4156		rm -f adhoc.cpp > /dev/null 2>&1
4157
4158		CXXFLAGS="-DNDEBUG -g2 -O2"
4159		CXX="/bin/g++" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4160
4161		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4162			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4163		else
4164			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4165			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4166				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4167			fi
4168			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4169			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4170				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4171			fi
4172		fi
4173	fi
4174fi
4175
4176# For Darwin, we need to test both -stdlib=libstdc++ (GNU) and
4177#  -stdlib=libc++ (LLVM) crossed with -std=c++03, -std=c++11, and -std=c++17
4178
4179############################################
4180# Darwin, c++03, libc++
4181if [[ ("$IS_DARWIN" -ne "0") && ("$HAVE_CXX03" -ne "0" && "$CLANG_COMPILER" -ne "0") ]]; then
4182	echo
4183	echo "************************************" | tee -a "$TEST_RESULTS"
4184	echo "Testing: Darwin, c++03, libc++ (LLVM)" | tee -a "$TEST_RESULTS"
4185	echo
4186
4187	"$MAKE" clean > /dev/null 2>&1
4188	rm -f adhoc.cpp > /dev/null 2>&1
4189
4190	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 -stdlib=libc++ ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4191	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4192
4193	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4194		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4195	else
4196		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4197		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4198			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4199		fi
4200		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4201		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4202			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4203		fi
4204	fi
4205fi
4206
4207############################################
4208# Darwin, c++03, libstdc++
4209if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX03" -ne "0") ]]; then
4210	echo
4211	echo "************************************" | tee -a "$TEST_RESULTS"
4212	echo "Testing: Darwin, c++03, libstdc++ (GNU)" | tee -a "$TEST_RESULTS"
4213	echo
4214
4215	"$MAKE" clean > /dev/null 2>&1
4216	rm -f adhoc.cpp > /dev/null 2>&1
4217
4218	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 -stdlib=libstdc++ ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4219	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4220
4221	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4222		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4223	else
4224		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4225		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4226			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4227		fi
4228		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4229		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4230			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4231		fi
4232	fi
4233fi
4234
4235############################################
4236# Darwin, c++11, libc++
4237if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX11" -ne "0" && "$CLANG_COMPILER" -ne "0") ]]; then
4238	echo
4239	echo "************************************" | tee -a "$TEST_RESULTS"
4240	echo "Testing: Darwin, c++11, libc++ (LLVM)" | tee -a "$TEST_RESULTS"
4241	echo
4242
4243	"$MAKE" clean > /dev/null 2>&1
4244	rm -f adhoc.cpp > /dev/null 2>&1
4245
4246	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 -stdlib=libc++ ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4247	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4248
4249	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4250		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4251	else
4252		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4253		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4254			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4255		fi
4256		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4257		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4258			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4259		fi
4260	fi
4261fi
4262
4263############################################
4264# Darwin, c++11, libstdc++
4265if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX11" -ne "0") ]]; then
4266	echo
4267	echo "************************************" | tee -a "$TEST_RESULTS"
4268	echo "Testing: Darwin, c++11, libstdc++ (GNU)" | tee -a "$TEST_RESULTS"
4269	echo
4270
4271	"$MAKE" clean > /dev/null 2>&1
4272	rm -f adhoc.cpp > /dev/null 2>&1
4273
4274	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 -stdlib=libstdc++ ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4275	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4276
4277	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4278		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4279	else
4280		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4281		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4282			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4283		fi
4284		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4285		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4286			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4287		fi
4288	fi
4289fi
4290
4291############################################
4292# Darwin, c++14, libc++
4293if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX14" -ne "0" && "$CLANG_COMPILER" -ne "0") ]]; then
4294	echo
4295	echo "************************************" | tee -a "$TEST_RESULTS"
4296	echo "Testing: Darwin, c++14, libc++ (LLVM)" | tee -a "$TEST_RESULTS"
4297	echo
4298
4299	"$MAKE" clean > /dev/null 2>&1
4300	rm -f adhoc.cpp > /dev/null 2>&1
4301
4302	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 -stdlib=libc++ ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4303	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4304
4305	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4306		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4307	else
4308		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4309		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4310			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4311		fi
4312		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4313		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4314			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4315		fi
4316	fi
4317fi
4318
4319############################################
4320# Darwin, c++14, libstdc++
4321if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX14" -ne "0") ]]; then
4322	echo
4323	echo "************************************" | tee -a "$TEST_RESULTS"
4324	echo "Testing: Darwin, c++14, libstdc++ (GNU)" | tee -a "$TEST_RESULTS"
4325	echo
4326
4327	"$MAKE" clean > /dev/null 2>&1
4328	rm -f adhoc.cpp > /dev/null 2>&1
4329
4330	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 -stdlib=libstdc++ ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4331	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4332
4333	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4334		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4335	else
4336		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4337		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4338			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4339		fi
4340		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4341		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4342			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4343		fi
4344	fi
4345fi
4346
4347############################################
4348# Darwin, c++17, libc++
4349if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX17" -ne "0" && "$CLANG_COMPILER" -ne "0") ]]; then
4350	echo
4351	echo "************************************" | tee -a "$TEST_RESULTS"
4352	echo "Testing: Darwin, c++17, libc++ (LLVM)" | tee -a "$TEST_RESULTS"
4353	echo
4354
4355	"$MAKE" clean > /dev/null 2>&1
4356	rm -f adhoc.cpp > /dev/null 2>&1
4357
4358	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++17 -stdlib=libc++ ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4359	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4360
4361	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4362		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4363	else
4364		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4365		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4366			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4367		fi
4368		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4369		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4370			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4371		fi
4372	fi
4373fi
4374
4375############################################
4376# Darwin, c++17, libstdc++
4377if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX17" -ne "0") ]]; then
4378	echo
4379	echo "************************************" | tee -a "$TEST_RESULTS"
4380	echo "Testing: Darwin, c++17, libstdc++ (GNU)" | tee -a "$TEST_RESULTS"
4381	echo
4382
4383	"$MAKE" clean > /dev/null 2>&1
4384	rm -f adhoc.cpp > /dev/null 2>&1
4385
4386	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++17 -stdlib=libstdc++ ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4387	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4388
4389	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4390		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4391	else
4392		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4393		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4394			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4395		fi
4396		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4397		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4398			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4399		fi
4400	fi
4401fi
4402
4403############################################
4404# Darwin, Intel multiarch, c++03
4405if [[ "$IS_DARWIN" -ne "0" && "$HAVE_INTEL_MULTIARCH" -ne "0" && "$HAVE_CXX03" -ne "0" ]]; then
4406	echo
4407	echo "************************************" | tee -a "$TEST_RESULTS"
4408	echo "Testing: Darwin, Intel multiarch, c++03" | tee -a "$TEST_RESULTS"
4409	echo
4410
4411	"$MAKE" clean > /dev/null 2>&1
4412	rm -f adhoc.cpp > /dev/null 2>&1
4413
4414	CXXFLAGS="$RELEASE_CXXFLAGS -arch i386 -arch x86_64 -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4415	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4416
4417	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4418		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4419	else
4420		echo "Running i386 version..."
4421		arch -i386 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4422		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4423			echo "ERROR: failed to execute validation suite (i386)" | tee -a "$TEST_RESULTS"
4424		fi
4425		arch -i386 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4426		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4427			echo "ERROR: failed to execute test vectors (i386)" | tee -a "$TEST_RESULTS"
4428		fi
4429
4430		echo "Running x86_64 version..."
4431		arch -x86_64 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4432		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4433			echo "ERROR: failed to execute validation suite (x86_64)" | tee -a "$TEST_RESULTS"
4434		fi
4435		arch -x86_64 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4436		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4437			echo "ERROR: failed to execute test vectors (x86_64)" | tee -a "$TEST_RESULTS"
4438		fi
4439	fi
4440fi
4441
4442############################################
4443# Darwin, Intel multiarch, c++11
4444if [[ "$IS_DARWIN" -ne "0" && "$HAVE_INTEL_MULTIARCH" -ne "0" && "$HAVE_CXX11" -ne "0" ]]; then
4445	echo
4446	echo "************************************" | tee -a "$TEST_RESULTS"
4447	echo "Testing: Darwin, Intel multiarch, c++11" | tee -a "$TEST_RESULTS"
4448	echo
4449
4450	"$MAKE" clean > /dev/null 2>&1
4451	rm -f adhoc.cpp > /dev/null 2>&1
4452
4453	CXXFLAGS="$RELEASE_CXXFLAGS -arch i386 -arch x86_64 -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4454	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4455
4456	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4457		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4458	else
4459		echo "Running i386 version..."
4460		arch -i386 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4461		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4462			echo "ERROR: failed to execute validation suite (i386)" | tee -a "$TEST_RESULTS"
4463		fi
4464		arch -i386 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4465		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4466			echo "ERROR: failed to execute test vectors (i386)" | tee -a "$TEST_RESULTS"
4467		fi
4468
4469		echo "Running x86_64 version..."
4470		arch -x86_64 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4471		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4472			echo "ERROR: failed to execute validation suite (x86_64)" | tee -a "$TEST_RESULTS"
4473		fi
4474		arch -x86_64 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4475		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4476			echo "ERROR: failed to execute test vectors (x86_64)" | tee -a "$TEST_RESULTS"
4477		fi
4478	fi
4479fi
4480
4481############################################
4482# Darwin, Intel multiarch, c++14
4483if [[ "$IS_DARWIN" -ne "0" && "$HAVE_INTEL_MULTIARCH" -ne "0" && "$HAVE_CXX14" -ne "0" ]]; then
4484	echo
4485	echo "************************************" | tee -a "$TEST_RESULTS"
4486	echo "Testing: Darwin, Intel multiarch, c++14" | tee -a "$TEST_RESULTS"
4487	echo
4488
4489	"$MAKE" clean > /dev/null 2>&1
4490	rm -f adhoc.cpp > /dev/null 2>&1
4491
4492	CXXFLAGS="$RELEASE_CXXFLAGS -arch i386 -arch x86_64 -std=c++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4493	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4494
4495	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4496		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4497	else
4498		echo "Running i386 version..."
4499		arch -i386 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4500		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4501			echo "ERROR: failed to execute validation suite (i386)" | tee -a "$TEST_RESULTS"
4502		fi
4503		arch -i386 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4504		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4505			echo "ERROR: failed to execute test vectors (i386)" | tee -a "$TEST_RESULTS"
4506		fi
4507
4508		echo "Running x86_64 version..."
4509		arch -x86_64 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4510		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4511			echo "ERROR: failed to execute validation suite (x86_64)" | tee -a "$TEST_RESULTS"
4512		fi
4513		arch -x86_64 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4514		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4515			echo "ERROR: failed to execute test vectors (x86_64)" | tee -a "$TEST_RESULTS"
4516		fi
4517	fi
4518fi
4519
4520############################################
4521# Darwin, Intel multiarch, c++17
4522if [[ "$IS_DARWIN" -ne "0" && "$HAVE_INTEL_MULTIARCH" -ne "0" && "$HAVE_CXX17" -ne "0" ]]; then
4523	echo
4524	echo "************************************" | tee -a "$TEST_RESULTS"
4525	echo "Testing: Darwin, Intel multiarch, c++17" | tee -a "$TEST_RESULTS"
4526	echo
4527
4528	"$MAKE" clean > /dev/null 2>&1
4529	rm -f adhoc.cpp > /dev/null 2>&1
4530
4531	CXXFLAGS="$RELEASE_CXXFLAGS -arch i386 -arch x86_64 -std=c++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4532	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4533
4534	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4535		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4536	else
4537		echo "Running i386 version..."
4538		arch -i386 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4539		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4540			echo "ERROR: failed to execute validation suite (i386)" | tee -a "$TEST_RESULTS"
4541		fi
4542		arch -i386 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4543		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4544			echo "ERROR: failed to execute test vectors (i386)" | tee -a "$TEST_RESULTS"
4545		fi
4546
4547		echo "Running x86_64 version..."
4548		arch -x86_64 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4549		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4550			echo "ERROR: failed to execute validation suite (x86_64)" | tee -a "$TEST_RESULTS"
4551		fi
4552		arch -x86_64 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4553		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4554			echo "ERROR: failed to execute test vectors (x86_64)" | tee -a "$TEST_RESULTS"
4555		fi
4556	fi
4557fi
4558
4559############################################
4560# Darwin, PowerPC multiarch
4561if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_PPC_MULTIARCH" -ne "0") ]]; then
4562	echo
4563	echo "************************************" | tee -a "$TEST_RESULTS"
4564	echo "Testing: Darwin, PowerPC multiarch" | tee -a "$TEST_RESULTS"
4565	echo
4566
4567	"$MAKE" clean > /dev/null 2>&1
4568	rm -f adhoc.cpp > /dev/null 2>&1
4569
4570	CXXFLAGS="$RELEASE_CXXFLAGS -arch ppc -arch ppc64 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4571	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4572
4573	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4574		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4575	else
4576		echo "Running PPC version..."
4577		arch -ppc ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4578		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4579			echo "ERROR: failed to execute validation suite (PPC)" | tee -a "$TEST_RESULTS"
4580		fi
4581		arch -ppc ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4582		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4583			echo "ERROR: failed to execute test vectors (PPC)" | tee -a "$TEST_RESULTS"
4584		fi
4585
4586		echo "Running PPC64 version..."
4587		arch -ppc64 ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4588		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4589			echo "ERROR: failed to execute validation suite (PPC64)" | tee -a "$TEST_RESULTS"
4590		fi
4591		arch -ppc64 ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4592		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4593			echo "ERROR: failed to execute test vectors (PPC64)" | tee -a "$TEST_RESULTS"
4594		fi
4595	fi
4596fi
4597
4598############################################
4599# Darwin, c++03, Malloc Guards
4600if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX03" -ne "0") ]]; then
4601	echo
4602	echo "************************************" | tee -a "$TEST_RESULTS"
4603	echo "Testing: Darwin, c++03, Malloc Guards" | tee -a "$TEST_RESULTS"
4604	echo
4605
4606	"$MAKE" clean > /dev/null 2>&1
4607	rm -f adhoc.cpp > /dev/null 2>&1
4608
4609	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4610	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4611
4612	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4613		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4614	else
4615		export MallocScribble=1
4616		export MallocPreScribble=1
4617		export MallocGuardEdges=1
4618
4619		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4620		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4621			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4622		fi
4623		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4624		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4625			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4626		fi
4627
4628		unset MallocScribble MallocPreScribble MallocGuardEdges
4629	fi
4630fi
4631
4632############################################
4633# Darwin, c++11, Malloc Guards
4634if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX11" -ne "0") ]]; then
4635	echo
4636	echo "************************************" | tee -a "$TEST_RESULTS"
4637	echo "Testing: Darwin, c++11, Malloc Guards" | tee -a "$TEST_RESULTS"
4638	echo
4639
4640	"$MAKE" clean > /dev/null 2>&1
4641	rm -f adhoc.cpp > /dev/null 2>&1
4642
4643	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4644	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4645
4646	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4647		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4648	else
4649		export MallocScribble=1
4650		export MallocPreScribble=1
4651		export MallocGuardEdges=1
4652
4653		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4654		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4655			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4656		fi
4657		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4658		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4659			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4660		fi
4661
4662		unset MallocScribble MallocPreScribble MallocGuardEdges
4663	fi
4664fi
4665
4666############################################
4667# Darwin, c++14, Malloc Guards
4668if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX14" -ne "0") ]]; then
4669	echo
4670	echo "************************************" | tee -a "$TEST_RESULTS"
4671	echo "Testing: Darwin, c++14, Malloc Guards" | tee -a "$TEST_RESULTS"
4672	echo
4673
4674	"$MAKE" clean > /dev/null 2>&1
4675	rm -f adhoc.cpp > /dev/null 2>&1
4676
4677	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4678	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4679
4680	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4681		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4682	else
4683		export MallocScribble=1
4684		export MallocPreScribble=1
4685		export MallocGuardEdges=1
4686
4687		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4688		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4689			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4690		fi
4691		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4692		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4693			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4694		fi
4695
4696		unset MallocScribble MallocPreScribble MallocGuardEdges
4697	fi
4698fi
4699
4700############################################
4701# Darwin, c++17, Malloc Guards
4702if [[ ("$IS_DARWIN" -ne "0" && "$HAVE_CXX17" -ne "0") ]]; then
4703	echo
4704	echo "************************************" | tee -a "$TEST_RESULTS"
4705	echo "Testing: Darwin, c++17, Malloc Guards" | tee -a "$TEST_RESULTS"
4706	echo
4707
4708	"$MAKE" clean > /dev/null 2>&1
4709	rm -f adhoc.cpp > /dev/null 2>&1
4710
4711	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4712	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4713
4714	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4715		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4716	else
4717		export MallocScribble=1
4718		export MallocPreScribble=1
4719		export MallocGuardEdges=1
4720
4721		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4722		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4723			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4724		fi
4725		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4726		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4727			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4728		fi
4729
4730		unset MallocScribble MallocPreScribble MallocGuardEdges
4731	fi
4732fi
4733
4734############################################
4735# Modern compiler and old hardware, like PII, PIII or Core2
4736if [[ ("$HAVE_X86_AES" -ne "0" || "$HAVE_X86_RDRAND" -ne "0" || "$HAVE_X86_RDSEED" -ne "0") ]]; then
4737
4738	echo
4739	echo "************************************" | tee -a "$TEST_RESULTS"
4740	echo "Testing: AES, RDRAND and RDSEED" | tee -a "$TEST_RESULTS"
4741	echo
4742
4743	OPTS=()
4744	if [[ ("$GCC_COMPILER" -ne "0") ]]; then
4745		OPTS=("-march=native")
4746	fi
4747	if [[ "$HAVE_X86_AES" -ne "0" ]]; then
4748		OPTS+=("-maes")
4749	fi
4750	if [[ "$HAVE_X86_RDRAND" -ne "0" ]]; then
4751		OPTS+=("-mrdrnd")
4752	fi
4753	if [[ "$HAVE_X86_RDSEED" -ne "0" ]]; then
4754		OPTS+=("-mrdseed")
4755	fi
4756	if [[ "$HAVE_X86_PCLMUL" -ne "0" ]]; then
4757		OPTS+=("-mpclmul")
4758	fi
4759
4760	"$MAKE" clean > /dev/null 2>&1
4761	rm -f adhoc.cpp > /dev/null 2>&1
4762
4763	CXXFLAGS="$RELEASE_CXXFLAGS ${OPTS[@]} ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4764	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4765	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4766		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4767	else
4768		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4769		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4770			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4771		fi
4772		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4773		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4774			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4775		fi
4776	fi
4777fi
4778
4779############################################
4780# Benchmarks
4781if [[ "$WANT_BENCHMARKS" -ne "0" ]]; then
4782
4783	############################################
4784	# Benchmarks, c++03
4785	if [[ "$HAVE_CXX03" -ne "0" ]]; then
4786		echo
4787		echo "************************************" | tee -a "$TEST_RESULTS"
4788		echo "Testing: Benchmarks, c++03" | tee -a "$TEST_RESULTS"
4789		echo
4790
4791		"$MAKE" clean > /dev/null 2>&1
4792
4793		CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4794		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4795
4796		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4797			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4798		else
4799			echo "**************************************" >> "$BENCHMARK_RESULTS"
4800			./cryptest.exe b 3 "$CPU_FREQ" 2>&1 | tee -a "$BENCHMARK_RESULTS"
4801			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4802				echo "ERROR: failed to execute benchmarks" | tee -a "$BENCHMARK_RESULTS"
4803			fi
4804		fi
4805	fi
4806
4807	############################################
4808	# Benchmarks, c++11
4809	if [[ "$HAVE_CXX11" -ne "0" ]]; then
4810		echo
4811		echo "************************************" | tee -a "$TEST_RESULTS"
4812		echo "Testing: Benchmarks, c++11" | tee -a "$TEST_RESULTS"
4813		echo
4814
4815		"$MAKE" clean > /dev/null 2>&1
4816		rm -f adhoc.cpp > /dev/null 2>&1
4817
4818		CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4819		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4820
4821		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4822			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4823		else
4824			echo "**************************************" >> "$BENCHMARK_RESULTS"
4825			./cryptest.exe b 3 "$CPU_FREQ" 2>&1 | tee -a "$BENCHMARK_RESULTS"
4826			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4827				echo "ERROR: failed to execute benchmarks" | tee -a "$BENCHMARK_RESULTS"
4828			fi
4829		fi
4830	fi
4831
4832	############################################
4833	# Benchmarks, c++14
4834	if [[ "$HAVE_CXX14" -ne "0" ]]; then
4835		echo
4836		echo "************************************" | tee -a "$TEST_RESULTS"
4837		echo "Testing: Benchmarks, c++14" | tee -a "$TEST_RESULTS"
4838		echo
4839
4840		"$MAKE" clean > /dev/null 2>&1
4841		rm -f adhoc.cpp > /dev/null 2>&1
4842
4843		CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4844		CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4845
4846		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4847			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4848		else
4849			echo "**************************************" >> "$BENCHMARK_RESULTS"
4850			./cryptest.exe b 3 "$CPU_FREQ" 2>&1 | tee -a "$BENCHMARK_RESULTS"
4851			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4852				echo "ERROR: failed to execute benchmarks" | tee -a "$BENCHMARK_RESULTS"
4853			fi
4854		fi
4855	fi
4856fi
4857
4858# For Cygwin, we need to test both PREFER_BERKELEY_STYLE_SOCKETS
4859#   and PREFER_WINDOWS_STYLE_SOCKETS
4860
4861############################################
4862# MinGW and PREFER_BERKELEY_STYLE_SOCKETS
4863if [[ "$IS_MINGW" -ne "0" ]]; then
4864	echo
4865	echo "************************************" | tee -a "$TEST_RESULTS"
4866	echo "Testing: MinGW, PREFER_BERKELEY_STYLE_SOCKETS" | tee -a "$TEST_RESULTS"
4867	echo
4868
4869	"$MAKE" clean > /dev/null 2>&1
4870	rm -f adhoc.cpp > /dev/null 2>&1
4871
4872	CXXFLAGS="$RELEASE_CXXFLAGS -DPREFER_BERKELEY_STYLE_SOCKETS -DNO_WINDOWS_STYLE_SOCKETS ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4873	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4874
4875	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4876		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4877	else
4878		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4879		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4880			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4881		fi
4882		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4883		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4884			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4885		fi
4886	fi
4887fi
4888
4889############################################
4890# MinGW and PREFER_WINDOWS_STYLE_SOCKETS
4891if [[ "$IS_MINGW" -ne "0" ]]; then
4892	echo
4893	echo "************************************" | tee -a "$TEST_RESULTS"
4894	echo "Testing: MinGW, PREFER_WINDOWS_STYLE_SOCKETS" | tee -a "$TEST_RESULTS"
4895	echo
4896
4897	"$MAKE" clean > /dev/null 2>&1
4898	rm -f adhoc.cpp > /dev/null 2>&1
4899
4900	CXXFLAGS="$RELEASE_CXXFLAGS -DPREFER_WINDOWS_STYLE_SOCKETS -DNO_BERKELEY_STYLE_SOCKETS ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4901	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4902
4903	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4904		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4905	else
4906		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4907		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4908			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
4909		fi
4910		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4911		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4912			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
4913		fi
4914	fi
4915fi
4916
4917############################################
4918# Valgrind, c++03. Requires -O1 for accurate results
4919if [[ "$HAVE_CXX03" -ne "0" && "$HAVE_VALGRIND" -ne "0" ]]; then
4920	echo
4921	echo "************************************" | tee -a "$TEST_RESULTS"
4922	echo "Testing: Valgrind, c++03" | tee -a "$TEST_RESULTS"
4923	echo
4924
4925	"$MAKE" clean > /dev/null 2>&1
4926	rm -f adhoc.cpp > /dev/null 2>&1
4927
4928	CXXFLAGS="$VALGRIND_CXXFLAGS -std=c++03 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4929	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4930
4931	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4932		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4933	else
4934		valgrind --track-origins=yes ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4935		valgrind --track-origins=yes ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4936	fi
4937fi
4938
4939############################################
4940# Valgrind, c++11. Requires -O1 for accurate results
4941if [[ ("$HAVE_VALGRIND" -ne "0" && "$HAVE_CXX11" -ne "0") ]]; then
4942	echo
4943	echo "************************************" | tee -a "$TEST_RESULTS"
4944	echo "Testing: Valgrind, c++11" | tee -a "$TEST_RESULTS"
4945	echo
4946
4947	"$MAKE" clean > /dev/null 2>&1
4948	rm -f adhoc.cpp > /dev/null 2>&1
4949
4950	CXXFLAGS="$VALGRIND_CXXFLAGS -std=c++11 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4951	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4952
4953	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4954		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4955	else
4956		valgrind --track-origins=yes ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4957		valgrind --track-origins=yes ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4958	fi
4959fi
4960
4961############################################
4962# Valgrind, c++14. Requires -O1 for accurate results
4963if [[ ("$HAVE_VALGRIND" -ne "0" && "$HAVE_CXX14" -ne "0") ]]; then
4964	echo
4965	echo "************************************" | tee -a "$TEST_RESULTS"
4966	echo "Testing: Valgrind, c++14" | tee -a "$TEST_RESULTS"
4967	echo
4968
4969	"$MAKE" clean > /dev/null 2>&1
4970	rm -f adhoc.cpp > /dev/null 2>&1
4971
4972	CXXFLAGS="$VALGRIND_CXXFLAGS -std=c++14 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4973	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4974
4975	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4976		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4977	else
4978		valgrind --track-origins=yes ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
4979		valgrind --track-origins=yes ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
4980	fi
4981fi
4982
4983############################################
4984# Valgrind, c++17. Requires -O1 for accurate results
4985if [[ ("$HAVE_VALGRIND" -ne "0" && "$HAVE_CXX17" -ne "0") ]]; then
4986	echo
4987	echo "************************************" | tee -a "$TEST_RESULTS"
4988	echo "Testing: Valgrind, c++17" | tee -a "$TEST_RESULTS"
4989	echo
4990
4991	"$MAKE" clean > /dev/null 2>&1
4992	rm -f adhoc.cpp > /dev/null 2>&1
4993
4994	CXXFLAGS="$VALGRIND_CXXFLAGS -std=c++17 ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
4995	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
4996
4997	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
4998		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
4999	else
5000		valgrind --track-origins=yes ./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5001		valgrind --track-origins=yes ./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5002	fi
5003fi
5004
5005############################################
5006# C++03 with elevated warnings
5007if [[ ("$HAVE_CXX03" -ne "0" && ("$HAVE_GCC" -ne "0" || "$HAVE_CLANG" -ne "0")) ]]; then
5008
5009	############################################
5010	# Debug build
5011	echo
5012	echo "************************************" | tee -a "$WARN_RESULTS"
5013	echo "Testing: Debug, c++03, elevated warnings" | tee -a "$WARN_RESULTS"
5014	echo
5015
5016	"$MAKE" clean > /dev/null 2>&1
5017	rm -f adhoc.cpp > /dev/null 2>&1
5018
5019	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++03 ${ELEVATED_CXXFLAGS[@]}"
5020	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
5021
5022	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5023		echo "ERROR: failed to make cryptest.exe" | tee -a "$WARN_RESULTS"
5024	fi
5025
5026	############################################
5027	# Release build
5028	echo
5029	echo "************************************" | tee -a "$WARN_RESULTS"
5030	echo "Testing: Release, c++03, elevated warnings" | tee -a "$WARN_RESULTS"
5031	echo
5032
5033	"$MAKE" clean > /dev/null 2>&1
5034	rm -f adhoc.cpp > /dev/null 2>&1
5035
5036	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++03 $RELEASE_CXXFLAGS_ELEVATED"
5037	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
5038	if [[ "$?" -ne "0" ]]; then
5039		echo "ERROR: failed to make cryptest.exe" | tee -a "$WARN_RESULTS"
5040	fi
5041fi
5042
5043############################################
5044# C++11 with elevated warnings
5045if [[ ("$HAVE_CXX11" -ne "0" && ("$HAVE_GCC" -ne "0" || "$HAVE_CLANG" -ne "0")) ]]; then
5046
5047	############################################
5048	# Debug build
5049	echo
5050	echo "************************************" | tee -a "$WARN_RESULTS"
5051	echo "Testing: Debug, c++11, elevated warnings" | tee -a "$WARN_RESULTS"
5052	echo
5053
5054	"$MAKE" clean > /dev/null 2>&1
5055	rm -f adhoc.cpp > /dev/null 2>&1
5056
5057	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++11 ${ELEVATED_CXXFLAGS[@]}"
5058	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
5059
5060	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5061		echo "ERROR: failed to make cryptest.exe" | tee -a "$WARN_RESULTS"
5062	fi
5063
5064	############################################
5065	# Release build
5066	echo
5067	echo "************************************" | tee -a "$WARN_RESULTS"
5068	echo "Testing: Release, c++11, elevated warnings" | tee -a "$WARN_RESULTS"
5069	echo
5070
5071	"$MAKE" clean > /dev/null 2>&1
5072	rm -f adhoc.cpp > /dev/null 2>&1
5073
5074	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++11 ${ELEVATED_CXXFLAGS[@]}"
5075	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
5076	if [[ "$?" -ne "0" ]]; then
5077		echo "ERROR: failed to make cryptest.exe" | tee -a "$WARN_RESULTS"
5078	fi
5079fi
5080
5081############################################
5082# C++14 with elevated warnings
5083if [[ ("$HAVE_CXX14" -ne "0" && ("$HAVE_GCC" -ne "0" || "$HAVE_CLANG" -ne "0")) ]]; then
5084
5085	############################################
5086	# Debug build
5087	echo
5088	echo "************************************" | tee -a "$WARN_RESULTS"
5089	echo "Testing: Debug, c++14, elevated warnings" | tee -a "$WARN_RESULTS"
5090	echo
5091
5092	"$MAKE" clean > /dev/null 2>&1
5093	rm -f adhoc.cpp > /dev/null 2>&1
5094
5095	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++14 ${ELEVATED_CXXFLAGS[@]}"
5096	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
5097
5098	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5099		echo "ERROR: failed to make cryptest.exe" | tee -a "$WARN_RESULTS"
5100	fi
5101
5102	############################################
5103	# Release build
5104	echo
5105	echo "************************************" | tee -a "$WARN_RESULTS"
5106	echo "Testing: Release, c++14, elevated warnings" | tee -a "$WARN_RESULTS"
5107	echo
5108
5109	"$MAKE" clean > /dev/null 2>&1
5110	rm -f adhoc.cpp > /dev/null 2>&1
5111
5112	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++14 ${ELEVATED_CXXFLAGS[@]}"
5113	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
5114	if [[ "$?" -ne "0" ]]; then
5115		echo "ERROR: failed to make cryptest.exe" | tee -a "$WARN_RESULTS"
5116	fi
5117fi
5118
5119############################################
5120# C++17 with elevated warnings
5121if [[ ("$HAVE_CXX17" -ne "0" && ("$HAVE_GCC" -ne "0" || "$HAVE_CLANG" -ne "0")) ]]; then
5122
5123	############################################
5124	# Debug build
5125	echo
5126	echo "************************************" | tee -a "$WARN_RESULTS"
5127	echo "Testing: Debug, c++17, elevated warnings" | tee -a "$WARN_RESULTS"
5128	echo
5129
5130	"$MAKE" clean > /dev/null 2>&1
5131	rm -f adhoc.cpp > /dev/null 2>&1
5132
5133	CXXFLAGS="$DEBUG_CXXFLAGS -std=c++17 ${ELEVATED_CXXFLAGS[@]}"
5134	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
5135
5136	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5137		echo "ERROR: failed to make cryptest.exe" | tee -a "$WARN_RESULTS"
5138	fi
5139
5140	############################################
5141	# Release build
5142	echo
5143	echo "************************************" | tee -a "$WARN_RESULTS"
5144	echo "Testing: Release, c++17, elevated warnings" | tee -a "$WARN_RESULTS"
5145	echo
5146
5147	"$MAKE" clean > /dev/null 2>&1
5148	rm -f adhoc.cpp > /dev/null 2>&1
5149
5150	CXXFLAGS="$RELEASE_CXXFLAGS -std=c++17 ${ELEVATED_CXXFLAGS[@]}"
5151	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$WARN_RESULTS"
5152
5153	if [[ "$?" -ne "0" ]]; then
5154		echo "ERROR: failed to make cryptest.exe" | tee -a "$WARN_RESULTS"
5155	fi
5156fi
5157
5158############################################
5159# Perform a quick check with Clang, if available.
5160#   This check was added after testing on Ubuntu 14.04 with Clang 3.4.
5161if [[ ("$CLANG_COMPILER" -eq "0") ]]; then
5162
5163	CLANG_CXX=$(which clang++ 2>&1 | "$GREP" -v "no clang++" | head -1)
5164	"$CLANG_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5165	if [[ "$?" -eq "0" ]]; then
5166
5167		############################################
5168		# Clang build
5169		echo
5170		echo "************************************" | tee -a "$TEST_RESULTS"
5171		echo "Testing: Clang compiler" | tee -a "$TEST_RESULTS"
5172		echo
5173
5174		"$MAKE" clean > /dev/null 2>&1
5175		rm -f adhoc.cpp > /dev/null 2>&1
5176
5177		CXXFLAGS="-DNDEBUG -g2 -O2"
5178		CXX="$CLANG_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5179		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5180			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5181		else
5182			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5183			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5184				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5185			fi
5186			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5187			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5188				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5189			fi
5190		fi
5191	fi
5192fi
5193
5194############################################
5195# Perform a quick check with GCC, if available.
5196if [[ ("$GCC_COMPILER" -eq "0") ]]; then
5197
5198	GCC_CXX=$(which g++ 2>&1 | "$GREP" -v "no g++" | head -1)
5199	"$GCC_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5200	if [[ "$?" -eq "0" ]]; then
5201
5202		############################################
5203		# GCC build
5204		echo
5205		echo "************************************" | tee -a "$TEST_RESULTS"
5206		echo "Testing: GCC compiler" | tee -a "$TEST_RESULTS"
5207		echo
5208
5209		"$MAKE" clean > /dev/null 2>&1
5210		rm -f adhoc.cpp > /dev/null 2>&1
5211
5212		CXXFLAGS="-DNDEBUG -g2 -O2"
5213		CXX="$GCC_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5214		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5215			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5216		else
5217			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5218			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5219				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5220			fi
5221			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5222			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5223				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5224			fi
5225		fi
5226	fi
5227fi
5228
5229############################################
5230# Perform a quick check with Intel ICPC, if available.
5231if [[ ("$INTEL_COMPILER" -eq "0") ]]; then
5232
5233	INTEL_CXX=$(which icpc 2>&1 | "$GREP" -v "no icpc" | head -1)
5234	if [[ (-z "$INTEL_CXX") ]]; then
5235		INTEL_CXX=$(find /opt/intel -name icpc 2>/dev/null | "$GREP" -iv composer | head -1)
5236	fi
5237	"$INTEL_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5238	if [[ "$?" -eq "0" ]]; then
5239
5240		############################################
5241		# INTEL build
5242		echo
5243		echo "************************************" | tee -a "$TEST_RESULTS"
5244		echo "Testing: INTEL compiler" | tee -a "$TEST_RESULTS"
5245		echo
5246
5247		"$MAKE" clean > /dev/null 2>&1
5248		rm -f adhoc.cpp > /dev/null 2>&1
5249
5250		CXXFLAGS="-DNDEBUG -g2 -O2"
5251		CXX="$INTEL_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5252		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5253			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5254		else
5255			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5256			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5257				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5258			fi
5259			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5260			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5261				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5262			fi
5263		fi
5264	fi
5265fi
5266
5267############################################
5268# Perform a quick check with MacPorts compilers, if available.
5269if [[ ("$IS_DARWIN" -ne "0" && "$MACPORTS_COMPILER" -eq "0") ]]; then
5270
5271	MACPORTS_CXX=$(find /opt/local/bin -name 'g++-mp-4*' 2>/dev/null | head -1)
5272	if [[ (! -z "$MACPORTS_CXX") ]]; then
5273		"$MACPORTS_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5274		if [[ "$?" -eq "0" ]]; then
5275
5276			############################################
5277			# MacPorts GCC 4.x build
5278			echo
5279			echo "************************************" | tee -a "$TEST_RESULTS"
5280			echo "Testing: MacPorts 4.x GCC compiler" | tee -a "$TEST_RESULTS"
5281			echo
5282
5283			"$MAKE" clean > /dev/null 2>&1
5284			rm -f adhoc.cpp > /dev/null 2>&1
5285
5286			# We want to use -stdlib=libstdc++ below, but it causes a compile error. Maybe MacPorts hardwired libc++.
5287			CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11"
5288			CXX="$MACPORTS_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5289			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5290				echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5291			else
5292				./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5293				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5294					echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5295				fi
5296				./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5297				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5298					echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5299				fi
5300			fi
5301		fi
5302	fi
5303
5304	MACPORTS_CXX=$(find /opt/local/bin -name 'g++-mp-5*' 2>/dev/null | head -1)
5305	if [[ (! -z "$MACPORTS_CXX") ]]; then
5306		"$MACPORTS_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5307		if [[ "$?" -eq "0" ]]; then
5308
5309			############################################
5310			# MacPorts GCC 5.x build
5311			echo
5312			echo "************************************" | tee -a "$TEST_RESULTS"
5313			echo "Testing: MacPorts 5.x GCC compiler" | tee -a "$TEST_RESULTS"
5314			echo
5315
5316			"$MAKE" clean > /dev/null 2>&1
5317			rm -f adhoc.cpp > /dev/null 2>&1
5318
5319			# We want to use -stdlib=libstdc++ below, but it causes a compile error. Maybe MacPorts hardwired libc++.
5320			CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11"
5321			CXX="$MACPORTS_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5322			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5323				echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5324			else
5325				./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5326				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5327					echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5328				fi
5329				./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5330				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5331					echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5332				fi
5333			fi
5334		fi
5335	fi
5336
5337	MACPORTS_CXX=$(find /opt/local/bin -name 'g++-mp-6*' 2>/dev/null | head -1)
5338	if [[ (! -z "$MACPORTS_CXX") ]]; then
5339		"$MACPORTS_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5340		if [[ "$?" -eq "0" ]]; then
5341
5342			############################################
5343			# MacPorts GCC 6.x build
5344			echo
5345			echo "************************************" | tee -a "$TEST_RESULTS"
5346			echo "Testing: MacPorts 6.x GCC compiler" | tee -a "$TEST_RESULTS"
5347			echo
5348
5349			"$MAKE" clean > /dev/null 2>&1
5350			rm -f adhoc.cpp > /dev/null 2>&1
5351
5352			# We want to use -stdlib=libstdc++ below, but it causes a compile error. Maybe MacPorts hardwired libc++.
5353			CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11"
5354			CXX="$MACPORTS_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5355			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5356				echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5357			else
5358				./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5359				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5360					echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5361				fi
5362				./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5363				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5364					echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5365				fi
5366			fi
5367		fi
5368	fi
5369
5370	MACPORTS_CXX=$(find /opt/local/bin -name 'g++-mp-7*' 2>/dev/null | head -1)
5371	if [[ (! -z "$MACPORTS_CXX") ]]; then
5372		"$MACPORTS_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5373		if [[ "$?" -eq "0" ]]; then
5374
5375			############################################
5376			# MacPorts GCC 7.x build
5377			echo
5378			echo "************************************" | tee -a "$TEST_RESULTS"
5379			echo "Testing: MacPorts 7.x GCC compiler" | tee -a "$TEST_RESULTS"
5380			echo
5381
5382			"$MAKE" clean > /dev/null 2>&1
5383			rm -f adhoc.cpp > /dev/null 2>&1
5384
5385			# We want to use -stdlib=libstdc++ below, but it causes a compile error. Maybe MacPorts hardwired libc++.
5386			CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11"
5387			CXX="$MACPORTS_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5388			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5389				echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5390			else
5391				./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5392				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5393					echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5394				fi
5395				./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5396				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5397					echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5398				fi
5399			fi
5400		fi
5401	fi
5402
5403	MACPORTS_CXX=$(find /opt/local/bin -name 'clang++-mp-3.7*' 2>/dev/null | head -1)
5404	if [[ (! -z "$MACPORTS_CXX") ]]; then
5405		"$MACPORTS_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5406		if [[ "$?" -eq "0" ]]; then
5407
5408			############################################
5409			# MacPorts 3.7 Clang build
5410			echo
5411			echo "************************************" | tee -a "$TEST_RESULTS"
5412			echo "Testing: MacPorts 3.7 Clang compiler" | tee -a "$TEST_RESULTS"
5413			echo
5414
5415			"$MAKE" clean > /dev/null 2>&1
5416			rm -f adhoc.cpp > /dev/null 2>&1
5417
5418			CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11 -stdlib=libc++"
5419			CXX="$MACPORTS_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5420			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5421				echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5422			else
5423				./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5424				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5425					echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5426				fi
5427				./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5428				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5429					echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5430				fi
5431			fi
5432		fi
5433	fi
5434
5435	MACPORTS_CXX=$(find /opt/local/bin -name 'clang++-mp-3.8*' 2>/dev/null | head -1)
5436	if [[ (! -z "$MACPORTS_CXX") ]]; then
5437		"$MACPORTS_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5438		if [[ "$?" -eq "0" ]]; then
5439
5440			############################################
5441			# MacPorts 3.8 Clang build
5442			echo
5443			echo "************************************" | tee -a "$TEST_RESULTS"
5444			echo "Testing: MacPorts 3.8 Clang compiler" | tee -a "$TEST_RESULTS"
5445			echo
5446
5447			"$MAKE" clean > /dev/null 2>&1
5448			rm -f adhoc.cpp > /dev/null 2>&1
5449
5450			CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11 -stdlib=libc++"
5451			CXX="$MACPORTS_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5452			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5453				echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5454			else
5455				./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5456				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5457					echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5458				fi
5459				./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5460				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5461					echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5462				fi
5463			fi
5464		fi
5465	fi
5466
5467	MACPORTS_CXX=$(find /opt/local/bin -name 'clang++-mp-3.9*' 2>/dev/null | head -1)
5468	if [[ (! -z "$MACPORTS_CXX") ]]; then
5469		"$MACPORTS_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5470		if [[ "$?" -eq "0" ]]; then
5471
5472			############################################
5473			# MacPorts 3.9 Clang build
5474			echo
5475			echo "************************************" | tee -a "$TEST_RESULTS"
5476			echo "Testing: MacPorts 3.9 Clang compiler" | tee -a "$TEST_RESULTS"
5477			echo
5478
5479			"$MAKE" clean > /dev/null 2>&1
5480			rm -f adhoc.cpp > /dev/null 2>&1
5481
5482			CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11 -stdlib=libc++"
5483			CXX="$MACPORTS_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5484			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5485				echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5486			else
5487				./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5488				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5489					echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5490				fi
5491				./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5492				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5493					echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5494				fi
5495			fi
5496		fi
5497	fi
5498
5499	MACPORTS_CXX=$(find /opt/local/bin -name 'clang++-mp-4*' 2>/dev/null | head -1)
5500	if [[ (! -z "$MACPORTS_CXX") ]]; then
5501		"$MACPORTS_CXX" -x c++ -DCRYPTOPP_ADHOC_MAIN adhoc.cpp.proto -o "$TMP/adhoc.exe" > /dev/null 2>&1
5502		if [[ "$?" -eq "0" ]]; then
5503
5504			############################################
5505			# MacPorts 4.x Clang build
5506			echo
5507			echo "************************************" | tee -a "$TEST_RESULTS"
5508			echo "Testing: MacPorts 4.x Clang compiler" | tee -a "$TEST_RESULTS"
5509			echo
5510
5511			"$MAKE" clean > /dev/null 2>&1
5512			rm -f adhoc.cpp > /dev/null 2>&1
5513
5514			CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11 -stdlib=libc++"
5515			CXX="$MACPORTS_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5516			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5517				echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5518			else
5519				./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5520				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5521					echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5522				fi
5523				./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5524				if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5525					echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5526				fi
5527			fi
5528		fi
5529	fi
5530fi
5531
5532############################################
5533# Perform a quick check with Xcode compiler, if available.
5534if [[ "$IS_DARWIN" -ne "0" ]]; then
5535	XCODE_CXX=$(find /Applications/Xcode*.app/Contents/Developer -name clang++ 2>/dev/null | head -1)
5536	if [[ (-z "$XCODE_CXX") ]]; then
5537		XCODE_CXX=$(find /Developer/Applications/Xcode.app -name clang++ 2>/dev/null | head -1)
5538	fi
5539
5540	if [[ !(-z "$XCODE_CXX") ]]; then
5541		echo
5542		echo "************************************" | tee -a "$TEST_RESULTS"
5543		echo "Testing: Xcode Clang compiler" | tee -a "$TEST_RESULTS"
5544		echo
5545
5546		"$MAKE" clean > /dev/null 2>&1
5547		rm -f adhoc.cpp > /dev/null 2>&1
5548
5549		CXXFLAGS="-DNDEBUG -g2 -O2"
5550		CXX="$XCODE_CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static cryptest.exe 2>&1 | tee -a "$TEST_RESULTS"
5551
5552		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5553			echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS"
5554		else
5555			./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS"
5556			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5557				echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS"
5558			fi
5559			./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS"
5560			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5561				echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS"
5562			fi
5563		fi
5564	fi
5565fi
5566
5567############################################
5568# Test an install with CRYPTOPP_DATA_DIR
5569if [[ ("$IS_CYGWIN" -eq "0") && ("$IS_MINGW" -eq "0") ]]; then
5570
5571	echo
5572	echo "************************************" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5573	echo "Testing: Test install with data directory" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5574	echo
5575
5576	"$MAKE" clean > /dev/null 2>&1
5577	rm -f adhoc.cpp > /dev/null 2>&1
5578
5579	INSTALL_DIR="/tmp/cryptopp_test"
5580	rm -rf "$INSTALL_DIR" > /dev/null 2>&1
5581
5582	CXXFLAGS="$RELEASE_CXXFLAGS -DCRYPTOPP_DATA_DIR='\"$INSTALL_DIR/share/cryptopp/\"' ${PLATFORM_CXXFLAGS[@]} $USER_CXXFLAGS"
5583	CXX="$CXX" CXXFLAGS="$CXXFLAGS" "$MAKE" "${MAKEARGS[@]}" static dynamic cryptest.exe 2>&1 | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5584
5585	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5586		echo "ERROR: failed to make cryptest.exe" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5587	else
5588		OLD_DIR=$(pwd)
5589		"$MAKE" "${MAKEARGS[@]}" install PREFIX="$INSTALL_DIR" 2>&1 | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5590		cd "$INSTALL_DIR/bin"
5591
5592		echo
5593		echo "************************************" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5594		echo "Testing: Install (validation suite)" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5595		echo
5596		./cryptest.exe v 2>&1 | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5597		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5598			echo "ERROR: failed to execute validation suite" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5599		fi
5600
5601		echo
5602		echo "************************************" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5603		echo "Testing: Install (test vectors)" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5604		echo
5605		./cryptest.exe tv all 2>&1 | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5606		if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5607			echo "ERROR: failed to execute test vectors" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5608		fi
5609
5610		if [[ "$WANT_BENCHMARKS" -ne "0" ]]; then
5611			echo
5612			echo "************************************" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5613			echo "Testing: Install (benchmarks)" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5614			echo
5615			./cryptest.exe b 1 "$CPU_FREQ" 2>&1 | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5616			if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5617				echo "ERROR: failed to execute benchmarks" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5618			fi
5619		fi
5620
5621		echo
5622		echo "************************************" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5623		echo "Testing: Install (help file)" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5624		echo
5625		./cryptest.exe h 2>&1 | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5626		if [[ ("${PIPESTATUS[0]}" -ne "1") ]]; then
5627			echo "ERROR: failed to provide help" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5628		fi
5629
5630		# Restore original PWD
5631		cd "$OLD_DIR"
5632	fi
5633fi
5634
5635############################################
5636# Test a remove with CRYPTOPP_DATA_DIR
5637if [[ ("$IS_CYGWIN" -eq "0" && "$IS_MINGW" -eq "0") ]]; then
5638
5639	echo
5640	echo "************************************" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5641	echo "Testing: Test remove with data directory" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5642	echo
5643
5644	"$MAKE" "${MAKEARGS[@]}" remove PREFIX="$INSTALL_DIR" 2>&1 | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5645	if [[ ("${PIPESTATUS[0]}" -ne "0") ]]; then
5646		echo "ERROR: failed to make remove" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5647	else
5648		# Test for complete removal
5649		if [[ (-d "$INSTALL_DIR/include/cryptopp") ]]; then
5650			echo "ERROR: failed to remove cryptopp include directory" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5651		fi
5652		if [[ (-d "$INSTALL_DIR/share/cryptopp") ]]; then
5653			echo "ERROR: failed to remove cryptopp share directory" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5654		fi
5655		if [[ (-d "$INSTALL_DIR/share/cryptopp/TestData") ]]; then
5656			echo "ERROR: failed to remove cryptopp test data directory" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5657		fi
5658		if [[ (-d "$INSTALL_DIR/share/cryptopp/TestVector") ]]; then
5659			echo "ERROR: failed to remove cryptopp test vector directory" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5660		fi
5661		if [[ (-e "$INSTALL_DIR/bin/cryptest.exe") ]]; then
5662			echo "ERROR: failed to remove cryptest.exe program" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5663		fi
5664		if [[ (-e "$INSTALL_DIR/lib/libcryptopp.a") ]]; then
5665			echo "ERROR: failed to remove libcryptopp.a static library" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5666		fi
5667		if [[ "$IS_DARWIN" -ne "0" && (-e "$INSTALL_DIR/lib/libcryptopp.dylib") ]]; then
5668			echo "ERROR: failed to remove libcryptopp.dylib dynamic library" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5669		elif [[ (-e "$INSTALL_DIR/lib/libcryptopp.so") ]]; then
5670			echo "ERROR: failed to remove libcryptopp.so dynamic library" | tee -a "$TEST_RESULTS" "$INSTALL_RESULTS"
5671		fi
5672	fi
5673fi
5674
5675#############################################
5676#############################################
5677################ END TESTING ################
5678#############################################
5679#############################################
5680
5681TEST_END=$(date)
5682
5683############################################
5684# Cleanup, but leave output files
5685"$MAKE" clean > /dev/null 2>&1
5686rm -f adhoc.cpp > /dev/null 2>&1
5687
5688############################################
5689# Report tests performed
5690
5691echo
5692echo "************************************************" | tee -a "$TEST_RESULTS"
5693echo "************************************************" | tee -a "$TEST_RESULTS"
5694echo | tee -a "$TEST_RESULTS"
5695
5696COUNT=$("$GREP" 'Testing:' "$TEST_RESULTS" "$WARN_RESULTS" | wc -l | "$AWK" '{print $1}')
5697if (( "$COUNT" == "0" )); then
5698	echo "No configurations tested" | tee -a "$TEST_RESULTS"
5699else
5700	echo "$COUNT configurations tested" | tee -a "$TEST_RESULTS"
5701	ESCAPED=$("$GREP" 'Testing: ' "$TEST_RESULTS" | "$AWK" -F ": " '{print " - " $2 "$"}')
5702	echo " "$ESCAPED | tr $ '\n' | tee -a "$TEST_RESULTS"
5703	ESCAPED=$("$GREP" 'Testing: ' "$WARN_RESULTS" | "$AWK" -F ": " '{print " - " $2 "$"}')
5704	echo " "$ESCAPED | tr '$' '\n' | tee -a "$TEST_RESULTS"
5705fi
5706echo | tee -a "$TEST_RESULTS"
5707
5708############################################
5709# Report errors
5710
5711echo
5712echo "************************************************" | tee -a "$TEST_RESULTS"
5713echo | tee -a "$TEST_RESULTS"
5714
5715# "FAILED" and "Exception" are from Crypto++
5716# "ERROR" is from this script
5717# "Error" is from the GNU assembler
5718# "error" is from the sanitizers
5719# "Illegal", "Conditional", "0 errors" and "suppressed errors" are from Valgrind.
5720ECOUNT=$("$EGREP" '(Error|ERROR|error|FAILED|Illegal|Conditional|CryptoPP::Exception)' $TEST_RESULTS | "$EGREP" -v '( 0 errors|suppressed errors|error detector)' | wc -l | "$AWK" '{print $1}')
5721if (( "$ECOUNT" == "0" )); then
5722	echo "No failures detected" | tee -a "$TEST_RESULTS"
5723else
5724	echo "$ECOUNT errors detected. See $TEST_RESULTS for details" | tee -a "$TEST_RESULTS"
5725	if (( "$ECOUNT" < 16 )); then
5726		"$EGREP" -n '(Error|ERROR|error|FAILED|Illegal|Conditional|CryptoPP::Exception)' "$TEST_RESULTS" | "$EGREP" -v '( 0 errors|suppressed errors|error detector)'
5727	fi
5728fi
5729
5730############################################
5731# Report warnings
5732
5733echo
5734echo "************************************************" | tee -a "$TEST_RESULTS" "$WARN_RESULTS"
5735echo | tee -a "$TEST_RESULTS" "$WARN_RESULTS"
5736
5737WCOUNT=$("$EGREP" '(warning:)' $WARN_RESULTS | wc -l | "$AWK" '{print $1}')
5738if (( "$WCOUNT" == "0" )); then
5739	echo "No warnings detected" | tee -a "$TEST_RESULTS" "$WARN_RESULTS"
5740else
5741	echo "$WCOUNT warnings detected. See $WARN_RESULTS for details" | tee -a "$TEST_RESULTS" "$WARN_RESULTS"
5742	# "$EGREP" -n '(warning:)' $WARN_RESULTS | "$GREP" -v 'deprecated-declarations'
5743fi
5744
5745############################################
5746# Report execution time
5747
5748echo
5749echo "************************************************" | tee -a "$TEST_RESULTS" "$WARN_RESULTS"
5750echo | tee -a "$TEST_RESULTS" "$WARN_RESULTS"
5751
5752echo "Testing started: $TEST_BEGIN" | tee -a "$TEST_RESULTS" "$WARN_RESULTS"
5753echo "Testing finished: $TEST_END" | tee -a "$TEST_RESULTS" "$WARN_RESULTS"
5754echo
5755
5756############################################
5757# http://tldp.org/LDP/abs/html/exitcodes.html#EXITCODESREF
5758if (( "$ECOUNT" == "0" )); then
5759	[[ "$0" = "$BASH_SOURCE" ]] && exit 0 || return 0
5760else
5761	[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
5762fi
5763