aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_all.sh
blob: f072eba315a5d5b5e2478e53265a74d4ee7a58f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
mytmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
echo "--------------------------------------------------"
echo "Created working directory: $mytmpdir"
echo "--------------------------------------------------"

if [[ -z $1 ]]; then
    test_dir=.
else
    test_dir=$1
fi

test_command() {
    local loc=$(command -v $1)
    if [[ $? -eq 0  ]]; then
        echo "Found $1: $loc"
    else
        echo "Could not find $1"
        exit 1
    fi
}

test_command iverilog
test_command gcc
test_command vericert

echo "--------------------------------------------------"

for cfile in $test_dir/*.c; do
    echo "Testing $cfile"
    outbase=$mytmpdir/$(basename $cfile)
    gcc -o $outbase.gcc $cfile >/dev/null 2>&1
    $outbase.gcc
    expected=$?
    vericert -drtl -o $outbase.v $cfile >/dev/null 2>&1
    if [[ ! -f $outbase.v ]]; then
        echo "ERROR"
        continue
    fi
    iverilog -o $outbase.iverilog $outbase.v
    actual=$($outbase.iverilog | tail -n1 | sed -E -e 's/[^0-9]+([0-9]+)/\1/')
    if [[ $expected = $actual ]]; then
        echo "OK"
    else
        echo "FAILED: $expected != $actual"
    fi
done

echo "--------------------------------------------------"

rm -rf $mytmpdir