[asio] Any interest in a boost::asio::mockup_serial_port ?
Dear Boost.Asio developers, I wanted to know if there was any interest for a mockup_serial_port_service, so that one might write cross platform unit-tests of code based on serial_port. I implemented this mockup this summer for a project where the best way to unit test some modules was to act as another peer on a serial port and needed to be doable on any platform supported by asio::serial_port. I find it quite useful, because there - is no need to use separate tools like socat on linux or install virtual COM ports applications on windows. Which ease the setup of the test environment - the fake serial port doesn't pollute the system where the test is run - many test cases can be run in parallel, as there is no native ressources involved. One might use it as this :
using namespace boost::asio;
boost::thread simulate_writing_device([](){ io_service ios; basic_serial_port
port{ios, "my_fake_serial_port"}; const std::string message = "Hello";
for (;;) { boost::asio::write(port, buffer(message.data(), message.size())); boost::this_thread::sleep_for(boost::chrono::seconds(1)); }
});
boost::thread simulate_reading_device([](){ io_service ios; basic_serial_port
port{ios, "my_fake_serial_port"}; for (;;) { char message[5]; boost::asio::read(port, buffer(message, 5)); std::cout << "received : " << std::string(message, 5) << std::endl; }
});
A short documentation is available here : http://goo.gl/24JnUg And the implementation is on github in a holdall library for the moment : https://goo.gl/E7KGdn It's a library whose goal is to shrink over the time as they get merged in upstreams project. Hopefully there is interest for this mockup_serial_port, and if so I'll cleanup the code some more and make a pull-request to Boost.Asio. Cheers from Berlin where meetingcpp already ended :'-( -- Damien Buhl
On 12/06/2015 04:38 AM, Damien Buhl wrote:
I wanted to know if there was any interest for a mockup_serial_port_service, so that one might write cross platform unit-tests of code based on serial_port.
I am interested. While I do not use serial ports, I like your approach of using mock services. This approach can AFAICS be extended to sockets as well.
Hopefully there is interest for this mockup_serial_port, and if so I'll cleanup the code some more and make a pull-request to Boost.Asio.
I could be wrong, but I do not believe that the Boost.Asio author reads this mailing-list (or even the dedicated Asio mailing-list), so you may want to gauge his interest by writing directly to him (or by creating a github issue.)
On 06/12/2015 13:24, Bjorn Reese wrote:
I am interested. While I do not use serial ports, I like your approach of using mock services. This approach can AFAICS be extended to sockets as well.
Great. :) Yes I believe we could even factor out the serial_port part and make some kind of common mockup service. I'll take a look into it.
Hopefully there is interest for this mockup_serial_port, and if so I'll cleanup the code some more and make a pull-request to Boost.Asio.
I could be wrong, but I do not believe that the Boost.Asio author reads this mailing-list (or even the dedicated Asio mailing-list), so you may want to gauge his interest by writing directly to him (or by creating a github issue.)
Then I'll forward it to the Asio mailing-list, thanks for the tip.
participants (2)
-
Bjorn Reese
-
Damien Buhl