Skip to content

Commit

Permalink
Add tests for unwind info optimizers
Browse files Browse the repository at this point in the history
Test Plan
=========

Added tests
  • Loading branch information
javierhonduco committed Nov 11, 2024
1 parent 2c148a6 commit 78fa49b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion src/unwind_info/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::unwind_info::types::{CfaType, CompactUnwindRow};
/// Remove unecessary end of function markers.
///
/// A function marker is superfluous when there is another unwind information entry
/// for the same program counter.
/// for the same program counter. This logic might be changed later on to delete markers
/// within a certain bytes of the closest instruction.
///
/// The input *must* be sorted.
pub fn remove_unnecesary_markers(unwind_info: &mut Vec<CompactUnwindRow>) {
Expand Down Expand Up @@ -67,3 +68,38 @@ pub fn remove_redundant(unwind_info: &mut Vec<CompactUnwindRow>) {

unwind_info.truncate(new_i);
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_remove_unnecesary_markers() {
let unwind_info = vec![
CompactUnwindRow::end_of_function_marker(0x100),
CompactUnwindRow {
pc: 0x100,
..Default::default()
},
];
let mut processed = unwind_info.clone();
remove_unnecesary_markers(&mut processed);

assert_eq!(
processed,
vec![CompactUnwindRow {
pc: 0x100,
..Default::default()
}]
)
}

#[test]
fn test_remove_redundant() {
let unwind_info = vec![CompactUnwindRow::default(), CompactUnwindRow::default()];
let mut processed = unwind_info.clone();
remove_redundant(&mut processed);

assert_eq!(processed, vec![CompactUnwindRow::default()])
}
}
2 changes: 1 addition & 1 deletion src/unwind_info/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum PltType {
Plt2 = 2,
}

#[derive(Debug, Default, Copy, Clone)]
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct CompactUnwindRow {
pub pc: u64,
pub cfa_type: u8,
Expand Down

0 comments on commit 78fa49b

Please sign in to comment.