Centralize test helpers and try to make spurious failures from output interleaving less frequent.

The "atomic_print*" helpers aren't actually atomic, but they should do better than the mixed stdio/direct-write.  If intermittent failures become a problem again we should be able to make the helpers actually atomic.  Or more so.

Resolves #343.