Skip to content

Commit 466d7ec

Browse files
committed
[Test] Added expect script to talk with qemu.
1 parent d281302 commit 466d7ec

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

before_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
apt install -y make nasm gcc cpulimit qemu-system-x86 gocr
2+
apt install -y make nasm gcc cpulimit qemu-system-x86 gocr expect

tests/lib.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SRC_DIR="src/"
44
SRC_TEST_DIR="src_test/"
5-
BUILD_TEST_DIR="build_test/"
5+
BUILD_TEST_DIR="build_test"
66
MONITOR_PORT=55555
77
QEMU_SCREENSHOT="/tmp/qemu.ppm"
88

@@ -73,17 +73,21 @@ function os_test_up() {
7373
# Keep polling QEMU monitor until we get our magic word!
7474
COMMAND_OUTPUT=""
7575
echo "Sending commands to QEMU and polling for the magic word '${magic_word:?}' every second."
76+
7677
while true; do
77-
COMMAND_OUTPUT="$(echo -e 'screendump '${QEMU_SCREENSHOT:?}'\nprint $eax\nquit' | \
78-
nc 127.0.0.1 ${MONITOR_PORT:?} | tr -d '\0')"
79-
echo "QEMU monitor response: ${COMMAND_OUTPUT:?}"
80-
echo "$COMMAND_OUTPUT" | \
78+
COMMAND_OUTPUT="$(./tests/qemu_monitor_expect.sh ${MONITOR_PORT:?} "print \$eax")"
79+
echo "QEMU monitor response: '${COMMAND_OUTPUT:?}'"
80+
echo "${COMMAND_OUTPUT:?}" | \
8181
grep -i "${magic_word:?}" && \
8282
echo "Magic Word Found! Continuing the test..." && \
8383
break
8484
sleep 1s
8585
done
8686

87+
sleep 5s
88+
./tests/qemu_monitor_expect.sh ${MONITOR_PORT:?} "screendump ${QEMU_SCREENSHOT:?}"
89+
./tests/qemu_monitor_expect.sh ${MONITOR_PORT:?} "quit"
90+
8791
if [ ! -f ${QEMU_SCREENSHOT:?} ]; then
8892
echo "Magic word found but no screenshot found! :( " >&2
8993
return -1

tests/qemu_monitor_expect.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/expect -f
2+
set timeout 10
3+
4+
set port [lindex $argv 0]
5+
set cmd [lindex $argv 1]
6+
7+
spawn telnet 127.0.0.1 $port
8+
9+
expect "(qemu) "
10+
11+
send -- "$cmd\r"
12+
13+
expect {
14+
"(qemu) " {}
15+
"closed" {}
16+
}

0 commit comments

Comments
 (0)