|
Boost : |
Subject: [boost] [asio] Any interest in a boost::asio::mockup_serial_port ?
From: Damien Buhl (damien.buhl_at_[hidden])
Date: 2015-12-05 22:38:40
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<mockup_serial_port_service> 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<mockup_serial_port_service> 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk