I have two laptops with a serial port. How do I test the actual bandwidth of the serial port between the two machines using a simple, small C program?
In reality, I need to do this on an embedded Linux system which is why the utility must be a small, simple C program (because the embedded environment only has limited library support meaning it doesn’t have python, perl, or any other fancy libraries).
I started this as a new question because I didn’t want to take this question off topic: Serial port loopback test
That question was regarding testing the bandwidth of a serial port in loopback mode, so that you don’t have to plug in an actual serial cable. The author (sdaau) put a lot of time into creating a multi-threaded serial bandwidth test program to answer his own question. I then used his simple C program and extended it to be used between two different physical machines connected with a serial cable.
It is necessary to start the “remote” side which will wait for the “initiator” side (the local side) to send a go byte, in which both will proceed to transfer data asynchronously. The program (which sdaau calls writeread.c) spawns 2 threads: one which writes data and the other which reads data. In this way, you are fully utilizing the serial port. You can pass in a datafile as a command-line argument.
As an example, here is the “remote” side:
As an example, here is the “local” (or initiator) side:
Note that I had some trouble redirecting the output on the remote side, meaning that
3> outputdidn’t really work. I’m not sure whats going on with that, but my local side worked fine. Also, note the remote side’s output timing is skewed because it has a timer running while it is waiting for the initiator. This means you should only trust the bandwidth printout from the local initiator side (see the original question for output results details).Since both sides are sending the same datafile in this example, you should be able to compare the “output” file with the datafile:
Complie the code with:
Here is the modified writeread.c code:
And here is the .h file which I have renamed from the original question to writeread.h: