tools: Don't fail TAP tests due to EAGAIN

It seems that in certain situations the stdout or stderr passed to
tap-driver returns EAGAIN on write(). So handle that by waiting
and trying again.