Skip to content

Commit 85d43c7

Browse files
committed
Port backtrace's cpp_smoke to rustc repo
1 parent 66d6064 commit 85d43c7

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/auxiliary/rust_test_helpers.c

+8
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,11 @@ uint16_t issue_97463_leak_uninit_data(uint32_t a, uint32_t b, uint32_t c) {
451451

452452
return data->b; /* leak data */
453453
}
454+
455+
void templated_trampoline(void (*func)()) {
456+
func();
457+
}
458+
459+
void cpp_trampoline(void (*func)()) {
460+
templated_trampoline(func);
461+
}

tests/ui/backtrace/smoke.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//Part of porting backtrace-rs tests to rustc repo:
2+
//Original test: <https://github.com/rust-lang/rust/issues/122899>
3+
//<https://github.com/rust-lang/backtrace-rs/tree/6fa4b85b9962c3e1be8c2e5cc605cd078134152b/crates/cpp_smoke_test>
4+
// ignore-tidy-linelength
5+
//@ run-pass
6+
//@ compile-flags: -Cstrip=none
7+
//@ needs-unwind
8+
9+
#![allow(improper_ctypes)]
10+
#![allow(improper_ctypes_definitions)]
11+
#![feature(backtrace_frames)]
12+
13+
use std::{backtrace::Backtrace, sync::atomic::{AtomicBool, Ordering}};
14+
15+
#[link(name = "rust_test_helpers", kind = "static")]
16+
extern "C" {
17+
fn cpp_trampoline(func: extern "C" fn()) -> ();
18+
}
19+
20+
fn main() {
21+
std::env::set_var("RUST_BACKTRACE", "1");
22+
static RAN_ASSERTS: AtomicBool = AtomicBool::new(false);
23+
extern "C" fn assert_cpp_frames() {
24+
let trace = Backtrace::capture();
25+
let actual = format!("{:?}", trace.frames());
26+
let expected = [
27+
"templated_trampoline",
28+
"cpp_trampoline",
29+
];
30+
for e in expected {
31+
assert!(actual.contains(e));
32+
}
33+
RAN_ASSERTS.store(true, Ordering::SeqCst);
34+
}
35+
assert!(!RAN_ASSERTS.load(Ordering::SeqCst));
36+
unsafe {
37+
cpp_trampoline(assert_cpp_frames);
38+
}
39+
assert!(RAN_ASSERTS.load(Ordering::SeqCst));
40+
}

0 commit comments

Comments
 (0)