public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 15ad685f3eae4d5f52cd1fbd131e95e96cdf26b0 9628 bytes (raw)

  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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
 
#!/bin/sh
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# PASST - Plug A Simple Socket Transport
#  for qemu/UNIX domain socket mode
#
# PASTA - Pack A Subtle Tap Abstraction
#  for network namespace/tap device mode
#
# test/lib/test - List tests and run them, evaluating directives from files
#
# Copyright (c) 2021 Red Hat GmbH
# Author: Stefano Brivio <sbrivio@redhat.com>

# test_iperf3() - Ugly helper for iperf3 directive
# $1:	Variable name: to put the measure bandwidth into
# $2:	Source/client context
# $3:	Destination/server context
# $4:	Destination name or address for client
# $5:	Port number, ${i} is translated to process index
# $6:	Number of processes to run in parallel
# $@:	Client options
test_iperf3() {
	__var="${1}"; shift
	__cctx="${1}"; shift
	__sctx="${1}"; shift
	__dest="${1}"; shift
	__port="${1}"; shift
	__procs="$((${1} - 1))"; shift
	__time="${1}"; shift

	pane_or_context_run_bg "${__sctx}" 				\
		 '('							\
		 '	for i in $(seq 0 '${__procs}'); do'		\
		 '		iperf3 -s1J -p'${__port}' -i'${__time}	\
		 '		   > s${i}.json &'			\
		 '	done;'						\
		 '	wait'						\
		 ')'

	sleep 1		# Wait for server to be ready

	pane_or_context_run "${__cctx}" 				\
		 '('							\
		 '	for i in $(seq 0 '${__procs}'); do'		\
		 '		iperf3 -c '${__dest}' -p '${__port}	\
		 '		  -t'${__time}' -T s${i} '"${@}"' &'	\
		 '	done;'						\
		 '	wait'						\
		 ')'

	pane_or_context_wait "${__sctx}"

	__jval=".end.sum_received.bits_per_second"
	for __opt in ${@}; do
		# UDP test
		[ "${__opt}" = "-u" ] && __jval=".intervals[0].sum.bits_per_second"
	done

	__bw=$(pane_or_context_output "${__sctx}"			\
		 'cat s*.json | jq -rMs "map('${__jval}') | add"')
	pane_or_context_run "${__sctx}"					\
		'for i in $(seq 0 '${__procs}'); do rm s${i}.json; done'

	TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__var}__" "${__bw}" )"
}

