forked from asterinas/asterinas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
203 lines (174 loc) · 5.89 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# SPDX-License-Identifier: MPL-2.0
# The Makefile provides a way to run arbitrary tests in the kernel
# mode using the kernel command line.
# Here are the options for the auto test feature.
AUTO_TEST ?= none
BOOT_LOADER ?= grub
BOOT_PROTOCOL ?= multiboot2
QEMU_MACHINE ?= q35
BUILD_SYSCALL_TEST ?= 0
EMULATE_IOMMU ?= 0
ENABLE_KVM ?= 1
INTEL_TDX ?= 0
SKIP_GRUB_MENU ?= 1
SYSCALL_TEST_DIR ?= /tmp
EXTRA_BLOCKLISTS_DIRS ?= ""
RELEASE_MODE ?= 0
# End of auto test features.
CARGO_OSDK := ~/.cargo/bin/cargo-osdk
CARGO_OSDK_ARGS :=
ifeq ($(AUTO_TEST), syscall)
BUILD_SYSCALL_TEST := 1
CARGO_OSDK_ARGS += --kcmd_args="SYSCALL_TEST_DIR=$(SYSCALL_TEST_DIR)"
CARGO_OSDK_ARGS += --kcmd_args="EXTRA_BLOCKLISTS_DIRS=$(EXTRA_BLOCKLISTS_DIRS)"
CARGO_OSDK_ARGS += --init_args="/opt/syscall_test/run_syscall_test.sh"
else ifeq ($(AUTO_TEST), regression)
CARGO_OSDK_ARGS += --init_args="/regression/run_regression_test.sh"
else ifeq ($(AUTO_TEST), boot)
CARGO_OSDK_ARGS += --init_args="/regression/boot_hello.sh"
endif
ifeq ($(RELEASE_MODE), 1)
CARGO_OSDK_ARGS += --profile release
endif
ifeq ($(INTEL_TDX), 1)
CARGO_OSDK_ARGS += --features intel_tdx
endif
CARGO_OSDK_ARGS += --boot.loader="$(BOOT_LOADER)"
CARGO_OSDK_ARGS += --boot.protocol="$(BOOT_PROTOCOL)"
CARGO_OSDK_ARGS += --qemu.machine="$(QEMU_MACHINE)"
ifeq ($(QEMU_MACHINE), microvm)
CARGO_OSDK_ARGS += --select microvm
endif
# To test the linux-efi-handover64 boot protocol, we need to use Debian's
# GRUB release, which is installed in /usr/bin in our Docker image.
ifeq ($(BOOT_PROTOCOL), linux-efi-handover64)
CARGO_OSDK_ARGS += --boot.grub-mkrescue=/usr/bin/grub-mkrescue
endif
ifeq ($(EMULATE_IOMMU), 1)
CARGO_OSDK_ARGS += --select iommu
endif
ifeq ($(ENABLE_KVM), 1)
CARGO_OSDK_ARGS += --qemu.args="--enable-kvm"
endif
# Pass make variables to all subdirectory makes
export
# Basically, non-OSDK crates do not depend on Aster Frame and can be checked
# or tested without OSDK.
NON_OSDK_CRATES := \
framework/libs/align_ext \
framework/libs/aster-main \
framework/libs/linux-bzimage/builder \
framework/libs/linux-bzimage/boot-params \
framework/libs/ktest \
framework/libs/ktest-proc-macro \
framework/libs/tdx-guest \
kernel/libs/cpio-decoder \
kernel/libs/int-to-c-enum \
kernel/libs/int-to-c-enum/derive \
kernel/libs/aster-rights \
kernel/libs/aster-rights-proc \
kernel/libs/keyable-arc \
kernel/libs/typeflags \
kernel/libs/typeflags-util
# In contrast, OSDK crates depend on Aster Frame (or being aster-frame itself)
# and need to be built or tested with OSDK.
OSDK_CRATES := \
framework/aster-frame \
framework/libs/linux-bzimage/setup \
kernel \
kernel/aster-nix \
kernel/comps/block \
kernel/comps/console \
kernel/comps/framebuffer \
kernel/comps/input \
kernel/comps/network \
kernel/comps/time \
kernel/comps/virtio \
kernel/libs/aster-util
.PHONY: all
all: build
# Install or update OSDK from source
# To uninstall, do `cargo uninstall cargo-osdk`
.PHONY: install_osdk
install_osdk:
@cargo install cargo-osdk --path osdk
# This will install OSDK if it is not already installed
# To update OSDK, we need to run `install_osdk` manually
$(CARGO_OSDK):
@make --no-print-directory install_osdk
.PHONY: initramfs
initramfs:
@make --no-print-directory -C regression
.PHONY: build
build: initramfs $(CARGO_OSDK)
@cargo osdk build $(CARGO_OSDK_ARGS)
.PHONY: tools
tools:
@cd kernel/libs/comp-sys && cargo install --path cargo-component
.PHONY: run
run: build
@cargo osdk run $(CARGO_OSDK_ARGS)
# Check the running status of auto tests from the QEMU log
ifeq ($(AUTO_TEST), syscall)
@tail --lines 100 qemu.log | grep -q "^.* of .* test cases passed." || (echo "Syscall test failed" && exit 1)
else ifeq ($(AUTO_TEST), regression)
@tail --lines 100 qemu.log | grep -q "^All regression tests passed." || (echo "Regression test failed" && exit 1)
else ifeq ($(AUTO_TEST), boot)
@tail --lines 100 qemu.log | grep -q "^Successfully booted." || (echo "Boot test failed" && exit 1)
endif
.PHONY: gdb_server
gdb_server: build
@cd kernel && cargo osdk run $(CARGO_OSDK_ARGS) -G --vsc --gdb-server-addr :1234
.PHONY: gdb_client
gdb_client: $(CARGO_OSDK)
@cd kernel && cargo osdk debug $(CARGO_OSDK_ARGS) --remote :1234
.PHONY: test
test:
@for dir in $(NON_OSDK_CRATES); do \
(cd $$dir && cargo test) || exit 1; \
done
.PHONY: ktest
ktest: initramfs $(CARGO_OSDK)
@# Exclude linux-bzimage-setup from ktest since it's hard to be unit tested
@for dir in $(OSDK_CRATES); do \
[ $$dir = "framework/libs/linux-bzimage/setup" ] && continue; \
(cd $$dir && cargo osdk test) || exit 1; \
done
docs: $(CARGO_OSDK)
@for dir in $(NON_OSDK_CRATES); do \
(cd $$dir && cargo doc --no-deps) || exit 1; \
done
@for dir in $(OSDK_CRATES); do \
(cd $$dir && cargo osdk doc --no-deps) || exit 1; \
done
@echo "" # Add a blank line
@cd docs && mdbook build # Build mdBook
.PHONY: format
format:
@./tools/format_all.sh
@make --no-print-directory -C regression format
.PHONY: check
check: $(CARGO_OSDK)
@cd osdk && cargo clippy -- -D warnings
@./tools/format_all.sh --check # Check Rust format issues
@# Check if STD_CRATES and NOSTD_CRATES combined is the same as all workspace members
@sed -n '/^\[workspace\]/,/^\[.*\]/{/members = \[/,/\]/p}' Cargo.toml | \
grep -v "members = \[" | tr -d '", \]' | \
sort > /tmp/all_crates
@echo $(NON_OSDK_CRATES) $(OSDK_CRATES) | tr ' ' '\n' | sort > /tmp/combined_crates
@diff -B /tmp/all_crates /tmp/combined_crates || \
(echo "Error: STD_CRATES and NOSTD_CRATES combined is not the same as all workspace members" && exit 1)
@rm /tmp/all_crates /tmp/combined_crates
@for dir in $(NON_OSDK_CRATES); do \
(cd $$dir && cargo clippy -- -D warnings) || exit 1; \
done
@for dir in $(OSDK_CRATES); do \
(cd $$dir && cargo osdk clippy -- -- -D warnings) || exit 1; \
done
@make --no-print-directory -C regression check
.PHONY: clean
clean:
@cargo clean
@cd docs && mdbook clean
@make --no-print-directory -C regression clean
@rm -f $(CARGO_OSDK)