Browse Source

feat(dadk-config): 在dadk manifest里面添加配置字段,并且增加测试用例 (#67)

* feat(dadk-config): 在dadk manifest里面添加配置字段,并且增加测试用例

增加了字段:
- rootfs_config
- hypervisor_config
- boot_config

自动测试: 增加对dadk manifest的模版的完整性校验

---------

Signed-off-by: longjin <longjin@DragonOS.org>
LoGin 5 months ago
parent
commit
e2cc487b9b

+ 1 - 1
crates/test_base/Cargo.toml

@@ -6,6 +6,6 @@ license = "GPL-2.0-only"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
+env_logger = "0.11.5"
 log = "0.4.21"
-simple_logger = "4.3.3"
 test-context = "0.3.0"

+ 69 - 0
crates/test_base/src/dadk_config.rs

@@ -0,0 +1,69 @@
+use std::path::PathBuf;
+
+use test_context::TestContext;
+
+#[derive(Debug, Clone)]
+pub struct DadkConfigTestContext {
+    /// 项目的根目录
+    test_base_path: PathBuf,
+}
+
+impl DadkConfigTestContext {
+    /// 获取项目的根目录
+    pub fn test_base_path(&self) -> &PathBuf {
+        &self.test_base_path
+    }
+
+    /// 获取项目目录下的文件的的绝对路径
+    pub fn abs_path(&self, relative_path: &str) -> PathBuf {
+        self.test_base_path.join(relative_path)
+    }
+}
+
+impl TestContext for DadkConfigTestContext {
+    fn setup() -> Self {
+        env_logger::try_init_from_env(env_logger::Env::default().default_filter_or("info")).ok();
+
+        // 获取dadk-config包的根目录
+        let mut test_base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+        test_base_path.pop();
+        test_base_path.pop();
+        test_base_path.push("dadk-config");
+        log::debug!(
+            "DadkConfigTestContext setup: project_base_path={:?}",
+            test_base_path
+        );
+        // 设置workdir
+        std::env::set_current_dir(&test_base_path).expect("Failed to setup test base path");
+
+        let r = DadkConfigTestContext { test_base_path };
+
+        r
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::env;
+
+    #[test]
+    fn test_test_base_path() {
+        let test_context = DadkConfigTestContext::setup();
+        let expected_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
+            .parent()
+            .unwrap()
+            .parent()
+            .unwrap()
+            .join("dadk-config");
+        assert_eq!(test_context.test_base_path(), &expected_path);
+    }
+
+    #[test]
+    fn test_abs_path() {
+        let test_context = DadkConfigTestContext::setup();
+        let relative_path = "some_relative_path";
+        let expected_path = test_context.test_base_path().join(relative_path);
+        assert_eq!(test_context.abs_path(relative_path), expected_path);
+    }
+}

+ 129 - 0
crates/test_base/src/global.rs

@@ -0,0 +1,129 @@
+use std::path::PathBuf;
+
+use test_context::TestContext;
+
+#[derive(Debug, Clone)]
+pub struct BaseGlobalTestContext {
+    /// 项目的根目录
+    project_base_path: PathBuf,
+}
+
+impl BaseGlobalTestContext {
+    const CONFIG_V1_DIR: &'static str = "tests/data/dadk_config_v1";
+    const FAKE_DRAGONOS_SYSROOT: &'static str = "tests/data/fake_dragonos_sysroot";
+    const FAKE_DADK_CACHE_ROOT: &'static str = "tests/data/fake_dadk_cache_root";
+
+    /// 获取项目的根目录
+    pub fn project_base_path(&self) -> &PathBuf {
+        &self.project_base_path
+    }
+
+    /// 获取项目目录下的文件的的绝对路径
+    pub fn abs_path(&self, relative_path: &str) -> PathBuf {
+        self.project_base_path.join(relative_path)
+    }
+
+    /// 获取`xxx.dadk`配置文件的目录
+    pub fn config_v1_dir(&self) -> PathBuf {
+        self.abs_path(Self::CONFIG_V1_DIR)
+    }
+
+    fn ensure_fake_dragonos_dir_exist(&self) {
+        let fake_dragonos_dir = self.fake_dragonos_sysroot();
+        if !fake_dragonos_dir.exists() {
+            std::fs::create_dir_all(&fake_dragonos_dir).ok();
+        }
+    }
+
+    fn ensure_fake_dadk_cache_root_exist(&self) {
+        std::env::set_var(
+            "DADK_CACHE_ROOT",
+            self.fake_dadk_cache_root().to_str().unwrap(),
+        );
+        let fake_dadk_cache_root = self.fake_dadk_cache_root();
+        if !fake_dadk_cache_root.exists() {
+            std::fs::create_dir_all(&fake_dadk_cache_root).ok();
+        }
+    }
+
+    pub fn fake_dadk_cache_root(&self) -> PathBuf {
+        self.abs_path(Self::FAKE_DADK_CACHE_ROOT)
+    }
+
+    /// 获取假的DragonOS sysroot目录
+    pub fn fake_dragonos_sysroot(&self) -> PathBuf {
+        self.abs_path(Self::FAKE_DRAGONOS_SYSROOT)
+    }
+}
+
+impl TestContext for BaseGlobalTestContext {
+    fn setup() -> Self {
+        env_logger::try_init_from_env(env_logger::Env::default().default_filter_or("info")).ok();
+
+        // 获取DADK项目的根目录
+        let mut project_base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+        project_base_path.pop();
+        project_base_path.pop();
+        // 设置workdir
+        std::env::set_current_dir(&project_base_path).expect("Failed to setup project_base_path");
+
+        let r = BaseGlobalTestContext { project_base_path };
+        r.ensure_fake_dragonos_dir_exist();
+        r.ensure_fake_dadk_cache_root_exist();
+        r
+    }
+}
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::env;
+
+    #[test]
+    fn test_project_base_path() {
+        let context = BaseGlobalTestContext::setup();
+        let binding = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+        let expected_path = binding.parent().unwrap().parent().unwrap();
+        assert_eq!(context.project_base_path(), &expected_path);
+    }
+
+    #[test]
+    fn test_abs_path() {
+        let context = BaseGlobalTestContext::setup();
+        let relative_path = "some/relative/path";
+        let expected_path = context.project_base_path().join(relative_path);
+        assert_eq!(context.abs_path(relative_path), expected_path);
+    }
+
+    #[test]
+    fn test_config_v1_dir() {
+        let context = BaseGlobalTestContext::setup();
+        let expected_path = context.abs_path(BaseGlobalTestContext::CONFIG_V1_DIR);
+        assert_eq!(context.config_v1_dir(), expected_path);
+    }
+
+    #[test]
+    fn test_fake_dadk_cache_root() {
+        let context = BaseGlobalTestContext::setup();
+        let expected_path = context.abs_path(BaseGlobalTestContext::FAKE_DADK_CACHE_ROOT);
+        assert_eq!(context.fake_dadk_cache_root(), expected_path);
+        assert!(expected_path.exists());
+    }
+
+    #[test]
+    fn test_fake_dragonos_sysroot() {
+        let context = BaseGlobalTestContext::setup();
+        let expected_path = context.abs_path(BaseGlobalTestContext::FAKE_DRAGONOS_SYSROOT);
+        assert_eq!(context.fake_dragonos_sysroot(), expected_path);
+        assert!(expected_path.exists());
+    }
+
+    #[test]
+    fn test_setup() {
+        let context = BaseGlobalTestContext::setup();
+        assert!(context.project_base_path().is_dir());
+        assert_eq!(
+            env::var("DADK_CACHE_ROOT").unwrap(),
+            context.fake_dadk_cache_root().to_str().unwrap()
+        );
+    }
+}

+ 2 - 77
crates/test_base/src/lib.rs

@@ -1,79 +1,4 @@
 pub extern crate test_context;
 
-use std::path::PathBuf;
-
-use simple_logger::SimpleLogger;
-use test_context::TestContext;
-
-#[derive(Debug, Clone)]
-pub struct BaseTestContext {
-    /// 项目的根目录
-    project_base_path: PathBuf,
-}
-
-impl BaseTestContext {
-    const CONFIG_V1_DIR: &'static str = "tests/data/dadk_config_v1";
-    const FAKE_DRAGONOS_SYSROOT: &'static str = "tests/data/fake_dragonos_sysroot";
-    const FAKE_DADK_CACHE_ROOT: &'static str = "tests/data/fake_dadk_cache_root";
-
-    /// 获取项目的根目录
-    pub fn project_base_path(&self) -> &PathBuf {
-        &self.project_base_path
-    }
-
-    /// 获取项目目录下的文件的的绝对路径
-    pub fn abs_path(&self, relative_path: &str) -> PathBuf {
-        self.project_base_path.join(relative_path)
-    }
-
-    /// 获取`xxx.dadk`配置文件的目录
-    pub fn config_v1_dir(&self) -> PathBuf {
-        self.abs_path(Self::CONFIG_V1_DIR)
-    }
-
-    fn ensure_fake_dragonos_dir_exist(&self) {
-        let fake_dragonos_dir = self.fake_dragonos_sysroot();
-        if !fake_dragonos_dir.exists() {
-            std::fs::create_dir_all(&fake_dragonos_dir).ok();
-        }
-    }
-
-    fn ensure_fake_dadk_cache_root_exist(&self) {
-        std::env::set_var(
-            "DADK_CACHE_ROOT",
-            self.fake_dadk_cache_root().to_str().unwrap(),
-        );
-        let fake_dadk_cache_root = self.fake_dadk_cache_root();
-        if !fake_dadk_cache_root.exists() {
-            std::fs::create_dir_all(&fake_dadk_cache_root).ok();
-        }
-    }
-
-    pub fn fake_dadk_cache_root(&self) -> PathBuf {
-        self.abs_path(Self::FAKE_DADK_CACHE_ROOT)
-    }
-
-    /// 获取假的DragonOS sysroot目录
-    pub fn fake_dragonos_sysroot(&self) -> PathBuf {
-        self.abs_path(Self::FAKE_DRAGONOS_SYSROOT)
-    }
-}
-
-impl TestContext for BaseTestContext {
-    fn setup() -> Self {
-        let logger = SimpleLogger::new().with_level(log::LevelFilter::Debug);
-
-        logger.init().ok();
-        // 获取DADK项目的根目录
-        let mut project_base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
-        project_base_path.pop();
-        project_base_path.pop();
-        // 设置workdir
-        std::env::set_current_dir(&project_base_path).ok();
-
-        let r = BaseTestContext { project_base_path };
-        r.ensure_fake_dragonos_dir_exist();
-        r.ensure_fake_dadk_cache_root_exist();
-        r
-    }
-}
+pub mod dadk_config;
+pub mod global;

+ 2 - 0
dadk-config/Cargo.toml

@@ -10,6 +10,7 @@ authors = [
 
 [dependencies]
 anyhow = { version = "1.0.90", features = ["std", "backtrace"] }
+cfg-if = "1.0.0"
 serde = { version = "1.0.160", features = ["serde_derive"] }
 serde_json = "1.0.96"
 toml = "0.8.12"
@@ -17,3 +18,4 @@ toml = "0.8.12"
 # 只有在test的情况下才会引入下列库
 [dev-dependencies]
 tempfile = "3.13.0"
+test_base = { path = "../crates/test_base" }

+ 8 - 13
dadk-config/src/common/target_arch.rs

@@ -1,8 +1,9 @@
 use serde::{Deserialize, Deserializer, Serialize};
 
 /// 目标处理器架构
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
 pub enum TargetArch {
+    #[default]
     X86_64,
     RiscV64,
 }
@@ -12,12 +13,6 @@ impl TargetArch {
     pub const EXPECTED: [&'static str; 2] = ["x86_64", "riscv64"];
 }
 
-impl Default for TargetArch {
-    fn default() -> Self {
-        TargetArch::X86_64
-    }
-}
-
 impl TryFrom<&str> for TargetArch {
     type Error = String;
 
@@ -30,18 +25,18 @@ impl TryFrom<&str> for TargetArch {
     }
 }
 
-impl Into<&str> for TargetArch {
-    fn into(self) -> &'static str {
-        match self {
+impl From<TargetArch> for &str {
+    fn from(val: TargetArch) -> Self {
+        match val {
             TargetArch::X86_64 => "x86_64",
             TargetArch::RiscV64 => "riscv64",
         }
     }
 }
 
-impl Into<String> for TargetArch {
-    fn into(self) -> String {
-        let x: &str = self.into();
+impl From<TargetArch> for String {
+    fn from(val: TargetArch) -> Self {
+        let x: &str = val.into();
         x.to_string()
     }
 }

+ 72 - 0
dadk-config/src/hypervisor/hyp_type.rs

@@ -0,0 +1,72 @@
+use serde::Deserialize;
+
+/// Supported hypervisor types
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum HypervisorType {
+    Qemu,
+    CloudHypervisor,
+}
+
+impl<'de> Deserialize<'de> for HypervisorType {
+    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+    where
+        D: serde::Deserializer<'de>,
+    {
+        let s = String::deserialize(deserializer)?;
+        match s.to_ascii_lowercase().as_str() {
+            "qemu" => Ok(HypervisorType::Qemu),
+            "cloud-hypervisor" => Ok(HypervisorType::CloudHypervisor),
+            _ => Err(serde::de::Error::custom(format!(
+                "Unknown hypervisor type: {}",
+                s
+            ))),
+        }
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use serde_json::{self};
+
+    #[test]
+    fn test_deserialize_qemu() {
+        let json = r#""qemu""#;
+        let hypervisor_type: HypervisorType = serde_json::from_str(json).unwrap();
+        assert_eq!(hypervisor_type, HypervisorType::Qemu);
+    }
+
+    #[test]
+    fn test_deserialize_cloud_hypervisor() {
+        let json = r#""cloud-hypervisor""#;
+        let hypervisor_type: HypervisorType = serde_json::from_str(json).unwrap();
+        assert_eq!(hypervisor_type, HypervisorType::CloudHypervisor);
+    }
+
+    #[test]
+    fn test_deserialize_invalid_type() {
+        let json = r#""invalid-type""#;
+        let result: Result<HypervisorType, _> = serde_json::from_str(json);
+        assert!(result.is_err());
+        let e = result.unwrap_err();
+        assert!(e
+            .to_string()
+            .contains("Unknown hypervisor type: invalid-type"));
+    }
+
+    #[test]
+    fn test_deserialize_case_insensitivity() {
+        let json = r#""QeMu""#;
+        let hypervisor_type: HypervisorType = serde_json::from_str(json).unwrap();
+        assert_eq!(hypervisor_type, HypervisorType::Qemu);
+    }
+
+    #[test]
+    fn test_deserialize_empty_string() {
+        let json = r#""""#;
+        let result: Result<HypervisorType, _> = serde_json::from_str(json);
+        assert!(result.is_err());
+        let e = result.unwrap_err();
+        assert!(e.to_string().contains("Unknown hypervisor type: "));
+    }
+}

+ 1 - 0
dadk-config/src/hypervisor/mod.rs

@@ -0,0 +1 @@
+pub mod hyp_type;

+ 4 - 1
dadk-config/src/lib.rs

@@ -1,5 +1,8 @@
-mod common;
+#[deny(clippy::all)]
+pub mod common;
+pub mod hypervisor;
 pub mod manifest;
+pub mod rootfs;
 pub mod user;
 
 extern crate anyhow;

+ 113 - 9
dadk-config/src/manifest.rs

@@ -8,15 +8,15 @@ use crate::common::target_arch::TargetArch;
 use std::fs;
 use toml;
 
-#[derive(Debug, Clone, Deserialize)]
-pub struct Metadata {
-    /// Target processor architecture
-    pub arch: TargetArch,
-}
-
+/// The main configuration file for DADK
 #[derive(Debug, Clone, Deserialize)]
 pub struct DadkManifest {
     pub metadata: Metadata,
+
+    /// A flag variable used to indicate whether
+    /// the default value function was called during deserialization.
+    #[serde(skip)]
+    pub used_default: bool,
 }
 
 impl DadkManifest {
@@ -27,24 +27,83 @@ impl DadkManifest {
     }
 
     fn do_load(content: &str) -> Result<Self> {
-        // 解析TOML内容
-        let manifest_toml: DadkManifest = toml::from_str(&content)?;
+        // Parse TOML content
+        let mut manifest_toml: DadkManifest = toml::from_str(content)?;
+
+        manifest_toml.used_default = check_used_default();
 
         Ok(manifest_toml)
     }
 }
 
+thread_local! {
+    /// Global variable to track if default values were used during deserialization.
+    static USED_DEFAULT: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
+}
+
+/// Call this function to set a flag when
+/// default values are used during DADK manifest parsing
+fn set_used_default() {
+    USED_DEFAULT.with(|used_default| {
+        used_default.set(true);
+    });
+}
+
+/// Check if default values were used during deserialization.
+fn check_used_default() -> bool {
+    USED_DEFAULT.with(|used_default| used_default.get())
+}
+
+#[derive(Debug, Clone, Deserialize)]
+pub struct Metadata {
+    /// Target processor architecture
+    pub arch: TargetArch,
+    /// Rootfs configuration file path
+    #[serde(default = "default_rootfs_config_path")]
+    pub rootfs_config: PathBuf,
+
+    /// Hypervisor configuration file path
+    #[serde(default = "default_hypervisor_config_path")]
+    pub hypervisor_config: PathBuf,
+
+    /// Boot configuration file path
+    #[serde(default = "default_boot_config_path")]
+    pub boot_config: PathBuf,
+}
+
+/// Returns the default path for the rootfs configuration file.
+fn default_rootfs_config_path() -> PathBuf {
+    set_used_default();
+    "config/rootfs.toml".into()
+}
+
+/// Returns the default path for the hypervisor configuration file.
+fn default_hypervisor_config_path() -> PathBuf {
+    set_used_default();
+    "config/hypervisor.toml".into()
+}
+
+/// Returns the default path for the boot configuration file.
+fn default_boot_config_path() -> PathBuf {
+    set_used_default();
+    "config/boot.toml".into()
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
     use std::io::Write;
     use tempfile::NamedTempFile;
 
+    /// Test loading a complete configuration file
     #[test]
-    fn test_load_success() -> Result<()> {
+    fn test_full_load_success() -> Result<()> {
         let toml_content = r#"
             [metadata]
             arch = "x86_64"
+            rootfs_config = "config/rootfs-x86_64.toml"
+            hypervisor_config = "config/hypervisor-x86_64.toml"
+            boot_config = "config/boot-x86_64.toml"
         "#;
 
         let mut temp_file = NamedTempFile::new()?;
@@ -54,10 +113,24 @@ mod tests {
         let manifest = DadkManifest::load(&path)?;
 
         assert_eq!(manifest.metadata.arch, TargetArch::X86_64);
+        assert_eq!(
+            manifest.metadata.rootfs_config,
+            PathBuf::from("config/rootfs-x86_64.toml")
+        );
+        assert_eq!(
+            manifest.metadata.hypervisor_config,
+            PathBuf::from("config/hypervisor-x86_64.toml")
+        );
+        assert_eq!(
+            manifest.metadata.boot_config,
+            PathBuf::from("config/boot-x86_64.toml")
+        );
+        assert!(!manifest.used_default);
 
         Ok(())
     }
 
+    /// Test whether an error is reported when the file does not exist.
     #[test]
     fn test_load_file_not_found() {
         let path = PathBuf::from("non_existent_file.toml");
@@ -66,6 +139,7 @@ mod tests {
         assert!(result.is_err());
     }
 
+    /// Test whether an error is reported when the TOML content is invalid
     #[test]
     fn test_load_invalid_toml() -> Result<()> {
         let invalid_toml_content = r#"
@@ -84,6 +158,7 @@ mod tests {
         Ok(())
     }
 
+    /// Test whether an error is reported when the arch field is invalid
     #[test]
     fn test_load_invalid_arch_toml() -> Result<()> {
         // Invalid arch value
@@ -103,6 +178,7 @@ mod tests {
         Ok(())
     }
 
+    /// Test whether an error is reported when a required field is missing
     #[test]
     fn test_load_missing_required_fields() -> Result<()> {
         let toml_content = r#"
@@ -120,4 +196,32 @@ mod tests {
 
         Ok(())
     }
+
+    /// Test whether default values are used
+    /// when the rootfs_config and other configuration file path fields are not set
+    #[test]
+    fn test_load_default_config_path_value() -> Result<()> {
+        let toml_content = r#"
+            [metadata]
+            arch = "x86_64"
+        "#;
+        let mut temp_file = NamedTempFile::new()?;
+        temp_file.write_all(toml_content.as_bytes())?;
+        let path = temp_file.path().to_path_buf();
+        let manifest = DadkManifest::load(&path)?;
+        assert_eq!(manifest.used_default, true);
+        assert_eq!(
+            manifest.metadata.rootfs_config,
+            PathBuf::from("config/rootfs.toml")
+        );
+        assert_eq!(
+            manifest.metadata.hypervisor_config,
+            PathBuf::from("config/hypervisor.toml")
+        );
+        assert_eq!(
+            manifest.metadata.boot_config,
+            PathBuf::from("config/boot.toml")
+        );
+        Ok(())
+    }
 }

+ 1 - 0
dadk-config/src/rootfs/mod.rs

@@ -0,0 +1 @@
+

+ 10 - 1
dadk-config/templates/dadk-manifest.toml

@@ -3,4 +3,13 @@
 
 [metadata]
 # Target architecture. Options: x86_64, riscv64
-target_arch = "x86_64"
+arch = "x86_64"
+
+# Hypervisor config path
+hypervisor_config = "config/hypervisor.toml"
+
+# RootFS config path
+rootfs_config = "config/rootfs.toml"
+
+# Boot config path
+boot_config = "config/boot.toml"

+ 19 - 0
dadk-config/tests/test_dadk_manifest.rs

@@ -0,0 +1,19 @@
+use dadk_config::{self, manifest::DadkManifest};
+use test_base::{
+    dadk_config::DadkConfigTestContext,
+    test_context::{self as test_context, test_context},
+};
+
+const TEMPLATES_DIR: &str = "templates";
+const DADK_MANIFEST_FILE_NAME: &str = "dadk-manifest.toml";
+
+/// 测试加载模板目录中的 dadk-manifest.toml 文件,验证它能被加载成功,并且已经包含了所有字段
+#[test_context(DadkConfigTestContext)]
+#[test]
+fn test_load_dadk_manifest_template(ctx: &DadkConfigTestContext) {
+    let manifest_path = ctx.abs_path(&format!("{TEMPLATES_DIR}/{DADK_MANIFEST_FILE_NAME}"));
+    assert_eq!(manifest_path.exists(), true);
+    assert_eq!(manifest_path.is_file(), true);
+    let manifest = DadkManifest::load(&manifest_path).expect("Failed to load manifest");
+    assert_eq!(manifest.used_default, false);
+}

+ 7 - 7
dadk-user/src/context.rs

@@ -7,7 +7,7 @@ use std::{
 use derive_builder::Builder;
 use log::error;
 #[cfg(test)]
-use test_base::{test_context::TestContext, BaseTestContext};
+use test_base::{global::BaseGlobalTestContext, test_context::TestContext};
 
 use crate::{
     console::Action, executor::cache::cache_root_init, parser::task::TargetArch,
@@ -33,7 +33,7 @@ pub struct DadkUserExecuteContext {
     target_arch: TargetArch,
 
     #[cfg(test)]
-    base_test_context: Option<BaseTestContext>,
+    base_test_context: Option<BaseGlobalTestContext>,
 
     #[builder(setter(skip), default = "Mutex::new(Weak::new())")]
     self_ref: Mutex<Weak<Self>>,
@@ -105,7 +105,7 @@ impl DadkUserExecuteContext {
 
 #[cfg(test)]
 pub trait TestContextExt: TestContext {
-    fn base_context(&self) -> &BaseTestContext;
+    fn base_context(&self) -> &BaseGlobalTestContext;
 
     fn execute_context(&self) -> &DadkUserExecuteContext;
 }
@@ -113,7 +113,7 @@ pub trait TestContextExt: TestContext {
 impl DadkUserExecuteContextBuilder {
     /// 用于测试的默认构建器
     #[cfg(test)]
-    fn default_test_execute_context_builder(base_context: &BaseTestContext) -> Self {
+    fn default_test_execute_context_builder(base_context: &BaseGlobalTestContext) -> Self {
         Self::default()
             .sysroot_dir(Some(base_context.fake_dragonos_sysroot()))
             .action(Action::Build)
@@ -132,7 +132,7 @@ pub struct DadkExecuteContextTestBuildX86_64V1 {
 #[cfg(test)]
 impl TestContext for DadkExecuteContextTestBuildX86_64V1 {
     fn setup() -> Self {
-        let base_context = BaseTestContext::setup();
+        let base_context = BaseGlobalTestContext::setup();
         let context =
             DadkUserExecuteContextBuilder::default_test_execute_context_builder(&base_context)
                 .target_arch(TargetArch::X86_64)
@@ -153,7 +153,7 @@ pub struct DadkExecuteContextTestBuildRiscV64V1 {
 #[cfg(test)]
 impl TestContext for DadkExecuteContextTestBuildRiscV64V1 {
     fn setup() -> Self {
-        let base_context = BaseTestContext::setup();
+        let base_context = BaseGlobalTestContext::setup();
         let context =
             DadkUserExecuteContextBuilder::default_test_execute_context_builder(&base_context)
                 .target_arch(TargetArch::RiscV64)
@@ -179,7 +179,7 @@ macro_rules! impl_for_test_context {
 
         #[cfg(test)]
         impl TestContextExt for $context {
-            fn base_context(&self) -> &BaseTestContext {
+            fn base_context(&self) -> &BaseGlobalTestContext {
                 self.base_test_context.as_ref().unwrap()
             }
 

+ 9 - 9
dadk-user/src/parser/tests.rs

@@ -1,6 +1,6 @@
 use test_base::{
+    global::BaseGlobalTestContext,
     test_context::{self as test_context, test_context},
-    BaseTestContext,
 };
 use tests::task::{BuildConfig, TargetArch, TaskType};
 
@@ -8,9 +8,9 @@ use crate::executor::source::LocalSource;
 
 use super::*;
 
-#[test_context(BaseTestContext)]
+#[test_context(BaseGlobalTestContext)]
 #[test]
-fn parse_normal_v1(ctx: &mut BaseTestContext) {
+fn parse_normal_v1(ctx: &mut BaseGlobalTestContext) {
     let parser = Parser::new(ctx.config_v1_dir());
     let config_file = ctx.config_v1_dir().join("app_normal_0_1_0.dadk");
     let result = parser.parse_config_file(&config_file);
@@ -48,9 +48,9 @@ fn parse_normal_v1(ctx: &mut BaseTestContext) {
     assert_eq!(result.install_once, false);
 }
 
-#[test_context(BaseTestContext)]
+#[test_context(BaseGlobalTestContext)]
 #[test]
-fn target_arch_field_has_one_v1(ctx: &mut BaseTestContext) {
+fn target_arch_field_has_one_v1(ctx: &mut BaseGlobalTestContext) {
     let parser = Parser::new(ctx.config_v1_dir());
     let config_file = ctx
         .config_v1_dir()
@@ -68,9 +68,9 @@ fn target_arch_field_has_one_v1(ctx: &mut BaseTestContext) {
     assert_eq!(result.target_arch[0], TargetArch::X86_64);
 }
 
-#[test_context(BaseTestContext)]
+#[test_context(BaseGlobalTestContext)]
 #[test]
-fn target_arch_field_has_one_uppercase_v1(ctx: &mut BaseTestContext) {
+fn target_arch_field_has_one_uppercase_v1(ctx: &mut BaseGlobalTestContext) {
     let parser = Parser::new(ctx.config_v1_dir());
     let config_file = ctx
         .config_v1_dir()
@@ -88,9 +88,9 @@ fn target_arch_field_has_one_uppercase_v1(ctx: &mut BaseTestContext) {
     assert_eq!(result.target_arch[0], TargetArch::X86_64);
 }
 
-#[test_context(BaseTestContext)]
+#[test_context(BaseGlobalTestContext)]
 #[test]
-fn target_arch_field_empty_should_failed_v1(ctx: &mut BaseTestContext) {
+fn target_arch_field_empty_should_failed_v1(ctx: &mut BaseGlobalTestContext) {
     let parser = Parser::new(ctx.config_v1_dir());
     let config_file = ctx
         .config_v1_dir()

+ 3 - 3
dadk-user/src/scheduler/tests.rs

@@ -1,6 +1,6 @@
 use test_base::{
+    global::BaseGlobalTestContext,
     test_context::{self as test_context, test_context},
-    BaseTestContext,
 };
 
 use crate::{
@@ -161,9 +161,9 @@ fn should_run_task_include_riscv64_on_riscv64(ctx: &DadkExecuteContextTestBuildR
 }
 
 /// 确保文件 app_all_target_arch_0_1_0.dadk 包含了所有的目标架构
-#[test_context(BaseTestContext)]
+#[test_context(BaseGlobalTestContext)]
 #[test]
-fn ensure_all_target_arch_testcase_v1(ctx: &BaseTestContext) {
+fn ensure_all_target_arch_testcase_v1(ctx: &BaseGlobalTestContext) {
     let config_file = ctx.config_v1_dir().join("app_all_target_arch_0_1_0.dadk");
     let task = Parser::new(ctx.config_v1_dir()).parse_config_file(&config_file);
     assert!(task.is_ok(), "parse error: {:?}", task);