Skip to content

Commit 70a8efd

Browse files
committed
Define INIT_APPNAME at compile-time and let tests use it
1 parent 0fc5840 commit 70a8efd

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

Makefile

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Program to auto start when kernel is ready.
2+
# List of program can be found at build/usr/bin/
3+
# Some of them are
4+
# sh.out
5+
# ls.out
6+
# tictactoe.out
7+
# calc.out
8+
INIT_APPNAME ?= sh.out
9+
110
ROOT_DIR = .
211
BUILD_DIR = build
312
INCLUDE_DIR = include/fuzzy
@@ -42,23 +51,9 @@ kernel_core = $(BUILD_DIR)/kernel/core
4251

4352
MINIMAL_DISK = $(BUILD_DIR)/minimal_disk
4453

45-
46-
# Program to auto start when kernel is ready.
47-
# 1 - Tic Tac Toe
48-
# 2 - Calculator
49-
# 3 - ls
50-
# 4 - cat
51-
# 5 - sh
52-
RUN_APP_ID = 1
53-
5454
# Apps
5555
SRC_APP = $(SRC_DIR)/usr/local/src
5656
BUILD_APP = $(BUILD_DIR)/usr/local/bin
57-
app_calc = $(BUILD_APP)/calc.out
58-
app_tic_tac_toe = $(BUILD_APP)/tictactoe.out
59-
app_ls = $(BUILD_APP)/ls.out
60-
app_cat = $(BUILD_APP)/cat.out
61-
app_sh = $(BUILD_APP)/sh.out
6257

6358
MEMORY_LOCATION_KERNEL = 0xC000
6459

external/src/Makefile.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ $(BUILD_DIR)/external/bin/mbr_builder: external/src/mbr_builder.c
88
mkdir -p $(dir $@)
99
$(HOST_CC) -o $@ $<
1010

11-
$(BUILD_DIR)/external/out/fuzzy_mount: $(patsubst $(SRC_APP)/%.c,$(BUILD_APP)/%.out,$(shell find $(SRC_APP)/ -name '*.c'))
11+
$(BUILD_DIR)/external/out/fuzzy_mount: $(patsubst $(SRC_APP)/%.c,$(BUILD_APP)/%.out,$(shell find $(SRC_APP)/ -name '*.c')) \
12+
README.md \
13+
.gdbinit
1214
# not a mount
1315
mkdir -p $@
1416
cp -f -t $@ $^

src/kernel/Makefile.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ debug_kernel: $(kernel_core)
77
$(SELF_BUILD_DIR)/%.o: $(SELF_SRC_DIR)/%.c $(BUILD_USR_INCLUDE_ALL)
88
mkdir -p $(dir $@)
99
$(KERNEL_CC) -c -o $@ \
10+
-D INIT_APPNAME=\"$(INIT_APPNAME)\" \
1011
-D __SOURCE_SNAPSHOT__=$(SOURCE_SNAPSHOT) \
1112
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
1213
-D MEMORY_LOCATION_APP=$(MEMORY_LOCATION_APP) \

src/kernel/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void kernel_core_entry() {
4545

4646
process_scheduler_init();
4747

48-
int sh_pid = spawn("sh.out");
49-
print_log("first user process created: %d", sh_pid);
48+
int init_pid = spawn(INIT_APPNAME);
49+
print_log("init process created: %d", init_pid);
5050
interrupt_pit_enable();
5151
while (1);
5252
}

tests/lib.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ BUILD_TEST_DIR="build_test"
66
MONITOR_PORT=55555
77
QEMU_SCREENSHOT="/tmp/$(basename $0 .sh).ppm"
88
QEMU_SCREENSHOT_ARTIFACT="${QEMU_SCREENSHOT%.ppm}.png"
9+
INIT_APPNAME="tictactoe.out"
910

1011
MAGIC_WORD_SLEEP="##SLEEP-10s##"
1112

@@ -88,7 +89,8 @@ export -f inject_test_code_c
8889
##########################################
8990
function sync_to_src_test() {
9091
# Prepare source code directory for tests.
91-
rsync -r "${SRC_DIR:?}" "${SRC_TEST_DIR:?}"
92+
rm -r "${SRC_TEST_DIR:?}"
93+
cp -r "${SRC_DIR:?}" "${SRC_TEST_DIR:?}"
9294

9395
find "${SRC_TEST_DIR:?}" -iname '*.asm' -exec bash -c 'inject_test_code_asm "$0" "$1"' {} "$1" \;
9496
find "${SRC_TEST_DIR:?}" -iname '*.c' -exec bash -c 'inject_test_code_c "$0" "$1"' {} "$1" \;
@@ -100,6 +102,7 @@ function sync_to_src_test() {
100102
# COMMAND_OUTPUT
101103
# SCREEN_CONTENT
102104
# QEMU_PID
105+
# INIT_APPNAME
103106
# Arguments:
104107
# Magic Word
105108
# Inject Keyword
@@ -115,7 +118,10 @@ function os_test_up() {
115118
sync_to_src_test "${test_inject_keyword:?}"
116119

117120
# Turn up QEMU in background
118-
make qemu \
121+
make clean BUILD_DIR="${BUILD_TEST_DIR:?}" \
122+
&& make configure \
123+
&& make qemu \
124+
INIT_APPNAME="${INIT_APPNAME:?}" \
119125
SRC_DIR="${SRC_TEST_DIR:?}" \
120126
BUILD_DIR="${BUILD_TEST_DIR:?}" \
121127
QEMU_SHUT_FLAGS="" \

0 commit comments

Comments
 (0)