diff --git a/test/env b/test/env index 21c2da6d..d9a19a04 100755 --- a/test/env +++ b/test/env @@ -50,6 +50,11 @@ usage: test/env [] -f -q [...] resulting topology is used as the default physical topology when running tests + -r + Use random container names instead of "infamyN". Useful for the + unit tests running in CI environments which may see occasional + name clashes for "infamy0" due to race conditions. + -t Rather than starting a qeneth network, attach to this existing topology. If the command is containerized, it will be launched @@ -91,6 +96,11 @@ name() nm=infamy id=0 + if [ -n "$random" ]; then + # Let podman/docker allocate random hostname and container name + return + fi + names=$($(runner) ps -f name='infamy.*' --format '{{.Names}}') while true; do name="$nm$id" @@ -109,7 +119,7 @@ name() break; done - echo "$name" + echo "--hostname $name --name $name" } # Global options @@ -117,7 +127,7 @@ containerize=yes [ -c /dev/kvm ] && kvm="--device=/dev/kvm" files= -while getopts "cCDf:hiKp:q:t:" opt; do +while getopts "cCDf:hiKp:q:rt:" opt; do case ${opt} in c) $(runner) image prune -af @@ -150,6 +160,9 @@ while getopts "cCDf:hiKp:q:t:" opt; do qenethdir="$OPTARG" network="--sysctl net.ipv6.conf.all.disable_ipv6=0" ;; + r) + random=true + ;; t) topology="$OPTARG" network="--network host --volume $topology:$topology:ro" @@ -186,8 +199,7 @@ if [ "$containerize" ]; then --env PROMPT_DIRTRIM="$ixdir" \ --env PS1="$(build_ps1)" \ --expose 9001-9010 --publish-all \ - --hostname "$(name)" \ - --name "$(name)" \ + $(name) \ $interactive \ --rm \ --security-opt seccomp=unconfined \ diff --git a/test/test.mk b/test/test.mk index 29bfd32f..fd7e183d 100644 --- a/test/test.mk +++ b/test/test.mk @@ -15,12 +15,14 @@ binaries-x86_64 += OVMF.fd binaries := $(foreach bin,$(binaries-$(ARCH)),-f $(BINARIES_DIR)/$(bin)) test: - $(test-dir)/env $(mode) $(binaries) $(ninepm) $(INFIX_TESTS) + $(test-dir)/env -r $(mode) $(binaries) $(ninepm) $(INFIX_TESTS) test-sh: $(test-dir)/env $(mode) $(binaries) -i /bin/sh +# Unit tests run with random (-r) hostname and container name to +# prevent race conditions when running in CI environments. test-unit: - $(test-dir)/env $(ninepm) $(UNIT_TESTS) + $(test-dir)/env -r $(ninepm) $(UNIT_TESTS) .PHONY: test test-sh test-unit