File: test_utils.sh

package info (click to toggle)
eztrace 2.0%2Brepack-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,132 kB
  • sloc: ansic: 23,501; perl: 910; sh: 857; cpp: 771; makefile: 696; fortran: 327; f90: 320; python: 57
file content (240 lines) | stat: -rw-r--r-- 5,166 bytes parent folder | download
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash

[ -n "$OTF2_PRINT_PATH" ]    || export OTF2_PRINT_PATH=otf2-print
[ -n "$EZTRACE_PATH" ]       || export EZTRACE_PATH=eztrace
[ -n "$EZTRACE_AVAIL_PATH" ] || export EZTRACE_AVAIL_PATH=eztrace_avail
[ -n "$EZTRACE_CC_PATH" ]    || export EZTRACE_CC_PATH=eztrace_cc
[ -n "$MPIRUN_PATH" ]        || export MPIRUN_PATH=mpirun
[ -n "$MPICC_PATH" ]         || export MPICC_PATH=mpicc


C_BLACK='\033[0;30m'
C_DGRAY='\033[1;30m'
C_LGRAY='\033[0;37m'
C_WHITE='\033[1;37m'

C_GREEN='\033[0;32m'
C_LGREEN='\033[1;32m'
C_BLUE='\033[0;34m'
C_LBLUE='\033[1;34m'
C_CYAN='\033[0;36m'
C_LCYAN='\033[1;36m'
C_ORANGE='\033[0;33m'
C_YELLOW='\033[1;33m'
C_RED='\033[0;31m'
C_LRED='\033[1;31m'
C_PURPLE='\033[0;35m'
C_LPURPLE='\033[1;35m'

C_NC='\033[0m'

C_BOLD='\033[1m'


function print_error {
  echo -e "  [${C_LRED}${C_BOLD}ERROR${C_NC}] $@"
}

function print_warning {
  echo -e "[${C_YELLOW}${C_BOLD}WARNING${C_NC}] $@"
}

function print_info {
  echo -e "   [${C_LBLUE}INFO${C_NC}] ${C_BOLD}$@${C_NC}"
}

function print_ok {
  echo -e "     [${C_LGREEN}OK${C_NC}] $@"
}

function print_simple {
  echo "          $@"
}


function check_last_return {
  if [[ $? != 0 ]] ; then
    if [[ "$@" != "" ]]; then
      print_error $@
    fi
    error_occured=true
  elif [[ "$@" != "" ]] ; then
    print_ok $@
  fi
}

function check_dependencies {
    echo "> Checking for dependencies..."
    for d in $@; do
        if ! command -v $d &>/dev/null; then
            print_error "Missing command: $d"
            return 1
        fi	
    done
    print_ok
}

function check_module {
    module=$1
    echo "> Checking for eztrace module '$module'..."
    [ -n "$EZTRACE_AVAIL_PATH" ] || EZTRACE_AVAIL_PATH=eztrace_avail
    if  "$EZTRACE_AVAIL_PATH" | grep "^$module[[:space:]]" > /dev/null ; then
	print_ok
    else
	print_error "Module '$module' not found"
	return 1
    fi
}

function check_compilation {
    echo "> Compiling test programs..."
    if [ -n "$verbose" ]; then
	make
    else
	make > /dev/null
    fi

    if [ "$?" != "0" ]; then
	print_error "Compilation failed"
	return 1
    fi
    print_ok
}

function run_test {
    test=$1
    if ! [ -x "$test" ]; then
	return
    fi
    echo "> Running $test..."
    if [ -n "$verbose" ]; then
	$test
    else
	$test > /dev/null 2>&1
    fi

    if [ "$?" != "0" ]; then
        print_error "Test $test failed"
        return 1
    fi
    print_ok
}

function run_and_check_command {
    cmd=$@
    echo "> Running $cmd"

    ((nb_test++))
    if [ -n "$verbose" ]; then
	$cmd
    else
	$cmd > /dev/null 2>&1
    fi
    if [ "$?" != "0" ]; then
	print_error "command '$cmd' failed"
	return 1
    fi

    print_ok
    ((nb_pass++))
    return 0
}

function trace_get_nb_event_of_type {
    trace_filename=$1
    event_type=$2

    "$OTF2_PRINT_PATH" "$trace_filename" 2>/dev/null |grep "^$event_type[[:space:]]"|wc -l
}

function trace_check_integrity {
    trace_filename=$1

    ((nb_test++))
    echo " > Checking for trace integrity"
    if ! "$OTF2_PRINT_PATH" "$trace_filename" > /dev/null 2>&1 ; then
	print_error "Cannot parse trace '$trace_filename'"
	((nb_failed++))
	return 1
    else
	((nb_pass++))
	print_ok
	return 0
    fi
}

function trace_check_enter_leave_parity {
    trace_filename=$1

    ((nb_test++))
    echo " > Checking for ENTER/LEAVE parity"
    nb_enter=$(trace_get_nb_event_of_type "$trace_filename" "ENTER")
    nb_leave=$(trace_get_nb_event_of_type "$trace_filename" "LEAVE")
    if [ $nb_enter -ne $nb_leave ]; then
	print_error "$nb_enter ENTER events / $nb_leave LEAVE events"
	((nb_failed++))
	return 1
    else
	print_ok "$nb_enter event of each type"
	((nb_pass++))
	return 0
    fi
}

function trace_check_event_type {
    trace_filename=$1
    event_type=$2
    expected_nb=$3
    actual_nb=$(trace_get_nb_event_of_type "$trace_filename" "$event_type")
    
    ((nb_test++))
    echo " > Checking the number of $event_type events"
    if [ $expected_nb -ne $actual_nb ]; then
	print_error "$actual_nb events (expected: $expected_nb)"
	((nb_failed++))
	return 1
    else
	print_ok
	((nb_pass++))
	return 0
    fi
}

function trace_check_nb_enter {
    trace_filename=$1
    event_type="$2"
    expected_nb=$3

    ((nb_test++))
    echo " > Checking the number of ENTER $event_type events"
    actual_nb=$("$OTF2_PRINT_PATH" "$trace_filename" 2>/dev/null |grep "^ENTER[[:space:]]"|awk -vFPAT='([^ ]+)|("[^"]+")' '{print $5}' | grep "\"$event_type\""| wc -l)
    if [ $expected_nb -ne $actual_nb ]; then
	print_error "$actual_nb events (expected: $expected_nb)"
	((nb_failed++))
	return 1
    else
	print_ok
	((nb_pass++))
	return 0
    fi
}

function trace_check_nb_leave {
    trace_filename=$1
    event_type=$2
    expected_nb=$3
    
    ((nb_test++))
    echo " > Checking the number of LEAVE $event_type events"
    actual_nb=$("$OTF2_PRINT_PATH" "$trace_filename" 2>/dev/null |grep "^LEAVE[[:space:]]"|awk  -vFPAT='([^ ]+)|("[^"]+")'  '{print $5}' | grep "\"$event_type\""| wc -l)
    if [ $expected_nb -ne $actual_nb ]; then
	print_error "$actual_nb events (expected: $expected_nb)"
	((nb_failed++))
	return 1
    else
	print_ok
	((nb_pass++))
	return 0
    fi
}