8 #include <sys/socket.h> 39 Main() : suite(0), test(0) {
40 suite_ok = suite_failed = 0;
41 total_ok = total_failed = 0;
48 close( status_fds[0] );
49 close( confirm_fds[1] );
55 std::cerr <<
"No such suite " << argv[1] << std::endl;
62 int t = strtol( argv[2], &end, 0 );
63 if ( end == argv[2] && t == 0 ) {
66 std::cerr <<
"No such test " << argv[2]
67 <<
" in suite " << argv[1] << std::endl;
87 #pragma GCC diagnostic push 88 #pragma GCC diagnostic ignored "-Wold-style-cast" 91 if ( WIFEXITED( status_code ) ) {
92 if ( WEXITSTATUS( status_code ) == 250 )
94 if ( WEXITSTATUS( status_code ) == 0 )
97 std::cout <<
"--> FAILED: "<<
current;
98 if ( WIFEXITED( status_code ) )
99 std::cout <<
" (exit status " << WEXITSTATUS( status_code ) <<
")";
100 if ( WIFSIGNALED( status_code ) )
101 std::cout <<
" (caught signal " << WTERMSIG( status_code ) <<
")";
102 std::cout << std::endl;
108 #pragma GCC diagnostic pop 114 if ( line ==
"done" ) {
116 #pragma GCC diagnostic push 117 #pragma GCC diagnostic ignored "-Wold-style-cast" 119 finished = waitpid( pid, &status_code, 0 );
121 assert( WIFEXITED( status_code ) );
122 assert_eq( WEXITSTATUS( status_code ), 0 );
124 #pragma GCC diagnostic pop 126 std::cout <<
"overall " << total_ok <<
"/" 127 << total_ok + total_failed
128 <<
" ok" << std::endl;
129 exit( total_failed == 0 ? 0 : 1 );
135 std::cout <<
"." << std::flush;
141 if ( line[0] ==
's' ) {
142 if ( line[2] ==
'd' ) {
143 std::cout <<
" " << suite_ok <<
"/" << suite_ok + suite_failed
144 <<
" ok" << std::endl;
149 suite_ok = suite_failed = 0;
151 if ( line[2] ==
's' ) {
152 if ( announced_suite < suite ) {
153 std::cout << std::string( line.begin() + 5, line.end() )
154 <<
": " << std::flush;
155 announced_suite =
suite;
159 if ( line[0] ==
't' ) {
160 if ( line[2] ==
'd' ) {
164 if ( line[2] ==
's' ) {
166 current = std::string( line.begin() + 5, line.end() );
173 close( status_fds[1] );
174 close( confirm_fds[0] );
179 if ( p_status.
eof() ) {
180 finished = waitpid( pid, &status_code, 0 );
181 if ( finished < 0 ) {
182 perror(
"waitpid failed" );
201 ::write( status_fds[ 1 ], line.c_str(), line.length() );
208 std::string line(
"ack\n" );
210 ::write( confirm_fds[ 1 ], line.c_str(), line.length() );
220 int main(
int _argc,
char **_argv )
229 want_fork = argc <= 2;
236 if ( socketpair( PF_UNIX,SOCK_STREAM, 0, status_fds ) )
238 if ( socketpair( PF_UNIX,SOCK_STREAM, 0, confirm_fds ) )
258 return Main().main( argc, argv );
int confirm_fds[2]
Definition: test-main.h:22
int suiteCount
Definition: test-runner.h:38
void status(std::string line)
Definition: test-main.h:196
RunSuite * findSuite(std::string name)
Definition: test-runner.h:41
void processStatus(std::string line)
Definition: test-main.h:112
void waitForAck()
Definition: test-main.h:213
wibble::sys::Pipe p_status
Definition: test-main.h:19
void child()
Definition: test-main.h:46
wibble::sys::Pipe p_confirm
Definition: test-main.h:20
int suite_ok
Definition: test-main.h:30
RunAll all
Definition: test-main.h:37
void runTest(RunSuite &s, int test)
Definition: test-runner.h:65
bool want_fork
Definition: test-main.h:35
std::string current
Definition: test-main.h:34
Definition: test-runner.h:31
int suite
Definition: test-main.h:18
#define assert_eq(x, y)
Definition: test.h:33
#define assert(x)
Definition: test.h:30
Main()
Definition: test-main.h:39
char ** argv
Definition: test-main.h:25
int main(int _argc, char **_argv)
Definition: test-main.h:220
int findTest(std::string name)
Definition: test-runner.h:22
int status_code
Definition: test-main.h:27
Definition: test-runner.h:17
int test_ok
Definition: test-main.h:28
std::string nextLineBlocking()
Definition: pipe.h:204
Definition: test-runner.h:36
void confirm()
Definition: test-main.h:207
int total_ok
Definition: test-main.h:31
int total_failed
Definition: test-main.h:31
int test
Definition: test-main.h:18
int suite_failed
Definition: test-main.h:30
int argc
Definition: test-main.h:24
pid_t pid
Definition: test-main.h:23
pid_t finished
Definition: test-main.h:26
int announced_suite
Definition: test-main.h:33
void runSuite(RunSuite &s, int fromTest, int suite, int suiteCount)
Definition: test-runner.h:48
Definition: test-main.h:16
RunSuite * suites
Definition: test-runner.h:37
int status_fds[2]
Definition: test-main.h:21
bool eof()
Definition: pipe.h:130
ListIterator< List > end(List)
Definition: list.h:425
void runFrom(int suite, int test)
Definition: test-runner.h:76
RunFeedback * feedback
Definition: test-runner.h:39