Skip to content

Commit

Permalink
Add simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim committed Feb 23, 2024
1 parent 4f45f2f commit 846b13c
Showing 1 changed file with 79 additions and 2 deletions.
81 changes: 79 additions & 2 deletions crates/symbolicator-proguard/src/symbolication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ impl ProguardService {

if !mapped_frames.is_empty() {
let mut result = Vec::new();
let bottom_class = mapped_frames[mapped_frames.len()].class();
let bottom_class = mapped_frames[mapped_frames.len() - 1].class();

// sentry expects stack traces in reverse order
for new_frame in mapped_frames.iter().rev() {
let mut mapped_frame = JvmFrame {
class: new_frame.class().to_owned(),
method: new_frame.class().to_owned(),
method: new_frame.method().to_owned(),
lineno: new_frame.line() as u32,
..frame.clone()
};
Expand Down Expand Up @@ -161,4 +161,81 @@ org.slf4j.helpers.Util$ClassContext -> org.a.b.g$b:
assert_eq!(exception.ty, "Util$ClassContextSecurityManager");
assert_eq!(exception.module, "org.slf4j.helpers");
}

// based on the Python test `test_resolving_inline`
#[test]
fn remap_frames_simple() {
let proguard_source = b"# compiler: R8
# compiler_version: 2.0.74
# min_api: 16
# pg_map_id: 5b46fdc
# common_typos_disable
$r8$backportedMethods$utility$Objects$2$equals -> a:
boolean equals(java.lang.Object,java.lang.Object) -> a
$r8$twr$utility -> b:
void $closeResource(java.lang.Throwable,java.lang.Object) -> a
android.support.v4.app.RemoteActionCompatParcelizer -> android.support.v4.app.RemoteActionCompatParcelizer:
1:1:void <init>():11:11 -> <init>
io.sentry.sample.-$$Lambda$r3Avcbztes2hicEObh02jjhQqd4 -> e.a.c.a:
io.sentry.sample.MainActivity f$0 -> b
io.sentry.sample.MainActivity -> io.sentry.sample.MainActivity:
1:1:void <init>():15:15 -> <init>
1:1:boolean onCreateOptionsMenu(android.view.Menu):60:60 -> onCreateOptionsMenu
1:1:boolean onOptionsItemSelected(android.view.MenuItem):69:69 -> onOptionsItemSelected
2:2:boolean onOptionsItemSelected(android.view.MenuItem):76:76 -> onOptionsItemSelected
1:1:void bar():54:54 -> t
1:1:void foo():44 -> t
1:1:void onClickHandler(android.view.View):40 -> t";

let frames = [
JvmFrame {
method: "onClick".to_owned(),
class: "e.a.c.a".to_owned(),
lineno: 2,
..Default::default()
},
JvmFrame {
method: "t".to_owned(),
class: "io.sentry.sample.MainActivity".to_owned(),
filename: Some("MainActivity.java".to_owned()),
lineno: 1,
..Default::default()
},
];

let mapping = ProguardMapping::new(proguard_source);
let mapper = ProguardMapper::new(mapping);

let mapped_frames: Vec<_> = frames
.iter()
.flat_map(|frame| ProguardService::map_frame(&[&mapper], frame).into_iter())
.collect();

assert_eq!(mapped_frames.len(), 4);

assert_eq!(mapped_frames[0].method, "onClick");
assert_eq!(
mapped_frames[0].class,
"io.sentry.sample.-$$Lambda$r3Avcbztes2hicEObh02jjhQqd4"
);

assert_eq!(
mapped_frames[1].filename,
Some("MainActivity.java".to_owned())
);
assert_eq!(mapped_frames[1].class, "io.sentry.sample.MainActivity");
assert_eq!(mapped_frames[1].method, "onClickHandler");
assert_eq!(mapped_frames[1].lineno, 40);

assert_eq!(mapped_frames[2].method, "foo");
assert_eq!(mapped_frames[2].lineno, 44);

assert_eq!(mapped_frames[3].method, "bar");
assert_eq!(mapped_frames[3].lineno, 54);
assert_eq!(
mapped_frames[3].filename,
Some("MainActivity.java".to_owned())
);
assert_eq!(mapped_frames[3].class, "io.sentry.sample.MainActivity");
}
}

0 comments on commit 846b13c

Please sign in to comment.