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/11/10 22:39:55 UTC

[48/50] [abbrv] incubator-mynewt-core git commit: MYNEWT-139: Regression testing on target devices

MYNEWT-139: Regression testing on target devices

Add support for semaphore and mempool testing on devices.
Refactor tests so that applications control resource allocation.
Add experimental code to suspend tasks.


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

Branch: refs/heads/master
Commit: bd6933cdcb4366c8c5259c16661eb232cd6c43f9
Parents: 406eeb0
Author: Peter Snyder <pe...@apache.org>
Authored: Thu Nov 10 13:29:40 2016 -0800
Committer: Peter Snyder <pe...@apache.org>
Committed: Thu Nov 10 13:29:40 2016 -0800

----------------------------------------------------------------------
 kernel/os/include/os/os_sched.h                 |   1 +
 kernel/os/include/os/os_task.h                  |   5 +-
 kernel/os/src/os_sched.c                        |  29 ++++
 kernel/os/src/os_task.c                         |  34 ++++
 kernel/os/test/src/eventq_test.c                |   2 -
 kernel/os/test/src/eventq_test.h                |   6 +
 kernel/os/test/src/mempool_test.c               | 168 ++-----------------
 kernel/os/test/src/mempool_test.h               |  16 +-
 kernel/os/test/src/mutex_test.c                 |  96 ++++++++---
 kernel/os/test/src/mutex_test.h                 |  41 +----
 kernel/os/test/src/os_test.c                    |  30 +++-
 kernel/os/test/src/os_test_priv.h               |  19 +++
 kernel/os/test/src/sem_test.c                   |  63 +++++--
 kernel/os/test/src/sem_test.h                   |  23 ---
 .../test/src/testcases/os_mempool_test_case.c   | 150 +++++++++++++++++
 .../os/test/src/testcases/os_mutex_test_basic.c |   8 +-
 .../test/src/testcases/os_mutex_test_case_1.c   |  21 +--
 .../test/src/testcases/os_mutex_test_case_2.c   |  23 ++-
 .../os/test/src/testcases/os_sem_test_basic.c   |   9 +-
 .../os/test/src/testcases/os_sem_test_case_1.c  |  13 +-
 .../os/test/src/testcases/os_sem_test_case_2.c  |  18 +-
 .../os/test/src/testcases/os_sem_test_case_3.c  |  18 +-
 .../os/test/src/testcases/os_sem_test_case_4.c  |  18 +-
 23 files changed, 488 insertions(+), 323 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/include/os/os_sched.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_sched.h b/kernel/os/include/os/os_sched.h
index 5f55a2d..df14ced 100644
--- a/kernel/os/include/os/os_sched.h
+++ b/kernel/os/include/os/os_sched.h
@@ -35,6 +35,7 @@ void os_sched_os_timer_exp(void);
 os_error_t os_sched_insert(struct os_task *);
 int os_sched_sleep(struct os_task *, os_time_t nticks);
 int os_sched_wakeup(struct os_task *);
+int os_sched_suspend(struct os_task *);
 void os_sched_resort(struct os_task *);
 os_time_t os_sched_wakeup_ticks(os_time_t now);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/include/os/os_task.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_task.h b/kernel/os/include/os/os_task.h
index 04de257..3aa46d5 100644
--- a/kernel/os/include/os/os_task.h
+++ b/kernel/os/include/os/os_task.h
@@ -46,7 +46,8 @@ struct os_task_obj
 /* Task states */
 typedef enum os_task_state {
     OS_TASK_READY = 1, 
-    OS_TASK_SLEEP = 2
+    OS_TASK_SLEEP = 2,
+    OS_TASK_SUSPEND = 3
 } os_task_state_t;
 
 /* Task flags */
@@ -95,6 +96,8 @@ struct os_task {
 int os_task_init(struct os_task *, const char *, os_task_func_t, void *,
         uint8_t, os_time_t, os_stack_t *, uint16_t);
 
+int os_task_suspend(struct os_task *t);
+
 uint8_t os_task_count(void);
 
 struct os_task_info {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/src/os_sched.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_sched.c b/kernel/os/src/os_sched.c
index 44ccd02..da90de1 100644
--- a/kernel/os/src/os_sched.c
+++ b/kernel/os/src/os_sched.c
@@ -194,6 +194,35 @@ os_sched_sleep(struct os_task *t, os_time_t nticks)
 }
 
 /**
+ * os sched suspend
+ *
+ * XXX
+ * NOTE - This routine is currently experimental and not ready for common use
+ *
+ * Stops a task and removes it from the run list
+ *
+ * @return int
+ *
+ * NOTE: must be called with interrupts disabled! This function does not call
+ * the scheduler
+ */
+int
+os_sched_suspend(struct os_task *t)
+{
+
+    if (t->t_state == OS_TASK_SLEEP) {
+        TAILQ_REMOVE(&g_os_sleep_list, t, t_os_list);
+    } else if (t->t_state == OS_TASK_READY) {
+        TAILQ_REMOVE(&g_os_run_list, t, t_os_list);
+    }
+    t->t_state = OS_TASK_SUSPEND;
+    t->t_next_wakeup = 0;
+    t->t_flags |= OS_TASK_FLAG_NO_TIMEOUT;
+
+    return OS_OK;
+}
+
+/**
  * os sched wakeup
  *
  * Called to wake up a task. Waking up a task consists of setting the task state

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/src/os_task.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_task.c b/kernel/os/src/os_task.c
index 9f7c2be..7254c8e 100644
--- a/kernel/os/src/os_task.c
+++ b/kernel/os/src/os_task.c
@@ -146,6 +146,40 @@ err:
     return (rc);
 }
 
+/*
+ * Suspend specified task
+ * XXX
+ * NOTE: This interface is currently experimental and not ready for common use
+ */
+int
+os_task_suspend(struct os_task *t)
+{
+    struct os_task *current;
+    int rc;
+    os_sr_t sr;
+
+    current = os_sched_get_current_task();
+    /*
+     * Can't suspend yourself
+     */
+    if (t->t_taskid == current->t_taskid) {
+        return OS_INVALID_PARM;
+    }
+
+    /*
+     * If state is not READY or SLEEP, assume task has not been initialized
+     */
+    if (t->t_state != OS_TASK_READY && t->t_state != OS_TASK_SLEEP)
+    {
+        return OS_NOT_STARTED;
+    }
+
+    OS_ENTER_CRITICAL(sr);
+    rc = os_sched_suspend(t);
+    OS_EXIT_CRITICAL(sr);
+    return rc;
+}
+
 /**
  * Iterate through tasks, and return the following information about them:
  *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/eventq_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/eventq_test.c b/kernel/os/test/src/eventq_test.c
index 5696645..01e8f3f 100644
--- a/kernel/os/test/src/eventq_test.c
+++ b/kernel/os/test/src/eventq_test.c
@@ -24,8 +24,6 @@
 #include "os_test_priv.h"
 #include "os/os_eventq.h"
 
-#define MY_STACK_SIZE        (5120)
-#define POLL_STACK_SIZE        (4096)
 /* Task 1 sending task */
 /* Define task stack and task object */
 #define SEND_TASK_PRIO        (1)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/eventq_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/eventq_test.h b/kernel/os/test/src/eventq_test.h
index 14eeb83..7d9af3d 100644
--- a/kernel/os/test/src/eventq_test.h
+++ b/kernel/os/test/src/eventq_test.h
@@ -30,8 +30,14 @@
 #extern "C" {
 #endif
 
+#if MYNEWT_VAL(SELFTEST)
 #define MY_STACK_SIZE        (5120)
 #define POLL_STACK_SIZE        (4096)
+#else
+#define MY_STACK_SIZE        (128)
+#define POLL_STACK_SIZE        (32) /* for now */
+#endif
+
 /* Task 1 sending task */
 /* Define task stack and task object */
 #define SEND_TASK_PRIO        (1)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/mempool_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mempool_test.c b/kernel/os/test/src/mempool_test.c
index c5ab365..1f4d23a 100644
--- a/kernel/os/test/src/mempool_test.c
+++ b/kernel/os/test/src/mempool_test.c
@@ -22,13 +22,6 @@
 #include "os/os.h"
 #include "os_test_priv.h"
 
-/* Create a memory pool for testing */
-#define NUM_MEM_BLOCKS  (10)
-#define MEM_BLOCK_SIZE  (80)
-
-/* Limit max blocks for testing */
-#define MEMPOOL_TEST_MAX_BLOCKS     (128)
-
 #if OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4
 int alignment = 4;
 #else
@@ -39,7 +32,8 @@ int alignment = 8;
 struct os_mempool g_TstMempool;
 
 /* Test memory pool buffer */
-os_membuf_t TstMembuf[OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE)];
+os_membuf_t *TstMembuf;
+uint32_t TstMembufSz;
 
 /* Array of block pointers. */
 void *block_array[MEMPOOL_TEST_MAX_BLOCKS];
