From d7e3d63c25186c8372c5355d8b7fda1b10fcf98b Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sun, 25 Aug 2024 18:57:17 +0700 Subject: [PATCH] Prepares to move test generation to run-time --- testing-macros/src/qemu.rs | 2 ++ testing/Cargo.toml | 1 + testing/src/qemu/mod.rs | 14 +++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/testing-macros/src/qemu.rs b/testing-macros/src/qemu.rs index f756329..0f294e5 100644 --- a/testing-macros/src/qemu.rs +++ b/testing-macros/src/qemu.rs @@ -36,6 +36,8 @@ pub fn parse_qemu_attribute(mut item: ItemFn) -> Result { 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)); })); diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 78a5077..23a07fb 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -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" diff --git a/testing/src/qemu/mod.rs b/testing/src/qemu/mod.rs index eb8d1cb..61bfd66 100644 --- a/testing/src/qemu/mod.rs +++ b/testing/src/qemu/mod.rs @@ -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, 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>(root: P) { let root = root.as_ref();