forked from mlichvar/linuxptp-testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.common
371 lines (313 loc) · 9.51 KB
/
test.common
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# Copyright (C) 2013 Miroslav Lichvar <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
export LC_ALL=C
export PATH=$(pwd):$PATH
if [ ! -e clknetsim ]; then
git clone https://github.com/mlichvar/clknetsim.git || exit 1
fi
if [ ! -x clknetsim/clknetsim -o ! -e clknetsim/clknetsim.so ]; then
pushd clknetsim
make || exit 1
popd
fi
export CLKNETSIM_PATH=clknetsim
. $CLKNETSIM_PATH/clknetsim.bash
default_limit=500
default_time_offset=1e-1
default_freq_offset=1e-4
default_base_delay=1e-7
default_jitter=1e-7
default_refclock_jitter=1e-7
default_refclock_offset=0.0
default_wander=1e-9
default_time_rms_limit=1e-6
default_freq_rms_limit=1e-6
default_time_max_limit=2e-6
default_freq_max_limit=2e-6
default_min_sync_time=10
default_max_sync_time=40
default_max_ptp4l_delay_limit=1e-4
default_nodes=3
default_subnets=""
default_master_nodes="1"
default_transparent_nodes=""
default_free_running_nodes=""
default_delay_correction=""
default_phc2sys_node=0
default_pmc_node=0
default_nsm_node=0
default_master_start=0.0
default_slave_start=9.0
default_phc2sys_start=9.0
default_pmc_start=50.0
default_nsm_start=50.0
default_master_step=""
default_slave_step=""
default_update_interval=0
default_log_packets=0
default_pcap_dumps=0
default_master_conf=""
default_slave_conf=""
default_transparent_conf=""
default_phc2sys_conf=""
default_pmc_conf=""
default_nsm_conf=""
default_phc2sys_uds=""
default_pmc_uds=""
default_phc2sys_phc_base=0
default_phc2sys_phc_swap=0
default_extra_ptp4l_options=""
default_extra_pmc_options=""
declare -a extra_node_confs
declare -a node_start
declare -a ptp4l_suffixes
for defoptname in ${!default_*}; do
optname=${defoptname#default_}
[ -z "${!optname}" ] && declare "$optname"="${!defoptname}"
done
test_start() {
rm -f tmp/*
echo "Testing $@:"
}
test_pass() {
echo "PASS"
exit 0
}
test_fail() {
echo "FAIL"
exit 1
}
test_ok() {
pad_line
echo -e "\tOK"
return 0
}
test_bad() {
pad_line
echo -e "\tBAD"
return 1
}
test_error() {
pad_line
echo -e "\tERROR"
return 1
}
msg_length=0
pad_line() {
local line_length=56
[ $msg_length -lt $line_length ] && \
printf "%$[$line_length - $msg_length]s" ""
msg_length=0
}
test_message() {
local level=$1 eol=$2
shift 2
local msg="$*"
while [ $level -gt 0 ]; do
echo -n " "
level=$[$level - 1]
msg_length=$[$msg_length + 2]
done
echo -n "$msg"
msg_length=$[$msg_length + ${#msg}]
if [ $eol -ne 0 ]; then
echo
msg_length=0
fi
}
check_sync() {
local i sync_time max_time_error max_freq_error ret=0
local rms_time_error rms_freq_error
test_message 2 1 "checking clock sync time, max/rms time/freq error:"
for i in $(seq 1 $nodes); do
[[ " $master_nodes " =~ [^0-9]$i[^0-9] ]] && continue
[ $i -eq $pmc_node ] && continue
[ $i -eq $nsm_node ] && continue
[[ " $free_running_nodes " =~ [^0-9]$i[^0-9] ]] && continue
sync_time=$(find_sync tmp/log.offset tmp/log.freq $i \
$time_max_limit $freq_max_limit 1.0)
max_time_error=$(get_stat 'Maximum absolute offset' $i)
max_freq_error=$(get_stat 'Maximum absolute frequency' $i)
rms_time_error=$(get_stat 'RMS offset' $i)
rms_freq_error=$(get_stat 'RMS frequency' $i)
test_message 3 0 "node $i: $sync_time $(printf '%.2e %.2e %.2e %.2e' \
$max_time_error $max_freq_error $rms_time_error $rms_freq_error)"
check_stat $sync_time $min_sync_time $max_sync_time && \
check_stat $max_time_error 0.0 $time_max_limit && \
check_stat $max_freq_error 0.0 $freq_max_limit && \
check_stat $rms_time_error 0.0 $time_rms_limit && \
check_stat $rms_freq_error 0.0 $freq_rms_limit && \
test_ok || test_bad
[ $? -eq 0 ] || ret=1
done
return $ret
}
check_ptp4l_delay() {
local i max_delay ret=0
test_message 2 1 "checking max abs path delay measured by ptp4l:"
for i in $(seq 1 $nodes); do
[[ " $master_nodes " =~ [^0-9]$i[^0-9] ]] && continue
[ $i -eq $pmc_node ] && continue
[ $i -eq $nsm_node ] && continue
max_delay=$(grep -oE 'delay +filtered +[-0-9]+ +raw +[-0-9]+$' tmp/log.$i | awk '
BEGIN {
max = 0.0
} {
abs = $5 < 0 ? -$5 : $5
if (max < abs)
max = abs
} END {
print max / 1e9
}')
test_message 3 0 "node $i: $(printf '%.2e' $max_delay)"
check_stat $max_delay 0.0 $max_ptp4l_delay_limit && test_ok || test_bad
[ $? -eq 0 ] || ret=1
done
return $ret
}
check_pmc_output() {
local pattern=$1
test_message 2 0 "checking pmc output:"
[[ "$(cat tmp/log.$pmc_node)" =~ $pattern ]] && test_ok || test_bad
}
check_nsm_output() {
local pattern=$1
test_message 2 0 "checking nsm output:"
[[ "$(cat tmp/log.$nsm_node)" =~ $pattern ]] && test_ok || test_bad
}
check_any_log_message() {
local matching_messages node=$1 match_pattern=$2 last_pattern=$3
matching_messages=$(grep "$match_pattern" tmp/log.$node)
test_message 2 0 "checking any \"$match_pattern\" in node $node log: "
[[ "$matching_messages" =~ $last_pattern ]] && test_ok || test_bad
}
check_last_log_message() {
local last_message node=$1 match_pattern=$2 last_pattern=$3
last_message=$(grep "$match_pattern" tmp/log.$node | tail -n 1)
test_message 2 0 "checking last \"$match_pattern\" in node $node log: "
[[ "$last_message" =~ $last_pattern ]] && test_ok || test_bad
}
print_nondefaults() {
local i defopt defoptname optname
test_message 2 1 "non-default settings:"
for defoptname in ${!default_*}; do
optname=${defoptname#default_}
[ "${!defoptname}" = "${!optname}" ] || \
test_message 3 1 $optname=${!optname}
done
for i in $(seq 1 $nodes); do
[ -z "${extra_node_confs[$i]}" ] || \
test_message 3 1 extra_node_confs[$i]=${extra_node_confs[$i]}
done
}
get_wander_expr() {
local scaled_wander
scaled_wander=$(awk "BEGIN {print $wander / \
sqrt($update_interval < 0 ? 2^-($update_interval) : 1)}")
echo "(+ $freq_offset (sum (* $scaled_wander (normal))))"
}
run_simulation() {
test_message 2 0 "running simulation:"
start_server $nodes \
-n $[$(echo "$subnets" | tr -cd '|' | wc -c) + 2] \
-o tmp/log.offset -f tmp/log.freq \
$([ $log_packets -ne 0 ] && echo -p tmp/log.packets) \
-R $(awk "BEGIN {print $update_interval < 0 ? 2^-($update_interval) : 1}") \
-r $(awk "BEGIN {print $max_sync_time * 2^$update_interval}") \
-l $(awk "BEGIN {print $limit * 2^$update_interval}") && test_ok || test_error
}
run_test() {
local i j s subnet ifaces test_subnets conf start
test_message 1 1 "network with $nodes nodes:"
print_nondefaults
[ -z "$subnets" ] && test_subnets=$(seq -s ' ' 1 $nodes) || test_subnets=$subnets
generate_config4 "$master_nodes $pmc_node $nsm_node" "$test_subnets" $time_offset \
"$(get_wander_expr)" \
"(+ $base_delay (* $jitter (exponential)))"
if [ -n "$delay_correction" ]; then
for i in $(seq 1 $nodes); do
for j in $(seq 1 $nodes); do
echo "node${i}_delay_correction${j} = $delay_correction" >> tmp/conf
done
done
fi
for i in $(seq 1 $nodes); do
ifaces="" subnet=0
for s in $test_subnets; do
[ $s = "|" ] && subnet=$[$subnet + 1] && continue
[ $s -eq $i ] && ifaces="$ifaces -i eth$subnet"
done
export CLKNETSIM_UNIX_SUBNET=$[$subnet + 2]
[ $pcap_dumps -ne 0 ] && export CLKNETSIM_PCAP_DUMP=tmp/pcap.$i
test_message 2 0 "starting node $i:"
if [ $i -eq $phc2sys_node ]; then
echo "node${i}_start = $phc2sys_start" >> tmp/conf
echo "node${i}_refclock = (+ $refclock_offset (* $refclock_jitter (normal)))" \
>> tmp/conf
if [ "$phc2sys_phc_base" -gt 0 ]; then
echo "node${i}_refclock_base = node${phc2sys_phc_base}" >> tmp/conf
fi
ifaces=""
for uds in $phc2sys_uds; do
ifaces="$ifaces -z /clknetsim/unix/$uds"
done
CLKNETSIM_PHC_SWAP=$phc2sys_phc_swap \
start_client $i phc2sys "$ifaces $phc2sys_conf" && \
test_ok || test_error
elif [ $i -eq $pmc_node ]; then
echo "node${i}_start = $pmc_start" >> tmp/conf
if [ "$pmc_uds" != "" ]; then
ifaces="-u -i /clknetsim/unix/pmc -s /clknetsim/unix/$pmc_uds"
fi
start_client $i pmc "$pmc_conf" "" "-b 0 $ifaces $extra_pmc_options" && \
test_ok || test_error
elif [ $i -eq $nsm_node ]; then
echo "node${i}_start = $nsm_start" >> tmp/conf
start_client $i nsm "$nsm_conf" "" "$ifaces" && \
test_ok || test_error
else
if [[ " $transparent_nodes " =~ [^0-9]$i[^0-9] ]]; then
start=$slave_start
conf=$transparent_conf
step=$slave_step
elif [[ " $master_nodes " =~ [^0-9]$i[^0-9] ]]; then
start=$master_start
conf=$master_conf
step=$master_step
else
start=$slave_start
conf=$slave_conf
step=$slave_step
fi
conf=$( echo "uds_address /clknetsim/unix/ptp4l"
echo "uds_ro_address /clknetsim/unix/ptp4lro"
echo "${conf}"
echo "${extra_node_confs[$i]}")
[ -z "$step" ] || echo "node${i}_step = $step" >> tmp/conf
# override individual node start time if set
if [[ -n "${node_start[$i]}" ]]; then
start=${node_start[$i]}
fi
echo "node${i}_start = $start" >> tmp/conf
start_client $i ptp4l "$conf" "${ptp4l_suffixes[i]}" \
"$ifaces $extra_ptp4l_options" && test_ok || test_error
fi
[ $? -ne 0 ] && return 1
done
run_simulation
}
run_ptp4l() {
run_test "$@"
}