Skip to content

Commit

Permalink
Merge pull request #3 from bxparks/develop
Browse files Browse the repository at this point in the history
0.1.1 - support usage inside continuous build
  • Loading branch information
bxparks authored Aug 14, 2019
2 parents 4c39122 + e134c91 commit 73d3969
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static void die(const char* s) {
}

static void disableRawMode() {
if (!isatty(STDIN_FILENO)) return;
if (!inRawMode) return;
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) == -1) {
inRawMode = false; // prevent exit(1) from being called twice
Expand All @@ -78,9 +79,9 @@ static void disableRawMode() {
}

static void enableRawMode() {
if (!isatty(STDIN_FILENO)) {
die("enableRawMode(): redirection on STDIN not supported");
}
// If STDIN is not a real tty, simply return instead of dying so that the
// unit tests can run in a continuous integration framework, e.g. Jenkins.
if (!isatty(STDIN_FILENO)) return;
if (tcgetattr(STDIN_FILENO, &orig_termios) == -1) {
die("enableRawMode(): tcgetattr() failure");
}
Expand All @@ -106,6 +107,7 @@ static void enableRawMode() {
}

static void handleControlC(int /*sig*/) {
if (!isatty(STDIN_FILENO)) return;
if (inRawMode) {
// If this returns an error, don't call die() because it will call exit(),
// which may call this again, causing an infinite recursion.
Expand Down
4 changes: 2 additions & 2 deletions Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// Macros defined when running under UnixHostDuino
#define UNIX_HOST_DUINO 1
// xx.yy.zz => xxyyzz (without leading 0)
#define UNIX_HOST_DUINO_VERSION 100
#define UNIX_HOST_DUINO_VERSION_STRING "0.1"
#define UNIX_HOST_DUINO_VERSION 101
#define UNIX_HOST_DUINO_VERSION_STRING "0.1.1"

// Used by digitalRead() and digitalWrite()
#define HIGH 0x1
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

* Unreleased
* 0.1.1 (2019-08-14)
* If the STDIN is not a real tty, continue without putting it into raw mode
or exiting with an error. This allows unit tests inside continuous build
frameworks.
* 0.1 (2019-07-31)
* Split from `AUnit` and renamed from `unitduino` to `UnixHostDuino`.
* Add `UNIT_HOST_DUINO` macro.
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Running an Arduino program natively on Linux or MacOS has some advantages:
* The development cycle can be lot faster because the compilers on the the
desktop machines are a lot faster, and we also avoid the upload and flash
process to the microcontroller.
* The desktop machine can run unit tests which are too much flash or too
* The desktop machine can run unit tests which require too much flash or too
much memory to fit inside an embedded microcontroller.

The disadvantages are:
Expand All @@ -28,7 +28,7 @@ The disadvantages are:
* There may be compiler differences between the desktop and the embedded
environments (e.g. 8-bit integers versus 64-bit integers).

Version: 0.1 (2019-07-31)
Version: 0.1.1 (2019-08-14)

## Usage

Expand Down Expand Up @@ -219,6 +219,20 @@ See [CHANGELOG.md](CHANGELOG.md).

[MIT License](https://opensource.org/licenses/MIT)

## Bugs and Limitations

If the executable (e.g. `SampleTest.out`) is piped to the `less(1)` or `more(1)`
command, sometimes (not all the time) the executable hangs and displays nothing
on the pager program. I don't know why, it probably has to do with the way that
the `less` or `more` programs manipulate the `stdin`. The solution is to
explicitly redirect the `stdin`:

```
$ ./SampleTest.out | less # hangs
$ ./SampleTest.out < /dev/null | less # works
```

## Feedback and Support

If you have any questions, comments, bug reports, or feature requests, please
Expand Down

0 comments on commit 73d3969

Please sign in to comment.