Reimplement the user mode test shortcut

This commit is contained in:
Zhang Junyang 2023-11-06 15:42:26 +08:00 committed by Tate, Hongliang Tian
parent 8eb1e06c2a
commit f8e4295e90
3 changed files with 17 additions and 86 deletions

View File

@ -63,38 +63,5 @@ exclude = [
"services/libs/comp-sys/controlled",
]
[workspace.metadata]
usermode_testable = [
"runner",
"framework/libs/align_ext",
"framework/libs/ktest",
"services/libs/cpio-decoder",
"services/libs/int-to-c-enum",
"services/libs/int-to-c-enum/derive",
"services/libs/jinux-rights",
"services/libs/jinux-rights-proc",
"services/libs/keyable-arc",
"services/libs/typeflags",
"services/libs/typeflags-util",
]
ktest_testable = [
"framework/jinux-frame",
"framework/libs/tdx-guest",
"services/comps/block",
"services/comps/framebuffer",
"services/comps/input",
"services/comps/network",
"services/comps/time",
"services/comps/virtio",
"services/libs/jinux-std",
"services/libs/jinux-util",
]
untestable = [
"framework/jinux-frame/src/arch/x86/boot/linux_boot/setup",
]
[features]
intel_tdx = ["jinux-frame/intel_tdx", "jinux-std/intel_tdx"]

View File

@ -76,6 +76,20 @@ export
# Toolchain variables that are used when building the Linux setup header
export CARGO := cargo
# Maintain a list of usermode crates that can be tested with `cargo test`
USERMODE_TESTABLE := \
runner \
framework/libs/align_ext \
framework/libs/ktest \
services/libs/cpio-decoder \
services/libs/int-to-c-enum \
services/libs/int-to-c-enum/derive \
services/libs/jinux-rights \
services/libs/jinux-rights-proc \
services/libs/keyable-arc \
services/libs/typeflags \
services/libs/typeflags-util
.PHONY: all setup build tools run test docs check clean
all: build
@ -97,7 +111,9 @@ run: build
@RUSTFLAGS="$(GLOBAL_RUSTC_FLAGS)" cargo krun $(CARGO_KRUN_ARGS)
test:
@python3 ./tools/test/run_tests.py
@for dir in $(USERMODE_TESTABLE); do \
(cd $$dir && cargo test) || exit 1; \
done
docs:
@cargo doc # Build Rust docs

View File

@ -1,52 +0,0 @@
#!/usr/bin/python3
# Use cargo metadata to get the manifest in json format.
def get_manifest():
import json
import subprocess
manifest = subprocess.check_output(
["cargo", "metadata", "--no-deps", "--format-version", "1"]
)
return json.loads(manifest)
# Run the user mode tests for the crates and exit if any test fails.
def run_usermode_tests(crates):
import os
import subprocess
for crate in crates:
print("Running tests for", crate)
result = subprocess.check_call(["cargo", "test", "--manifest-path", crate + "/Cargo.toml"])
if result != 0:
print("Test failed for", crate)
os.exit(result)
# The member id returned by the cargo metadata command is
# `<package name> <package name> (path+file:///<absolute path to member>)`.
# We need a relative path as we specify them in `Cargo.toml`.
def member_id_to_crate_rel_path(member_id):
import os
annotation = member_id.split(" ")[2]
abs_path = annotation \
.replace("(", "") \
.replace(")", "") \
.replace("path+file://", "")
return os.path.relpath(abs_path, os.getcwd())
def main():
import os
manifest = get_manifest()
usermode_testables = manifest["metadata"]["usermode_testable"]
ktest_testables = manifest["metadata"]["ktest_testable"]
untestables = manifest["metadata"]["untestable"]
# A sanity check to make sure we have registered all crates.
all_members = sorted([member_id_to_crate_rel_path(p["id"]) for p in manifest["packages"]])
test_members = sorted(usermode_testables + ktest_testables + untestables + ["."])
if (all_members != test_members):
print("Test members does not match all the workspace members in Cargo.toml. "
"Please setup the testablity of all the crates in Cargo.toml correctly.")
os._exit(1)
run_usermode_tests(usermode_testables)
if __name__ == "__main__":
main()