@@ -61,152 +55,26 @@ mempool_test_get_pool_size(int num_blocks, int block_size)
 }
 
 void
-mempool_test(int num_blocks, int block_size)
+os_mempool_ts_pretest(void* arg)
 {
-    int cnt;
-    int true_block_size;
-    int mem_pool_size;
-    uint32_t test_block;
-    uint8_t *tstptr;
-    void **free_ptr;
-    void *block;
-    os_error_t rc;
-
-    /* Check for too many blocks */
-    TEST_ASSERT(num_blocks <= MEMPOOL_TEST_MAX_BLOCKS);
-
-    rc = os_mempool_init(&g_TstMempool, num_blocks, MEM_BLOCK_SIZE, 
-                         &TstMembuf[0], "TestMemPool");
-    TEST_ASSERT_FATAL(rc == 0, "Error creating memory pool %d", rc);
-
-    TEST_ASSERT(g_TstMempool.mp_num_free == num_blocks,
-                "Number of free blocks not equal to total blocks!");
-
-    TEST_ASSERT(SLIST_FIRST(&g_TstMempool) == (void *)&TstMembuf[0],
-                "Free list pointer does not point to first block!");
-
-    mem_pool_size = mempool_test_get_pool_size(num_blocks, block_size);
-    TEST_ASSERT(mem_pool_size == sizeof(TstMembuf),
-                "Total memory pool size not correct! (%d vs %lu)",
-                mem_pool_size, (unsigned long)sizeof(TstMembuf));
-
-    /* Get the real block size */
-#if (OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4)
-    true_block_size = (g_TstMempool.mp_block_size + 3) & ~3;
-#else
-    true_block_size = (g_TstMempool.mp_block_size + 7) & ~7;
-#endif
-
-    /* Traverse free list. Better add up to number of blocks! */
-    cnt = 0;
-    free_ptr = (void **)&TstMembuf;
-    tstptr = (uint8_t *)&TstMembuf;
-    while (1) {
-        /* Increment # of elements by 1 */
-        ++cnt;
-
-        /* If the free list is NULL, leave */
-        if (*free_ptr == NULL) {
-            break;
-        }
-
-        TEST_ASSERT(((uint8_t *)*free_ptr - (uint8_t *)free_ptr) ==
-                        true_block_size,
-                    "Free pointers are more than one block apart!");
-
-        /* Move to next memory block */
-        tstptr += true_block_size;
-
-        TEST_ASSERT(*free_ptr == (void *)tstptr,
-                    "Error: free_ptr=%p testptr=%p\n", *free_ptr, tstptr);
-
-        free_ptr = *free_ptr;
-    }
-
-    /* Last one in list better be NULL */
-    TEST_ASSERT(cnt == g_TstMempool.mp_num_blocks,
-                "Free list contains too many elements (%u)", cnt);
-
-    /* Get a block */
-    block = os_memblock_get(&g_TstMempool);
-    TEST_ASSERT(block != NULL,
-                "Error: get block fails when pool should have elements");
-
-    TEST_ASSERT(g_TstMempool.mp_num_free == (num_blocks-1),
-                "Number of free blocks incorrect (%u vs %u)",
-                g_TstMempool.mp_num_free, (num_blocks-1));
-
-    /* Put back the block */
-    rc = os_memblock_put(&g_TstMempool, block);
-    TEST_ASSERT(rc == 0, "Put block fails with error code=%d\n", rc);
-
-    TEST_ASSERT(g_TstMempool.mp_num_free == num_blocks,
-                "Number of free blocks incorrect (%u vs %u)",
-                g_TstMempool.mp_num_free, num_blocks);
-
-    /* remove all the blocks. Make sure we get count. */
-    memset(block_array, 0, sizeof(block_array));
-    cnt = 0;
-    while (1) {
-        block = os_memblock_get(&g_TstMempool);
-        if (block == NULL) {
-            break;
-        }
-        block_array[cnt] = block;
-        ++cnt;
-        if (cnt == MEMPOOL_TEST_MAX_BLOCKS) {
-            break;
-        }
-    }
-
-    TEST_ASSERT((cnt == g_TstMempool.mp_num_blocks) && 
-                (cnt != MEMPOOL_TEST_MAX_BLOCKS),
-                "Got more blocks than mempool contains (%d vs %d)",
-                cnt, g_TstMempool.mp_num_blocks);
-
-    /* Better be no free blocks left! */
-    TEST_ASSERT(g_TstMempool.mp_num_free == 0,
-                "Got all blocks but number free not zero! (%d)",
-                g_TstMempool.mp_num_free);
-
-    /* Now put them all back */
-    for (cnt = 0; cnt < g_TstMempool.mp_num_blocks; ++cnt) {
-        rc = os_memblock_put(&g_TstMempool, block_array[cnt]);
-        TEST_ASSERT(rc == 0,
-                    "Error putting back block %p (cnt=%d err=%d)", 
-                    block_array[cnt], cnt, rc);
-    }
-
-    /* Better be no free blocks left! */
-    TEST_ASSERT(g_TstMempool.mp_num_free == g_TstMempool.mp_num_blocks,
-                "Put all blocks but number free not equal to total!");
-
-    /* Better get error when we try these things! */
-    rc = os_memblock_put(NULL, block_array[0]);
-    TEST_ASSERT(rc != 0,
-                "Should have got an error trying to put to null pool");
-
-    rc = os_memblock_put(&g_TstMempool, NULL);
-    TEST_ASSERT(rc != 0, "No error trying to put to NULL block");
-
-    TEST_ASSERT(os_memblock_get(NULL) == NULL,
-                "No error trying to get a block from NULL pool");
+    sysinit();
+}
 
