I'm currently writing up some CPPunit tests for a program that tests a hardware communication port (yes, I'm writing unit tests for a tester app ;-) ). One of the classes I'm testing is basically a wrapper around the device's file descriptor; I make read()
and write()
calls on the file descriptor. Is there a device file/driver on Linux where if you write()
to it, when you read()
from it you will read back what you wrote (like a FIFO queue device)? If I had this device file, it would be really simple to plop that in place of the actual device file in my wrapper and would make it easy to emulate "loopback" scenarios that might occur on real-world hardware.
Essentially what I'm looking for would be a sort of hypothetical "/dev/echo"
device.
Ex: The device would behave as follows:
open("/dev/echo", O_RDRW);
write(fdEcho, 123, sizeof(int));
write(fdEcho, 456, sizeof(int));
write(fdEcho, 789, sizeof(int));
read(fdEcho, iData, sizeof(int); // returns 123
read(fdEcho, iData2, sizeof(int); // returns 456
read(fdEcho, iData3, sizeof(int); // returns 789