eclipse / mraa

Linux Library for low speed IO Communication in C with bindings for C++, Python, Node.js & Java. Supports generic io platforms, as well as Intel Edison, Intel Joule, Raspberry Pi and many more.
http://mraa.io
MIT License
1.37k stars 613 forks source link

[RFC] Adding mock capability #531

Closed alext-mkrs closed 8 years ago

alext-mkrs commented 8 years ago

Following discussions in #44 and #514 I'm going to dive a bit deeper into this and introduce mocking capability on a more basic level, which would make it available through all language bindings we support, without making extensive changes in the established code base.

This RFC is for the general architectural approach to this, as I can see at least a couple. Please let me know, what do you think, @arfoll, @tingleby and anyone else interested in the matter. Below are my thoughts based on my understanding of mraa's internals and a sort of a vision I have for this mocking capability. If you see any other general way of implementing this, I'm all ears.

  1. As long as we don't have a full-blown HAL in the library, where we could intercept calls to the HW and mock real platforms (like Edison), implementing something like this would require hacks and #ifdef's all over the place, so I don't think that would be a good way to go. If we were to go there, we'd probably want to #ifdef pieces of current HW-dependent code in our generic (like gpio.c) and board-specific (like intel_nuc5.c) files.
  2. In view of that, more viable approach I see here would be to add this capability as yet another "platform", like if it's an actual piece of HW. This contains the code (as we are using our established infra) and should require only a set of _replace functions in addition to the standard platform definition. The drawback is that we are not able to trick the user they're dealing with an actual Edison board, but the positive is that we have cleaner code and faster implementation of the capability + we can define it however we want in terms of pin numbers and their layout.
alext-mkrs commented 8 years ago

Just to make it clear - by "platform" I mean either the whole "platform type" or "architecture", like arm and x86 we currently have, or just another "platform" like NUC or Edison, within x86 type.

The former is cleaner and IMHO more logical + allows to create several different "mock boards", the latter would also work and save us some code to copy, but is inelegant.

alext-mkrs commented 8 years ago

You can see what I'm aiming at in this branch of my mraa repo fork.

alext-mkrs commented 8 years ago

As the first commit based on the proposed approach went in, this RFC is no longer needed. Closing.