Check non-OSDK crates with cfg(test) and without cfg(test)
This commit is contained in:
parent
dcdfb897cc
commit
d33535f43c
8
Makefile
8
Makefile
|
|
@ -274,7 +274,9 @@ $(CARGO_OSDK): $(OSDK_SRC_FILES)
|
|||
|
||||
.PHONY: check_osdk
|
||||
check_osdk:
|
||||
@cd osdk && cargo clippy -- -D warnings
|
||||
@# Run clippy on OSDK with and without the test configuration.
|
||||
@cd osdk && cargo clippy --no-deps -- -D warnings
|
||||
@cd osdk && cargo clippy --tests --no-deps -- -D warnings
|
||||
|
||||
.PHONY: test_osdk
|
||||
test_osdk:
|
||||
|
|
@ -453,7 +455,9 @@ check: initramfs $(CARGO_OSDK)
|
|||
@# Check compilation of the Rust code
|
||||
@for dir in $(NON_OSDK_CRATES); do \
|
||||
echo "Checking $$dir"; \
|
||||
# Run clippy on each crate with and without the test configuration. \
|
||||
(cd $$dir && cargo clippy --no-deps -- -D warnings) || exit 1; \
|
||||
(cd $$dir && cargo clippy --tests --no-deps -- -D warnings) || exit 1; \
|
||||
done
|
||||
@for dir in $(OSDK_CRATES); do \
|
||||
echo "Checking $$dir"; \
|
||||
|
|
@ -462,7 +466,7 @@ check: initramfs $(CARGO_OSDK)
|
|||
[ "$$dir" = "ostd/libs/linux-bzimage/setup" ] && [ "$(OSDK_TARGET_ARCH)" != "x86_64" ] && continue; \
|
||||
# Run clippy on each crate with and without the ktest configuration. \
|
||||
(cd $$dir && cargo osdk clippy -- --no-deps -- -D warnings) || exit 1; \
|
||||
(cd $$dir && cargo osdk clippy --ktest -- --no-deps -- -D warnings) || exit 1; \
|
||||
(cd $$dir && cargo osdk clippy --ktests -- --no-deps -- -D warnings) || exit 1; \
|
||||
done
|
||||
@
|
||||
@# Check formatting issues of the C code and Nix files (regression tests)
|
||||
|
|
|
|||
|
|
@ -6,56 +6,56 @@ use crate::util::*;
|
|||
|
||||
#[test]
|
||||
fn cli_help_message() {
|
||||
let output = cargo_osdk(&["-h"]).output().unwrap();
|
||||
let output = cargo_osdk(["-h"]).output().unwrap();
|
||||
assert_success(&output);
|
||||
assert_stdout_contains_msg(&output, "cargo osdk <COMMAND>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_new_help_message() {
|
||||
let output = cargo_osdk(&["new", "-h"]).output().unwrap();
|
||||
let output = cargo_osdk(["new", "-h"]).output().unwrap();
|
||||
assert_success(&output);
|
||||
assert_stdout_contains_msg(&output, "cargo osdk new [OPTIONS] <name>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_build_help_message() {
|
||||
let output = cargo_osdk(&["build", "-h"]).output().unwrap();
|
||||
let output = cargo_osdk(["build", "-h"]).output().unwrap();
|
||||
assert_success(&output);
|
||||
assert_stdout_contains_msg(&output, "cargo osdk build [OPTIONS]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_run_help_message() {
|
||||
let output = cargo_osdk(&["run", "-h"]).output().unwrap();
|
||||
let output = cargo_osdk(["run", "-h"]).output().unwrap();
|
||||
assert_success(&output);
|
||||
assert_stdout_contains_msg(&output, "cargo osdk run [OPTIONS]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_test_help_message() {
|
||||
let output = cargo_osdk(&["test", "-h"]).output().unwrap();
|
||||
let output = cargo_osdk(["test", "-h"]).output().unwrap();
|
||||
assert_success(&output);
|
||||
assert_stdout_contains_msg(&output, "cargo osdk test [OPTIONS] [TESTNAME]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_check_help_message() {
|
||||
let output = cargo_osdk(&["check", "-h"]).output().unwrap();
|
||||
let output = cargo_osdk(["check", "-h"]).output().unwrap();
|
||||
assert_success(&output);
|
||||
assert_stdout_contains_msg(&output, "cargo osdk check");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_clippy_help_message() {
|
||||
let output = cargo_osdk(&["clippy", "-h"]).output().unwrap();
|
||||
let output = cargo_osdk(["clippy", "-h"]).output().unwrap();
|
||||
assert_success(&output);
|
||||
assert_stdout_contains_msg(&output, "cargo osdk clippy");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_new_crate_with_hyphen() {
|
||||
let output = cargo_osdk(&["new", "--kernel", "my-first-os"])
|
||||
let output = cargo_osdk(["new", "--kernel", "my-first-os"])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_success(&output);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ mod workspace {
|
|||
}
|
||||
impl Drop for WorkSpace {
|
||||
fn drop(&mut self) {
|
||||
remove_dir_all(&self.os_dir()).unwrap();
|
||||
remove_dir_all(self.os_dir()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -64,7 +64,6 @@ mod workspace {
|
|||
mod coverage_feature {
|
||||
use super::*;
|
||||
use crate::util::{cargo_osdk, depends_on_coverage};
|
||||
use assert_cmd::Command;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
|
|
@ -78,7 +77,7 @@ mod coverage_feature {
|
|||
let osdk_path = Path::new(&workspace.os_dir()).join("OSDK.toml");
|
||||
depends_on_coverage(&manifest_path, &osdk_path);
|
||||
let mut instance = cargo_osdk(["run", "--coverage"]);
|
||||
instance.current_dir(&workspace.os_dir());
|
||||
instance.current_dir(workspace.os_dir());
|
||||
|
||||
let _output = instance
|
||||
.output()
|
||||
|
|
@ -111,7 +110,7 @@ mod qemu_gdb_feature {
|
|||
"--gdb-server",
|
||||
format!("addr={},wait-client", unix_socket.as_str()).as_str(),
|
||||
]);
|
||||
instance.current_dir(&workspace.os_dir());
|
||||
instance.current_dir(workspace.os_dir());
|
||||
|
||||
let sock = unix_socket.clone();
|
||||
let _gdb = std::thread::spawn(move || {
|
||||
|
|
@ -159,7 +158,7 @@ mod qemu_gdb_feature {
|
|||
"--gdb-server",
|
||||
format!("wait-client,vscode,addr={}", addr).as_str(),
|
||||
]);
|
||||
instance.current_dir(&workspace.os_dir());
|
||||
instance.current_dir(workspace.os_dir());
|
||||
|
||||
let dir = workspace.os_dir();
|
||||
let bin_file_path = Path::new(&workspace.os_dir())
|
||||
|
|
@ -175,7 +174,7 @@ mod qemu_gdb_feature {
|
|||
check_launch_file_existence(&dir),
|
||||
"VSCode launch config file is not found during debugging session"
|
||||
);
|
||||
gdb_continue_via(&addr);
|
||||
gdb_continue_via(addr);
|
||||
});
|
||||
|
||||
let output = instance
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ fn create_a_kernel_project() {
|
|||
fs::remove_dir_all(&kernel_path).unwrap();
|
||||
}
|
||||
|
||||
cargo_osdk(&["new", "--kernel", kernel])
|
||||
cargo_osdk(["new", "--kernel", kernel])
|
||||
.current_dir(workdir)
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ fn create_a_library_project() {
|
|||
fs::remove_dir_all(&module_path).unwrap();
|
||||
}
|
||||
|
||||
cargo_osdk(&["new", module]).current_dir(workdir).unwrap();
|
||||
cargo_osdk(["new", module]).current_dir(workdir).unwrap();
|
||||
|
||||
assert!(module_path.is_dir());
|
||||
assert!(module_path.join("Cargo.toml").is_file());
|
||||
|
|
|
|||
|
|
@ -15,18 +15,18 @@ fn create_and_run_kernel() {
|
|||
fs::remove_dir_all(&os_dir).unwrap();
|
||||
}
|
||||
|
||||
let mut command = cargo_osdk(&["new", "--kernel", os_name]);
|
||||
let mut command = cargo_osdk(["new", "--kernel", os_name]);
|
||||
command.current_dir(work_dir);
|
||||
command.ok().unwrap();
|
||||
|
||||
// Makes the kernel depend on local OSTD
|
||||
edit_config_files(&os_dir);
|
||||
|
||||
let mut command = cargo_osdk(&["build"]);
|
||||
let mut command = cargo_osdk(["build"]);
|
||||
command.current_dir(&os_dir);
|
||||
command.ok().unwrap();
|
||||
|
||||
let mut command = cargo_osdk(&["run"]);
|
||||
let mut command = cargo_osdk(["run"]);
|
||||
command.current_dir(&os_dir);
|
||||
let output = command.output().unwrap();
|
||||
|
||||
|
|
@ -47,13 +47,13 @@ fn create_and_test_library() {
|
|||
fs::remove_dir_all(&module_dir).unwrap();
|
||||
}
|
||||
|
||||
let mut command = cargo_osdk(&["new", module_name]);
|
||||
let mut command = cargo_osdk(["new", module_name]);
|
||||
command.current_dir(work_dir);
|
||||
command.ok().unwrap();
|
||||
|
||||
edit_config_files(&module_dir);
|
||||
|
||||
let mut command = cargo_osdk(&["test"]);
|
||||
let mut command = cargo_osdk(["test"]);
|
||||
command.current_dir(&module_dir);
|
||||
command.ok().unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ fn work_in_workspace() {
|
|||
// Create a kernel project and a library project
|
||||
let kernel = "myos";
|
||||
let module = "mylib";
|
||||
cargo_osdk(&["new", "--kernel", kernel])
|
||||
cargo_osdk(["new", "--kernel", kernel])
|
||||
.current_dir(&workspace_dir)
|
||||
.ok()
|
||||
.unwrap();
|
||||
cargo_osdk(&["new", module])
|
||||
cargo_osdk(["new", module])
|
||||
.current_dir(&workspace_dir)
|
||||
.ok()
|
||||
.unwrap();
|
||||
|
|
@ -85,11 +85,11 @@ fn work_in_workspace() {
|
|||
.unwrap();
|
||||
|
||||
// Run subcommand build & run
|
||||
cargo_osdk(&["build"])
|
||||
cargo_osdk(["build"])
|
||||
.current_dir(&workspace_dir)
|
||||
.ok()
|
||||
.unwrap();
|
||||
let output = cargo_osdk(&["run"])
|
||||
let output = cargo_osdk(["run"])
|
||||
.current_dir(&workspace_dir)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
|
@ -97,7 +97,7 @@ fn work_in_workspace() {
|
|||
assert!(stdout.contains("The available memory is"));
|
||||
|
||||
// Run subcommand test
|
||||
cargo_osdk(&["test"])
|
||||
cargo_osdk(["test"])
|
||||
.current_dir(&workspace_dir)
|
||||
.ok()
|
||||
.unwrap();
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ fn write_a_kernel_in_100_lines() {
|
|||
}
|
||||
|
||||
// Creates a new kernel project
|
||||
cargo_osdk(&["new", "--kernel", os_name])
|
||||
.current_dir(&workdir)
|
||||
cargo_osdk(["new", "--kernel", os_name])
|
||||
.current_dir(workdir)
|
||||
.ok()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ fn write_a_kernel_in_100_lines() {
|
|||
let user_program_contents = include_str!("write_a_kernel_in_100_lines_templates/hello.S");
|
||||
fs::write(os_dir.join("hello.S"), user_program_contents).unwrap();
|
||||
Command::new("gcc")
|
||||
.args(&["-static", "-nostdlib", "hello.S", "-o", "hello"])
|
||||
.args(["-static", "-nostdlib", "hello.S", "-o", "hello"])
|
||||
.current_dir(&os_dir)
|
||||
.ok()
|
||||
.unwrap();
|
||||
|
|
@ -55,7 +55,7 @@ fn write_a_kernel_in_100_lines() {
|
|||
fs::write(os_dir.join("Cargo.toml"), new_file_content).unwrap();
|
||||
|
||||
// Runs the kernel
|
||||
let output = cargo_osdk(&["run"]).current_dir(&os_dir).ok().unwrap();
|
||||
let output = cargo_osdk(["run"]).current_dir(&os_dir).ok().unwrap();
|
||||
let stdout = std::str::from_utf8(&output.stdout).unwrap();
|
||||
println!("stdout = {}", stdout);
|
||||
|
||||
|
|
|
|||
|
|
@ -123,8 +123,7 @@ pub(crate) fn depends_on_local_ostd(manifest_path: impl AsRef<Path>) {
|
|||
let mut manifest: Table = toml::from_str(&manifest_content).unwrap();
|
||||
let dep = manifest
|
||||
.get_mut("dependencies")
|
||||
.map(Value::as_table_mut)
|
||||
.flatten()
|
||||
.and_then(Value::as_table_mut)
|
||||
.unwrap();
|
||||
|
||||
let mut table = Table::new();
|
||||
|
|
@ -145,11 +144,10 @@ pub(crate) fn depends_on_coverage(manifest_path: impl AsRef<Path>, osdk_path: im
|
|||
// Add features = ["coverage"] to ostd dependency
|
||||
let dep = manifest
|
||||
.get_mut("dependencies")
|
||||
.map(Value::as_table_mut)
|
||||
.flatten()
|
||||
.and_then(Value::as_table_mut)
|
||||
.unwrap();
|
||||
|
||||
if let Some(ostd_dep) = dep.get_mut("ostd").map(Value::as_table_mut).flatten() {
|
||||
if let Some(ostd_dep) = dep.get_mut("ostd").and_then(Value::as_table_mut) {
|
||||
let features = vec![Value::String("coverage".to_string())];
|
||||
ostd_dep.insert("features".to_string(), Value::Array(features));
|
||||
}
|
||||
|
|
@ -177,10 +175,7 @@ pub(crate) fn add_tdx_scheme(osdk_path: impl AsRef<Path>) -> std::io::Result<()>
|
|||
.parent()
|
||||
.unwrap()
|
||||
.join("scheme.tdx.template");
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.append(true)
|
||||
.open(osdk_path)?;
|
||||
let mut file = OpenOptions::new().append(true).open(osdk_path)?;
|
||||
let tdx_qemu_cfg = fs::read_to_string(template_path)?;
|
||||
file.write_all(format!("\n\n{}", tdx_qemu_cfg).as_bytes())?;
|
||||
Ok(())
|
||||
|
|
@ -195,7 +190,7 @@ fn conditionally_add_tdx_args<T: AsRef<OsStr>, I: IntoIterator<Item = T> + Copy>
|
|||
args: I,
|
||||
) {
|
||||
if is_tdx_enabled() && contains_build_run_or_test(args) {
|
||||
command.args(&["--scheme", "tdx"]);
|
||||
command.args(["--scheme", "tdx"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ mod tests {
|
|||
let params = Parameters::new(args).unwrap();
|
||||
assert_eq!(params.scml_paths, vec!["test.scml"]);
|
||||
assert_eq!(params.input_path(), "input.txt");
|
||||
assert_eq!(params.quiet(), false);
|
||||
assert!(!params.quiet());
|
||||
assert_eq!(params.program_path(), "");
|
||||
assert!(params.program_args().is_empty());
|
||||
assert!(params.offline());
|
||||
|
|
@ -181,7 +181,7 @@ mod tests {
|
|||
let params = Parameters::new(args).unwrap();
|
||||
assert_eq!(params.scml_paths, vec!["test.scml"]);
|
||||
assert_eq!(params.input_path(), "");
|
||||
assert_eq!(params.quiet(), false);
|
||||
assert!(!params.quiet());
|
||||
assert_eq!(params.program_path(), "my_program");
|
||||
assert_eq!(params.program_args(), &["arg1", "arg2"]);
|
||||
assert!(!params.offline());
|
||||
|
|
|
|||
Loading…
Reference in New Issue