tests.rs 5.6 KB

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