libept
test-runner.h
Go to the documentation of this file.
1 #include <unistd.h>
2 
3 #define RUN(x, y) x().y()
4 
5 struct RunTest {
6  const char *name;
7  void (*run)();
8 };
9 
10 struct RunSuite {
11  const char *name;
13  int testCount;
14 };
15 
16 struct RunAll {
19  FILE *status, *confirm;
20 
21  RunSuite *findSuite( std::string name ) {
22  for ( int i = 0; i < suiteCount; ++i )
23  if ( suites[i].name == name )
24  return suites + i;
25  return 0;
26  }
27 
28  void waitForAck() {
29  size_t n = 0; char *line = 0;
30  size_t read = getline( &line, &n, confirm );
31  assert_eq( read, 4 );
32  assert_eq( std::string( "ack\n" ), line );
33  free( line );
34  }
35 
36  void runSuite( RunSuite &s, int fromTest, int suite, int suiteCount )
37  {
38  fprintf( status, "s/s: (%d/%d) %s\n", suite + 1, suiteCount, s.name );
39  for ( int i = fromTest; i < s.testCount; ++i ) {
40  fprintf( status, "t/s: (%d/%d) %s\n", i, s.testCount,
41  s.tests[i].name );
42  fflush( status );
43  waitForAck();
44  s.tests[i].run();
45  fprintf( status, "t/d: %s\n", s.tests[i].name );
46  fflush( status );
47  waitForAck();
48  // exit( 0 ); // TODO make this optional; safety vs
49  // performance tradeoff
50  }
51  fprintf( status, "s/d: %s\n", s.name );
52  }
53 
54  void runFrom( int suite, int test )
55  {
56  for ( int i = suite; i < suiteCount; ++i ) {
57  assert( suite <= suiteCount );
58  runSuite( suites[i], test, i, suiteCount );
59  test = 0;
60  }
61  }
62 };
63