test_one_line() {
	__line="${1}"

	[ ${DEBUG} -eq 1 ] && info DEBUG: "${__line}"

	# Strip comments
	__line="${__line%%#*}"

	if [ -n "${TEST_ONE_in_def}" ]; then
		[ "${__line}" = "endef" ] && TEST_ONE_in_def= && return
		# Append $__line to variable TEST_ONE_DEF_<definition name>
		__ifs="${IFS}"
		IFS=
		eval TEST_ONE_DEF_$TEST_ONE_in_def=\"\$\(printf \"%s\\n%s\" \"\$TEST_ONE_DEF_$TEST_ONE_in_def\" \"$__line\"\)\"
		IFS="${__ifs}"
		return
	fi

	# tab-split command and arguments, apply variable substitutions
	__cmd="${__line%%$(printf '\t')*}"
	__arg="${__line#*$(printf '\t')*}"
	__arg="$(subs_apply "${TEST_ONE_subs}" "${__arg}")"

	[ ${TEST_ONE_nok} -eq 1 ] && [ "${__cmd}" != "test" ] && continue
	case ${__cmd} in
	"def")
		TEST_ONE_in_def="${__arg}"
		# Clear variable TEST_ONE_DEF_<definition name>
		__ifs="${IFS}"
		IFS= eval TEST_ONE_DEF_$TEST_ONE_in_def=
		IFS="${__ifs}"
		;;
	"tempdir")
		__tmpdir="$(mktemp -d)"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__arg}__" "${__tmpdir}")"
		TEST_ONE_dirclean="$(list_add "${TEST_ONE_dirclean}" "${__tmpdir}")"
		;;
	"temp")
		__tmpfile="$(mktemp)"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__arg}__" "${__tmpfile}")"
		TEST_ONE_dirclean="$(list_add "${TEST_ONE_dirclean}" "${__tmpfile}")"
		;;
	"test")
		[ ${TEST_ONE_perf_nok} -eq 0 ] || TEST_ONE_nok=1
		[ ${TEST_ONE_nok} -eq 1 ] && status_test_fail
		[ ${TEST_ONE_nok} -eq 0 ] && status_test_ok

		status_test_start "${__arg}"
		TEST_ONE_nok=0
		TEST_ONE_perf_nok=0
		;;
	"host")
		pane_or_context_run host "${__arg}" || TEST_ONE_nok=1
		;;
	"hostb")
		pane_or_context_run_bg host "${__arg}"
		;;
	"hostw")
		pane_or_context_wait host || TEST_ONE_nok=1
		;;
	"hint")
		tmux send-keys -t ${PANE_HOST} "C-c"
		;;
	"htools")
		pane_or_context_run host 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
		;;
	"passt")
		pane_or_context_run passt "${__arg}" || TEST_ONE_nok=1
		;;
	"passtb")
		pane_or_context_run_bg passt "${__arg}"
		;;
	"passtw")
		pane_or_context_wait passt || TEST_ONE_nok=1
		;;
	"pout")
		__varname="${__arg%% *}"
		__output="$(pane_or_context_output passt "${__arg#* }")"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
		;;
	"guest")
		pane_or_context_run guest "${__arg}" || TEST_ONE_nok=1
		;;
	"guestb")
		pane_or_context_run_bg guest "${__arg}"
		;;
	"guestw")
		pane_or_context_wait guest || TEST_ONE_nok=1
		;;
	"guest1")
		pane_or_context_run guest_1 "${__arg}" || TEST_ONE_nok=1
		;;
	"guest1b")
		pane_or_context_run_bg guest_1 "${__arg}"
		;;
	"guest1w")
		pane_or_context_wait guest_1 || TEST_ONE_nok=1
		;;
	"gtools")
		pane_or_context_run guest 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
		;;
	"g1tools")
		pane_or_context_run guest_1 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
		;;
	"g2tools")
		pane_or_context_run guest_2 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
		;;
	"guest2")
		pane_or_context_run guest_2 "${__arg}" || TEST_ONE_nok=1
		;;
	"guest2b")
		pane_or_context_run_bg guest_2 "${__arg}"
		;;
	"guest2w")
		pane_or_context_wait guest_2 || TEST_ONE_nok=1
		;;
	"ns")
		pane_or_context_run ns "${__arg}" || TEST_ONE_nok=1
		;;
	"ns1")
		pane_or_context_run ns1 "${__arg}" || TEST_ONE_nok=1
		;;
	"ns2")
		pane_or_context_run ns2 "${__arg}" || TEST_ONE_nok=1
		;;
	"nsb")
		pane_or_context_run_bg ns "${__arg}"
		;;
	"ns1b")
		pane_or_context_run_bg ns1 "${__arg}"
		;;
	"ns2b")
		pane_or_context_run_bg ns2 "${__arg}"
		;;
	"nsw")
		pane_or_context_wait ns || TEST_ONE_nok=1
		;;
	"ns1w")
		pane_or_context_wait ns1 || TEST_ONE_nok=1
		;;
	"ns2w")
		pane_or_context_wait ns2 || TEST_ONE_nok=1
		;;
	"nstools")
		pane_or_context_run ns 'which '"${__arg}"' >/dev/null' || TEST_ONE_skip=1
		;;
	"gout")
		__varname="${__arg%% *}"
		__output="$(pane_or_context_output guest "${__arg#* }")"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
		;;
	"g1out")
		__varname="${__arg%% *}"
		__output="$(pane_or_context_output guest_1 "${__arg#* }")"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
		;;
	"g2out")
		__varname="${__arg%% *}"
		__output="$(pane_or_context_output guest_2 "${__arg#* }")"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
		;;
	"hout")
		__varname="${__arg%% *}"
		__output="$(pane_or_context_output host "${__arg#* }")"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
		;;
	"nsout")
		__varname="${__arg%% *}"
		__output="$(pane_or_context_output ns "${__arg#* }")"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
		;;
	"ns1out")
		__varname="${__arg%% *}"
		__output="$(pane_or_context_output ns1 "${__arg#* }")"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
		;;
	"ns2out")
		__varname="${__arg%% *}"
		__output="$(pane_or_context_output ns2 "${__arg#* }")"
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__varname}__" "${__output}")"
		;;
	"check")
		info_check "${__arg}"
		__nok=0
		eval "${__arg} || __nok=1"
		if [ ${__nok} -eq 1 ]; then
			TEST_ONE_nok=1
			info_check_failed
		else
			info_check_passed
		fi
		;;
	"sleep")
		sleep "${__arg}"
		;;
	"info")
		info "${__arg}"
		;;
	"report")
		perf_report ${__arg}
		;;
	"th")
		table_header ${__arg}
		;;
	"tr")
		table_row "${__arg}"
		;;
	"tl")
		table_line "${__arg}"
		;;
	"te")
		table_end
		;;
	"bw")
		table_value_throughput ${__arg} || TEST_ONE_perf_nok=1
		;;
	"lat")
		table_value_latency ${__arg} || TEST_ONE_perf_nok=1
		;;
	"iperf3")
		test_iperf3 ${__arg}
		;;
	"set")
		TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__arg%% *}__" "${__arg#* }")"
		;;

	# Demo commands
	"say")
		text_write "${__arg}"
		;;
	"em")
		em_write "${__arg}"
		;;
	"nl")
		info_nolog ""
		;;
	"hl")
		pane_highlight "${__arg}"
		;;
	"bsp")
		text_backspace "${__arg}"
		;;
	"killp")
		pane_kill "${__arg}"
		;;
	"resize")
		pane_resize ${__arg}
		;;
	*)
		__def_body="$(eval printf \"\$TEST_ONE_DEF_$__cmd\")"
		if [ -n "${__def_body}" ]; then
			__ifs="${IFS}"
			IFS='
