Skip to content

Commit d7e3d63

Browse files
committed
Prepares to move test generation to run-time
1 parent 108d149 commit d7e3d63

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

testing-macros/src/qemu.rs

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ pub fn parse_qemu_attribute(mut item: ItemFn) -> Result<TokenStream, Error> {
3636
let root = root.to_str().unwrap();
3737

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

testing/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ repository = "https://github.com/ultimicro/zfi"
77
edition = "2021"
88

99
[dependencies]
10+
blake3 = "1.5.4"
1011
fatfs = "0.3"
1112
gpt = "3.1"
1213
regex = "1.9"

testing/src/qemu/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@ use std::fs::{create_dir_all, File};
1111
use std::io::{BufRead, BufReader, Cursor};
1212
use std::ops::{Deref, DerefMut};
1313
use std::panic::panic_any;
14-
use std::path::Path;
14+
use std::path::{Path, PathBuf};
1515
use std::process::{Child, Command, Stdio};
1616
use std::sync::{Arc, Mutex};
1717

18+
/// Generate a Cargo project in `dest` with `name` as a project name and `body` as a body of
19+
/// `efi_main`.
20+
///
21+
/// The project will be created as a sub-directory of `dest`.
22+
pub fn gen_qemu_test(dest: impl AsRef<Path>, name: &str, body: &str) -> PathBuf {
23+
let root = dest
24+
.as_ref()
25+
.join(format!("{}-{}", name, blake3::hash(body.as_bytes())));
26+
27+
root
28+
}
29+
1830
/// Run the project that was generated by [`qemu`] attribute.
1931
pub fn run_qemu_test<P: AsRef<Path>>(root: P) {
2032
let root = root.as_ref();

0 commit comments

Comments
 (0)