| 1 | #[allow(dead_code)] |
| 2 | #[path = "common/corpus.rs"] |
| 3 | mod common; |
| 4 | |
| 5 | use std::fs; |
| 6 | |
| 7 | fn assemble_fixture(name: &str) -> common::TempPaths { |
| 8 | let paths = common::TempPaths::new("afs_metadata_tls_zerofill"); |
| 9 | let asm = common::read_fixture(name); |
| 10 | fs::write(&paths.asm, &asm).expect("write fixture"); |
| 11 | common::assemble_with_ours(&asm, &paths.obj); |
| 12 | common::assemble_with_system(&paths.asm, &paths.ref_obj); |
| 13 | paths |
| 14 | } |
| 15 | |
| 16 | fn normalize_tool_output(text: &str) -> String { |
| 17 | text.lines() |
| 18 | .filter(|line| !line.trim_end().ends_with(".o:") && !line.trim_end().ends_with(":")) |
| 19 | .map(str::trim_end) |
| 20 | .filter(|line| !line.is_empty()) |
| 21 | .collect::<Vec<_>>() |
| 22 | .join("\n") |
| 23 | } |
| 24 | |
| 25 | #[test] |
| 26 | fn metadata_tls_zerofill_matches_system_as() { |
| 27 | let paths = assemble_fixture("metadata_tls_zerofill.s"); |
| 28 | |
| 29 | let ours_header = common::object_header(&paths.obj); |
| 30 | let ref_header = common::object_header(&paths.ref_obj); |
| 31 | let ours_load = common::object_load_commands(&paths.obj); |
| 32 | let ref_load = common::object_load_commands(&paths.ref_obj); |
| 33 | let ours_relocs = common::object_relocations(&paths.obj); |
| 34 | let ref_relocs = common::object_relocations(&paths.ref_obj); |
| 35 | let ours_symbols = common::object_symbols_verbose(&paths.obj); |
| 36 | let ref_symbols = common::object_symbols_verbose(&paths.ref_obj); |
| 37 | |
| 38 | assert!( |
| 39 | normalize_tool_output(&ours_load).contains("sectname __thread_bss"), |
| 40 | "missing __thread_bss section\n{}", |
| 41 | ours_load |
| 42 | ); |
| 43 | assert!( |
| 44 | normalize_tool_output(&ours_load).contains("sectname __thread_vars"), |
| 45 | "missing __thread_vars section\n{}", |
| 46 | ours_load |
| 47 | ); |
| 48 | assert!( |
| 49 | normalize_tool_output(&ours_load).contains("minos 14.1"), |
| 50 | "missing 14.1 minos in load commands\n{}", |
| 51 | ours_load |
| 52 | ); |
| 53 | assert!( |
| 54 | normalize_tool_output(&ours_symbols).contains("_tls_counter$tlv$init"), |
| 55 | "missing tls init symbol\n{}", |
| 56 | ours_symbols |
| 57 | ); |
| 58 | assert!( |
| 59 | normalize_tool_output(&ours_symbols).contains("_tls_counter"), |
| 60 | "missing tls variable symbol\n{}", |
| 61 | ours_symbols |
| 62 | ); |
| 63 | |
| 64 | assert_eq!( |
| 65 | normalize_tool_output(&ours_header), |
| 66 | normalize_tool_output(&ref_header) |
| 67 | ); |
| 68 | assert_eq!( |
| 69 | normalize_tool_output(&ours_load), |
| 70 | normalize_tool_output(&ref_load) |
| 71 | ); |
| 72 | assert_eq!( |
| 73 | normalize_tool_output(&ours_relocs), |
| 74 | normalize_tool_output(&ref_relocs) |
| 75 | ); |
| 76 | assert_eq!( |
| 77 | normalize_tool_output(&ours_symbols), |
| 78 | normalize_tool_output(&ref_symbols) |
| 79 | ); |
| 80 | } |
| 81 |