Rust · 2762 bytes Raw Blame History
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("tests/fixtures").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 external_i128_call_uses_pair_arg_and_return_regs_at_o0() {
24 let asm = capture_text(
25 CaptureRequest {
26 input: fixture("integer16_external_call.f90"),
27 requested: BTreeSet::from([Stage::Asm]),
28 opt_level: OptLevel::O0,
29 },
30 Stage::Asm,
31 );
32
33 assert!(
34 asm.contains("bl _add_ext"),
35 "external integer(16) call should branch to the declared symbol:\n{}",
36 asm
37 );
38 assert!(
39 asm.matches("ldp x0, x1").count() >= 1,
40 "external integer(16) ABI should load the outgoing pair-register arg with LDP x0, x1:\n{}",
41 asm
42 );
43 assert!(
44 asm.matches("stp x0, x1").count() >= 1,
45 "external integer(16) ABI should spill the returned pair-register value with STP x0, x1:\n{}",
46 asm
47 );
48 }
49
50 #[test]
51 fn external_i128_call_object_snapshot_tracks_external_symbol_at_o0() {
52 let obj = capture_text(
53 CaptureRequest {
54 input: fixture("integer16_external_call.f90"),
55 requested: BTreeSet::from([Stage::Obj]),
56 opt_level: OptLevel::O0,
57 },
58 Stage::Obj,
59 );
60
61 assert!(
62 obj.contains("external _add_ext"),
63 "object snapshot should preserve the unresolved external integer(16) symbol:\n{}",
64 obj
65 );
66 }
67
68 #[test]
69 fn external_i128_call_object_snapshot_is_deterministic_at_o0() {
70 let source = fixture("integer16_external_call.f90");
71 let first = capture_text(
72 CaptureRequest {
73 input: source.clone(),
74 requested: BTreeSet::from([Stage::Obj]),
75 opt_level: OptLevel::O0,
76 },
77 Stage::Obj,
78 );
79 let second = capture_text(
80 CaptureRequest {
81 input: source,
82 requested: BTreeSet::from([Stage::Obj]),
83 opt_level: OptLevel::O0,
84 },
85 Stage::Obj,
86 );
87
88 assert_eq!(
89 first, second,
90 "external integer(16) call object snapshots should be deterministic at O0"
91 );
92 }
93