Skip to content

Commit

Permalink
Add more tests for Debug representation
Browse files Browse the repository at this point in the history
This change introduces two more tests covering the Debug representation
of various types.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Nov 6, 2023
1 parent 34ac168 commit f23c40a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/elf/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,34 @@ mod tests {

use std::path::Path;

#[cfg(feature = "dwarf")]
use crate::dwarf::DwarfResolver;


/// Exercise the `Debug` representation of various types.
#[test]
fn debug_repr() {
let path = Path::new(&env!("CARGO_MANIFEST_DIR"))
.join("data")
.join("test-stable-addresses.bin");

let parser = Rc::new(ElfParser::open(&path).unwrap());
let backend = ElfBackend::Elf(parser.clone());
let resolver = ElfResolver::with_backend(&path, backend).unwrap();
let dbg = format!("{resolver:?}");
assert!(dbg.starts_with("ELF"), "{dbg}");
assert!(dbg.ends_with("test-stable-addresses.bin"), "{dbg}");

#[cfg(feature = "dwarf")]
{
let dwarf = DwarfResolver::from_parser(parser, true).unwrap();
let backend = ElfBackend::Dwarf(Rc::new(dwarf));
let resolver = ElfResolver::with_backend(&path, backend).unwrap();
let dbg = format!("{resolver:?}");
assert!(dbg.starts_with("DWARF"), "{dbg}");
assert!(dbg.ends_with("test-stable-addresses.bin"), "{dbg}");
}
}

/// Check that we fail finding an offset for an address not
/// representing a symbol in an ELF file.
Expand Down
13 changes: 13 additions & 0 deletions src/gsym/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ mod tests {
use test_log::test;


/// Exercise the `Debug` representation of various types.
#[test]
fn debug_repr() {
let test_gsym = Path::new(&env!("CARGO_MANIFEST_DIR"))
.join("data")
.join("test-stable-addresses.gsym");

let resolver = GsymResolver::new(test_gsym).unwrap();
let dbg = format!("{resolver:?}");
assert!(dbg.starts_with("GSYM"), "{dbg}");
assert!(dbg.ends_with("test-stable-addresses.gsym"), "{dbg}");
}

/// Check that we can create a `GsymResolver` using a "raw" slice of data.
#[test]
fn creation_from_raw_data() {
Expand Down

0 comments on commit f23c40a

Please sign in to comment.