Skip to content

Commit

Permalink
ref(symcache): Add a test for mostly overlapping functions (#545)
Browse files Browse the repository at this point in the history
Because we don't track file name functions, there are situations 
where the only distinguishing difference between two otherwise 
identical functions is their entry_pc. It's important to ensure that 
this doesn't change, so a test demonstrating one of those 
situations has been added to ensure that this behaviour isn't
broken.
  • Loading branch information
relaxolotl committed Apr 27, 2022
1 parent 4d98429 commit b4597b2
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: symbolic-symcache/tests/test_writer.rs
expression: FunctionsDebug(&symcache)

---
0 _mh_execute_header
3f50 main
3f80 shell
3f90 unique_i_swear
3fa0 spin
3fb0 unique_i_swear

19 changes: 19 additions & 0 deletions symbolic-symcache/tests/test_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ fn test_write_functions_macos() -> Result<(), Error> {
Ok(())
}

// Tests that functions with identical names, compilation directories, and languages but different
// entry_pcs have separate, distinct entries in the symcache. The specific use case generating this
// is two identically-named static C functions nestled in two different files sharing a common
// compilation directory. See the overlapping_funcs directory in sentry-testutils for related files.
#[test]
fn test_write_functions_overlapping_funcs() -> Result<(), Error> {
let buffer = ByteView::open(fixture(
"macos/overlapping_funcs.dSYM/Contents/Resources/DWARF/overlapping_funcs",
))?;
let object = Object::parse(&buffer)?;

let mut buffer = Vec::new();
SymCacheWriter::write_object(&object, Cursor::new(&mut buffer))?;
let symcache = SymCache::parse(&buffer)?;
insta::assert_debug_snapshot!("overlapping_funcs", FunctionsDebug(&symcache));

Ok(())
}

#[test]
fn test_write_large_symbol_names() -> Result<(), Error> {
let buffer = ByteView::open(fixture("regression/large_symbol.sym"))?;
Expand Down
Binary file not shown.
5 changes: 5 additions & 0 deletions symbolic-testutils/overlapping_funcs/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# Replace clang with gcc if needed. Produces overlapping_funcs.dSYM which should be placed in
# symbolic-testutils/fixtures/macos for test_write_functions_overlapping_funcs. Also produces an
# executable which can be ignored. Or run it for a surprise! (It doesn't do anything.)
clang -Weverything main.c -v -g -o overlapping_funcs testachio.c testaroni.c
9 changes: 9 additions & 0 deletions symbolic-testutils/overlapping_funcs/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "testachio.h"
#include "testaroni.h"

int main()
{
spin();
shell();
return 0;
}
10 changes: 10 additions & 0 deletions symbolic-testutils/overlapping_funcs/testachio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "testachio.h"

void shell(void)
{
unique_i_swear();
}

static void unique_i_swear(void)
{
}
2 changes: 2 additions & 0 deletions symbolic-testutils/overlapping_funcs/testachio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
void shell(void);
static void unique_i_swear(void);
10 changes: 10 additions & 0 deletions symbolic-testutils/overlapping_funcs/testaroni.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "testaroni.h"

void spin(void)
{
unique_i_swear();
}

static void unique_i_swear(void)
{
}
2 changes: 2 additions & 0 deletions symbolic-testutils/overlapping_funcs/testaroni.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
void spin(void);
static void unique_i_swear(void);

0 comments on commit b4597b2

Please sign in to comment.