Line data Source code
1 :
2 : /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #ifndef LBTEST_TEST_H
19 : #define LBTEST_TEST_H
20 :
21 : #include <lunchbox/log.h>
22 : #include <lunchbox/sleep.h>
23 : #include <lunchbox/thread.h>
24 :
25 : #include <cstdlib>
26 : #include <fstream>
27 :
28 : #define OUTPUT lunchbox::Log::instance( __FILE__, __LINE__ )
29 :
30 : #define TEST( x ) \
31 : { \
32 : LBVERB << "Test " << #x << std::endl; \
33 : if( !(x) ) \
34 : { \
35 : OUTPUT << #x << " failed (l." << __LINE__ << ')' << std::endl; \
36 : lunchbox::abort(); \
37 : } \
38 : }
39 :
40 : #define TESTINFO( x, info ) \
41 : { \
42 : LBVERB << "Test " << #x << ": " << info << std::endl; \
43 : if( !(x) ) \
44 : { \
45 : OUTPUT << #x << " failed (l." << __LINE__ << "): " << info \
46 : << std::endl; \
47 : lunchbox::abort(); \
48 : } \
49 : }
50 :
51 : int testMain( int argc, char **argv );
52 :
53 : namespace
54 : {
55 29 : class Watchdog : public lunchbox::Thread
56 : {
57 : public:
58 29 : explicit Watchdog( const std::string& name ) : _name( name ) {}
59 :
60 26 : virtual void run()
61 : {
62 26 : lunchbox::Thread::setName( "Watchdog" );
63 : #ifdef TEST_RUNTIME
64 7 : lunchbox::sleep( TEST_RUNTIME * 1000 );
65 0 : TESTINFO( false,
66 : "Watchdog triggered - " << _name <<
67 0 : " did not terminate within " << TEST_RUNTIME << "s" );
68 : #else
69 19 : lunchbox::sleep( 60000 );
70 0 : TESTINFO( false,
71 : "Watchdog triggered - " << _name <<
72 0 : " did not terminate within 1 minute" );
73 : #endif
74 0 : }
75 :
76 : private:
77 : const std::string _name;
78 : };
79 : }
80 :
81 29 : int main( int argc, char **argv )
82 : {
83 : #ifndef TEST_NO_WATCHDOG
84 29 : Watchdog watchdog( argv[0] );
85 29 : watchdog.start();
86 : #endif
87 :
88 29 : const int result = testMain( argc, argv );
89 29 : if( result != EXIT_SUCCESS )
90 0 : return result;
91 :
92 : #ifndef TEST_NO_WATCHDOG
93 29 : watchdog.cancel();
94 29 : lunchbox::sleep( 10 ); // give watchdog time to terminate
95 : #endif
96 29 : return EXIT_SUCCESS;
97 : }
98 :
99 : # define main testMain
100 :
101 : #endif // LBTEST_TEST_H
|