Skip to content

Commit 5efeedf

Browse files
committed
Update, fix, and tweak some tests
1 parent f265e15 commit 5efeedf

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

src/capture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl Backtrace {
129129
/// and the last frame is likely something about how this thread or the main
130130
/// function started.
131131
pub fn frames(&self) -> &[BacktraceFrame] {
132-
&self.frames
132+
&self.frames[self.actual_start_index..]
133133
}
134134

135135
/// If this backtrace was created from `new_unresolved` then this function

tests/skip_inner_frames.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ use backtrace::Backtrace;
44

55
const FRAME_RANGE: usize = 128; // should be close enough not to give false positives
66

7-
// FIXME: on Windows 32-bit ('i686-pc-windows-msvc') backtraces contain some spurious calls
8-
// which are not in the code (for instance calls to RtlFindCharInUnicodeString), however generated
9-
// backtraces are consistent between runs (so probably this is not an issue with synchronization?).
10-
// Until resolved those test are ignored and `Backtrace::ext_index()` always returns None.
11-
#[test]
12-
#[cfg_attr(not(all(target_os = "windows", target_arch = "x86")), ignore)]
13-
fn ext_index_must_be_0_on_win32() {
14-
let b = Backtrace::new();
15-
assert_eq!(b.ext_index(), 0);
16-
}
17-
187
#[test]
198
#[cfg_attr(any(not(any(feature = "libunwind", feature = "unix-backtrace", feature = "dbghelp")), all(target_os = "windows", target_arch = "x86")), ignore)]
209
fn backtrace_new_unresolved_should_start_with_call_site_trace() {
@@ -24,10 +13,9 @@ fn backtrace_new_unresolved_should_start_with_call_site_trace() {
2413
println!("{:#?}", b);
2514

2615
assert!(!b.frames().is_empty());
27-
assert!(b.ext_index() > 0);
2816

2917
let this_ip = backtrace_new_unresolved_should_start_with_call_site_trace as usize;
30-
let frame_ip = b.ext_frames().first().unwrap().ip() as usize;
18+
let frame_ip = b.frames().first().unwrap().ip() as usize;
3119

3220
assert!(frame_ip >= this_ip);
3321
assert!(frame_ip <= this_ip + FRAME_RANGE);
@@ -40,11 +28,10 @@ fn backtrace_new_should_start_with_call_site_trace() {
4028
println!("{:?}", b);
4129

4230
assert!(!b.frames().is_empty());
43-
assert!(b.ext_index() > 0);
4431

4532
let this_ip = backtrace_new_should_start_with_call_site_trace as usize;
46-
let frame_ip = b.ext_frames().first().unwrap().ip() as usize;
33+
let frame_ip = b.frames().first().unwrap().ip() as usize;
4734

4835
assert!(frame_ip >= this_ip);
4936
assert!(frame_ip <= this_ip + FRAME_RANGE);
50-
}
37+
}

tests/smoke.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fn smoke_test_frames() {
6464
expected_file: &str,
6565
expected_line: u32) {
6666
if offset > idx { return }
67+
println!("frame: {}", idx);
6768
let (ip, sym) = syms[idx - offset];
6869
let ip = ip as usize;
6970
let sym = sym as usize;
@@ -72,8 +73,9 @@ fn smoke_test_frames() {
7273

7374
// windows dbghelp is *quite* liberal (and wrong) in many of its reports
7475
// right now...
75-
if !DBGHELP && cfg!(debug) {
76-
// this assertion fails for release build.
76+
//
77+
// This assertion can also fail for release builds, so skip it there
78+
if !DBGHELP && cfg!(debug_assertions) {
7779
assert!(sym - actual_fn_pointer < 1024);
7880
}
7981

@@ -90,6 +92,7 @@ fn smoke_test_frames() {
9092
addr = sym.addr();
9193
line = sym.lineno();
9294
file = sym.filename().map(|v| v.to_path_buf());
95+
println!(" sym: {:?}", name);
9396
});
9497

9598
// dbghelp doesn't always resolve symbols right now
@@ -105,8 +108,13 @@ fn smoke_test_frames() {
105108
!(DBGHELP && !MSVC)
106109
{
107110
let name = name.expect("didn't find a name");
108-
assert!(name.contains(expected_name),
109-
"didn't find `{}` in `{}`", expected_name, name);
111+
112+
// in release mode names get weird as functions can get merged
113+
// together with `mergefunc`, so only assert this in debug mode
114+
if cfg!(debug_assertions) {
115+
assert!(name.contains(expected_name),
116+
"didn't find `{}` in `{}`", expected_name, name);
117+
}
110118
}
111119

112120
if can_resolve {

0 commit comments

Comments
 (0)