'
			for __def_line in ${__def_body}; do
				IFS= test_one_line "${__def_line}"
			done
			IFS="${__ifs}"
		fi
		;;
	esac
}

# test_one() - Run a single test file evaluating directives
# $1:	Name of test file, relative to test/ directory
test_one() {
	TEST_ONE_dirclean=
	__test_file="test/${1}"

	__type="$(file -b --mime-type ${__test_file})"
	if [ "${__type}" = "text/x-shellscript" ]; then
		status_file_start "${1}" 1
		"${__test_file}" && status_test_ok || status_test_fail
		return
	fi

	if [ ${DEMO} -eq 0 ]; then
		__ntests="$(grep -c "^test$(printf '\t')" "${__test_file}")"
		status_file_start "${1}" "${__ntests}"
	fi

	[ ${CI} -eq 1 ] && video_link "${1}"

	TEST_ONE_subs="$(list_add_pair "" "__BASEPATH__" "${BASEPATH}")"
	TEST_ONE_nok=-1
	TEST_ONE_perf_nok=0
	TEST_ONE_skip=0
	TEST_ONE_in_def=
	while IFS= read -r __line; do
		test_one_line "${__line}"
		[ ${TEST_ONE_skip} -eq 1 ] && break
	done < "${__test_file}"

	for __d in ${TEST_ONE_dirclean}; do
		rm -rf ${__d}
	done

	[ ${DEMO} -eq 1 ] && return

	[ ${TEST_ONE_skip} -eq 1 ] && status_test_skip && return
	[ ${TEST_ONE_perf_nok} -eq 0 ] || TEST_ONE_nok=1
	[ ${TEST_ONE_nok} -eq 0 ] && status_test_ok || status_test_fail
}

# test() - Build list of tests to run, in order, then issue test_one()
# $@:	Test files to run, relative to test/
test() {
	__list=

	cd test
	for __f; do
		__type="$(file -b --mime-type ${__f})"
		if [ "${__type}" = "text/x-shellscript" ]; then
			__list="$(list_add "${__list}" "${__f}")"
			continue
		fi
		__list="$(list_add "${__list}" "${__f}")"
	done
	cd ..

	for __f in ${__list}; do
		test_one "${__f}"
	done
}

debug log:

solving 15ad685 ...
found 15ad685 in https://archives.passt.top/passt-dev/20220902021500.25358-5-david@gibson.dropbear.id.au/
found d4357b7 in https://archives.passt.top/passt-dev/20220902020434.24238-5-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20220901130805.3938040-5-david@gibson.dropbear.id.au/
found 8eb1ee5 in https://archives.passt.top/passt-dev/20220901130805.3938040-4-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20220902020434.24238-4-david@gibson.dropbear.id.au/
found 600399b in https://passt.top/passt
preparing index
index prepared:
100755 600399b12931195cf80792c81d5a4199524cd82f	test/lib/test

applying [1/3] https://archives.passt.top/passt-dev/20220901130805.3938040-4-david@gibson.dropbear.id.au/
diff --git a/test/lib/test b/test/lib/test
index 600399b..8eb1ee5 100755

Checking patch test/lib/test...
Applied patch test/lib/test cleanly.

skipping https://archives.passt.top/passt-dev/20220902020434.24238-4-david@gibson.dropbear.id.au/ for 8eb1ee5
index at:
100755 8eb1ee52f8c34490639eb4f8eba112f7ee420e87	test/lib/test

applying [2/3] https://archives.passt.top/passt-dev/20220902020434.24238-5-david@gibson.dropbear.id.au/
diff --git a/test/lib/test b/test/lib/test
index 8eb1ee5..d4357b7 100755

Checking patch test/lib/test...
Applied patch test/lib/test cleanly.

skipping https://archives.passt.top/passt-dev/20220901130805.3938040-5-david@gibson.dropbear.id.au/ for d4357b7
index at:
100755 d4357b71007a4f2c418230fcbf9b47f1cdeb9dc9	test/lib/test

applying [3/3] https://archives.passt.top/passt-dev/20220902021500.25358-5-david@gibson.dropbear.id.au/
diff --git a/test/lib/test b/test/lib/test
index d4357b7..15ad685 100755

Checking patch test/lib/test...
Applied patch test/lib/test cleanly.

index at:
100755 15ad685f3eae4d5f52cd1fbd131e95e96cdf26b0	test/lib/test

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).