xref: /isa-l/tools/test_checks.sh (revision a4535d776ca12e4a5f6816e5e12bcc066e1ece4d)
1#!/usr/bin/env bash
2
3set -xe #exit on fail
4
5# Defaults
6cpus=1
7S=$RANDOM
8MAKE=make
9READLINK=readlink
10
11# Override defaults if exist
12command -V gmake >/dev/null 2>&1 && MAKE=gmake
13command -V greadlink >/dev/null 2>&1 && READLINK=greadlink
14
15out="$PWD"
16src=$($READLINK -f $(dirname $0))/..
17source $src/tools/test_tools.sh
18cd "$src"
19tmp_install_dir=$out/tmp_install
20
21# Run on mult cpus
22if command -V lscpu >/dev/null 2>&1; then
23    cpus=`lscpu -p | tail -1 | cut -d, -f 2`
24    cpus=$(($cpus + 1))
25elif command -V sysctl; then
26    if sysctl -n hw.ncpu >/dev/null 2>&1; then
27	cpus=$(sysctl -n hw.ncpu)
28	cpus=$(($cpus + 1))
29    fi
30fi
31echo "Using $cpus cpu threads"
32
33# Pick a random test seed
34if [ -z "$S" ]; then
35    S=`tr -cd 0-9 </dev/urandom | head -c 4 | sed -e 's/^0*/1/g'`
36    [ "$S" -gt 0 ] 2> /dev/null || S="123"
37fi
38echo "Running with TEST_SEED=$S"
39
40# Fix Darwin issues
41if uname | grep -q 'Darwin' 2>&1; then
42    export SED=`which sed`
43fi
44
45# Build and run check tests
46if [ -z "$CFLAGS" ]; then
47    CFLAGS='-g -O2 -fsanitize=undefined -fno-sanitize=nonnull-attribute -fsanitize-undefined-trap-on-error'
48
49    if [ $CC ]; then
50       echo int main\(\)\{\}\; | $CC $CFLAGS -xc -o /dev/null - >& /dev/null && sanitize=1
51    elif ( command -V gcc > /dev/null ); then
52       echo int main\(\)\{\}\; |  gcc $CFLAGS -xc -o /dev/null - >& /dev/null && sanitize=1
53    elif ( command -V clang > /dev/null ); then
54       echo int main\(\)\{\}\; |  clang $CFLAGS -xc -o /dev/null - >& /dev/null && sanitize=1
55    fi
56
57    if [ $sanitize ]; then
58	echo "Sanitizing undefined behaviour"
59	export CFLAGS=$CFLAGS
60    fi
61fi
62
63time ./autogen.sh
64time ./configure --prefix=$tmp_install_dir $opt_config_target
65time $MAKE -j $cpus
66test_start "check_tests"
67time $MAKE check -j $cpus D="-D TEST_SEED=$S"
68test_end "check_tests" $?
69
70# Build other tests if deps found
71if command -V ldconfig >/dev/null 2>&1; then
72    if ldconfig -p | grep -q libz.so; then
73	test_start "other_check_tests"
74	time $MAKE other -j $cpus
75	test_end "other_check_tests" $?
76	test_start "example_tests"
77	time $MAKE ex    -j $cpus
78	test_end "example_tests" $?
79	test_start "unit_tests"
80	time $MAKE tests -j $cpus
81	test_end "unit_tests" $?
82    fi
83fi
84test_start "installation_test"
85time $MAKE install
86test_end "installation_test" $?
87
88# Check for gnu executable stack set
89if command -V readelf >/dev/null 2>&1; then
90    if readelf -W -l $tmp_install_dir/lib/libisal.so | grep 'GNU_STACK' | grep -q 'RWE'; then
91	echo Stack NX check $tmp_install_dir/lib/libisal.so Fail
92	exit 1
93    else
94	echo Stack NX check $tmp_install_dir/lib/libisal.so Pass
95    fi
96else
97    echo Stack NX check not supported
98fi
99
100$MAKE clean
101
102# Check that make clean did not leave any junk behind
103if git status > /dev/null 2>&1; then
104    if git status --porcelain --ignored | grep -x '.*\.o\|.*\.lo\|.*\.a\|.*\.la\|.*\.s'; then
105	echo Clean directory check Fail
106	exit 1
107    else
108	echo Clean directory check Pass
109    fi
110else
111    echo Clean directory check not supported
112fi
113
114
115echo $0: Pass
116