-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new integration tests:
backtrace
, throw
and longjmp
- Loading branch information
Showing
4 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <stdlib.h> | ||
#include <execinfo.h> | ||
|
||
void __attribute__ ((noinline)) foo() { | ||
malloc( 123456 ); | ||
|
||
void * buffer[ 32 ]; | ||
const int count = backtrace( buffer, 32 ); | ||
if( count == 0 ) { | ||
exit( 1 ); | ||
} | ||
char ** symbols = backtrace_symbols( buffer, count ); | ||
free( symbols ); | ||
} | ||
|
||
void __attribute__ ((noinline)) bar() { | ||
foo(); | ||
|
||
void * buffer[ 32 ]; | ||
const int count = backtrace( buffer, 32 ); | ||
if( count == 0 ) { | ||
exit( 1 ); | ||
} | ||
char ** symbols = backtrace_symbols( buffer, count ); | ||
free( symbols ); | ||
} | ||
|
||
int main() { | ||
bar(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <setjmp.h> | ||
|
||
int catch_1 = 0; | ||
int catch_2 = 0; | ||
|
||
int f1 = 0; | ||
int f2 = 0; | ||
int f3a = 0; | ||
int f3b = 0; | ||
int f4 = 0; | ||
int f5a = 0; | ||
int f5b = 0; | ||
|
||
jmp_buf buf_a; | ||
jmp_buf buf_b; | ||
|
||
void __attribute__ ((noinline)) foobar_0() { | ||
malloc( 123456 ); | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_1() { | ||
foobar_0(); | ||
|
||
printf( ">> before throw\n" ); | ||
longjmp( buf_a, 1 ); | ||
f1 = 1; | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_2() { | ||
foobar_1(); | ||
f2 = 1; | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_3() { | ||
printf( ">> before try\n" ); | ||
if( setjmp( buf_a ) == 0 ) { | ||
foobar_2(); | ||
f3a = 1; | ||
} else { | ||
catch_1 = 1; | ||
printf( ">> inside catch\n" ); | ||
malloc( 123457 ); | ||
longjmp( buf_b, 1 ); | ||
} | ||
f3b = 1; | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_4() { | ||
foobar_3(); | ||
f4 = 1; | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_5() { | ||
if( setjmp( buf_b ) == 0 ) { | ||
foobar_4(); | ||
f5a = 1; | ||
} else { | ||
catch_2 = 1; | ||
malloc( 123458 ); | ||
} | ||
f5b = 1; | ||
} | ||
|
||
int main() { | ||
printf( ">> start\n" ); | ||
foobar_5(); | ||
|
||
if( catch_1 && catch_2 && !f1 && !f2 && !f3a && !f3b && !f4 && !f5a && f5b ) { | ||
malloc( 123459 ); | ||
return 0; | ||
} | ||
|
||
abort(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
bool catch_1 = false; | ||
bool catch_2 = false; | ||
|
||
bool f1 = false; | ||
bool f2 = false; | ||
bool f3a = false; | ||
bool f3b = false; | ||
bool f4 = false; | ||
bool f5a = false; | ||
bool f5b = false; | ||
|
||
extern "C" { | ||
|
||
void __attribute__ ((noinline)) foobar_0() { | ||
malloc( 123456 ); | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_1() { | ||
foobar_0(); | ||
|
||
printf( ">> before throw\n" ); | ||
throw "dummy"; | ||
f1 = true; | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_2() { | ||
foobar_1(); | ||
f2 = true; | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_3() { | ||
printf( ">> before try\n" ); | ||
try { | ||
foobar_2(); | ||
f3a = true; | ||
} catch (...) { | ||
catch_1 = true; | ||
printf( ">> inside catch\n" ); | ||
malloc( 123457 ); | ||
throw; | ||
} | ||
f3b = true; | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_4() { | ||
foobar_3(); | ||
f4 = true; | ||
} | ||
|
||
void __attribute__ ((noinline)) foobar_5() { | ||
try { | ||
foobar_4(); | ||
f5a = true; | ||
} catch (...) { | ||
catch_2 = true; | ||
malloc( 123458 ); | ||
} | ||
f5b = true; | ||
} | ||
|
||
} | ||
|
||
int main() { | ||
printf( ">> start\n" ); | ||
foobar_5(); | ||
|
||
if( catch_1 && catch_2 && !f1 && !f2 && !f3a && !f3b && !f4 && !f5a && f5b ) { | ||
malloc( 123459 ); | ||
return 0; | ||
} | ||
|
||
abort(); | ||
} |