test: wait for the swtpm socket to appear

On slower/overloaded systems it may take a bit for the swtpm socket
to show up:

I: Started swtpm as PID 189419 with state dir /tmp/tmp.pWqUutuGUj
I: Configured emulated TPM2 device tpm-spapr
+ tee /var/tmp/systemd-test-TEST-70-TPM2_1/console.log
+ timeout --foreground 1200 /bin/qemu-system-ppc64le -smp 4 ...
qemu-system-ppc64le: -chardev socket,id=chrtpm,path=/tmp/tmp.pWqUutuGUj/sock: Failed to connect to '/tmp/tmp.pWqUutuGUj/sock': No such file or directory
E: qemu failed with exit code 1

Spotted regularly in the ppc64le cron job and in some Ubuntu CI/CentOS CI
pr runs [0].

[0] https://github.com/systemd/systemd/pull/29183#issuecomment-1721727927
This commit is contained in:
Frantisek Sumsal 2023-09-23 09:13:56 +02:00 committed by Luca Boccassi
parent 3a89904e45
commit 18c3ffbfcc

View file

@ -379,7 +379,12 @@ qemu_setup_swtpm_socket() {
swtpm socket --tpm2 --tpmstate dir="$state_dir" --ctrl type=unixio,path="$state_dir/sock" &
pid=$!
if ! kill -0 "$pid"; then
echo >&2 "Failed to setup swtpm socket"
derror "Failed to start swtpm"
return 1
fi
if ! timeout 5 bash -c "until [[ -S $state_dir/sock ]]; do sleep .5; done"; then
derror "Failed to setup swtpm socket"
return 1
fi