@@ -87,21 +87,39 @@ fn expect_aborted(status: ExitStatus) {
87
87
// Android signals an abort() call with SIGSEGV at address 0xdeadbaad
88
88
// See e.g. https://groups.google.com/g/android-ndk/c/laW1CJc7Icc
89
89
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 )
93
100
. map ( |n| format ! ( "/data/tombstones/tombstone_{n:02}" ) )
94
101
. filter ( |f| std:: path:: Path :: new ( & f) . exists ( ) )
95
102
. last ( )
96
103
. expect ( "no tombstone found" ) ;
104
+
97
105
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
+
99
109
// If the next assert fails sporadically we might have an issue with parallel crashing apps
100
110
assert ! ( tombstone
101
111
. contains( & std:: env:: current_exe( ) . unwrap( ) . into_os_string( ) . into_string( ) . unwrap( ) ) ) ;
102
112
assert ! ( tombstone. contains(
103
113
"signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad"
104
114
) ) ;
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) ;
105
123
}
106
124
}
107
125
0 commit comments