| 1 | //! Focused tests for Sprint 27 harness glue. |
| 2 | |
| 3 | mod common; |
| 4 | |
| 5 | use common::harness::{ |
| 6 | apply_section_tolerances, diff_macho, parse_case_tolerances, string_table_within_five_percent, |
| 7 | }; |
| 8 | |
| 9 | #[test] |
| 10 | fn notes_tolerance_block_parses_section_range() { |
| 11 | let notes = r#" |
| 12 | tolerated: |
| 13 | - region: __TEXT,__text bytes 0x1-0x3 reason: "known padding drift" |
| 14 | "#; |
| 15 | let tolerances = parse_case_tolerances(Some(notes)).expect("parse case tolerances"); |
| 16 | assert_eq!(tolerances.len(), 1); |
| 17 | assert_eq!(tolerances[0].reason, "known padding drift"); |
| 18 | } |
| 19 | |
| 20 | #[test] |
| 21 | fn notes_tolerance_can_hide_section_byte_diff() { |
| 22 | let notes = r#" |
| 23 | tolerated: |
| 24 | - region: __TEXT,__text bytes 0x1-0x1 reason: "known one-byte drift" |
| 25 | "#; |
| 26 | let tolerances = parse_case_tolerances(Some(notes)).expect("parse case tolerances"); |
| 27 | let diff = diff_macho(b"abc", b"adc"); |
| 28 | let filtered = apply_section_tolerances(diff, "__TEXT", "__text", &tolerances); |
| 29 | assert!( |
| 30 | filtered.is_clean(), |
| 31 | "expected tolerance to absorb diff: {filtered:#?}" |
| 32 | ); |
| 33 | assert_eq!(filtered.tolerated.len(), 1); |
| 34 | } |
| 35 | |
| 36 | #[test] |
| 37 | fn notes_tolerance_does_not_hide_other_sections() { |
| 38 | let notes = r#" |
| 39 | tolerated: |
| 40 | - region: __TEXT,__text bytes 0x1-0x1 reason: "known one-byte drift" |
| 41 | "#; |
| 42 | let tolerances = parse_case_tolerances(Some(notes)).expect("parse case tolerances"); |
| 43 | let diff = diff_macho(b"abc", b"adc"); |
| 44 | let filtered = apply_section_tolerances(diff, "__DATA", "__data", &tolerances); |
| 45 | assert!( |
| 46 | !filtered.is_clean(), |
| 47 | "unexpectedly tolerated unrelated diff: {filtered:#?}" |
| 48 | ); |
| 49 | assert_eq!(filtered.critical.len(), 1); |
| 50 | } |
| 51 | |
| 52 | #[test] |
| 53 | fn string_table_near_parity_accepts_small_suffix_dedup_drift() { |
| 54 | assert!( |
| 55 | string_table_within_five_percent(101, 100), |
| 56 | "1% string-table drift should stay within the Sprint 27 allowance" |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | #[test] |
| 61 | fn string_table_near_parity_rejects_large_suffix_dedup_drift() { |
| 62 | assert!( |
| 63 | !string_table_within_five_percent(120, 100), |
| 64 | "20% string-table drift should fail the Sprint 27 allowance" |
| 65 | ); |
| 66 | } |
| 67 |