-    /* Attempt to free a block outside the range of the membuf */
-    test_block = g_TstMempool.mp_membuf_addr;
-    test_block -= 4;
-    rc = os_memblock_put(&g_TstMempool, (void *)test_block);
-    TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
+void
+os_mempool_ts_posttest(void* arg)
+{
+    return;
+}
 
-    test_block += (true_block_size * g_TstMempool.mp_num_blocks) + 100;
-    rc = os_memblock_put(&g_TstMempool, (void *)test_block);
-    TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
+void
+os_mempool_test_init(void *arg)
+{
+    TstMembufSz = (sizeof(os_membuf_t) *
+                 OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE));
+    TstMembuf = malloc(TstMembufSz);
 
-    /* Attempt to free on bad boundary */
-    test_block = g_TstMempool.mp_membuf_addr;
-    test_block += (true_block_size / 2);
-    rc = os_memblock_put(&g_TstMempool, (void *)test_block);
-    TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
+    tu_suite_set_pre_test_cb(os_mempool_ts_pretest, NULL);
+    tu_suite_set_post_test_cb(os_mempool_ts_posttest, NULL);
 }
 
 TEST_CASE_DECL(os_mempool_test_case)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/mempool_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mempool_test.h b/kernel/os/test/src/mempool_test.h
index 6f15e33..8a4d50a 100644
--- a/kernel/os/test/src/mempool_test.h
+++ b/kernel/os/test/src/mempool_test.h
@@ -29,12 +29,19 @@
 #extern "C" {
 #endif
 
+/* Limit max blocks for testing */
+#ifndef MEMPOOL_TEST_MAX_BLOCKS
+#define MEMPOOL_TEST_MAX_BLOCKS     (128)
+#endif
+
 /* Create a memory pool for testing */
-#define NUM_MEM_BLOCKS  (10)
+#ifndef MEM_BLOCK_SIZE
 #define MEM_BLOCK_SIZE  (80)
+#endif
 
-/* Limit max blocks for testing */
-#define MEMPOOL_TEST_MAX_BLOCKS     (128)
+#ifndef NUM_MEM_BLOCKS
+#define NUM_MEM_BLOCKS  (10)
+#endif
 
 extern int alignment;
 
@@ -42,7 +49,8 @@ extern int alignment;
 extern struct os_mempool g_TstMempool;
 
 /* Test memory pool buffer */
-extern os_membuf_t TstMembuf[OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE)];
+extern os_membuf_t *TstMembuf;
+extern uint32_t TstMembufSz;
 
 /* Array of block pointers. */
 extern void *block_array[MEMPOOL_TEST_MAX_BLOCKS];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/mutex_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mutex_test.c b/kernel/os/test/src/mutex_test.c
index c381cdd..8af567a 100644
--- a/kernel/os/test/src/mutex_test.c
+++ b/kernel/os/test/src/mutex_test.c
@@ -27,11 +27,24 @@
 #include "os_test_priv.h"
 
 #ifdef ARCH_sim
-#define MUTEX_TEST_STACK_SIZE   1024
-#else
-#define MUTEX_TEST_STACK_SIZE   256
+#define MUTEX_TEST_STACK_SIZE     OS_STACK_ALIGN(1024)
 #endif
 
+#if MYNEWT_VAL(SELFTEST)
+struct os_task task1;
+os_stack_t *stack1;
+
+struct os_task task2;
+os_stack_t *stack2;
+
+struct os_task task3;
+os_stack_t *stack3;
+
+struct os_task task4;
+os_stack_t *stack4;
+#endif /* MYNEWT_VAL(SELFTEST) */
+
+#if 0
 struct os_task task14;
 os_stack_t stack14[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
 
@@ -48,11 +61,12 @@ os_stack_t stack17[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
 #define TASK15_PRIO (5)
 #define TASK16_PRIO (6)
 #define TASK17_PRIO (7)
+#endif
 
-volatile int g_task14_val;
-volatile int g_task15_val;
-volatile int g_task16_val;
-volatile int g_task17_val;
+volatile int g_task1_val;
+volatile int g_task2_val;
+volatile int g_task3_val;
+volatile int g_task4_val;
 struct os_mutex g_mutex1;
 struct os_mutex g_mutex2;
 
@@ -138,23 +152,23 @@ mutex_test_basic_handler(void *arg)
 }
 
 void 
-mutex_test1_task14_handler(void *arg)
+mutex_test1_task1_handler(void *arg)
 {
     os_error_t err;
     struct os_task *t;
     int iters;
 
     t = os_sched_get_current_task();
-    TEST_ASSERT(t->t_func == mutex_test1_task14_handler);
+    TEST_ASSERT(t->t_func == mutex_test1_task1_handler);
 
     for (iters = 0; iters < 3; iters++) {
         os_time_delay(OS_TICKS_PER_SEC / 10);
 
-        g_task14_val = 1;
+        g_task1_val = 1;
 
         err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC / 10);
         TEST_ASSERT(err == OS_OK);
-        TEST_ASSERT(g_task16_val == 1);
+        TEST_ASSERT(g_task3_val == 1);
 
         os_time_delay(OS_TICKS_PER_SEC / 10);
     }
@@ -163,28 +177,28 @@ mutex_test1_task14_handler(void *arg)
 }
 
 void 
