1*73779f3dSLoGin use test_base::{ 2*73779f3dSLoGin test_context::{self as test_context, test_context}, 3*73779f3dSLoGin BaseTestContext, 4*73779f3dSLoGin }; 5*73779f3dSLoGin 6*73779f3dSLoGin use crate::{ 7*73779f3dSLoGin context::{ 8*73779f3dSLoGin DadkExecuteContextTestBuildRiscV64V1, DadkExecuteContextTestBuildX86_64V1, TestContextExt, 9*73779f3dSLoGin }, 10*73779f3dSLoGin parser::{task::TargetArch, Parser}, 11*73779f3dSLoGin }; 12*73779f3dSLoGin 13*73779f3dSLoGin use super::*; 14*73779f3dSLoGin 15*73779f3dSLoGin /// 不应在x86_64上运行仅限riscv64的任务 16*73779f3dSLoGin #[test_context(DadkExecuteContextTestBuildX86_64V1)] 17*73779f3dSLoGin #[test] 18*73779f3dSLoGin fn should_not_run_task_only_riscv64_on_x86_64(ctx: &DadkExecuteContextTestBuildX86_64V1) { 19*73779f3dSLoGin let config_file = ctx 20*73779f3dSLoGin .base_context() 21*73779f3dSLoGin .config_v1_dir() 22*73779f3dSLoGin .join("app_target_arch_riscv64_only_0_1_0.dadk"); 23*73779f3dSLoGin let task = Parser::new(ctx.base_context().config_v1_dir()).parse_config_file(&config_file); 24*73779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task); 25*73779f3dSLoGin let task = task.unwrap(); 26*73779f3dSLoGin assert!( 27*73779f3dSLoGin task.target_arch.len() == 1, 28*73779f3dSLoGin "target_arch length error: {:?}", 29*73779f3dSLoGin task 30*73779f3dSLoGin ); 31*73779f3dSLoGin assert!( 32*73779f3dSLoGin task.target_arch[0] == TargetArch::RiscV64, 33*73779f3dSLoGin "target_arch should be riscv64: {:?}", 34*73779f3dSLoGin task 35*73779f3dSLoGin ); 36*73779f3dSLoGin 37*73779f3dSLoGin let scheduler = Scheduler::new( 38*73779f3dSLoGin ctx.execute_context().self_ref().unwrap(), 39*73779f3dSLoGin ctx.base_context().fake_dragonos_sysroot(), 40*73779f3dSLoGin *ctx.execute_context().action(), 41*73779f3dSLoGin vec![], 42*73779f3dSLoGin ); 43*73779f3dSLoGin 44*73779f3dSLoGin assert!(scheduler.is_ok(), "Create scheduler error: {:?}", scheduler); 45*73779f3dSLoGin 46*73779f3dSLoGin let mut scheduler = scheduler.unwrap(); 47*73779f3dSLoGin 48*73779f3dSLoGin let entity = scheduler.add_task(config_file, task); 49*73779f3dSLoGin assert!( 50*73779f3dSLoGin entity.is_err(), 51*73779f3dSLoGin "Add task should return error: {:?}", 52*73779f3dSLoGin entity 53*73779f3dSLoGin ); 54*73779f3dSLoGin } 55*73779f3dSLoGin 56*73779f3dSLoGin /// 不应在riscv64上运行仅限x86_64的任务 57*73779f3dSLoGin #[test_context(DadkExecuteContextTestBuildRiscV64V1)] 58*73779f3dSLoGin #[test] 59*73779f3dSLoGin fn should_not_run_task_only_x86_64_on_riscv64(ctx: &DadkExecuteContextTestBuildRiscV64V1) { 60*73779f3dSLoGin let config_file = ctx 61*73779f3dSLoGin .base_context() 62*73779f3dSLoGin .config_v1_dir() 63*73779f3dSLoGin .join("app_target_arch_x86_64_only_0_1_0.dadk"); 64*73779f3dSLoGin let task = Parser::new(ctx.base_context().config_v1_dir()).parse_config_file(&config_file); 65*73779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task); 66*73779f3dSLoGin let task = task.unwrap(); 67*73779f3dSLoGin assert!( 68*73779f3dSLoGin task.target_arch.len() == 1, 69*73779f3dSLoGin "target_arch length error: {:?}", 70*73779f3dSLoGin task 71*73779f3dSLoGin ); 72*73779f3dSLoGin assert!( 73*73779f3dSLoGin task.target_arch[0] == TargetArch::X86_64, 74*73779f3dSLoGin "target_arch should be x86_64: {:?}", 75*73779f3dSLoGin task 76*73779f3dSLoGin ); 77*73779f3dSLoGin 78*73779f3dSLoGin let scheduler = Scheduler::new( 79*73779f3dSLoGin ctx.execute_context().self_ref().unwrap(), 80*73779f3dSLoGin ctx.base_context().fake_dragonos_sysroot(), 81*73779f3dSLoGin *ctx.execute_context().action(), 82*73779f3dSLoGin vec![], 83*73779f3dSLoGin ); 84*73779f3dSLoGin 85*73779f3dSLoGin assert!(scheduler.is_ok(), "Create scheduler error: {:?}", scheduler); 86*73779f3dSLoGin 87*73779f3dSLoGin let mut scheduler = scheduler.unwrap(); 88*73779f3dSLoGin 89*73779f3dSLoGin let entity = scheduler.add_task(config_file, task); 90*73779f3dSLoGin assert!( 91*73779f3dSLoGin entity.is_err(), 92*73779f3dSLoGin "Add task should return error: {:?}", 93*73779f3dSLoGin entity 94*73779f3dSLoGin ); 95*73779f3dSLoGin } 96*73779f3dSLoGin 97*73779f3dSLoGin /// 应在x86_64上运行包含x86_64的任务 98*73779f3dSLoGin #[test_context(DadkExecuteContextTestBuildX86_64V1)] 99*73779f3dSLoGin #[test] 100*73779f3dSLoGin fn should_run_task_include_x86_64_on_x86_64(ctx: &DadkExecuteContextTestBuildX86_64V1) { 101*73779f3dSLoGin let config_file = ctx 102*73779f3dSLoGin .base_context() 103*73779f3dSLoGin .config_v1_dir() 104*73779f3dSLoGin .join("app_all_target_arch_0_1_0.dadk"); 105*73779f3dSLoGin let task = Parser::new(ctx.base_context().config_v1_dir()).parse_config_file(&config_file); 106*73779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task); 107*73779f3dSLoGin let task = task.unwrap(); 108*73779f3dSLoGin 109*73779f3dSLoGin assert!( 110*73779f3dSLoGin task.target_arch.contains(&TargetArch::X86_64), 111*73779f3dSLoGin "Cannot find target_arch x86_64: {:?}", 112*73779f3dSLoGin task 113*73779f3dSLoGin ); 114*73779f3dSLoGin 115*73779f3dSLoGin let scheduler = Scheduler::new( 116*73779f3dSLoGin ctx.execute_context().self_ref().unwrap(), 117*73779f3dSLoGin ctx.base_context().fake_dragonos_sysroot(), 118*73779f3dSLoGin *ctx.execute_context().action(), 119*73779f3dSLoGin vec![], 120*73779f3dSLoGin ); 121*73779f3dSLoGin 122*73779f3dSLoGin assert!(scheduler.is_ok(), "Create scheduler error: {:?}", scheduler); 123*73779f3dSLoGin 124*73779f3dSLoGin let mut scheduler = scheduler.unwrap(); 125*73779f3dSLoGin 126*73779f3dSLoGin let entity = scheduler.add_task(config_file, task); 127*73779f3dSLoGin assert!(entity.is_ok(), "Add task should return ok: {:?}", entity); 128*73779f3dSLoGin } 129*73779f3dSLoGin 130*73779f3dSLoGin /// 应在riscv64上运行包含riscv64的任务 131*73779f3dSLoGin #[test_context(DadkExecuteContextTestBuildRiscV64V1)] 132*73779f3dSLoGin #[test] 133*73779f3dSLoGin fn should_run_task_include_riscv64_on_riscv64(ctx: &DadkExecuteContextTestBuildRiscV64V1) { 134*73779f3dSLoGin let config_file = ctx 135*73779f3dSLoGin .base_context() 136*73779f3dSLoGin .config_v1_dir() 137*73779f3dSLoGin .join("app_all_target_arch_0_1_0.dadk"); 138*73779f3dSLoGin let task = Parser::new(ctx.base_context().config_v1_dir()).parse_config_file(&config_file); 139*73779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task); 140*73779f3dSLoGin let task = task.unwrap(); 141*73779f3dSLoGin 142*73779f3dSLoGin assert!( 143*73779f3dSLoGin task.target_arch.contains(&TargetArch::RiscV64), 144*73779f3dSLoGin "Cannot find target_arch riscv64: {:?}", 145*73779f3dSLoGin task 146*73779f3dSLoGin ); 147*73779f3dSLoGin 148*73779f3dSLoGin let scheduler = Scheduler::new( 149*73779f3dSLoGin ctx.execute_context().self_ref().unwrap(), 150*73779f3dSLoGin ctx.base_context().fake_dragonos_sysroot(), 151*73779f3dSLoGin *ctx.execute_context().action(), 152*73779f3dSLoGin vec![], 153*73779f3dSLoGin ); 154*73779f3dSLoGin 155*73779f3dSLoGin assert!(scheduler.is_ok(), "Create scheduler error: {:?}", scheduler); 156*73779f3dSLoGin 157*73779f3dSLoGin let mut scheduler = scheduler.unwrap(); 158*73779f3dSLoGin 159*73779f3dSLoGin let entity = scheduler.add_task(config_file, task); 160*73779f3dSLoGin assert!(entity.is_ok(), "Add task should return ok: {:?}", entity); 161*73779f3dSLoGin } 162*73779f3dSLoGin 163*73779f3dSLoGin /// 确保文件 app_all_target_arch_0_1_0.dadk 包含了所有的目标架构 164*73779f3dSLoGin #[test_context(BaseTestContext)] 165*73779f3dSLoGin #[test] 166*73779f3dSLoGin fn ensure_all_target_arch_testcase_v1(ctx: &BaseTestContext) { 167*73779f3dSLoGin let config_file = ctx.config_v1_dir().join("app_all_target_arch_0_1_0.dadk"); 168*73779f3dSLoGin let task = Parser::new(ctx.config_v1_dir()).parse_config_file(&config_file); 169*73779f3dSLoGin assert!(task.is_ok(), "parse error: {:?}", task); 170*73779f3dSLoGin let task = task.unwrap(); 171*73779f3dSLoGin 172*73779f3dSLoGin for a in TargetArch::EXPECTED.iter() { 173*73779f3dSLoGin let target_arch = TargetArch::try_from(*a).unwrap(); 174*73779f3dSLoGin assert!( 175*73779f3dSLoGin task.target_arch.contains(&target_arch), 176*73779f3dSLoGin "Cannot find target_arch '{:?}' in task: {:?}", 177*73779f3dSLoGin a, 178*73779f3dSLoGin task 179*73779f3dSLoGin ); 180*73779f3dSLoGin } 181*73779f3dSLoGin } 182