Skip to content

Commit

Permalink
Add test for symbolization of additional "entry" types
Browse files Browse the repository at this point in the history
Add a test covering the symbolization of maps "entries" without a path
as well as with a "component" (as opposed to a file).

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o committed Jul 12, 2024
1 parent f5eb787 commit 801bd6a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/normalize/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub enum UserMeta<'src> {

impl<'src> UserMeta<'src> {
/// Retrieve the [`Apk`] of this enum, if this variant is active.
#[inline]
pub fn apk(&self) -> Option<&Apk> {
match self {
Self::Apk(entry) => Some(entry),
Expand All @@ -120,6 +121,7 @@ impl<'src> UserMeta<'src> {
}

/// Retrieve the [`Elf`] of this enum, if this variant is active.
#[inline]
pub fn elf(&self) -> Option<&Elf<'src>> {
match self {
Self::Elf(elf) => Some(elf),
Expand All @@ -128,6 +130,7 @@ impl<'src> UserMeta<'src> {
}

/// Retrieve the [`Unknown`] of this enum, if this variant is active.
#[inline]
pub fn unknown(&self) -> Option<&Unknown> {
match self {
Self::Unknown(unknown) => Some(unknown),
Expand Down
49 changes: 47 additions & 2 deletions src/symbolize/symbolizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,12 +1365,12 @@ impl Default for Symbolizer {
mod tests {
use super::*;

use test_log::test;

use crate::symbolize;
use crate::symbolize::CodeInfo;
use crate::test_helper::find_the_answer_fn_in_zip;

use test_log::test;


/// Exercise the `Debug` representation of various types.
#[test]
Expand Down Expand Up @@ -1505,6 +1505,51 @@ mod tests {
}
}

/// Check that we do not normalize addresses belonging to a
/// "component" (as opposed to a file).
#[test]
fn symbolize_entry_various() {
let addrs = [0x10000, 0x30000];

let entries = [
Ok(MapsEntry {
range: 0x10000..0x20000,
mode: 0x1,
offset: 0,
path_name: Some(PathName::Component("a-component".to_string())),
}),
Ok(MapsEntry {
range: 0x30000..0x40000,
mode: 0x1,
offset: 0,
path_name: None,
}),
];
let symbolizer = Symbolizer::new();
let mut handler = SymbolizeHandler {
symbolizer: &symbolizer,
pid: Pid::Slf,
debug_syms: false,
perf_map: false,
map_files: false,
all_symbols: Vec::new(),
};
let () = normalize_sorted_user_addrs_with_entries(
addrs.as_slice().iter().copied(),
entries.into_iter(),
&mut handler,
)
.unwrap();

let syms = handler.all_symbols;
assert_eq!(syms.len(), 2);
assert!(
matches!(syms[0], Symbolized::Unknown(Reason::Unsupported)),
"{:?}",
syms[0]
);
}

/// Check that we can symbolize an address residing in a zip archive.
#[test]
fn symbolize_zip() {
Expand Down

0 comments on commit 801bd6a

Please sign in to comment.