Skip to content

Commit 53caa9f

Browse files
committed
Ensure crash is caused by libc::abort
1 parent 9a97cc8 commit 53caa9f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/test/ui/process/process-panic-after-fork.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,39 @@ fn expect_aborted(status: ExitStatus) {
8787
// Android signals an abort() call with SIGSEGV at address 0xdeadbaad
8888
// See e.g. https://groups.google.com/g/android-ndk/c/laW1CJc7Icc
8989
assert!(signal == libc::SIGSEGV);
90-
// Check if the crash occured at addres deadbaad to ensure it is not some undefined
91-
// behavior but actually an abort
92-
let tombstone = (0..100)
90+
91+
// Additional checks performed:
92+
// 1. Crash is from same executable (path) as we are (must be because of fork):
93+
// This ensures that we look into the correct tombstone.
94+
// 2. Cause of crash is a SIGSEGV with address 0xdeadbaad.
95+
// 3. libc::abort call is in one of top two functions on callstack.
96+
// The last two steps distinguish between a normal SIGSEGV and one caused
97+
// by libc::abort.
98+
99+
let tombstone_name = (0..100)
93100
.map(|n| format!("/data/tombstones/tombstone_{n:02}"))
94101
.filter(|f| std::path::Path::new(&f).exists())
95102
.last()
96103
.expect("no tombstone found");
104+
97105
let tombstone =
98-
std::fs::read_to_string(&tombstone).expect("Cannot read tombstone file");
106+
std::fs::read_to_string(&tombstone_name).expect("Cannot read tombstone file");
107+
println!("Content of {tombstone_name}:\n{tombstone}");
108+
99109
// If the next assert fails sporadically we might have an issue with parallel crashing apps
100110
assert!(tombstone
101111
.contains(&std::env::current_exe().unwrap().into_os_string().into_string().unwrap()));
102112
assert!(tombstone.contains(
103113
"signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad"
104114
));
115+
let abort_on_top = tombstone
116+
.lines()
117+
.skip_while(|l| !l.contains("backtrace:"))
118+
.skip(1)
119+
.take_while(|l| l.starts_with(" #"))
120+
.take(2)
121+
.any(|f| f.contains("/system/lib/libc.so (abort"));
122+
assert!(abort_on_top);
105123
}
106124
}
107125

0 commit comments

Comments
 (0)