xref: /isa-l/tools/test_extended.sh (revision df073be348a90fab995aa8a6bbbb3176ed46303c)
1#!/usr/bin/env bash
2
3# Extended tests: Run a few more options other than make check
4
5set -xe #exit on fail
6
7# Defaults
8cpus=1
9S=$RANDOM
10MAKE=make
11READLINK=readlink
12test_level=check
13build_opt=''
14msg=''
15
16# Override defaults if exist
17command -V gmake >/dev/null 2>&1 && MAKE=gmake
18command -V greadlink >/dev/null 2>&1 && READLINK=greadlink
19[ -n "$CC" ] && build_opt+="CC=$CC "
20[ -n "$AS" ] && build_opt+="AS=$AS "
21
22out="$PWD"
23src=$($READLINK -f $(dirname $0))/..
24source $src/tools/test_tools.sh
25cd "$src"
26
27# Run on mult cpus
28if command -V lscpu >/dev/null 2>&1; then
29    cpus=`lscpu -p | tail -1 | cut -d, -f 2`
30    cpus=$(($cpus + 1))
31elif command -V sysctl; then
32    if sysctl -n hw.ncpu >/dev/null 2>&1; then
33	cpus=$(sysctl -n hw.ncpu)
34	cpus=$(($cpus + 1))
35    fi
36fi
37echo "Using $cpus cpu threads"
38
39if [ -z "$S" ]; then
40    S=`tr -cd 0-9 </dev/urandom | head -c 4 | sed -e 's/^0*/1/g'`
41    [ "$S" -gt 0 ] 2> /dev/null || S="123"
42fi
43msg+="Running with TEST_SEED=$S".$'\n'
44
45# Fix Darwin issues
46if uname | grep -q 'Darwin' 2>&1; then
47    export SED=`which sed`
48fi
49
50# Check for test libs to add
51if command -V ldconfig >/dev/null 2>&1; then
52    if ldconfig -p | grep -q libz.so; then
53	test_level=test
54	msg+=$'With extra tests\n'
55    fi
56    if ldconfig -p | grep -q libefence.so; then
57	build_opt+="LDFLAGS+='-lefence' "
58	msg+=$'With efence\n'
59    fi
60fi
61
62# Std makefile build test
63$MAKE -f Makefile.unx clean
64test_start "extended_build_test"
65time $MAKE -f Makefile.unx -j $cpus $build_opt
66test_end "extended_build_test" $?
67msg+=$'Std makefile build: Pass\n'
68
69# Check for gnu executable stack set
70if command -V readelf >/dev/null 2>&1; then
71    test_start "stack_nx_check"
72    if readelf -W -l bin/libisal.so | grep 'GNU_STACK' | grep -q 'RWE'; then
73	echo $0: Stack NX check bin/libisal.so: Fail
74	test_end "stack_nx_check" 1
75	exit 1
76    else
77	test_end "stack_nx_check" 0
78	msg+=$'Stack NX check bin/lib/libisal.so: Pass\n'
79    fi
80else
81    msg+=$'Stack NX check not supported: Skip\n'
82fi
83
84# Std makefile build perf tests
85test_start "extended_perf_test"
86time $MAKE -f Makefile.unx -j $cpus perfs
87test_end "extended_perf_test" $?
88msg+=$'Std makefile build perf: Pass\n'
89
90# Std makefile run tests
91test_start "extended_makefile_tests"
92time $MAKE -f Makefile.unx -j $cpus $build_opt D="TEST_SEED=$S" $test_level
93test_end "extended_makefile_tests" $?
94msg+=$'Std makefile tests: Pass\n'
95
96# Std makefile build other
97test_start "extended_other_tests"
98time $MAKE -f Makefile.unx -j $cpus $build_opt D="TEST_SEED=$S" other
99test_end "extended_other_tests" $?
100msg+=$'Other tests build: Pass\n'
101
102# Try to pick a random src file
103if command -V shuf >/dev/null 2>&1; then
104    in_file=$(find $src -type f -size +0 -name \*.c -o -name \*.asm -print 2>/dev/null | shuf | head -1 );
105else
106    in_file=configure.ac
107fi
108
109echo Other tests using $in_file
110test_start "igzip_file_perf"
111./igzip_file_perf $in_file
112test_end "igzip_file_perf" $?
113test_start "igzip_hist_perf"
114./igzip_hist_perf $in_file
115test_end "igzip_hist_perf" $?
116test_start "igzip_semi_dyn_file_perf"
117./igzip_semi_dyn_file_perf $in_file
118test_end "igzip_semi_dyn_file_perf" $?
119test_start "igzip_fuzz_inflate"
120./igzip_fuzz_inflate $in_file
121test_end "igzip_fuzz_inflate" $?
122msg+=$'Other tests run: Pass\n'
123
124if command -V shuf >/dev/null 2>&1; then
125    in_files=$(find $src -type f -size +0 -print 2>/dev/null | shuf | head -10 );
126    test_start "igzip_rand_test"
127    ./igzip_rand_test $in_files
128    test_end "igzip_rand_test" $?
129    test_start "igzip_inflate_test"
130    ./igzip_inflate_test $in_files
131    test_end "igzip_inflate_test" $?
132    msg+=$'Compression file tests: Pass\n'
133else
134    msg+=$'Compression file test: Skip\n'
135fi
136
137time $MAKE -f Makefile.unx -j $cpus $build_opt ex
138msg+=$'Examples build: Pass\n'
139
140test_start "ec_simple_example"
141./ec_simple_example -r $S
142test_end "ec_simple_example" $?
143test_start "crc_simple_test"
144./crc_simple_test
145test_end "crc_simple_test" $?
146test_start "crc64_example"
147./crc64_example
148test_end "crc64_example" $?
149test_start "xor_example"
150./xor_example
151test_end "xor_example" $?
152test_start "igzip_example"
153./igzip_example ${in_file} ${in_file}.cmp
154test_end "igzip_example" $?
155rm -rf ${in_file}.cmp
156msg+=$'Examples run: Pass\n'
157
158# Test custom hufftables
159test_start "generate_custom_hufftables"
160./generate_custom_hufftables $in_file
161$MAKE -f Makefile.unx clean
162$MAKE -f Makefile.unx -j $cpus D="NO_STATIC_INFLATE_H" checks
163./igzip_rand_test $in_file
164rm -rf hufftables_c.c
165test_end "generate_custom_hufftables" $?
166
167msg+=$'Custom hufftable build: Pass\n'
168
169# Test NO_NT_LDST
170test_start "no_nt_ldst"
171$MAKE -f Makefile.unx clean
172$MAKE -f Makefile.unx -j $cpus D="NO_NT_LDST" checks
173test_end "no_nt_ldst" $?
174
175# Test EC_ALIGNED_ADDR
176test_start "ec_aligned_address"
177$MAKE -f Makefile.unx clean
178$MAKE -f Makefile.unx -j $cpus D="EC_ALIGNED_ADDR" checks
179test_end "ec_aligned_address" $?
180
181# Test EC_ALIGNED_ADDR & NO_NT_LDST
182test_start "ec_aligned_addres_no_nt_ldsts"
183$MAKE -f Makefile.unx clean
184$MAKE -f Makefile.unx -j $cpus D="EC_ALIGNED_ADDR NO_NT_LDST" checks
185test_end "ec_aligned_address_no_nt_ldst" $?
186
187$MAKE -f Makefile.unx clean
188
189test_start "nmake_file_consistency"
190$MAKE -f Makefile.unx host_cpu="x86_64" test_nmake_file
191test_end "nmake_file_consistency" $?
192msg+=$'Nmake file consistency: Pass\n'
193
194# noarch build
195test_start "noarch_build"
196time $MAKE -f Makefile.unx -j $cpus arch=noarch $build_opt
197test_end "noarch_build" $?
198test_start "noarch_build_random"
199time $MAKE -f Makefile.unx -j $cpus arch=noarch $build_opt D="TEST_SEED=$S" check
200test_end "noarch_build_random" $?
201$MAKE -f Makefile.unx arch=noarch clean
202msg+=$'Noarch build: Pass\n'
203
204# Test other implementations with SDE
205if [ $(uname -m) == "x86_64" ] && command -V sde64 >/dev/null 2>&1; then
206    # Compile tests
207    $MAKE -f Makefile.unx -j $cpus checks
208    # Loop through architectures
209    while [ $# -gt 0 ]
210    do
211        test_start "SDE test on $1 architecture"
212        time sde64 -$1 -- $MAKE -f Makefile.unx -j $cpus D="TEST_SEED=$S" check
213        test_start "SDE test on $1 architecture" $?
214        # Drop architecture from list, to test the next one
215        shift;
216    done
217        msg+=$'Running tests with SDE: Pass\n'
218    else
219        msg+=$'Running tests with SDE: Skip\n'
220fi
221
222# Try mingw build
223if [ $(uname -m) == "x86_64" ] && command -V x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
224    test_start "mingw_build"
225    time $MAKE -f Makefile.unx -j $cpus arch=mingw
226    test_end "mingw_build" $?
227    msg+=$'Mingw build: Pass\n'
228
229    if command -V wine >/dev/null 2>&1; then
230	test_start "mingw_check_tests"
231	time $MAKE -f Makefile.unx -j $cpus arch=mingw D="TEST_SEED=$S" check
232	test_end "mingw_check_tests" $?
233	msg+=$'Mingw check tests: Pass\n'
234    else
235	msg+=$'No wine, mingw check: Skip\n'
236    fi
237    $MAKE -f Makefile.unx  arch=mingw clean
238else
239    msg+=$'No mingw build: Skip\n'
240fi
241
242set +x
243echo
244echo "Summary test $0:"
245echo "Build opt: $build_opt"
246echo "$msg"
247echo "$0: Final: Pass"
248