Skip to content

Commit 38ed76a

Browse files
committed
[test] Upload per app screenshot as artifacts
1 parent 5405e65 commit 38ed76a

File tree

8 files changed

+39
-14
lines changed

8 files changed

+39
-14
lines changed

tests/app/cat_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Test is supposed to be sourced from shell_test.sh
44

5+
QEMU_SCREENSHOT_NAME="cat_test.ppm"
6+
57
python3 -m tests.qemu.monitor -p ${MONITOR_PORT:?} -sc run cat
68

79
test_create_screen_dump

tests/app/ls_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Test is supposed to be sourced from shell_test.sh
44

5+
QEMU_SCREENSHOT_NAME="ls_test.ppm"
6+
57
python3 -m tests.qemu.monitor -p ${MONITOR_PORT:?} -sc run ls
68

79
test_create_screen_dump

tests/app/tictactoe_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Test is supposed to be sourced from shell_test.sh
44

5+
QEMU_SCREENSHOT_NAME="tictactoe_test.ppm"
6+
57
python3 -m tests.qemu.monitor -p ${MONITOR_PORT:?} -sc run tictactoe
68

79
test_create_screen_dump

tests/app_ttt_test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
source tests/lib.sh
4+
5+
TEST_INJECT_WORD="__TEST_INJECT_APP_TTT_ENTRY__"
6+
TEST_MAGIC_WANT="${MAGIC_WORD_SLEEP:?}"
7+
8+
os_test_up "${TEST_MAGIC_WANT:?}" "${TEST_INJECT_WORD:?}" INIT_APPNAME="tictactoe" || exit -1
9+
10+
# Test
11+
set -e
12+
test_screen_content $LINENO "TicTacToe"
13+
14+
python -m tests.qemu.monitor --quit
15+
wait ${QEMU_PID:?}
16+
echo "$0 passed!!!"

tests/lib.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ SRC_DIR="src/"
66
SRC_TEST_DIR="src_test/"
77
BUILD_TEST_DIR="build_test"
88
MONITOR_PORT=55555
9-
QEMU_SCREENSHOT="/tmp/$(basename $0 .sh).ppm"
10-
QEMU_SCREENSHOT_ARTIFACT="${QEMU_SCREENSHOT%.ppm}.png"
9+
QEMU_SCREENSHOT_BASEDIR="/tmp"
10+
QEMU_SCREENSHOT_NAME="$(basename $0 .sh).ppm" # subtests are expected to override
1111

1212
MAGIC_WORD_SLEEP="##SLEEP-10s##"
1313
MAGIC_WORD_NO_TEST_INJECT="TEST-INJECT-WORD-NOT-NEEDED"
@@ -25,7 +25,6 @@ function err() {
2525
exit -1
2626
}
2727

28-
2928
##########################################
3029
# Resolves filename from build target.
3130
# Arguments:
@@ -69,21 +68,27 @@ function test_screen_content() {
6968
##########################################
7069
# Test Helper: Create QEMU screen dump
7170
# Globals:
72-
# QEMU_SCREENSHOT
73-
# QEMU_SCREENSHOT_ARTIFACT
71+
# QEMU_SCREENSHOT_NAME
72+
# SCREEN_CONTENT
7473
# Output:
7574
# raises error or screen dump in text.
7675
##########################################
7776
function test_create_screen_dump() {
78-
python -m tests.qemu.monitor -qc screendump ${QEMU_SCREENSHOT:?}
77+
qemu_screenshot_fname="${QEMU_SCREENSHOT_BASEDIR:?}/${QEMU_SCREENSHOT_NAME:?}"
78+
qemu_screenshot_png="${qemu_screenshot_fname%.ppm}.png" # lazy compute
79+
80+
# Cleanup from any old screenshot
81+
rm -f ${qemu_screenshot_fname:?}
7982

80-
if [ ! -f ${QEMU_SCREENSHOT:?} ]; then
83+
python -m tests.qemu.monitor -qc screendump ${qemu_screenshot_fname:?}
84+
85+
if [ ! -f ${qemu_screenshot_fname:?} ]; then
8186
err -1 "[create_screen_dump] failed to create qemu screen dump"
8287
fi
8388

84-
convert ${QEMU_SCREENSHOT:?} ${QEMU_SCREENSHOT_ARTIFACT:?}
89+
convert ${qemu_screenshot_fname:?} ${qemu_screenshot_png:?}
8590

86-
SCREEN_CONTENT="$(gocr -i ${QEMU_SCREENSHOT:?})"
91+
SCREEN_CONTENT="$(gocr -i ${qemu_screenshot_fname:?})"
8792
echo "Screen Content: '${SCREEN_CONTENT:?}'"
8893
}
8994

@@ -115,7 +120,7 @@ function sync_to_src_test() {
115120
rm -r "${SRC_TEST_DIR:?}"
116121
cp -r "${SRC_DIR:?}" "${SRC_TEST_DIR:?}"
117122

118-
if [[ "${1:?}" == "${MAGIC_WORD_NO_TEST_INJECT}" ]]; then
123+
if [[ "${1:?}" == "${MAGIC_WORD_NO_TEST_INJECT:?}" ]]; then
119124
return
120125
fi
121126

@@ -158,9 +163,6 @@ function os_test_up() {
158163
done
159164
echo "QEMU monitor is available."
160165

161-
# Cleanup from any previous execution
162-
rm -f ${QEMU_SCREENSHOT:?}
163-
164166
# Keep polling QEMU monitor until we get our magic word!
165167
COMMAND_OUTPUT=""
166168
echo "Sending commands to QEMU and polling for the magic word '${magic_word:?}' every second."

tests/qemu/monitor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def handle_qemu_quit(monitor, args):
5959
return
6060
logger.info("Handle: qemu quit")
6161
monitor.send_qemu_command("quit\n", wait_prompt=False)
62+
time.sleep(1)
6263

6364
def main():
6465
logging.basicConfig(level=logging.INFO)

tests/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
timeout 2m bash tests/bootloader_stage1_test.sh &&
66
timeout 2m bash tests/bootloader_stage2_test.sh &&
77
timeout 2m bash tests/kernel_core_entry_test.sh &&
8-
timeout 2m bash tests/fuzzy_app_test.sh
8+
timeout 2m bash tests/fuzzy_shell_test.sh
99

1010
# Done
1111
echo "All tests passed!"

0 commit comments

Comments
 (0)