9 #include <sys/socket.h>
17 wibble::sys::Pipe p_status;
18 wibble::sys::Pipe p_confirm;
28 int suite_ok, suite_failed;
29 int total_ok, total_failed;
37 Main() : suite(0), test(0) {
38 suite_ok = suite_failed = 0;
39 total_ok = total_failed = 0;
45 close( status_fds[0] );
46 close( confirm_fds[1] );
47 p_confirm = wibble::sys::Pipe( confirm_fds[0] );
49 RunSuite *s = all.findSuite( argv[1] );
51 std::cerr <<
"No such suite " << argv[1] << std::endl;
58 int t = strtol( argv[2], &end, 0 );
59 if ( end == argv[2] && t == 0 ) {
62 std::cerr <<
"No such test " << argv[2]
63 <<
" in suite " << argv[1] << std::endl;
71 all.runSuite( *s, test, 0, 1 );
74 all.runFrom( suite, test );
84 if ( WIFEXITED( status_code ) ) {
85 if ( WEXITSTATUS( status_code ) == 250 )
87 if ( WEXITSTATUS( status_code ) == 0 )
90 std::cout <<
"--> FAILED: "<< current;
91 if ( WIFEXITED( status_code ) )
92 std::cout <<
" (exit status " << WEXITSTATUS( status_code ) <<
")";
93 if ( WIFSIGNALED( status_code ) )
94 std::cout <<
" (caught signal " << WTERMSIG( status_code ) <<
")";
95 std::cout << std::endl;
103 void processStatus( std::string line ) {
105 if ( line ==
"done" ) {
107 finished = waitpid( pid, &status_code, 0 );
109 assert( WIFEXITED( status_code ) );
110 assert_eq( WEXITSTATUS( status_code ), 0 );
112 std::cout <<
"overall " << total_ok <<
"/"
113 << total_ok + total_failed
114 <<
" ok" << std::endl;
115 exit( total_failed == 0 ? 0 : 1 );
121 std::cout <<
"." << std::flush;
127 if ( line[0] ==
's' ) {
128 if ( line[2] ==
'd' ) {
129 std::cout <<
" " << suite_ok <<
"/" << suite_ok + suite_failed
130 <<
" ok" << std::endl;
133 total_ok += suite_ok;
134 total_failed += suite_failed;
135 suite_ok = suite_failed = 0;
137 if ( line[2] ==
's' ) {
138 if ( announced_suite < suite ) {
139 std::cout << std::string( line.begin() + 5, line.end() )
140 <<
": " << std::flush;
141 announced_suite = suite;
145 if ( line[0] ==
't' ) {
146 if ( line[2] ==
'd' ) {
150 if ( line[2] ==
's' ) {
152 current = std::string( line.begin() + 5, line.end() );
158 close( status_fds[1] );
159 close( confirm_fds[0] );
160 p_status = wibble::sys::Pipe( status_fds[ 0 ]);
164 if ( p_status.eof() ) {
165 finished = waitpid( pid, &status_code, 0 );
166 if ( finished < 0 ) {
167 perror(
"waitpid failed" );
175 line = p_status.nextLineBlocking();
176 processStatus( line );
180 void status( std::string line ) {
184 ::write( status_fds[ 1 ], line.c_str(), line.length() );
186 processStatus( line );
190 std::string line(
"ack\n" );
192 ::write( confirm_fds[ 1 ], line.c_str(), line.length() );
197 std::string line = p_confirm.nextLineBlocking();
202 int main(
int _argc,
char **_argv )
207 all.suiteCount =
sizeof(suites)/
sizeof(
RunSuite);
210 want_fork = argc <= 2;
213 if ( socketpair( PF_UNIX,SOCK_STREAM, 0, status_fds ) )
215 if ( socketpair( PF_UNIX,SOCK_STREAM, 0, confirm_fds ) )
232 int main(
int argc,
char **argv ) {
233 return Main().main( argc, argv );
239 int main(
int argc,
char **argv ) {
240 std::cerr <<
"Sorry, test runner not implemented on this non-POSIX platform." << std::endl;