1eaa67f3cSLoGin use dadk_config::common::target_arch::TargetArch;
273779f3dSLoGin use test_base::{
3e2cc487bSLoGin global::BaseGlobalTestContext,
473779f3dSLoGin test_context::{self as test_context, test_context},
573779f3dSLoGin };
673779f3dSLoGin
773779f3dSLoGin use crate::{
873779f3dSLoGin context::{
973779f3dSLoGin DadkExecuteContextTestBuildRiscV64V1, DadkExecuteContextTestBuildX86_64V1, TestContextExt,
1073779f3dSLoGin },
11eaa67f3cSLoGin parser::Parser,
1273779f3dSLoGin };
1373779f3dSLoGin
1473779f3dSLoGin use super::*;
1573779f3dSLoGin
1673779f3dSLoGin /// 不应在x86_64上运行仅限riscv64的任务
1773779f3dSLoGin #[test_context(DadkExecuteContextTestBuildX86_64V1)]
should_not_run_task_only_riscv64_on_x86_64(ctx: &DadkExecuteContextTestBuildX86_64V1)1873779f3dSLoGin #[test]
1973779f3dSLoGin fn should_not_run_task_only_riscv64_on_x86_64(ctx: &DadkExecuteContextTestBuildX86_64V1) {
2073779f3dSLoGin let config_file = ctx
2173779f3dSLoGin .base_context()
225129c63bSJomo .config_v2_dir()
235129c63bSJomo .join("app_target_arch_riscv64_only_0_2_0.toml");
24*d2ade6efSJomo let task = Parser::new(ctx.base_context().config_v2_dir()).parse_config_file(&config_file);
2573779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task);
2673779f3dSLoGin let task = task.unwrap();
2773779f3dSLoGin assert!(
2873779f3dSLoGin task.target_arch.len() == 1,
2973779f3dSLoGin "target_arch length error: {:?}",
3073779f3dSLoGin task
3173779f3dSLoGin );
3273779f3dSLoGin assert!(
3373779f3dSLoGin task.target_arch[0] == TargetArch::RiscV64,
3473779f3dSLoGin "target_arch should be riscv64: {:?}",
3573779f3dSLoGin task
3673779f3dSLoGin );
3773779f3dSLoGin
3873779f3dSLoGin let scheduler = Scheduler::new(
3973779f3dSLoGin ctx.execute_context().self_ref().unwrap(),
4073779f3dSLoGin ctx.base_context().fake_dragonos_sysroot(),
4173779f3dSLoGin *ctx.execute_context().action(),
4273779f3dSLoGin vec![],
4373779f3dSLoGin );
4473779f3dSLoGin
4573779f3dSLoGin assert!(scheduler.is_ok(), "Create scheduler error: {:?}", scheduler);
4673779f3dSLoGin
4773779f3dSLoGin let mut scheduler = scheduler.unwrap();
4873779f3dSLoGin
4973779f3dSLoGin let entity = scheduler.add_task(config_file, task);
5073779f3dSLoGin assert!(
5173779f3dSLoGin entity.is_err(),
5273779f3dSLoGin "Add task should return error: {:?}",
5373779f3dSLoGin entity
5473779f3dSLoGin );
5573779f3dSLoGin }
5673779f3dSLoGin
5773779f3dSLoGin /// 不应在riscv64上运行仅限x86_64的任务
5873779f3dSLoGin #[test_context(DadkExecuteContextTestBuildRiscV64V1)]
should_not_run_task_only_x86_64_on_riscv64(ctx: &DadkExecuteContextTestBuildRiscV64V1)5973779f3dSLoGin #[test]
6073779f3dSLoGin fn should_not_run_task_only_x86_64_on_riscv64(ctx: &DadkExecuteContextTestBuildRiscV64V1) {
6173779f3dSLoGin let config_file = ctx
6273779f3dSLoGin .base_context()
635129c63bSJomo .config_v2_dir()
645129c63bSJomo .join("app_target_arch_x86_64_only_0_2_0.toml");
65*d2ade6efSJomo let task = Parser::new(ctx.base_context().config_v2_dir()).parse_config_file(&config_file);
6673779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task);
6773779f3dSLoGin let task = task.unwrap();
6873779f3dSLoGin assert!(
6973779f3dSLoGin task.target_arch.len() == 1,
7073779f3dSLoGin "target_arch length error: {:?}",
7173779f3dSLoGin task
7273779f3dSLoGin );
7373779f3dSLoGin assert!(
7473779f3dSLoGin task.target_arch[0] == TargetArch::X86_64,
7573779f3dSLoGin "target_arch should be x86_64: {:?}",
7673779f3dSLoGin task
7773779f3dSLoGin );
7873779f3dSLoGin
7973779f3dSLoGin let scheduler = Scheduler::new(
8073779f3dSLoGin ctx.execute_context().self_ref().unwrap(),
8173779f3dSLoGin ctx.base_context().fake_dragonos_sysroot(),
8273779f3dSLoGin *ctx.execute_context().action(),
8373779f3dSLoGin vec![],
8473779f3dSLoGin );
8573779f3dSLoGin
8673779f3dSLoGin assert!(scheduler.is_ok(), "Create scheduler error: {:?}", scheduler);
8773779f3dSLoGin
8873779f3dSLoGin let mut scheduler = scheduler.unwrap();
8973779f3dSLoGin
9073779f3dSLoGin let entity = scheduler.add_task(config_file, task);
9173779f3dSLoGin assert!(
9273779f3dSLoGin entity.is_err(),
9373779f3dSLoGin "Add task should return error: {:?}",
9473779f3dSLoGin entity
9573779f3dSLoGin );
9673779f3dSLoGin }
9773779f3dSLoGin
9873779f3dSLoGin /// 应在x86_64上运行包含x86_64的任务
9973779f3dSLoGin #[test_context(DadkExecuteContextTestBuildX86_64V1)]
should_run_task_include_x86_64_on_x86_64(ctx: &DadkExecuteContextTestBuildX86_64V1)10073779f3dSLoGin #[test]
10173779f3dSLoGin fn should_run_task_include_x86_64_on_x86_64(ctx: &DadkExecuteContextTestBuildX86_64V1) {
10273779f3dSLoGin let config_file = ctx
10373779f3dSLoGin .base_context()
1045129c63bSJomo .config_v2_dir()
1055129c63bSJomo .join("app_all_target_arch_0_2_0.toml");
106*d2ade6efSJomo let task = Parser::new(ctx.base_context().config_v2_dir()).parse_config_file(&config_file);
10773779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task);
10873779f3dSLoGin let task = task.unwrap();
10973779f3dSLoGin
11073779f3dSLoGin assert!(
11173779f3dSLoGin task.target_arch.contains(&TargetArch::X86_64),
11273779f3dSLoGin "Cannot find target_arch x86_64: {:?}",
11373779f3dSLoGin task
11473779f3dSLoGin );
11573779f3dSLoGin
11673779f3dSLoGin let scheduler = Scheduler::new(
11773779f3dSLoGin ctx.execute_context().self_ref().unwrap(),
11873779f3dSLoGin ctx.base_context().fake_dragonos_sysroot(),
11973779f3dSLoGin *ctx.execute_context().action(),
12073779f3dSLoGin vec![],
12173779f3dSLoGin );
12273779f3dSLoGin
12373779f3dSLoGin assert!(scheduler.is_ok(), "Create scheduler error: {:?}", scheduler);
12473779f3dSLoGin
12573779f3dSLoGin let mut scheduler = scheduler.unwrap();
12673779f3dSLoGin
12773779f3dSLoGin let entity = scheduler.add_task(config_file, task);
12873779f3dSLoGin assert!(entity.is_ok(), "Add task should return ok: {:?}", entity);
12973779f3dSLoGin }
13073779f3dSLoGin
13173779f3dSLoGin /// 应在riscv64上运行包含riscv64的任务
13273779f3dSLoGin #[test_context(DadkExecuteContextTestBuildRiscV64V1)]
should_run_task_include_riscv64_on_riscv64(ctx: &DadkExecuteContextTestBuildRiscV64V1)13373779f3dSLoGin #[test]
13473779f3dSLoGin fn should_run_task_include_riscv64_on_riscv64(ctx: &DadkExecuteContextTestBuildRiscV64V1) {
13573779f3dSLoGin let config_file = ctx
13673779f3dSLoGin .base_context()
1375129c63bSJomo .config_v2_dir()
1385129c63bSJomo .join("app_all_target_arch_0_2_0.toml");
139*d2ade6efSJomo let task = Parser::new(ctx.base_context().config_v2_dir()).parse_config_file(&config_file);
14073779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task);
14173779f3dSLoGin let task = task.unwrap();
14273779f3dSLoGin
14373779f3dSLoGin assert!(
14473779f3dSLoGin task.target_arch.contains(&TargetArch::RiscV64),
14573779f3dSLoGin "Cannot find target_arch riscv64: {:?}",
14673779f3dSLoGin task
14773779f3dSLoGin );
14873779f3dSLoGin
14973779f3dSLoGin let scheduler = Scheduler::new(
15073779f3dSLoGin ctx.execute_context().self_ref().unwrap(),
15173779f3dSLoGin ctx.base_context().fake_dragonos_sysroot(),
15273779f3dSLoGin *ctx.execute_context().action(),
15373779f3dSLoGin vec![],
15473779f3dSLoGin );
15573779f3dSLoGin
15673779f3dSLoGin assert!(scheduler.is_ok(), "Create scheduler error: {:?}", scheduler);
15773779f3dSLoGin
15873779f3dSLoGin let mut scheduler = scheduler.unwrap();
15973779f3dSLoGin
16073779f3dSLoGin let entity = scheduler.add_task(config_file, task);
16173779f3dSLoGin assert!(entity.is_ok(), "Add task should return ok: {:?}", entity);
16273779f3dSLoGin }
16373779f3dSLoGin
1645129c63bSJomo /// 确保文件 app_all_target_arch_0_2_0.toml 包含了所有的目标架构
165e2cc487bSLoGin #[test_context(BaseGlobalTestContext)]
ensure_all_target_arch_testcase_v1(ctx: &BaseTestContext)16673779f3dSLoGin #[test]
167e2cc487bSLoGin fn ensure_all_target_arch_testcase_v1(ctx: &BaseGlobalTestContext) {
1685129c63bSJomo let config_file = ctx.config_v2_dir().join("app_all_target_arch_0_2_0.toml");
169*d2ade6efSJomo let task = Parser::new(ctx.config_v2_dir()).parse_config_file(&config_file);
17073779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task);
17173779f3dSLoGin let task = task.unwrap();
17273779f3dSLoGin
17373779f3dSLoGin for a in TargetArch::EXPECTED.iter() {
17473779f3dSLoGin let target_arch = TargetArch::try_from(*a).unwrap();
17573779f3dSLoGin assert!(
17673779f3dSLoGin task.target_arch.contains(&target_arch),
17773779f3dSLoGin "Cannot find target_arch '{:?}' in task: {:?}",
17873779f3dSLoGin a,
17973779f3dSLoGin task
18073779f3dSLoGin );
18173779f3dSLoGin }
18273779f3dSLoGin }
183