Skip to content

Commit ff9422a

Browse files
committed
Merge branch 'tests'
2 parents 1705884 + 6e63f01 commit ff9422a

File tree

6 files changed

+70
-7
lines changed

6 files changed

+70
-7
lines changed

src/bootloader/stage1.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
label_bts2_loaded:
3434
move_xy 06, 07, 00
3535
print_hex_string_ext 0x8000, 10, C_WHITE, 0
36-
; __TEST_INJECT__: mov eax, 0x9A11C824
37-
; __TEST_INJECT__: HLT
36+
; __TEST_INJECT_BT1__: mov eax, 0x9A11C824
37+
; __TEST_INJECT_BT1__: HLT
3838
JMP 0x8000
3939
JMP label_exit
4040

src/bootloader/stage2.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ global label_exit
4040
mov eax, cr0
4141
or eax, 0x00000001
4242
mov cr0, eax
43+
44+
; __TEST_INJECT_BT2__: mov eax, 0x198A65C3
45+
; __TEST_INJECT_BT2__: HLT
4346
jmp 0x08:0x0000 ; address of smart kernel init
4447

4548
label_exit:

tests/bootloader_stage1_test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
TEST_INJECT_WORD="__TEST_INJECT_BT1__"
4+
TEST_MAGIC_WANT="9A11C824"
5+
6+
source tests/lib.sh
7+
8+
os_test_up "${TEST_INJECT_WORD:?}" || exit -1
9+
10+
# Test
11+
set -e
12+
echo "${SCREEN_CONTENT:?}" | grep "Bootloader: Stage 1" || ( echo "Test Failed!" && exit -1 )
13+
wait ${QEMU_PID:?}
14+
echo "$0 passed!!!"

tests/bootloader_stage2_test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
TEST_INJECT_WORD="__TEST_INJECT_BT2__"
4+
TEST_MAGIC_WANT="198A65C3"
5+
6+
source tests/lib.sh
7+
8+
os_test_up "${TEST_INJECT_WORD:?}" || exit -1
9+
10+
# Test
11+
set -e
12+
echo "${SCREEN_CONTENT:?}" | grep "Bootloader: Stage 2" || ( echo "Test Failed!" && exit -1 )
13+
echo "${SCREEN_CONTENT:?}" | grep "Loading GDT Table and entering protected mode" || ( echo "Test Failed!" && exit -1 )
14+
wait ${QEMU_PID:?}
15+
echo "$0 passed!!!"

tests/lib.sh

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,51 @@ SRC_TEST_DIR="src_test/"
55
MONITOR_PORT=55555
66
QEMU_SCREENSHOT="/tmp/qemu.ppm"
77

8+
9+
##########################################
10+
# Activate Code for testing within source.
11+
# Arguments:
12+
# Filename
13+
# Inject Keyword
14+
##########################################
15+
function inject_test_code() {
16+
echo "Injecting Test Code in $1 (if any)"
17+
sed -i "s/;\s*${2}:\s*//g" "$1"
18+
}
19+
export -f inject_test_code
20+
21+
22+
##########################################
23+
# Copy SRC to Test Sorce and Inject Code.
24+
# Arguments:
25+
# Inject Keyword
26+
##########################################
27+
function sync_to_src_test() {
28+
echo "HEREEEEEE!"
29+
# Prepare source code directory for tests.
30+
rsync -r "${SRC_DIR:?}" "${SRC_TEST_DIR:?}"
31+
32+
find "${SRC_TEST_DIR:?}" -iname '*.asm' -exec bash -c 'inject_test_code "$0" "$1"' {} "$1" \;
33+
}
34+
35+
836
###################################################
937
# Turn up OS in QEMU and wait for $TEST_MAGIC_WANT.
1038
# Globals:
1139
# TEST_MAGIC_WANT
1240
# COMMAND_OUTPUT
1341
# SCREEN_CONTENT
1442
# QEMU_PID
43+
# Arguments:
44+
# Inject Keyword
1545
# Outputs:
1646
# Logs
1747
# Returns:
1848
# 0 on success, non-zero on error.
1949
###################################################
20-
function os_up() {
50+
function os_test_up() {
51+
sync_to_src_test "$1"
52+
2153
# Turn up QEMU in background
2254
make qemu SRC_DIR="${SRC_TEST_DIR:?}" \
2355
QEMU_SHUT_FLAGS="" \
@@ -44,6 +76,7 @@ function os_up() {
4476
echo "Magic Word Found! Continuing the test..." && \
4577
break
4678
echo "Magic word not found! Got: $COMMAND_OUTPUT"
79+
sleep 1s
4780
done
4881

4982
if [ ! -f ${QEMU_SCREENSHOT:?} ]; then

tests/run.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#!/bin/bash
22
set -e
33

4-
# Preprocess
5-
bash tests/preprocess.sh
6-
74
# Execute Tests
8-
bash tests/stage1_test.sh
5+
bash tests/bootloader_stage1_test.sh
6+
bash tests/bootloader_stage2_test.sh
97

108
# Done
119
echo "All tests passed!"

0 commit comments

Comments
 (0)