aboutsummaryrefslogtreecommitdiff
path: root/test/run-test
blob: ffe653c0e5700d776c5b4bbd3e7b84af0f914bfa (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
51
52
53
54
55
56
57
# Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
#
# Jansson is free software; you can redistribute it and/or modify
# it under the terms of the MIT license. See LICENSE for details.

VALGRIND_CMDLINE="valgrind --leak-check=full --show-reachable=yes --track-origins=yes -q"

run_testprog() {
    local prog=$1
    local prefix=$2
    if [ -n "$VALGRIND" ]; then
        local runner="$VALGRIND_CMDLINE "
    fi

    case "$prog" in
        load_file_dump_file)
            $runner./$prog \
                $prefix.in \
                $prefix.$prog.stdout \
                2>$prefix.$prog.stderr
            ;;
        *)
            $runner./$prog \
                <$prefix.in \
                >$prefix.$prog.stdout \
                2>$prefix.$prog.stderr
            ;;
    esac

    if [ -n "$VALGRIND" ]; then
        # Check for Valgrind error output. The valgrind option
        # --error-exitcode is not enough because Valgrind doesn't
        # think unfreed allocs are errors.
        if grep -E -q '^==[0-9]+== ' $prefix.$prog.stderr; then
            echo "### $prefix ($prog) failed:" >&2
            echo "valgrind detected an error" >&2
            echo "for details, see test/$prefix.$prog.stderr" >&2
            exit 1
        fi
    fi
}

for testfile in $TESTFILES; do
    tmpdir="testlogs/`basename $testfile`"
    rm -rf $tmpdir
    mkdir -p $tmpdir
    if echo "$testfile" | grep -q -E -e '-strip$'; then
        opts="--strip"
    fi
    ${srcdir}/split-testfile.py $opts $testfile $tmpdir | while read name; do
        run_test loadf_dumpf $tmpdir/$name
        run_test loads_dumps $tmpdir/$name
        run_test load_file_dump_file $tmpdir/$name
        echo -n '.'
    done || exit 1
    echo
done