From 1d70f8e55b344aa8642919b968a79bcc04a62a70 Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 24 Feb 2023 15:14:20 -0800 Subject: [PATCH 1/7] Try adding check that VM is running (QEMU VM doesn't seem to be launching at all?) --- scripts/run-qemu.sh.in | 5 ++++- scripts/travis.sh | 30 ++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/run-qemu.sh.in b/scripts/run-qemu.sh.in index 5d625d109..ced877da0 100755 --- a/scripts/run-qemu.sh.in +++ b/scripts/run-qemu.sh.in @@ -31,4 +31,7 @@ done; -netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::${HOST_PORT}-:22 \ -device virtio-net-device,netdev=net0 \ -device virtio-rng-pci \ - -smp $SMP + -smp $SMP \ + -monitor tcp:127.0.0.1:55555,server,nowait + #-monitor unix:/qemu-monitor-socket,server,nowait + diff --git a/scripts/travis.sh b/scripts/travis.sh index f7040c893..231c3fa5d 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -4,8 +4,34 @@ EXPECTED_LOG_DIR=$1 # Launch QEMU test screen -L -dmS qemu ./scripts/run-qemu.sh -# TODO: check for connectivity before starting, instead of sleeping -sleep 20 +sleep 5 + +# We check if the VM is running +attempts=10 +attempt_delay=5 +running=0 +for ((i = 0; i < $attempts; ++i)); do + #result=$(echo "info status" | socat - unix-connect:/qemu-monitor-socket | grep "VM Status: running") + #result=$(echo "info status" | telnet 127.0.0.1 55555 | grep "VM Status: running") + result=$((echo "info status" && sleep 1) | netcat -N 127.0.0.1 55555 | grep "VM Status: running") + qemu_monitor_result=$((echo "info status" && sleep 1) | netcat -N 127.0.0.1 55555) + #qemu_monitor_result=$(echo "info status" | socat - unix-connect:/qemu-monitor-socket) + echo "Received from monitor: $qemu_monitor_result" + if [ -n $result ]; then + echo "VM not yet running. [check $((i + 1)) of $attempts - using delay of $attempt_delay seconds]" + sleep $attempt_delay + else + echo "VM confirmed to be running. Proceeding to run test(s)." + running=1 + break + fi +done + +if [ $running -eq 0 ]; then + echo "[FAIL] VM not confirmed as running in max of $attempts attempts - aborting." + exit 1 +fi + ./scripts/test-qemu.sh 2>&1 | grep -v "Warning: Permanently added" | tee output.log diff output.log $EXPECTED_LOG_DIR/test-qemu.expected.log From 85670c21991fb73bcf86b318bad32bf4b9c1edf4 Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 24 Feb 2023 19:11:43 -0800 Subject: [PATCH 2/7] Fix patch macro and VM verification --- CMakeLists.txt | 2 +- scripts/run-qemu.sh.in | 4 +--- scripts/travis.sh | 35 +++++++++++++++++++---------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5693eef6f..a6f26877c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON) macro(add_patch submodule patch working_directory patch_list) add_custom_command(OUTPUT ${patch}.applied WORKING_DIRECTORY ${working_directory} - COMMAND patch --forward -p0 < ${patchdir}/${submodule}/${patch} + COMMAND patch --forward -p0 < ${patchdir}/${submodule}/${patch} || true COMMAND touch ${CMAKE_BINARY_DIR}/${patch}.applied COMMENT "Applying ${patch}") list(APPEND ${patch_list} ${patch}.applied) diff --git a/scripts/run-qemu.sh.in b/scripts/run-qemu.sh.in index ced877da0..8f3cb79ec 100755 --- a/scripts/run-qemu.sh.in +++ b/scripts/run-qemu.sh.in @@ -32,6 +32,4 @@ done; -device virtio-net-device,netdev=net0 \ -device virtio-rng-pci \ -smp $SMP \ - -monitor tcp:127.0.0.1:55555,server,nowait - #-monitor unix:/qemu-monitor-socket,server,nowait - + -monitor unix:qemu-monitor.sock,server,nowait diff --git a/scripts/travis.sh b/scripts/travis.sh index 231c3fa5d..0bbb4f639 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -1,25 +1,24 @@ #!/bin/bash EXPECTED_LOG_DIR=$1 +MONITOR_SOCKET=qemu-monitor.sock +ATTEMPTS=10 +ATTEMPT_DELAY=5 -# Launch QEMU test +# Launch QEMU screen -L -dmS qemu ./scripts/run-qemu.sh -sleep 5 +sleep 1 -# We check if the VM is running -attempts=10 -attempt_delay=5 +# Verify VM is running before running tests - abort after 10 failed attempts running=0 -for ((i = 0; i < $attempts; ++i)); do - #result=$(echo "info status" | socat - unix-connect:/qemu-monitor-socket | grep "VM Status: running") - #result=$(echo "info status" | telnet 127.0.0.1 55555 | grep "VM Status: running") - result=$((echo "info status" && sleep 1) | netcat -N 127.0.0.1 55555 | grep "VM Status: running") - qemu_monitor_result=$((echo "info status" && sleep 1) | netcat -N 127.0.0.1 55555) - #qemu_monitor_result=$(echo "info status" | socat - unix-connect:/qemu-monitor-socket) - echo "Received from monitor: $qemu_monitor_result" - if [ -n $result ]; then - echo "VM not yet running. [check $((i + 1)) of $attempts - using delay of $attempt_delay seconds]" - sleep $attempt_delay +for ((i = 0; i < $ATTEMPTS; ++i)); do + result=$((echo "info status" && sleep 1) | \ + socat - unix-connect:qemu-monitor.sock | \ + grep -oF "running") + if [[ -z "$result" ]]; then + attempt=$((i+1)) + echo "VM not yet running. (check $attempt/$ATTEMPTS)" + [ $attempt -ne $ATTEMPTS ] && sleep $ATTEMPT_DELAY else echo "VM confirmed to be running. Proceeding to run test(s)." running=1 @@ -27,11 +26,15 @@ for ((i = 0; i < $attempts; ++i)); do fi done +# Clean up socket +rm $MONITOR_SOCKET + if [ $running -eq 0 ]; then - echo "[FAIL] VM not confirmed as running in max of $attempts attempts - aborting." + echo "[FAIL] VM not confirmed as running after max of $ATTEMPTS attempts - aborting." exit 1 fi + ./scripts/test-qemu.sh 2>&1 | grep -v "Warning: Permanently added" | tee output.log diff output.log $EXPECTED_LOG_DIR/test-qemu.expected.log From bc712f822f6cf1d576cfa88d3d2dac65a8c4df8c Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 24 Feb 2023 19:18:31 -0800 Subject: [PATCH 3/7] Add socat as dependency to docker files --- docker/Dockerfile | 3 ++- docker/Dockerfile.32.nobuild | 3 ++- docker/Dockerfile.nobuild | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 9655ccef1..7e8d370c8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,7 +9,8 @@ RUN apt -y install autoconf automake autotools-dev bc \ gperf libgmp-dev libmpc-dev libmpfr-dev libtool texinfo tmux \ patchutils zlib1g-dev wget bzip2 patch vim-common lbzip2 python \ pkg-config libglib2.0-dev libpixman-1-dev libssl-dev screen \ - device-tree-compiler expect makeself unzip cpio rsync cmake ninja-build p7zip-full + device-tree-compiler expect makeself unzip cpio rsync cmake ninja-build \ + p7zip-full socat RUN apt-get update && apt-get install --reinstall ca-certificates RUN git clone https://github.com/keystone-enclave/keystone /keystone diff --git a/docker/Dockerfile.32.nobuild b/docker/Dockerfile.32.nobuild index 1f38ba6af..d5754ef17 100644 --- a/docker/Dockerfile.32.nobuild +++ b/docker/Dockerfile.32.nobuild @@ -9,7 +9,8 @@ RUN apt -y install autoconf automake autotools-dev bc \ gperf libgmp-dev libmpc-dev libmpfr-dev libtool texinfo tmux \ patchutils zlib1g-dev wget bzip2 patch vim-common lbzip2 python \ pkg-config libglib2.0-dev libpixman-1-dev libssl-dev screen \ - device-tree-compiler expect makeself unzip cpio rsync cmake ninja-build p7zip-full + device-tree-compiler expect makeself unzip cpio rsync cmake ninja-build \ + p7zip-full socat RUN apt-get update && apt-get install --reinstall ca-certificates RUN git clone https://github.com/keystone-enclave/keystone /keystone diff --git a/docker/Dockerfile.nobuild b/docker/Dockerfile.nobuild index 54f8b9fcf..640725d6e 100644 --- a/docker/Dockerfile.nobuild +++ b/docker/Dockerfile.nobuild @@ -9,7 +9,8 @@ RUN apt -y install autoconf automake autotools-dev bc \ gperf libgmp-dev libmpc-dev libmpfr-dev libtool texinfo tmux \ patchutils zlib1g-dev wget bzip2 patch vim-common lbzip2 python \ pkg-config libglib2.0-dev libpixman-1-dev libssl-dev screen \ - device-tree-compiler expect makeself unzip cpio rsync cmake ninja-build p7zip-full + device-tree-compiler expect makeself unzip cpio rsync cmake ninja-build \ + p7zip-full socat RUN apt-get update && apt-get install --reinstall ca-certificates RUN git clone https://github.com/keystone-enclave/keystone /keystone From 1cd82d0aec1f261b9799156171c840883ffae6e5 Mon Sep 17 00:00:00 2001 From: red-robby Date: Fri, 24 Feb 2023 19:21:39 -0800 Subject: [PATCH 4/7] Make indenting of old code consistent --- scripts/travis.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/travis.sh b/scripts/travis.sh index 0bbb4f639..dda9dd89c 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -38,11 +38,10 @@ fi ./scripts/test-qemu.sh 2>&1 | grep -v "Warning: Permanently added" | tee output.log diff output.log $EXPECTED_LOG_DIR/test-qemu.expected.log -if [ $? -eq 0 ] -then - echo "[PASS] output.log matches with the expected output" - exit 0 +if [ $? -eq 0 ]; then + echo "[PASS] output.log matches with the expected output" + exit 0 else - echo "[FAIL] output.log does not match with the expected output" - exit 1 + echo "[FAIL] output.log does not match with the expected output" + exit 1 fi From 4b219da471b68beeab8d1765ca498443d21c18a2 Mon Sep 17 00:00:00 2001 From: red-robby Date: Sat, 25 Feb 2023 15:54:37 -0800 Subject: [PATCH 5/7] Refactor script to remove redundant max attempt check --- scripts/travis.sh | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/scripts/travis.sh b/scripts/travis.sh index dda9dd89c..75c0fdcc8 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -10,30 +10,22 @@ screen -L -dmS qemu ./scripts/run-qemu.sh sleep 1 # Verify VM is running before running tests - abort after 10 failed attempts -running=0 -for ((i = 0; i < $ATTEMPTS; ++i)); do +for ((i = 0;;)); do result=$((echo "info status" && sleep 1) | \ socat - unix-connect:qemu-monitor.sock | \ grep -oF "running") - if [[ -z "$result" ]]; then - attempt=$((i+1)) - echo "VM not yet running. (check $attempt/$ATTEMPTS)" - [ $attempt -ne $ATTEMPTS ] && sleep $ATTEMPT_DELAY - else - echo "VM confirmed to be running. Proceeding to run test(s)." - running=1 - break + [[ -z "$result" ]] || break + echo "VM not yet running. (check $((++i))/$ATTEMPTS)" + if [[ $i -eq $ATTEMPTS ]]; then + echo "[FAIL] VM not confirmed as running after max of $ATTEMPTS checks - aborting." + exit 1 fi + sleep $ATTEMPT_DELAY done # Clean up socket rm $MONITOR_SOCKET - -if [ $running -eq 0 ]; then - echo "[FAIL] VM not confirmed as running after max of $ATTEMPTS attempts - aborting." - exit 1 -fi - +echo "VM confirmed to be running. Proceeding to run test(s)." ./scripts/test-qemu.sh 2>&1 | grep -v "Warning: Permanently added" | tee output.log From c14ccdf01cddd67a6b8302a258bc9c043ac28c05 Mon Sep 17 00:00:00 2001 From: red-robby Date: Sat, 25 Feb 2023 16:02:25 -0800 Subject: [PATCH 6/7] Use monitor socket variable in socat call --- scripts/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/travis.sh b/scripts/travis.sh index 75c0fdcc8..e8cf43ebc 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -12,7 +12,7 @@ sleep 1 # Verify VM is running before running tests - abort after 10 failed attempts for ((i = 0;;)); do result=$((echo "info status" && sleep 1) | \ - socat - unix-connect:qemu-monitor.sock | \ + socat - unix-connect:$MONITOR_SOCKET | \ grep -oF "running") [[ -z "$result" ]] || break echo "VM not yet running. (check $((++i))/$ATTEMPTS)" From d0d42a8e24edfd1fdb15dcdb200c74de5d71e47a Mon Sep 17 00:00:00 2001 From: red-robby Date: Sat, 25 Feb 2023 16:43:39 -0800 Subject: [PATCH 7/7] Add space to ensure shell disambiguates for opening subshell See https://www.shellcheck.net/wiki/SC1102 --- scripts/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/travis.sh b/scripts/travis.sh index e8cf43ebc..da831f2c7 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -11,7 +11,7 @@ sleep 1 # Verify VM is running before running tests - abort after 10 failed attempts for ((i = 0;;)); do - result=$((echo "info status" && sleep 1) | \ + result=$( (echo "info status" && sleep 1) | \ socat - unix-connect:$MONITOR_SOCKET | \ grep -oF "running") [[ -z "$result" ]] || break