You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/01/14 00:24:29 UTC

[2/3] incubator-mynewt-larva git commit: Fix testutil bug: clear timers and signals.

Fix testutil bug: clear timers and signals.

If the OS were stopped, and subsequent tests took long enough, the
itimer would deliver a SIGVTALRM signal.  Because the OS was no longer
running, the signal handler would perform invalid memory accesses.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/b2fde971
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/b2fde971
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/b2fde971

Branch: refs/heads/master
Commit: b2fde9718f10f8936aafd54c128799874e6bb260
Parents: 40662ac
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Jan 13 13:12:33 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Jan 13 15:23:35 2016 -0800

----------------------------------------------------------------------
 libs/os/include/os/arch/sim/os/os_arch.h       |  1 +
 libs/os/src/arch/sim/os_arch_sim.c             | 39 +++++++++++++++++++++
 libs/testutil/src/arch/sim/testutil_arch_sim.c |  3 +-
 3 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b2fde971/libs/os/include/os/arch/sim/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/sim/os/os_arch.h b/libs/os/include/os/arch/sim/os/os_arch.h
index 3466727..3b0f212 100644
--- a/libs/os/include/os/arch/sim/os/os_arch.h
+++ b/libs/os/include/os/arch/sim/os/os_arch.h
@@ -58,6 +58,7 @@ void os_arch_ctx_sw_isr(struct os_task *);
 os_sr_t os_arch_save_sr(void);
 void os_arch_restore_sr(int);
 os_error_t os_arch_os_init(void);
+void os_arch_os_stop(void);
 os_error_t os_arch_os_start(void);
 
 void os_bsp_init(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b2fde971/libs/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_arch_sim.c b/libs/os/src/arch/sim/os_arch_sim.c
index 0c83487..25f3833 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -245,6 +245,17 @@ initialize_signals(void)
     sigaction(SIGVTALRM, &sa, NULL);
 }
 
+static void
+cancel_signals(void)
+{
+    struct sigaction sa;
+
+    memset(&sa, 0, sizeof sa);
+    sa.sa_handler = SIG_DFL;
+
+    sigaction(SIGALRM, &sa, NULL);
+    sigaction(SIGVTALRM, &sa, NULL);
+}
 
 static void
 timer_handler(int sig)
@@ -305,6 +316,24 @@ start_timer(void)
     }
 }
 
+static void
+stop_timer(void)
+{
+    struct itimerval it;
+    int rc;
+
+    memset(&it, 0, sizeof(it));
+
+    rc = setitimer(ITIMER_VIRTUAL, &it, NULL);
+    if (rc != 0) {
+        const char msg[] = "Cannot stop itimer";
+        write(2, msg, sizeof(msg));
+        _exit(1);
+    }
+
+    cancel_signals();
+}
+
 os_error_t 
 os_arch_os_init(void)
 {
@@ -340,3 +369,13 @@ os_arch_os_start(void)
     return 0;
 }
 
+/**
+ * Stops the tick timer and clears the "started" flag.  This function is only
+ * implemented for sim.
+ */
+void
+os_arch_os_stop(void)
+{
+    stop_timer();
+    g_os_started = 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b2fde971/libs/testutil/src/arch/sim/testutil_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/testutil/src/arch/sim/testutil_arch_sim.c b/libs/testutil/src/arch/sim/testutil_arch_sim.c
index dbb39b4..3ab49bf 100644
--- a/libs/testutil/src/arch/sim/testutil_arch_sim.c
+++ b/libs/testutil/src/arch/sim/testutil_arch_sim.c
@@ -15,12 +15,13 @@
  */
 
 #include "os/os.h"
+#include "os/os_arch.h"
 #include "os/os_test.h"
 #include "testutil_priv.h"
 
 void
 tu_arch_restart(void)
 {
-    g_os_started = 0;
+    os_arch_os_stop();
     tu_case_abort();
 }