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