From 6243aca6c37e4c9cce9b871a173cde921b45d970 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Fri, 2 Aug 2019 20:20:42 -0700 Subject: [PATCH 1/5] Arduino.cpp: Don't bother setting STDIN to raw mode if not a real tty (e.g. if being run inside a continuous build) --- Arduino.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Arduino.cpp b/Arduino.cpp index f243680..14a46a8 100644 --- a/Arduino.cpp +++ b/Arduino.cpp @@ -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 @@ -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"); } @@ -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. From 3cf750c485cc33b60ecb48addf4f802dbd93ce65 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Fri, 2 Aug 2019 20:35:53 -0700 Subject: [PATCH 2/5] CHANGELOG.md: Update that STDIN is left alone if redirected, to allow running inside continuous builds --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7dd2ec..db04dc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog * Unreleased + * If the STDIN is not a real tty, don't bother putting it into raw mode, + to allow 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. From 315e9009258bf26dc8cff90d022c5fa904df4d0e Mon Sep 17 00:00:00 2001 From: Brian Park Date: Mon, 5 Aug 2019 11:57:10 -0700 Subject: [PATCH 3/5] README.md: Add a BUGS section that explains hanging with less(1) command and how to work around it --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 3b85259..6713857 100644 --- a/README.md +++ b/README.md @@ -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 From f1237d70bb207b49b9614d41fb46ce05b1ec77e3 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Wed, 14 Aug 2019 09:58:14 -0700 Subject: [PATCH 4/5] README.md: Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6713857..3846837 100644 --- a/README.md +++ b/README.md @@ -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: From e134c915e08234837dd73a1a8560f4758711e056 Mon Sep 17 00:00:00 2001 From: Brian Park Date: Wed, 14 Aug 2019 10:01:02 -0700 Subject: [PATCH 5/5] Bump version to 0.1.1 --- Arduino.h | 4 ++-- CHANGELOG.md | 6 ++++-- README.md | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Arduino.h b/Arduino.h index a5b65ec..a8b5a11 100644 --- a/Arduino.h +++ b/Arduino.h @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index db04dc3..d130c94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # Changelog * Unreleased - * If the STDIN is not a real tty, don't bother putting it into raw mode, - to allow unit tests inside continuous build frameworks. +* 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. diff --git a/README.md b/README.md index 3846837..6577b84 100644 --- a/README.md +++ b/README.md @@ -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