-mutex_test2_task14_handler(void *arg)
+mutex_test2_task1_handler(void *arg)
 {
     os_error_t err;
     struct os_task *t;
     int iters;
 
     t = os_sched_get_current_task();
-    TEST_ASSERT(t->t_func == mutex_test2_task14_handler);
+    TEST_ASSERT(t->t_func == mutex_test2_task1_handler);
 
     for (iters = 0; iters < 3; iters++) {
         err = os_mutex_pend(&g_mutex1, 0);
         TEST_ASSERT(err == OS_OK, "err=%d", err);
 
-        g_task14_val = 1;
+        g_task1_val = 1;
         os_time_delay(OS_TICKS_PER_SEC / 10);
 
         /* 
-         * Task17 should have its mutex wait flag set; at least the first time
+         * Task4 should have its mutex wait flag set; at least the first time
          * through!
          */
         if (iters == 0) {
-            TEST_ASSERT(task17.t_flags & OS_TASK_FLAG_MUTEX_WAIT);
+            TEST_ASSERT(task4.t_flags & OS_TASK_FLAG_MUTEX_WAIT);
         }
 
         if (g_mutex_test == 4) {
@@ -199,7 +213,7 @@ mutex_test2_task14_handler(void *arg)
 }
 
 void 
-task15_handler(void *arg) 
+mutex_task2_handler(void *arg) 
 {
     os_error_t err;
     struct os_task *t;
@@ -207,7 +221,7 @@ task15_handler(void *arg)
     if (g_mutex_test == 1) {
         while (1) {
             t = os_sched_get_current_task();
-            TEST_ASSERT(t->t_func == task15_handler);
+            TEST_ASSERT(t->t_func == mutex_task2_handler);
 
             os_time_delay(OS_TICKS_PER_SEC / 20);
             while (1) {
@@ -227,7 +241,7 @@ task15_handler(void *arg)
 
         while (1) {
             t = os_sched_get_current_task();
-            TEST_ASSERT(t->t_func == task15_handler);
+            TEST_ASSERT(t->t_func == mutex_task2_handler);
 
             err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
             if (g_mutex_test == 4) {
@@ -242,7 +256,7 @@ task15_handler(void *arg)
 }
 
 void 
-task16_handler(void *arg) 
+mutex_task3_handler(void *arg) 
 {
     os_error_t err;
     struct os_task *t;
@@ -250,17 +264,17 @@ task16_handler(void *arg)
     if (g_mutex_test == 1) {
         while (1) {
             t = os_sched_get_current_task();
-            TEST_ASSERT(t->t_func == task16_handler);
+            TEST_ASSERT(t->t_func == mutex_task3_handler);
 
             /* Get mutex 1 */
             err = os_mutex_pend(&g_mutex1, OS_TIMEOUT_NEVER);
             TEST_ASSERT(err == OS_OK);
 
-            while (g_task14_val != 1) {
+            while (g_task1_val != 1) {
                 /* Wait till task 1 wakes up and sets val. */
             }
 
-            g_task16_val = 1;
+            g_task3_val = 1;
 
             err = os_mutex_release(&g_mutex1);
             TEST_ASSERT(err == OS_OK);
@@ -278,7 +292,7 @@ task16_handler(void *arg)
 
         while (1) {
             t = os_sched_get_current_task();
-            TEST_ASSERT(t->t_func == task16_handler);
+            TEST_ASSERT(t->t_func == mutex_task3_handler);
 
             err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
             if (g_mutex_test == 4) {
@@ -298,14 +312,14 @@ task16_handler(void *arg)
 }
 
 void 
-task17_handler(void *arg)
+mutex_task4_handler(void *arg)
 {
     os_error_t err;
     struct os_task *t;
 
     while (1) {
         t = os_sched_get_current_task();
-        TEST_ASSERT(t->t_func == task17_handler);
+        TEST_ASSERT(t->t_func == mutex_task4_handler);
 
         if (g_mutex_test == 5) {
             err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC / 10);
@@ -329,6 +343,36 @@ task17_handler(void *arg)
     }
 }
 
+void
+os_mutex_ts_pretest(void* arg)
+{
+    sysinit();
+}
+
+void
+os_mutex_ts_posttest(void* arg)
+{
+    return;
+}
+
+void
+os_mutex_test_init(void *arg)
+{
+#if MYNEWT_VAL(SELFTEST)
+    stack1 = malloc(sizeof(os_stack_t) * MUTEX_TEST_STACK_SIZE);
+    assert(stack1);
+    stack2 = malloc(sizeof(os_stack_t) * MUTEX_TEST_STACK_SIZE);
+    assert(stack2);
+    stack3 = malloc(sizeof(os_stack_t) * MUTEX_TEST_STACK_SIZE);
+    assert(stack3);
+    stack4 = malloc(sizeof(os_stack_t) * MUTEX_TEST_STACK_SIZE);
+    assert(stack4);
+#endif
+
+    tu_suite_set_pre_test_cb(os_mutex_ts_pretest, NULL);
+    tu_suite_set_post_test_cb(os_mutex_ts_posttest, NULL);
+}
+
 TEST_CASE_DECL(os_mutex_test_basic)
 TEST_CASE_DECL(os_mutex_test_case_1)
 TEST_CASE_DECL(os_mutex_test_case_2)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/mutex_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mutex_test.h b/kernel/os/test/src/mutex_test.h
index de2fb2f..f32231c 100644
--- a/kernel/os/test/src/mutex_test.h
+++ b/kernel/os/test/src/mutex_test.h
@@ -33,43 +33,20 @@
 #extern "C" {
 #endif
 
-#ifdef ARCH_sim
-#define MUTEX_TEST_STACK_SIZE   1024
-#else
-#define MUTEX_TEST_STACK_SIZE   256
-#endif
-
-extern struct os_task task14;
-extern os_stack_t stack14[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
-
-extern struct os_task task15;
-extern os_stack_t stack15[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
-
-extern struct os_task task16;
-extern os_stack_t stack16[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
-
-extern struct os_task task17;
-extern os_stack_t stack17[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
-
-#define TASK14_PRIO (4)
-#define TASK15_PRIO (5)
-#define TASK16_PRIO (6)
-#define TASK17_PRIO (7)
-
-extern volatile int g_task14_val;
-extern volatile int g_task15_val;
-extern volatile int g_task16_val;
-extern volatile int g_task17_val;
+extern volatile int g_task1_val;
+extern volatile int g_task2_val;
+extern volatile int g_task3_val;
+extern volatile int g_task4_val;
 extern struct os_mutex g_mutex1;
 extern struct os_mutex g_mutex2;
 extern volatile int g_mutex_test;
 
 void mutex_test_basic_handler(void *arg);
-void mutex_test1_task14_handler(void *arg);
-void mutex_test2_task14_handler(void *arg);
-void task15_handler(void *arg);
-void task16_handler(void *arg);
-void task17_handler(void *arg);
+void mutex_test1_task1_handler(void *arg);
+void mutex_test2_task1_handler(void *arg);
+void mutex_task2_handler(void *arg);
+void mutex_task3_handler(void *arg);
+void mutex_task4_handler(void *arg);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/os_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/os_test.c b/kernel/os/test/src/os_test.c
index 1e817a7..c8e1b14 100644
--- a/kernel/os/test/src/os_test.c
+++ b/kernel/os/test/src/os_test.c
@@ -30,10 +30,11 @@
 #include <sys/time.h>
 #include "os/os.h"
 
+#if MYNEWT_VAL(SELFTEST) /* these parameters only work in a native env */
+
 void
 os_test_restart(void)
 {
-#if MYNEWT_VAL(SELFTEST)
     struct sigaction sa;
     struct itimerval it;
     int rc;
@@ -52,26 +53,38 @@ os_test_restart(void)
         perror("Cannot set itimer");
         abort();
     }
-#endif /* MYNEWT_VAL(SELFTEST) */
 
-    tu_restart();
+#if MYNEWT_VAL(SELFTEST)
+   tu_restart();
+#endif
 }
 
+extern void os_mempool_test_init(void *arg);
+extern void os_sem_test_init(void *arg);
+extern void os_mutex_test_init(void *arg);
+
 int
 os_test_all(void)
 {
+
+    tu_suite_set_init_cb(os_mempool_test_init, NULL);
     os_mempool_test_suite();
+
+    tu_suite_set_init_cb(os_mutex_test_init, NULL);
     os_mutex_test_suite();
+
+    tu_suite_set_init_cb(os_sem_test_init, NULL);
     os_sem_test_suite();
+
     os_mbuf_test_suite();
+
     os_eventq_test_suite();
+
     os_callout_test_suite();
 
     return tu_case_failed;
 }
 
-#if MYNEWT_VAL(SELFTEST)
-
 int
 main(int argc, char **argv)
 {
@@ -83,5 +96,10 @@ main(int argc, char **argv)
 
     return tu_any_failed;
 }
-
+#else
+void
+os_test_restart(void)
+{
+    return;
+}
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/os_test_priv.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/os_test_priv.h b/kernel/os/test/src/os_test_priv.h
index 1f74a53..dc676ff 100644
--- a/kernel/os/test/src/os_test_priv.h
+++ b/kernel/os/test/src/os_test_priv.h
@@ -37,6 +37,25 @@
 extern "C" {
 #endif
 
+/*
+ * shared amongst all os tests
+ */
+extern struct os_task task1;
+extern os_stack_t *stack1;
+#define TASK1_PRIO (20) 
+
+extern struct os_task task2;
+extern os_stack_t *stack2;
+#define TASK2_PRIO (21) 
+
+extern struct os_task task3;
+extern os_stack_t *stack3;
+#define TASK3_PRIO (22) 
+
+extern struct os_task task4;
+extern os_stack_t *stack4;
+#define TASK4_PRIO (23) 
+
 void os_test_restart(void);
 
 int os_mempool_test_suite(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/sem_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/sem_test.c b/kernel/os/test/src/sem_test.c
index 8f3b163..6745a24 100644
--- a/kernel/os/test/src/sem_test.c
+++ b/kernel/os/test/src/sem_test.c
@@ -23,29 +23,22 @@
 #include "os/os.h"
 #include "os_test_priv.h"
 
+#if MYNEWT_VAL(SELFTEST)
 #ifdef ARCH_sim
-#define SEM_TEST_STACK_SIZE     1024
-#else 
-#define SEM_TEST_STACK_SIZE     512
+#define SEM_TEST_STACK_SIZE     OS_STACK_ALIGN(1024)
 #endif
 
-#if MYNEWT_VAL(SELFTEST)
 struct os_task task1;
-os_stack_t stack1[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
+os_stack_t *stack1;
 
 struct os_task task2;
-os_stack_t stack2[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
+os_stack_t *stack2;
 
 struct os_task task3;
-os_stack_t stack3[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
+os_stack_t *stack3;
 
 struct os_task task4;
-os_stack_t stack4[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-#define TASK1_PRIO (1) 
-#define TASK2_PRIO (2) 
-#define TASK3_PRIO (3) 
-#define TASK4_PRIO (4) 
+os_stack_t *stack4;
 #endif /* MYNEWT_VAL(SELFTEST) */
 
 struct os_sem g_sem1;
@@ -59,7 +52,6 @@ struct os_sem g_sem1;
  *  order, get the semaphore, then release it and go back to sleep.
  * 
  */
-
 char sem_test_buf[128];
 
 /**
@@ -96,7 +88,9 @@ sem_test_sleep_task_handler(void *arg)
     TEST_ASSERT(t->t_func == sem_test_sleep_task_handler);
 
     os_time_delay(2 * OS_TICKS_PER_SEC);
+#if MYNEWT_VAL(SELFTEST)
     os_test_restart();
+#endif
 }
 
 void
@@ -148,7 +142,8 @@ sem_test_basic_handler(void *arg)
     TEST_ASSERT(sem->sem_tokens == 0 && SLIST_EMPTY(&sem->sem_head),
                 "Semaphore internals wrong after getting semaphore\n"
                 "%s\n"
-                "Task: task=%p prio=%u", sem_test_sem_to_s(sem), t, t->t_prio);
+                "Task: task=%p prio=%u", sem_test_sem_to_s(sem),
+                t, t->t_prio);
 
     /* Get the semaphore again; should fail */
     err = os_sem_pend(sem, 0);
@@ -186,7 +181,9 @@ sem_test_basic_handler(void *arg)
                 "Task: task=%p prio=%u\n", sem_test_sem_to_s(sem), t,
                 t->t_prio);
 
+#if MYNEWT_VAL(SELFTEST)
     os_test_restart();
+#endif
 }
 
 void 
@@ -200,7 +197,6 @@ sem_test_1_task1_handler(void *arg)
         t = os_sched_get_current_task();
         TEST_ASSERT(t->t_func == sem_test_1_task1_handler);
 
-
         err = os_sem_pend(&g_sem1, 0);
         TEST_ASSERT(err == OS_OK);
 
@@ -215,13 +211,16 @@ sem_test_1_task1_handler(void *arg)
         os_time_delay(OS_TICKS_PER_SEC / 10);
     }
 
+#if MYNEWT_VAL(SELFTEST)
     os_test_restart();
+#endif
 }
 
 void 
 sem_test_1_task2_handler(void *arg) 
 {
-    sem_test_pend_release_loop(0, OS_TICKS_PER_SEC / 10, OS_TICKS_PER_SEC / 10);
+    sem_test_pend_release_loop(0, OS_TICKS_PER_SEC / 10,
+                               OS_TICKS_PER_SEC / 10);
 }
 
 void 
@@ -284,6 +283,36 @@ sem_test_4_task4_handler(void *arg)
     sem_test_pend_release_loop(0, 2000, 2000);
 }
 
+void
+os_sem_ts_pretest(void* arg)
+{
+    sysinit();
+}
+
+void
+os_sem_ts_posttest(void* arg)
+{
+    return;
+}
+
+void
+os_sem_test_init(void *arg)
+{
+#if MYNEWT_VAL(SELFTEST)
+    stack1 = malloc(sizeof(os_stack_t) * SEM_TEST_STACK_SIZE);
+    assert(stack1);
+    stack2 = malloc(sizeof(os_stack_t) * SEM_TEST_STACK_SIZE);
+    assert(stack2);
+    stack3 = malloc(sizeof(os_stack_t) * SEM_TEST_STACK_SIZE);
+    assert(stack3);
+    stack4 = malloc(sizeof(os_stack_t) * SEM_TEST_STACK_SIZE);
+    assert(stack4);
+#endif
+
+    tu_suite_set_pre_test_cb(os_sem_ts_pretest, NULL);
+    tu_suite_set_post_test_cb(os_sem_ts_posttest, NULL);
+}
+
 TEST_CASE_DECL(os_sem_test_basic)
 TEST_CASE_DECL(os_sem_test_case_1)
 TEST_CASE_DECL(os_sem_test_case_2)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/sem_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/sem_test.h b/kernel/os/test/src/sem_test.h
index 7327277..1d0bf09 100644
--- a/kernel/os/test/src/sem_test.h
+++ b/kernel/os/test/src/sem_test.h
@@ -30,29 +30,6 @@
 #extern "C" {
 #endif
 
-#ifdef ARCH_sim
-#define SEM_TEST_STACK_SIZE     1024
-#else 
-#define SEM_TEST_STACK_SIZE     512
-#endif
-
-extern struct os_task task1;
-extern os_stack_t stack1[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-extern struct os_task task2;
-extern os_stack_t stack2[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-extern struct os_task task3;
-extern os_stack_t stack3[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-extern struct os_task task4;
-extern os_stack_t stack4[OS_STACK_ALIGN(SEM_TEST_STACK_SIZE)];
-
-#define TASK1_PRIO (1) 
-#define TASK2_PRIO (2) 
-#define TASK3_PRIO (3) 
-#define TASK4_PRIO (4) 
-
 extern struct os_sem g_sem1;
 
 const char *sem_test_sem_to_s(const struct os_sem *sem);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_mempool_test_case.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mempool_test_case.c b/kernel/os/test/src/testcases/os_mempool_test_case.c
index 8e5d02a..f9e8ab2 100644
--- a/kernel/os/test/src/testcases/os_mempool_test_case.c
+++ b/kernel/os/test/src/testcases/os_mempool_test_case.c
@@ -25,6 +25,156 @@
  * 
  * @return int 
  */
+void
+mempool_test(int num_blocks, int block_size)
+{
+    int cnt;
+    int true_block_size;
+    int mem_pool_size;
+    uint32_t test_block;
+    uint8_t *tstptr;
+    void **free_ptr;
+    void *block;
+    os_error_t rc;
+
+    /* Check for too many blocks */
+    TEST_ASSERT(num_blocks <= MEMPOOL_TEST_MAX_BLOCKS);
+
+    rc = os_mempool_init(&g_TstMempool, num_blocks, MEM_BLOCK_SIZE, 
+                         &TstMembuf[0], "TestMemPool");
+    TEST_ASSERT_FATAL(rc == 0, "Error creating memory pool %d", rc);
+
+    TEST_ASSERT(g_TstMempool.mp_num_free == num_blocks,
+                "Number of free blocks not equal to total blocks!");
+
+    TEST_ASSERT(SLIST_FIRST(&g_TstMempool) == (void *)&TstMembuf[0],
+                "Free list pointer does not point to first block!");
+
+    mem_pool_size = mempool_test_get_pool_size(num_blocks, block_size);
+    TEST_ASSERT(mem_pool_size == TstMembufSz,
+                "Total memory pool size not correct! (%d vs %lu)",
+                mem_pool_size, (unsigned long)TstMembufSz);
+
+    /* Get the real block size */
+#if (OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4)
+    true_block_size = (g_TstMempool.mp_block_size + 3) & ~3;
+#else
+    true_block_size = (g_TstMempool.mp_block_size + 7) & ~7;
+#endif
+
+    /* Traverse free list. Better add up to number of blocks! */
+    cnt = 0;
+    free_ptr = (void **)TstMembuf;
+    tstptr = (uint8_t *)TstMembuf;
+    while (1) {
+        /* Increment # of elements by 1 */
+        ++cnt;
+
+        /* If the free list is NULL, leave */
+        if (*free_ptr == NULL) {
+            break;
+        }
+
+        TEST_ASSERT(((uint8_t *)*free_ptr - (uint8_t *)free_ptr) ==
+                        true_block_size,
+                    "Free pointers are more than one block apart!");
+
+        /* Move to next memory block */
+        tstptr += true_block_size;
+
+        TEST_ASSERT(*free_ptr == (void *)tstptr,
+                    "Error: free_ptr=%p testptr=%p\n", *free_ptr, tstptr);
+
+        free_ptr = *free_ptr;
+    }
+
+    /* Last one in list better be NULL */
+    TEST_ASSERT(cnt == g_TstMempool.mp_num_blocks,
+                "Free list contains too many elements (%u/%u)",
+                cnt, g_TstMempool.mp_num_blocks);
+
+    /* Get a block */
+    block = os_memblock_get(&g_TstMempool);
+    TEST_ASSERT(block != NULL,
+                "Error: get block fails when pool should have elements");
+
+    TEST_ASSERT(g_TstMempool.mp_num_free == (num_blocks-1),
+                "Number of free blocks incorrect (%u vs %u)",
+                g_TstMempool.mp_num_free, (num_blocks-1));
+
+    /* Put back the block */
+    rc = os_memblock_put(&g_TstMempool, block);
+    TEST_ASSERT(rc == 0, "Put block fails with error code=%d\n", rc);
+
+    TEST_ASSERT(g_TstMempool.mp_num_free == num_blocks,
+                "Number of free blocks incorrect (%u vs %u)",
+                g_TstMempool.mp_num_free, num_blocks);
+
+    /* remove all the blocks. Make sure we get count. */
+    memset(block_array, 0, sizeof(block_array));
+    cnt = 0;
+    while (1) {
+        block = os_memblock_get(&g_TstMempool);
+        if (block == NULL) {
+            break;
+        }
+        block_array[cnt] = block;
+        ++cnt;
+        if (cnt == MEMPOOL_TEST_MAX_BLOCKS) {
+            break;
+        }
+    }
+
+    TEST_ASSERT((cnt == g_TstMempool.mp_num_blocks) && 
+                (cnt != MEMPOOL_TEST_MAX_BLOCKS),
+                "Got more blocks than mempool contains (%d vs %d)",
+                cnt, g_TstMempool.mp_num_blocks);
+
+    /* Better be no free blocks left! */
+    TEST_ASSERT(g_TstMempool.mp_num_free == 0,
+                "Got all blocks but number free not zero! (%d)",
+                g_TstMempool.mp_num_free);
+
+    /* Now put them all back */
+    for (cnt = 0; cnt < g_TstMempool.mp_num_blocks; ++cnt) {
+        rc = os_memblock_put(&g_TstMempool, block_array[cnt]);
+        TEST_ASSERT(rc == 0,
+                    "Error putting back block %p (cnt=%d err=%d)", 
+                    block_array[cnt], cnt, rc);
+    }
+
+    /* Better be no free blocks left! */
+    TEST_ASSERT(g_TstMempool.mp_num_free == g_TstMempool.mp_num_blocks,
+                "Put all blocks but number free not equal to total!");
+
+    /* Better get error when we try these things! */
+    rc = os_memblock_put(NULL, block_array[0]);
+    TEST_ASSERT(rc != 0,
+                "Should have got an error trying to put to null pool");
+
+    rc = os_memblock_put(&g_TstMempool, NULL);
+    TEST_ASSERT(rc != 0, "No error trying to put to NULL block");
+
+    TEST_ASSERT(os_memblock_get(NULL) == NULL,
+                "No error trying to get a block from NULL pool");
+
+    /* Attempt to free a block outside the range of the membuf */
+    test_block = g_TstMempool.mp_membuf_addr;
+    test_block -= 4;
+    rc = os_memblock_put(&g_TstMempool, (void *)test_block);
+    TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
+
+    test_block += (true_block_size * g_TstMempool.mp_num_blocks) + 100;
+    rc = os_memblock_put(&g_TstMempool, (void *)test_block);
+    TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
+
+    /* Attempt to free on bad boundary */
+    test_block = g_TstMempool.mp_membuf_addr;
+    test_block += (true_block_size / 2);
+    rc = os_memblock_put(&g_TstMempool, (void *)test_block);
+    TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
+}
+
 TEST_CASE(os_mempool_test_case)
 {
     mempool_test(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_mutex_test_basic.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mutex_test_basic.c b/kernel/os/test/src/testcases/os_mutex_test_basic.c
index 3098893..2f76d89 100644
--- a/kernel/os/test/src/testcases/os_mutex_test_basic.c
+++ b/kernel/os/test/src/testcases/os_mutex_test_basic.c
@@ -20,13 +20,13 @@
 
 TEST_CASE(os_mutex_test_basic)
 {
-    sysinit();
 
     os_mutex_init(&g_mutex1);
 
-    os_task_init(&task14, "task14", mutex_test_basic_handler, NULL,
-                 TASK14_PRIO, OS_WAIT_FOREVER, stack14,
-                 OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+    os_task_init(&task1, "task1", mutex_test_basic_handler, NULL,
+                 TASK1_PRIO, OS_WAIT_FOREVER, stack1, sizeof(stack1));
 
+#if MYNEWT_VAL(SELFTEST)
     os_start();
+#endif
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_mutex_test_case_1.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mutex_test_case_1.c b/kernel/os/test/src/testcases/os_mutex_test_case_1.c
index f3cdf0f..30a8b6c 100644
--- a/kernel/os/test/src/testcases/os_mutex_test_case_1.c
+++ b/kernel/os/test/src/testcases/os_mutex_test_case_1.c
@@ -22,27 +22,24 @@ TEST_CASE(os_mutex_test_case_1)
 {
     int rc;
 
-    sysinit();
-
     g_mutex_test = 1;
-    g_task14_val = 0;
-    g_task15_val = 0;
-    g_task16_val = 0;
+    g_task1_val = 0;
+    g_task2_val = 0;
+    g_task3_val = 0;
 
     rc = os_mutex_init(&g_mutex1);
     TEST_ASSERT(rc == 0);
     rc = os_mutex_init(&g_mutex2);
     TEST_ASSERT(rc == 0);
 
-    os_task_init(&task14, "task14", mutex_test1_task14_handler, NULL,
-                 TASK14_PRIO, OS_WAIT_FOREVER, stack14,
-                 OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+    os_task_init(&task1, "task1", mutex_test1_task1_handler, NULL,
+                 TASK1_PRIO, OS_WAIT_FOREVER, stack1, sizeof(stack1));
 
-    os_task_init(&task15, "task15", task15_handler, NULL, TASK15_PRIO, 
-            OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+    os_task_init(&task2, "task2", mutex_task2_handler, NULL, TASK2_PRIO, 
+            OS_WAIT_FOREVER, stack2, sizeof(stack2));
 
-    os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO, 
-            OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+    os_task_init(&task3, "task3", mutex_task3_handler, NULL, TASK3_PRIO, 
+            OS_WAIT_FOREVER, stack3, sizeof(stack3));
 
     os_start();
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_mutex_test_case_2.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mutex_test_case_2.c b/kernel/os/test/src/testcases/os_mutex_test_case_2.c
index 62129b0..eb321bf 100644
--- a/kernel/os/test/src/testcases/os_mutex_test_case_2.c
+++ b/kernel/os/test/src/testcases/os_mutex_test_case_2.c
@@ -23,24 +23,23 @@ TEST_CASE(os_mutex_test_case_2)
     sysinit();
 
     g_mutex_test = 2;
-    g_task14_val = 0;
-    g_task15_val = 0;
-    g_task16_val = 0;
+    g_task1_val = 0;
+    g_task2_val = 0;
+    g_task3_val = 0;
     os_mutex_init(&g_mutex1);
     os_mutex_init(&g_mutex2);
 
-    os_task_init(&task14, "task14", mutex_test2_task14_handler, NULL,
-                 TASK14_PRIO, OS_WAIT_FOREVER, stack14,
-                 OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+    os_task_init(&task1, "task1", mutex_test2_task1_handler, NULL,
+                 TASK1_PRIO, OS_WAIT_FOREVER, stack1, sizeof(stack1));
 
-    os_task_init(&task15, "task15", task15_handler, NULL, TASK15_PRIO, 
-            OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+    os_task_init(&task2, "task2", mutex_task2_handler, NULL, TASK2_PRIO, 
+            OS_WAIT_FOREVER, stack2, sizeof(stack2));
 
-    os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO, 
-            OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+    os_task_init(&task3, "task3", mutex_task3_handler, NULL, TASK3_PRIO, 
+            OS_WAIT_FOREVER, stack3, sizeof(stack3));
 
-    os_task_init(&task17, "task17", task17_handler, NULL, TASK17_PRIO, 
-            OS_WAIT_FOREVER, stack17, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+    os_task_init(&task4, "task4", mutex_task4_handler, NULL, TASK4_PRIO, 
+            OS_WAIT_FOREVER, stack4, sizeof(stack4));
  
     os_start();
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_sem_test_basic.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_sem_test_basic.c b/kernel/os/test/src/testcases/os_sem_test_basic.c
index d3af5d2..2cdc9a1 100644
--- a/kernel/os/test/src/testcases/os_sem_test_basic.c
+++ b/kernel/os/test/src/testcases/os_sem_test_basic.c
@@ -22,13 +22,14 @@ TEST_CASE(os_sem_test_basic)
 {
     os_error_t err;
 
-    sysinit();
-
     err = os_sem_init(&g_sem1, 1);
     TEST_ASSERT(err == OS_OK);
 
-    os_task_init(&task1, "task1", sem_test_basic_handler, NULL, TASK1_PRIO, 
-            OS_WAIT_FOREVER, stack1, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+    os_task_init(&task1, "task1", sem_test_basic_handler, NULL,
+                 TASK1_PRIO, OS_WAIT_FOREVER, stack1,
+                 sizeof(stack1));
 
+#if MYNEWT_VAL(SELFTEST)
     os_start();
+#endif
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_sem_test_case_1.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_sem_test_case_1.c b/kernel/os/test/src/testcases/os_sem_test_case_1.c
index b84b950..6d603a9 100644
--- a/kernel/os/test/src/testcases/os_sem_test_case_1.c
+++ b/kernel/os/test/src/testcases/os_sem_test_case_1.c
@@ -22,21 +22,22 @@ TEST_CASE(os_sem_test_case_1)
 {
     os_error_t err;
 
-    sysinit();
-
     err = os_sem_init(&g_sem1, 1);
     TEST_ASSERT(err == OS_OK);
 
     os_task_init(&task1, "task1", sem_test_1_task1_handler, NULL,
                  TASK1_PRIO, OS_WAIT_FOREVER, stack1,
-                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+                 sizeof(stack1));
 
     os_task_init(&task2, "task2", sem_test_1_task2_handler, NULL,
                  TASK2_PRIO, OS_WAIT_FOREVER, stack2,
-                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+                 sizeof(stack2));
 
-    os_task_init(&task3, "task3", sem_test_1_task3_handler, NULL, TASK3_PRIO, 
-                 OS_WAIT_FOREVER, stack3, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+    os_task_init(&task3, "task3", sem_test_1_task3_handler, NULL,
+                 TASK3_PRIO, OS_WAIT_FOREVER, stack3,
+                 sizeof(stack3));
 
+#if MYNEWT_VAL(SELFTEST)
     os_start();
+#endif
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_sem_test_case_2.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_sem_test_case_2.c b/kernel/os/test/src/testcases/os_sem_test_case_2.c
index e862b7c..e25f6ef 100644
--- a/kernel/os/test/src/testcases/os_sem_test_case_2.c
+++ b/kernel/os/test/src/testcases/os_sem_test_case_2.c
@@ -22,24 +22,26 @@ TEST_CASE(os_sem_test_case_2)
 {
     os_error_t err;
 
-    sysinit();
-
     err = os_sem_init(&g_sem1, 1);
     TEST_ASSERT(err == OS_OK);
 
     os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL,
                  TASK1_PRIO, OS_WAIT_FOREVER, stack1,
-                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+                 sizeof(stack1));
 
     os_task_init(&task2, "task2", sem_test_2_task2_handler, NULL,
                  TASK2_PRIO, OS_WAIT_FOREVER, stack2,
-                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+                 sizeof(stack2));
 
-    os_task_init(&task3, "task3", sem_test_2_task3_handler, NULL, TASK3_PRIO,
-            OS_WAIT_FOREVER, stack3, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+    os_task_init(&task3, "task3", sem_test_2_task3_handler, NULL,
+                 TASK3_PRIO, OS_WAIT_FOREVER, stack3,
+                 sizeof(stack3));
 
-    os_task_init(&task4, "task4", sem_test_2_task4_handler, NULL, TASK4_PRIO,
-            OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+    os_task_init(&task4, "task4", sem_test_2_task4_handler, NULL,
+                 TASK4_PRIO, OS_WAIT_FOREVER, stack4,
+                 sizeof(stack4));
 
+#if MYNEWT_VAL(SELFTEST)
     os_start();
+#endif
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_sem_test_case_3.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_sem_test_case_3.c b/kernel/os/test/src/testcases/os_sem_test_case_3.c
index 7e367c6..2dc3dbe 100644
--- a/kernel/os/test/src/testcases/os_sem_test_case_3.c
+++ b/kernel/os/test/src/testcases/os_sem_test_case_3.c
@@ -22,24 +22,26 @@ TEST_CASE(os_sem_test_case_3)
 {
     os_error_t err;
 
-    sysinit();
-
     err = os_sem_init(&g_sem1, 1);
     TEST_ASSERT(err == OS_OK);
 
     os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL,
                  TASK1_PRIO, OS_WAIT_FOREVER, stack1,
-                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+                 sizeof(stack1));
 
     os_task_init(&task2, "task2", sem_test_3_task2_handler, NULL,
                  TASK2_PRIO, OS_WAIT_FOREVER, stack2,
-                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+                 sizeof(stack2));
 
-    os_task_init(&task3, "task3", sem_test_3_task3_handler, NULL, TASK3_PRIO,
-            OS_WAIT_FOREVER, stack3, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+    os_task_init(&task3, "task3", sem_test_3_task3_handler, NULL,
+                 TASK3_PRIO, OS_WAIT_FOREVER, stack3,
+                 sizeof(stack3));
 
-    os_task_init(&task4, "task4", sem_test_3_task4_handler, NULL, TASK4_PRIO,
-            OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+    os_task_init(&task4, "task4", sem_test_3_task4_handler, NULL,
+                 TASK4_PRIO, OS_WAIT_FOREVER, stack4,
+                 sizeof(stack4));
 
+#if MYNEWT_VAL(SELFTEST)
     os_start();
+#endif
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bd6933cd/kernel/os/test/src/testcases/os_sem_test_case_4.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_sem_test_case_4.c b/kernel/os/test/src/testcases/os_sem_test_case_4.c
index e0827e2..a9f32de 100644
--- a/kernel/os/test/src/testcases/os_sem_test_case_4.c
+++ b/kernel/os/test/src/testcases/os_sem_test_case_4.c
@@ -22,24 +22,26 @@ TEST_CASE(os_sem_test_case_4)
 {
     os_error_t err;
 
-    sysinit();
-
     err = os_sem_init(&g_sem1, 1);
     TEST_ASSERT(err == OS_OK);
 
     os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL,
                  TASK1_PRIO, OS_WAIT_FOREVER, stack1,
-                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+                 sizeof(stack1));
 
     os_task_init(&task2, "task2", sem_test_4_task2_handler, NULL,
                  TASK2_PRIO, OS_WAIT_FOREVER, stack2,
-                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+                 sizeof(stack2));
 
-    os_task_init(&task3, "task3", sem_test_4_task3_handler, NULL, TASK3_PRIO,
-                 OS_WAIT_FOREVER, stack3, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+    os_task_init(&task3, "task3", sem_test_4_task3_handler, NULL,
+                 TASK3_PRIO, OS_WAIT_FOREVER, stack3,
+                 sizeof(stack3));
 
-    os_task_init(&task4, "task4", sem_test_4_task4_handler, NULL, TASK4_PRIO,
-                 OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+    os_task_init(&task4, "task4", sem_test_4_task4_handler, NULL,
+                 TASK4_PRIO, OS_WAIT_FOREVER, stack4,
+                 sizeof(stack4));
 
+#if MYNEWT_VAL(SELFTEST)
     os_start();
+#endif
 }