Welcome to mirror list, hosted at ThFree Co, Russian Federation.

run_mrt.sh - github.com/marian-nmt/marian-regression-tests.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c75e85899d9ff71ec29721c9f609b81a5b6099a6 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash

SHELL=/bin/bash

export EXIT_CODE_SUCCESS=0
export EXIT_CODE_SKIP=100

export MRT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export MRT_TOOLS=$MRT_ROOT/tools
export MRT_MARIAN=${MARIAN:-$MRT_TOOLS/marian}
export MRT_MODELS=$MRT_ROOT/models
export MRT_DATA=$MRT_ROOT/data
if [[ $(command -v optirun) ]]; then
  export RUN_PREFIX=optirun
else
  export RUN_PREFIX=""
fi
echo "RUN_PREFIX: $RUN_PREFIX"

export MRT_RUN_MARIAN="$RUN_PREFIX $MRT_MARIAN/build/marian"
export MRT_RUN_MARIAN_DECODER="$RUN_PREFIX $MRT_MARIAN/build/marian-decoder"
export MRT_RUN_MARIAN_SCORER="$MRT_MARIAN/build/marian-scorer"

# Check if Marian is compiled with CUDNN
export MRT_MARIAN_USE_CUDNN=$(cmake -L $MRT_MARIAN/build 2> /dev/null | grep -P "USE_CUDNN:BOOL=(ON|on|1)")

# Number of available devices
export MRT_NUM_DEVICES=${NUM_DEVICES:-1}


prefix=tests
if [ $# -ge 1 ]; then
    prefix="$1"
fi


function log {
    echo [$(date "+%m/%d/%Y %T")] $@
}

function logn {
    echo -n [$(date "+%m/%d/%Y %T")] $@
}

function format_time {
    dt=$(echo "$2 - $1" | bc)
    dh=$(echo "$dt/3600" | bc)
    dt2=$(echo "$dt-3600*$dh" | bc)
    dm=$(echo "$dt2/60" | bc)
    ds=$(echo "$dt2-60*$dm" | bc)
    LANG=C printf "%02d:%02d:%02.3fs" $dh $dm $ds
}

log "Using Marian: $MRT_MARIAN"
log "Using CUDNN: $MRT_MARIAN_USE_CUDNN"
log "Using number of devices: $MRT_NUM_DEVICES"
log "Using CUDA visible devices: $CUDA_VISIBLE_DEVICES"

success=true
count_passed=0
count_skipped=0
count_failed=0
count_all=0

time_start=$(date +%s.%N)

# Traverse test directories
cd $MRT_ROOT
for test_dir in $(find $prefix -type d | grep -v "/_")
do
    log "Checking directory: $test_dir"
    nosetup=false

    # Run setup script if exists
    if [ -e $test_dir/setup.sh ]; then
        log "Running setup script"

        cd $test_dir
        $SHELL setup.sh &> setup.log
        if [ $? -ne 0 ]; then
            log "Warning: setup script returns a non-success exit code"
            success=false
            nosetup=true
        else
            rm setup.log
        fi
        cd $MRT_ROOT
    fi

    # Run tests
    for test_path in $(ls -A $test_dir/test_*.sh 2>/dev/null)
    do
        test_time_start=$(date +%s.%N)
        ((++count_all))

        # Tests are executed from their directory
        cd $test_dir
        test_file=$(basename $test_path)
        test_name="${test_file%.*}"

        # Skip tests if setup failed
        logn "Running $test_path ... "
        if [ "$nosetup" = true ]; then
            ((++count_skipped))
            echo " skipped"
            cd $MRT_ROOT
            continue;
        fi

        # Run test
        $SHELL -x $test_file > $test_name.stdout 2> $test_name.stderr
        exit_code=$?

        # Check exit code
        if [ $exit_code -eq $EXIT_CODE_SUCCESS ]; then
            ((++count_passed))
            rm $test_name.stdout $test_name.stderr
            echo " OK"
        elif [ $exit_code -eq $EXIT_CODE_SKIP ]; then
            ((++count_skipped))
            echo " skipped"
        else
            ((++count_failed))
            echo " failed"
            success=false
        fi

        # Report time
        test_time_end=$(date +%s.%N)
        test_time=$(format_time $test_time_start $test_time_end)
        log "Test took $test_time"

        cd $MRT_ROOT
    done
    cd $MRT_ROOT

    # Run teardown script if exists
    if [ -e $test_dir/teardown.sh ]; then
        log "Running teardown script"

        cd $test_dir
        $SHELL teardown.sh &> teardown.log
        if [ $? -ne 0 ]; then
            log "Warning: teardown script returns a non-success exit code"
            success=false
        else
            rm teardown.log
        fi
        cd $MRT_ROOT
    fi
done

time_end=$(date +%s.%N)
time_total=$(format_time $time_start $time_end)

echo "---------------------"
echo "Ran $count_all tests in $time_total, $count_passed passed, $count_skipped skipped, $count_failed failed"

# Exit code
$success && [ $count_all -gt 0 ]