#define DECLARE(x, ...) __trace( "decl: " #x, ## __VA_ARGS__ ) ; x #define TRACE(x, ...) do { __trace( "trace: " #x, ## __VA_ARGS__ ) ; x ; } while ( false ) #define PSEUDO(x, ...) do { __trace( "trace: " x, ## __VA_ARGS__ ) ; } while ( false ) #define ASSERT(x, ...) do { __trace( "assert: " #x, ## __VA_ARGS__ ) ; assert( x ); } while ( false ) #define ASSERTV(x, ...) do { __trace( "trace: " #x, ## __VA_ARGS__ ) ; assert( x ); } while ( false ) #define CLEAR() __trace( "clear:" ); #define SAVE() __trace( "save:" ); #define EXCEPT(e, x, ...) do { __trace( "assert: " #x " throws " #e, ## __VA_ARGS__ ) ; \ assert_throws< e >( [&]{ x; } ); } while ( false ) #include #include #include // #include #include void __trace_() { std::cerr << std::endl; } template< typename arg_t, typename... args_t > void __trace_( const arg_t &a, const args_t & ... as ) { std::cerr << a << " "; __trace_( as... ); } template< typename arg_t, typename... args_t > void __trace( const arg_t &a, const args_t & ... as ) { std::cerr << a; if ( sizeof...( as ) > 0 ) std::cerr << "\t// "; __trace_( as... ); } template< typename T, typename F > void assert_throws( const F &f ) { try { f(); int stat; char *dem = abi::__cxa_demangle( typeid( T ).name(), nullptr, nullptr, &stat ); std::cerr << "failed: expected an exception of type " << dem << std::endl; abort(); } catch ( T & ) {} } [[gnu::constructor]] void set_alarm() { const char *env = std::getenv( "FRAG_DEADLINE" ); if ( !env ) return; time_t dead = std::atol( env ); time_t now = ::time( nullptr ); if ( dead - now <= 10 ) { __trace( "trace: less than 10 seconds left, giving up" ); exit( 1 ); } __trace( "trace: configuring time limits", "subtest =", ( dead - now - 10 ) / 2, "total =", dead - now - 10, "seconds" ); SAVE(); alarm( ( dead - now - 10 ) / 2 ); } int vg_select( int n, int m ) { if ( 1 /* RUNNING_ON_VALGRIND */ ) return m; else return n; }