| 1 | use std::collections::BTreeSet; |
| 2 | use std::path::PathBuf; |
| 3 | |
| 4 | use armfortas::driver::OptLevel; |
| 5 | use armfortas::testing::{capture_from_path, CaptureRequest, CapturedStage, Stage}; |
| 6 | |
| 7 | fn fixture(name: &str) -> PathBuf { |
| 8 | let path = PathBuf::from("test_programs").join(name); |
| 9 | assert!(path.exists(), "missing test fixture {}", path.display()); |
| 10 | path |
| 11 | } |
| 12 | |
| 13 | fn capture_text(request: CaptureRequest, stage: Stage) -> String { |
| 14 | let result = capture_from_path(&request).expect("capture should succeed"); |
| 15 | match result.get(stage) { |
| 16 | Some(CapturedStage::Text(text)) => text.clone(), |
| 17 | Some(CapturedStage::Run(_)) => panic!("expected text stage for {}", stage.as_str()), |
| 18 | None => panic!("missing requested stage {}", stage.as_str()), |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | #[test] |
| 23 | fn masked_do_concurrent_lowers_guarded_body() { |
| 24 | let raw_ir = capture_text( |
| 25 | CaptureRequest { |
| 26 | input: fixture("do_concurrent_mask.f90"), |
| 27 | requested: BTreeSet::from([Stage::Ir]), |
| 28 | opt_level: OptLevel::O0, |
| 29 | }, |
| 30 | Stage::Ir, |
| 31 | ); |
| 32 | |
| 33 | assert!(raw_ir.contains("doconc_check_")); |
| 34 | assert!(raw_ir.contains("if_then_")); |
| 35 | } |
| 36 | |
| 37 | #[test] |
| 38 | fn multi_control_do_concurrent_lowers_nested_loops() { |
| 39 | let raw_ir = capture_text( |
| 40 | CaptureRequest { |
| 41 | input: fixture("do_concurrent_multi_control.f90"), |
| 42 | requested: BTreeSet::from([Stage::Ir]), |
| 43 | opt_level: OptLevel::O0, |
| 44 | }, |
| 45 | Stage::Ir, |
| 46 | ); |
| 47 | |
| 48 | assert!( |
| 49 | raw_ir.matches("doconc_check_").count() >= 2, |
| 50 | "multi-control DO CONCURRENT should lower to nested concurrent loops:\n{}", |
| 51 | raw_ir |
| 52 | ); |
| 53 | } |
| 54 |