xref: /isa-l_crypto/tools/test_checks.sh (revision b8ae03008d580cccbebf13cbb2a64eb0bb5bf90e)
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# Get configuration options if available
22if [ $# -gt 0 ]; then
23    opt_config=$1
24    shift;
25fi
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
39# Pick a random test seed
40if [ -z "$S" ]; then
41    S=`tr -cd 0-9 </dev/urandom | head -c 4 | sed -e 's/^0*/1/g'`
42    [ "$S" -gt 0 ] 2> /dev/null || S="123"
43fi
44echo "Running with TEST_SEED=$S"
45
46# Fix Darwin issues
47if uname | grep -q 'Darwin' 2>&1; then
48    export SED=`which sed`
49    opt_config+=' --target=darwin'
50fi
51
52# Tests
53time ./autogen.sh
54time ./configure --prefix=$tmp_install_dir $opt_config
55time $MAKE -j $cpus
56test_start "check_tests"
57time $MAKE check -j $cpus D="-D TEST_SEED=$S"
58test_end "check_tests" $?
59test_start "installation_test"
60time $MAKE install
61test_end "installation_test" $?
62
63# Check for gnu executable stack set
64if command -V readelf >/dev/null 2>&1; then
65    if readelf -W -l $tmp_install_dir/lib/libisal_crypto.so | grep 'GNU_STACK' | grep -q 'RWE'; then
66	echo Stack NX check $tmp_install_dir/lib/libisal_crypto.so Fail
67	exit 1
68    else
69	echo Stack NX check $tmp_install_dir/lib/libisal_crypto.so Pass
70    fi
71else
72    echo Stack NX check not supported
73fi
74
75$MAKE clean
76
77
78
79echo $0: Pass
80