Comments (9)
If you're interested in this, I can port my pull request from gitlab and resubmit it here.
from serialport-rs.
Thank you for your offer!
I admittedly have only given the issue a quick read, but I think you make some good arguments! I figure now is as good a time as any to make API changes as well. I will need to read through the original comment thread again at some point.
I don't have a timeline for when I will get to it, but if you're willing to open a PR with your changes here I would encourage you to do so!
from serialport-rs.
Very good suggestions.
If I'm understanding this correctly, I think that the final bullet item under your Disadvantages section is actually a 'feature' suggestion and should be moved out of the 'Disadvantages' section. Or maybe I'm misreading it?
from serialport-rs.
from serialport-rs.
The disadvantage is that if the Serialport type is a concrete (struct) type rather than a trait, it is harder to mock out in unit tests. I just then spend much more time describing ways to make it easier to work around that disadvantage.
Does the serial port itself need to be a trait for mocking? I'm wondering to which extend mocking will be used and makes sense in unit tests. I've seen https://github.com/dbrgn/embedded-hal-mock where mocking happens with respect to traits of embedded-hal. This allows for example to mock I2C communication at the level of the I2C traits like i2c::Read
, i2c::Write
, and i2c::WriteRead
but not the initialization of a certain I2C controller.
Wouldn't mocking io::Read
and io::Write
for a serial port be a Pareto-style solution for mocking general serial communication? Just as a first thought, mocking things like changing baud rate, parity, ... "in-flight" looks like where things get rough. In contrast, just mocking the read and write traits seems pretty straightforward to me. And if there is a really a good use case, we could still introduce for example a configuration trait for it.
from serialport-rs.
from serialport-rs.
Per 'sirhcel's comment above, with regards to this crate's unit test having the ability to operate without physical serial ports (using mocked hardware), I believe a key question to ask is how beneficial this approach can realistically be. Writing code that in-fact copies data streams around in memory (rather than actually transferring over a physical port) is quite difficult to accurately and precisely implement in a way that comes close to modeling real hardware with respect to behavior and timing. It's the intricacies of various platform I/O and serial hardware port behavior that offers the most benefit while unit testing. I also recognize that in an ideal world one would like to unit test their code without operator involvement and in a fully automated fashion, but in the world of physical hardware this is rarely feasible.
from serialport-rs.
That is esssentially what my proposal is -- make SerialPort a struct and let people mock read/write and optionally add a trait for the serialport controls, if needed. Note that because of how traits work in rust, anyone who really needs it could just write their own 'serialport controls' trait to test against and implement it for our SerialPort type, so I don't even think it's necessary to provide such a trait, but I wanted to describe the option in case other people thought it was important.
Alright, then we are on the same page. This is the way I would like to go forward with it. And just not confusing things: Are you referring to PR #34 from #28 (comment)?
from serialport-rs.
Per 'sirhcel's comment above, with regards to this crate's unit test having the ability to operate without physical serial ports (using mocked hardware), I believe a key question to ask is how beneficial this approach can realistically be. Writing code that in-fact copies data streams around in memory (rather than actually transferring over a physical port) is quite difficult to accurately and precisely implement in a way that comes close to modeling real hardware with respect to behavior and timing. It's the intricacies of various platform I/O and serial hardware port behavior that offers the most benefit while unit testing. I also recognize that in an ideal world one would like to unit test their code without operator involvement and in a fully automated fashion, but in the world of physical hardware this is rarely feasible.
Sorry I did not read the original message right in the first place. Now I understand that @zstewar1 talked about the possibilities to mock the proposed static serial port. Yes, a static serial port struct would be harder to mock completely. But to me this does not seem relevant as - as you already said - mocking timing behaviour and other nitty gritty details won't get you both finished and far.
So from my Pareto-perspective, implementing io::Read
and io::Write
is fine for almost anyone. And if there is a significant demand, I bet we will learn about it when working towards 5.0.
In theory, we could statically analyze code of our known and actively maintained dependents. But I have only vaguely heared about this and crater so far. Any show and tell is welcome.
from serialport-rs.
Related Issues (20)
- Dependency on unmaintained crates HOT 12
- Publish 4.2.2 version on crates.io HOT 2
- Type of a serialport HOT 2
- Last port.write does not send all bytes on FTDI dongle HOT 7
- Read always timeout in arm-unknown-linux-musleabihf HOT 5
- Serial write stalls application on some Windows machines HOT 7
- Windows USB001 possible? HOT 2
- Wrong informations with Com port HOT 2
- FlowControl::Hardware not set on Siliconlabs Ember dongle on Linux HOT 9
- Linux: `serialport::available_ports()` returns generic USB strings instead of actual descriptor values HOT 3
- Add supported architecture HOT 2
- windows: UsbPortInfo: Provide the same info about Manufacturer and Product name as POSIX HOT 2
- Auto reconnect HOT 1
- use read_to_end always return TimedOut err HOT 2
- Stuck when writing data to the serial port if paired port is not open [Windows 11] HOT 2
- USB ports detected as unknown in docker HOT 1
- Print to COM port via USB to SERIAL converter cable on Windows HOT 1
- Set a Custom Baudrate HOT 1
- Unplug serial device cause system shutdown on windows HOT 5
- Fast receive missing beginning of packet HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serialport-rs.