Refactor test scripts to use functions (#18)

The goal was to remove a lot of the duplicated code. Also made it
easier to sweep the protocol and number of bytes transferred.