Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for unwind info optimizers #107

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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