Skip to content

Commit

Permalink
Prepares to move test generation to run-time
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Aug 25, 2024
1 parent 108d149 commit d7e3d63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions testing-macros/src/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub fn parse_qemu_attribute(mut item: ItemFn) -> Result<TokenStream, Error> {
let root = root.to_str().unwrap();

item.block = Box::new(parse_quote!({
let dest = std::path::PathBuf::from(env!("CARGO_TARGET_TMPDIR"));
::zfi_testing::gen_qemu_test(dest, #name, #body);
::zfi_testing::run_qemu_test(::std::path::Path::new(#root));
}));

Expand Down
1 change: 1 addition & 0 deletions testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository = "https://github.com/ultimicro/zfi"
edition = "2021"

[dependencies]
blake3 = "1.5.4"
fatfs = "0.3"
gpt = "3.1"
regex = "1.9"
Expand Down
14 changes: 13 additions & 1 deletion testing/src/qemu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ use std::fs::{create_dir_all, File};
use std::io::{BufRead, BufReader, Cursor};
use std::ops::{Deref, DerefMut};
use std::panic::panic_any;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::process::{Child, Command, Stdio};
use std::sync::{Arc, Mutex};

/// Generate a Cargo project in `dest` with `name` as a project name and `body` as a body of
/// `efi_main`.
///
/// The project will be created as a sub-directory of `dest`.
pub fn gen_qemu_test(dest: impl AsRef<Path>, name: &str, body: &str) -> PathBuf {
let root = dest
.as_ref()
.join(format!("{}-{}", name, blake3::hash(body.as_bytes())));

root
}

/// Run the project that was generated by [`qemu`] attribute.
pub fn run_qemu_test<P: AsRef<Path>>(root: P) {
let root = root.as_ref();
Expand Down

0 comments on commit d7e3d63

Please sign in to comment.