Flush stdout with initial BEGIN_TEST message (#3185)
Flush stdout with initial BEGIN_TEST message (#3185)

Each unit test suite is encapsulated in BEGIN_TEST and END_TEST macro's. An initial message is printed to stdout by the former macro: fprintf(stdout, "Running %-50s ... ", __FILE__);

When writing a test suite that initially forks a number of child processes, the kernel sometimes still have the data buffered for the stdout fd, before the fork is executed. In a 3-fork test suite this creates the following output:

$ ./bin/s2n_foo_test 
Running ../tests/unit/s2n_foo_test.c    ... In child 0
Running ../tests/unit/s2n_foo_test.c    ... In child 1
Running ../tests/unit/s2n_foo_test.c    ... In child 2
Running ../tests/unit/s2n_foo_test.c    ... PASSED          3 tests

which is not the intention. To prevent this, simply flush stdout.
PKRoma/s2n,PKRoma/s2n,PKRoma/s2n,PKRoma/s2n,PKRoma/s2n,PKRoma/s2n,PKRoma/s2n,PKRoma/s2n