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

[34/49] incubator-mynewt-core git commit: directory re-org

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/kernel/os/src/os_sem.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_sem.c b/kernel/os/src/os_sem.c
new file mode 100644
index 0000000..181e5de
--- /dev/null
+++ b/kernel/os/src/os_sem.c
@@ -0,0 +1,212 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/os.h"
+#include <assert.h>
+
+/* XXX:
+ * 1) Should I check to see if we are within an ISR for some of these?
+ * 2) Would I do anything different for os_sem_release() if we were in an
+ *    ISR when this was called?
+ */
+
+/**
+ * os sem create
+ *  
+ * Create a semaphore and initialize it. 
+ * 
+ * @param sem Pointer to semaphore 
+ *        tokens: # of tokens the semaphore should contain initially.   
+ * 
+ * @return os_error_t 
+ *      OS_INVALID_PARM     Semaphore passed in was NULL.
+ *      OS_OK               no error.
+ */
+os_error_t
+os_sem_init(struct os_sem *sem, uint16_t tokens)
+{
+    if (!sem) {
+        return OS_INVALID_PARM;
+    }
+
+    sem->sem_tokens = tokens;
+    SLIST_FIRST(&sem->sem_head) = NULL;
+
+    return OS_OK;
+}
+
+/**
+ * os sem release
+ *  
+ * Release a semaphore. 
+ * 
+ * @param sem Pointer to the semaphore to be released
+ * 
+ * @return os_error_t 
+ *      OS_INVALID_PARM Semaphore passed in was NULL.
+ *      OS_OK No error
+ */
+os_error_t
+os_sem_release(struct os_sem *sem)
+{
+    int resched;
+    os_sr_t sr;
+    struct os_task *current;
+    struct os_task *rdy;
+
+    /* OS must be started to release semaphores */ 
+    if (!g_os_started) {
+        return (OS_NOT_STARTED);
+    }
+
+    /* Check for valid semaphore */
+    if (!sem) {
+        return OS_INVALID_PARM;
+    }
+
+    /* Get current task */
+    resched = 0;
+    current = os_sched_get_current_task();
+
+    OS_ENTER_CRITICAL(sr);
+
+    /* Check if tasks are waiting for the semaphore */
+    rdy = SLIST_FIRST(&sem->sem_head);
+    if (rdy) {
+        /* Clear flag that we are waiting on the semaphore; wake up task */
+        rdy->t_flags &= ~OS_TASK_FLAG_SEM_WAIT;
+        os_sched_wakeup(rdy);
+
+        /* Schedule if waiting task higher priority */
+        if (current->t_prio > rdy->t_prio) {
+            resched = 1;
+        }
+    } else {
+        /* Add to the number of tokens */
+        sem->sem_tokens++;
+    }
+
+    OS_EXIT_CRITICAL(sr);
+
+    /* Re-schedule if needed */
+    if (resched) {
+        os_sched(rdy);
+    }
+
+    return OS_OK;
+}
+
+/**
+ * os sem pend 
+ *  
+ * Pend (wait) for a semaphore. 
+ * 
+ * @param mu Pointer to semaphore.
+ * @param timeout Timeout, in os ticks. A timeout of 0 means do 
+ *                not wait if not available. A timeout of
+ *                0xFFFFFFFF means wait forever.
+ *              
+ * 
+ * @return os_error_t 
+ *      OS_INVALID_PARM     Semaphore passed in was NULL.
+ *      OS_TIMEOUT          Semaphore was owned by another task and timeout=0
+ *      OS_OK               no error.
+ */ 
+os_error_t
+os_sem_pend(struct os_sem *sem, uint32_t timeout)
+{
+    os_sr_t sr;
+    os_error_t rc;
+    int sched;
+    struct os_task *current;
+    struct os_task *entry;
+    struct os_task *last;
+
+    /* Check if OS is started */
+    if (!g_os_started) {
+        return (OS_NOT_STARTED);
+    }
+
+    /* Check for valid semaphore */
+    if (!sem) {
+        return OS_INVALID_PARM;
+    }
+
+    /* Assume we dont have to put task to sleep; get current task */
+    sched = 0;
+    current = os_sched_get_current_task();
+
+    OS_ENTER_CRITICAL(sr);
+
+    /* 
+     * If there is a token available, take it. If no token, either return
+     * with error if timeout was 0 or put this task to sleep.
+     */
+    if (sem->sem_tokens != 0) {
+        sem->sem_tokens--;
+        rc = OS_OK;
+    } else if (timeout == 0) {
+        rc = OS_TIMEOUT;
+    } else {
+        /* Silence gcc maybe-uninitialized warning. */
+        rc = OS_OK;
+
+        /* Link current task to tasks waiting for semaphore */
+        current->t_obj = sem; 
+        current->t_flags |= OS_TASK_FLAG_SEM_WAIT;
+        last = NULL;
+        if (!SLIST_EMPTY(&sem->sem_head)) {
+            /* Insert in priority order */
+            SLIST_FOREACH(entry, &sem->sem_head, t_obj_list) {
+                if (current->t_prio < entry->t_prio) { 
+                    break;
+                }
+                last = entry;
+            }
+        }
+
+        if (last) {
+            SLIST_INSERT_AFTER(last, current, t_obj_list);
+        } else {
+            SLIST_INSERT_HEAD(&sem->sem_head, current, t_obj_list);
+        }
+
+        /* We will put this task to sleep */
+        sched = 1;
+        os_sched_sleep(current, timeout);
+    }
+
+    OS_EXIT_CRITICAL(sr);
+
+    if (sched) {
+        os_sched(NULL);
+        /* Check if we timed out or got the semaphore */
+        if (current->t_flags & OS_TASK_FLAG_SEM_WAIT) {
+            OS_ENTER_CRITICAL(sr);
+            current->t_flags &= ~OS_TASK_FLAG_SEM_WAIT;
+            OS_EXIT_CRITICAL(sr);
+            rc = OS_TIMEOUT;
+        } else {
+            rc = OS_OK; 
+        }
+    }
+
+    return rc;
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/kernel/os/src/os_task.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_task.c b/kernel/os/src/os_task.c
new file mode 100644
index 0000000..9e2860b
--- /dev/null
+++ b/kernel/os/src/os_task.c
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include "os/os.h"
+#include "os_priv.h"
+
+#include <string.h>
+
+uint8_t g_task_id;
+
+struct os_task_stailq g_os_task_list;
+
+static void
+_clear_stack(os_stack_t *stack_bottom, int size)
+{
+    int i;
+
+    for (i = 0; i < size; i++) {
+        stack_bottom[i] = OS_STACK_PATTERN;
+    }
+}
+
+static inline uint8_t
+os_task_next_id(void)
+{
+    uint8_t rc;
+    os_sr_t sr;
+
+    OS_ENTER_CRITICAL(sr);
+    rc = g_task_id;
+    g_task_id++;
+    OS_EXIT_CRITICAL(sr);
+
+    return (rc);
+}
+
+/**
+ * Return the number of tasks initialized.
+ *
+ * @return number of tasks initialized
+ */
+uint8_t
+os_task_count(void)
+{
+    return (g_task_id);
+}
+
+/**
+ * Initialize a task.
+ *
+ * This function initializes the task structure pointed to by t,
+ * clearing and setting it's stack pointer, provides sane defaults
+ * and sets the task as ready to run, and inserts it into the operating
+ * system scheduler.
+ *
+ * @param t The task to initialize
+ * @param name The name of the task to initialize
+ * @param func The task function to call
+ * @param arg The argument to pass to this task function
+ * @param prio The priority at which to run this task
+ * @param sanity_itvl The time at which this task should check in with the
+ *                    sanity task.  OS_WAIT_FOREVER means never check in
+ *                    here.
+ * @param stack_bottom A pointer to the bottom of a task's stack
+ * @param stack_size The overall size of the task's stack.
+ *
+ * @return 0 on success, non-zero on failure.
+ */
+int
+os_task_init(struct os_task *t, const char *name, os_task_func_t func,
+        void *arg, uint8_t prio, os_time_t sanity_itvl,
+        os_stack_t *stack_bottom, uint16_t stack_size)
+{
+    struct os_sanity_check *sc;
+    int rc;
+
+    memset(t, 0, sizeof(*t));
+
+    t->t_func = func;
+    t->t_arg = arg;
+
+    t->t_taskid = os_task_next_id();
+    t->t_prio = prio;
+
+    t->t_state = OS_TASK_READY;
+    t->t_name = name;
+    t->t_next_wakeup = 0;
+
+    rc = os_sanity_check_init(&t->t_sanity_check);
+    if (rc != OS_OK) {
+        goto err;
+    }
+
+    if (sanity_itvl != OS_WAIT_FOREVER) {
+        sc = (struct os_sanity_check *) &t->t_sanity_check;
+        sc->sc_checkin_itvl = sanity_itvl;
+
+        rc = os_sanity_check_register(sc);
+        if (rc != OS_OK) {
+            goto err;
+        }
+    }
+
+    _clear_stack(stack_bottom, stack_size);
+    t->t_stackptr = os_arch_task_stack_init(t, &stack_bottom[stack_size],
+            stack_size);
+    t->t_stacktop = &stack_bottom[stack_size];
+    t->t_stacksize = stack_size;
+
+    /* insert this task into the task list */
+    STAILQ_INSERT_TAIL(&g_os_task_list, t, t_os_task_list);
+
+    /* insert this task into the scheduler list */
+    rc = os_sched_insert(t);
+    if (rc != OS_OK) {
+        goto err;
+    }
+
+
+    return (0);
+err:
+    return (rc);
+}
+
+/**
+ * Iterate through tasks, and return the following information about them:
+ *
+ * - Priority
+ * - Task ID
+ * - State (ACTIVE, SLEEP)
+ * - Total Stack Usage
+ * - Stack Size
+ * - Context Switch Count
+ * - Runtime
+ * - Last & Next Sanity checkin
+ * - Task Name
+ *
+ * To get the first task in the list, call os_task_info_get_next() with a
+ * NULL pointer in the prev argument, and os_task_info_get_next() will
+ * return a pointer to the task structure, and fill out the os_task_info
+ * structure pointed to by oti.
+ *
+ * To get the next task in the list, provide the task structure returned
+ * by the previous call to os_task_info_get_next(), and os_task_info_get_next()
+ * will fill out the task structure pointed to by oti again, and return
+ * the next task in the list.
+ *
+ * @param prev The previous task returned by os_task_info_get_next(), or NULL
+ *             to begin iteration.
+ * @param oti  The OS task info structure to fill out.
+ *
+ * @return A pointer to the OS task that has been read, or NULL when finished
+ *         iterating through all tasks.
+ */
+struct os_task *
+os_task_info_get_next(const struct os_task *prev, struct os_task_info *oti)
+{
+    struct os_task *next;
+    os_stack_t *top;
+    os_stack_t *bottom;
+
+    if (prev != NULL) {
+        next = STAILQ_NEXT(prev, t_os_task_list);
+    } else {
+        next = STAILQ_FIRST(&g_os_task_list);
+    }
+
+    if (next == NULL) {
+        return (NULL);
+    }
+
+    /* Otherwise, copy OS task information into the OTI structure, and
+     * return 1, which means continue
+     */
+    oti->oti_prio = next->t_prio;
+    oti->oti_taskid = next->t_taskid;
+    oti->oti_state = next->t_state;
+
+    top = next->t_stacktop;
+    bottom = next->t_stacktop - next->t_stacksize;
+    while (bottom < top) {
+        if (*bottom != OS_STACK_PATTERN) {
+            break;
+        }
+        ++bottom;
+    }
+
+    oti->oti_stkusage = (uint16_t) (next->t_stacktop - bottom);
+    oti->oti_stksize = next->t_stacksize;
+    oti->oti_cswcnt = next->t_ctx_sw_cnt;
+    oti->oti_runtime = next->t_run_time;
+    oti->oti_last_checkin = next->t_sanity_check.sc_checkin_last;
+    oti->oti_next_checkin = next->t_sanity_check.sc_checkin_last +
+        next->t_sanity_check.sc_checkin_itvl;
+    strncpy(oti->oti_name, next->t_name, sizeof(oti->oti_name));
+
+    return (next);
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/kernel/os/src/os_time.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_time.c b/kernel/os/src/os_time.c
new file mode 100644
index 0000000..4ef439f
--- /dev/null
+++ b/kernel/os/src/os_time.c
@@ -0,0 +1,248 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <util/util.h>
+#include <assert.h>
+
+#include "os/os.h"
+#include "os/queue.h"
+
+CTASSERT(sizeof(os_time_t) == 4);
+
+#define OS_USEC_PER_TICK    (1000000 / OS_TICKS_PER_SEC)
+
+os_time_t g_os_time;
+
+/*
+ * Time-of-day collateral.
+ */
+static struct {
+    os_time_t ostime;
+    struct os_timeval uptime;
+    struct os_timeval utctime;
+    struct os_timezone timezone;
+} basetod;
+
+static void
+os_deltatime(os_time_t delta, const struct os_timeval *base,
+    struct os_timeval *result)
+{
+    struct os_timeval tvdelta;
+
+    tvdelta.tv_sec = delta / OS_TICKS_PER_SEC;
+    tvdelta.tv_usec = (delta % OS_TICKS_PER_SEC) * OS_USEC_PER_TICK;
+    os_timeradd(base, &tvdelta, result);
+}
+
+/**
+ * Get the current OS time in ticks
+ *
+ * @return OS time in ticks
+ */
+os_time_t
+os_time_get(void)
+{
+    return (g_os_time);
+}
+
+static void
+os_time_tick(int ticks)
+{
+    os_sr_t sr;
+    os_time_t delta, prev_os_time;
+
+    assert(ticks >= 0);
+
+    OS_ENTER_CRITICAL(sr);
+    prev_os_time = g_os_time;
+    g_os_time += ticks;
+
+    /*
+     * Update 'basetod' when 'g_os_time' crosses the 0x00000000 and
+     * 0x80000000 thresholds.
+     */
+    if ((prev_os_time ^ g_os_time) >> 31) {
+        delta = g_os_time - basetod.ostime;
+        os_deltatime(delta, &basetod.uptime, &basetod.uptime);
+        os_deltatime(delta, &basetod.utctime, &basetod.utctime);
+        basetod.ostime = g_os_time;
+    }
+    OS_EXIT_CRITICAL(sr);
+}
+
+/**
+ * Move OS time forward ticks.
+ *
+ * @param ticks The number of ticks to move time forward.
+ */
+void
+os_time_advance(int ticks)
+{
+    assert(ticks >= 0);
+
+    if (ticks > 0) {
+        if (!os_started()) {
+            g_os_time += ticks;
+        } else {
+            os_time_tick(ticks);
+            os_callout_tick();
+            os_sched_os_timer_exp();
+            os_sched(NULL);
+        }
+    }
+}
+
+/**
+ * Puts the current task to sleep for the specified number of os ticks. There
+ * is no delay if ticks is <= 0.
+ *
+ * @param osticks Number of ticks to delay (<= 0 means no delay).
+ */
+void
+os_time_delay(int32_t osticks)
+{
+    os_sr_t sr;
+
+    if (osticks > 0) {
+        OS_ENTER_CRITICAL(sr);
+        os_sched_sleep(os_sched_get_current_task(), (os_time_t)osticks);
+        OS_EXIT_CRITICAL(sr);
+        os_sched(NULL);
+    }
+}
+
+/**
+ * Set the time of day.  This does not modify os time, but rather just modifies
+ * the offset by which we are tracking real time against os time.
+ *
+ * @param utctime A timeval representing the UTC time we are setting
+ * @param tz The time-zone to apply against the utctime being set.
+ *
+ * @return 0 on success, non-zero on failure.
+ */
+int
+os_settimeofday(struct os_timeval *utctime, struct os_timezone *tz)
+{
+    os_sr_t sr;
+    os_time_t delta;
+
+    OS_ENTER_CRITICAL(sr);
+    if (utctime != NULL) {
+        /*
+         * Update all time-of-day base values.
+         */
+        delta = os_time_get() - basetod.ostime;
+        os_deltatime(delta, &basetod.uptime, &basetod.uptime);
+        basetod.utctime = *utctime;
+        basetod.ostime += delta;
+    }
+
+    if (tz != NULL) {
+        basetod.timezone = *tz;
+    }
+    OS_EXIT_CRITICAL(sr);
+
+    return (0);
+}
+
+/**
+ * Get the current time of day.  Returns the time of day in UTC
+ * into the tv argument, and returns the timezone (if set) into
+ * tz.
+ *
+ * @param tv The structure to put the UTC time of day into
+ * @param tz The structure to put the timezone information into
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+os_gettimeofday(struct os_timeval *tv, struct os_timezone *tz)
+{
+    os_sr_t sr;
+    os_time_t delta;
+
+    OS_ENTER_CRITICAL(sr);
+    if (tv != NULL) {
+        delta = os_time_get() - basetod.ostime;
+        os_deltatime(delta, &basetod.utctime, tv);
+    }
+
+    if (tz != NULL) {
+        *tz = basetod.timezone;
+    }
+    OS_EXIT_CRITICAL(sr);
+
+    return (0);
+}
+
+/**
+ * Get time since boot in microseconds.
+ *
+ * @return time since boot in microseconds
+ */
+int64_t
+os_get_uptime_usec(void)
+{
+  struct os_timeval tv;
+  os_time_t delta;
+  os_sr_t sr;
+  os_time_t ostime;
+
+
+  OS_ENTER_CRITICAL(sr);
+  tv = basetod.uptime;
+  ostime = basetod.ostime;
+  delta = os_time_get() - ostime;
+  OS_EXIT_CRITICAL(sr);
+
+  os_deltatime(delta, &tv, &tv);
+
+  return(tv.tv_sec * 1000000 + tv.tv_usec);
+}
+
+/**
+ * Converts milliseconds to OS ticks.
+ *
+ * @param ms                    The milliseconds input.
+ * @param out_ticks             The OS ticks output.
+ *
+ * @return                      0 on success; OS_EINVAL if the result is too
+ *                                  large to fit in a uint32_t.
+ */
+int
+os_time_ms_to_ticks(uint32_t ms, uint32_t *out_ticks)
+{
+    uint64_t ticks;
+
+#if OS_TICKS_PER_SEC == 1000
+    *out_ticks = ms;
+    return 0;
+#endif
+
+    _Static_assert(OS_TICKS_PER_SEC <= UINT32_MAX,
+                   "OS_TICKS_PER_SEC must be <= UINT32_MAX");
+
+    ticks = (uint64_t)ms * OS_TICKS_PER_SEC / 1000;
+    if (ticks > UINT32_MAX) {
+        return OS_EINVAL;
+    }
+
+    *out_ticks = ticks;
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/kernel/os/test/pkg.yml
----------------------------------------------------------------------
diff --git a/kernel/os/test/pkg.yml b/kernel/os/test/pkg.yml
new file mode 100644
index 0000000..378e257
--- /dev/null
+++ b/kernel/os/test/pkg.yml
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+pkg.name: kernel/os/test
+pkg.type: unittest
+pkg.description: "OS unit tests."
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps: 
+    - kernel/os
+    - test/testutil
+
+pkg.deps.SELFTEST:
+    - sys/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/kernel/os/test/src/arch/cortex_m4/os_test_arch_arm.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/arch/cortex_m4/os_test_arch_arm.c b/kernel/os/test/src/arch/cortex_m4/os_test_arch_arm.c
new file mode 100644
index 0000000..35134f7
--- /dev/null
+++ b/kernel/os/test/src/arch/cortex_m4/os_test_arch_arm.c
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "testutil/testutil.h"
+#include "os_test_priv.h"
+
+void
+os_test_restart(void)
+{
+    tu_restart();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/kernel/os/test/src/arch/sim/os_test_arch_sim.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/arch/sim/os_test_arch_sim.c b/kernel/os/test/src/arch/sim/os_test_arch_sim.c
new file mode 100644
index 0000000..3b6cfbf
--- /dev/null
+++ b/kernel/os/test/src/arch/sim/os_test_arch_sim.c
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdio.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/time.h>
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+
+void
+os_test_restart(void)
+{
+    struct sigaction sa;
+    struct itimerval it;
+    int rc;
+
+    g_os_started = 0;
+
+    memset(&sa, 0, sizeof sa);
+    sa.sa_handler = SIG_IGN;
+
+    sigaction(SIGALRM, &sa, NULL);
+    sigaction(SIGVTALRM, &sa, NULL);
+
+    memset(&it, 0, sizeof(it));
+    rc = setitimer(ITIMER_VIRTUAL, &it, NULL);
+    if (rc != 0) {
+        perror("Cannot set itimer");
+        abort();
+    }
+
+    tu_restart();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/kernel/os/test/src/callout_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/callout_test.c b/kernel/os/test/src/callout_test.c
new file mode 100644
index 0000000..4e3811d
--- /dev/null
+++ b/kernel/os/test/src/callout_test.c
@@ -0,0 +1,330 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ 
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+#include "os/os_eventq.h"
+#include "os/os_callout.h"
+#include "os/os_time.h"
+
+/* Task 1 for sending */
+#define CALLOUT_STACK_SIZE        (5120)
+#define SEND_CALLOUT_TASK_PRIO        (1)
+struct os_task callout_task_struct_send;
+os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE];
+
+#define RECEIVE_CALLOUT_TASK_PRIO        (2)
+struct os_task callout_task_struct_receive;
+os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE];
+
+/* Delearing variables for callout_func */
+struct os_callout_func callout_func_test;
+
+/* The event to be sent*/
+struct os_eventq callout_evq;
+struct os_event callout_ev;
+
+/* The callout_stop task */
+#define SEND_STOP_CALLOUT_TASK_PRIO        (3)
+struct os_task callout_task_struct_stop_send;
+os_stack_t callout_task_stack_stop_send[CALLOUT_STACK_SIZE];
+
+#define RECEIVE_STOP_CALLOUT_TASK_PRIO        (4)
+struct os_task callout_task_struct_stop_receive;
+os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE];
+
+/* Delearing variables for callout_stop_func */
+#define MULTI_SIZE    (2)
+struct os_callout_func callout_func_stop_test[MULTI_SIZE];
+
+/* The event to be sent*/
+struct os_eventq callout_stop_evq[MULTI_SIZE];
+struct os_event callout_stop_ev;
+
+/* Declearing varables for callout_speak */
+#define SPEAK_CALLOUT_TASK_PRIO        (5)
+struct os_task callout_task_struct_speak;
+os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE];
+
+/* Declearing varaibles for listen */
+#define LISTEN_CALLOUT_TASK_PRIO        (6)
+struct os_task callout_task_struct_listen;
+os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE];
+
+struct os_callout_func callout_func_speak;
+
+/* Global variables to be used by the callout functions */
+int p;
+int q;
+int t;
+/* This is the function for callout_init*/
+void
+my_callout_func(void *arg)
+{
+    p = 4;
+}
+
+/* This is the function for callout_init of stop test_case*/
+void
+my_callout_stop_func(void *arg)
+{
+    q = 1;
+}
+/* This is the function for callout_init for speak test_case*/
+void
+my_callout_speak_func(void *arg)
+{
+    t = 2;
+}
+
+/* This is a callout task to send data */
+void
+callout_task_send(void *arg )
+{
+   int i;
+    /* Should say whether callout is armed or not */
+    i= os_callout_queued(&callout_func_test.cf_c);
+    TEST_ASSERT(i == 0);
+
+    /* Arm the callout */
+    i = os_callout_reset(&callout_func_test.cf_c, OS_TICKS_PER_SEC/ 50);
+    TEST_ASSERT_FATAL(i == 0);
+
+    /* Should say whether callout is armed or not */
+    i = os_callout_queued(&callout_func_test.cf_c);
+    TEST_ASSERT(i == 1);
+
+    /* Send the callout */ 
+    os_time_delay(OS_TICKS_PER_SEC );
+}
+
+/* This is the callout to receive data */
+void
+callout_task_receive( void *arg)
+{
+    int i;
+    struct os_event *event;
+    struct os_callout_func *callout;
+    os_time_t now;
+    os_time_t tm;
+    os_sr_t sr; 
+    /* Recieve using the os_eventq_poll */
+    event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
+    TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
+    TEST_ASSERT(event->ev_arg == NULL);
+    callout = (struct os_callout_func *)event;
+    TEST_ASSERT(callout->cf_func == my_callout_func);
+
+    /* Should say whether callout is armed or not */
+    i = os_callout_queued(&callout_func_test.cf_c);
+    TEST_ASSERT(i == 0);
+
+    OS_ENTER_CRITICAL(sr);
+    now = os_time_get();
+    tm = os_callout_wakeup_ticks(now);
+    TEST_ASSERT(tm == OS_TIMEOUT_NEVER);
+    OS_EXIT_CRITICAL(sr);
+    
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+
+}
+
+/* This is callout to send the stop_callout */
+void
+callout_task_stop_send( void *arg)
+{
+    int k;
+    int j;    
+     /* Should say whether callout is armed or not */
+    for(k = 0; k<MULTI_SIZE; k++){
+        j = os_callout_queued(&callout_func_stop_test[k].cf_c);
+        TEST_ASSERT(j == 0);
+    }
+
+
+    /* Show that  callout is not armed after calling callout_stop */
+    for(k = 0; k<MULTI_SIZE; k++){
+        os_callout_stop(&callout_func_stop_test[k].cf_c);
+        j = os_callout_queued(&callout_func_stop_test[k].cf_c);
+        TEST_ASSERT(j == 0);
+    }
+    /* Arm the callout */
+    for(k = 0; k<MULTI_SIZE; k++){
+        j = os_callout_reset(&callout_func_stop_test[k].cf_c, OS_TICKS_PER_SEC/ 50);
+        TEST_ASSERT_FATAL(j == 0);
+    }
+    os_time_delay( OS_TICKS_PER_SEC );
+}
+
+/* This is the callout to receive stop_callout data */
+void
+callout_task_stop_receive( void *arg )
+{
+    int k;
+    struct os_event *event;
+    struct os_callout_func *callout;
+    /* Recieving using the os_eventq_poll */
+    for(k=0; k<MULTI_SIZE; k++){
+        event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, 1,
+           OS_WAIT_FOREVER);
+        TEST_ASSERT(event->ev_type ==  OS_EVENT_T_TIMER);
+        TEST_ASSERT(event->ev_arg == NULL);
+        callout = (struct os_callout_func *)event;
+        TEST_ASSERT(callout->cf_func == my_callout_stop_func);
+
+
+     }
+     
+    /* Show that event is removed from the queued after calling callout_stop */
+    for(k=0; k<MULTI_SIZE; k++){
+        os_callout_stop(&callout_func_stop_test[k].cf_c);
+        /* Testing that the event has been removed from queue */
+        TEST_ASSERT_FATAL(1); 
+     }
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+
+}
+
+/* This is a callout task to send data */
+void
+callout_task_stop_speak( void *arg )
+{
+    int i;
+    /* Arm the callout */
+    i = os_callout_reset(&callout_func_speak.cf_c, OS_TICKS_PER_SEC/ 50);
+    TEST_ASSERT_FATAL(i == 0);
+
+    /* should say whether callout is armed or not */
+    i = os_callout_queued(&callout_func_speak.cf_c);
+    TEST_ASSERT(i == 1);
+
+    os_callout_stop(&callout_func_speak.cf_c);
+    
+    /* Send the callout */ 
+    os_time_delay(OS_TICKS_PER_SEC/ 100 );
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+}
+
+void
+callout_task_stop_listen( void *arg )
+{
+    struct os_event *event;
+    struct os_callout_func *callout;
+    event = os_eventq_get(callout_func_speak.cf_c.c_evq);
+    TEST_ASSERT_FATAL(0);
+    callout = (struct os_callout_func *)event;
+    TEST_ASSERT(callout->cf_func == my_callout_speak_func);
+
+}
+
+/* Test case to test the basics of the callout */
+TEST_CASE(callout_test)
+{
+
+    /* Initializing the OS */
+    os_init();
+    
+    /* Initialize the sending task */
+    os_task_init(&callout_task_struct_send, "callout_task_send",
+        callout_task_send, NULL, SEND_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_send, CALLOUT_STACK_SIZE);
+
+    /* Initialize the receive task */
+    os_task_init(&callout_task_struct_receive, "callout_task_receive",
+        callout_task_receive, NULL, RECEIVE_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_receive, CALLOUT_STACK_SIZE);
+
+    os_eventq_init(&callout_evq);
+    
+    /* Initialize the callout function */
+    os_callout_func_init(&callout_func_test, &callout_evq,
+        my_callout_func, NULL);
+
+    /* Does not return until OS_restart is called */
+    os_start();
+}
+
+/* Test case of the callout_task_stop */
+TEST_CASE(callout_test_stop)
+{
+    int k;
+    /* Initializing the OS */
+    os_init();
+
+    /* Initialize the sending task */
+    os_task_init(&callout_task_struct_stop_send, "callout_task_stop_send",
+        callout_task_stop_send, NULL, SEND_STOP_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_stop_send, CALLOUT_STACK_SIZE);
+
+    /* Initialize the receiving task */
+    os_task_init(&callout_task_struct_stop_receive, "callout_task_stop_receive",
+        callout_task_stop_receive, NULL, RECEIVE_STOP_CALLOUT_TASK_PRIO,
+        OS_WAIT_FOREVER, callout_task_stack_stop_receive, CALLOUT_STACK_SIZE);
+
+    for(k = 0; k< MULTI_SIZE; k++){
+        os_eventq_init(&callout_stop_evq[k]);
+    }
+    
+    /* Initialize the callout function */
+    for(k = 0; k<MULTI_SIZE; k++){
+        os_callout_func_init(&callout_func_stop_test[k], &callout_stop_evq[k],
+           my_callout_stop_func, NULL);
+    }
+
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
+/* Test case to test case for speak and listen */
+TEST_CASE(callout_test_speak)
+{
+    /* Initializing the OS */
+    os_init();
+    
+    /* Initialize the sending task */
+    os_task_init(&callout_task_struct_speak, "callout_task_speak",
+        callout_task_stop_speak, NULL, SPEAK_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_speak, CALLOUT_STACK_SIZE);
+
+    /* Initialize the receive task */
+    os_task_init(&callout_task_struct_listen, "callout_task_listen",
+        callout_task_stop_listen, NULL, LISTEN_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+        callout_task_stack_listen, CALLOUT_STACK_SIZE);
+
+    os_eventq_init(&callout_evq);
+    
+    /* Initialize the callout function */
+    os_callout_func_init(&callout_func_speak, &callout_evq,
+        my_callout_speak_func, NULL);    
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
+TEST_SUITE(os_callout_test_suite)
+{   
+    callout_test();
+    callout_test_stop();
+    callout_test_speak();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/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
new file mode 100644
index 0000000..3fceb0e
--- /dev/null
+++ b/kernel/os/test/src/eventq_test.c
@@ -0,0 +1,416 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ 
+#include <string.h>
+#include "testutil/testutil.h"
+#include "os/os.h"
+#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)
+struct os_task eventq_task_s;
+os_stack_t eventq_task_stack_s[MY_STACK_SIZE];
+
+/* Task 2 receiving task */
+#define RECEIVE_TASK_PRIO     (2)
+struct os_task eventq_task_r;
+os_stack_t eventq_task_stack_r[MY_STACK_SIZE];
+
+struct os_eventq my_eventq;
+
+#define SIZE_MULTI_EVENT        (4)
+struct os_eventq multi_eventq[SIZE_MULTI_EVENT];
+
+/* This is to set the events we will use below */
+struct os_event g_event;
+struct os_event m_event[SIZE_MULTI_EVENT];
+
+/* Setting the event to send and receive multiple data */
+uint8_t my_event_type = 1;
+
+/* Setting up data for the poll */
+/* Define the task stack for the eventq_task_poll_send */
+#define SEND_TASK_POLL_PRIO        (3)
+struct os_task eventq_task_poll_s;
+os_stack_t eventq_task_stack_poll_s[POLL_STACK_SIZE];
+
+/* Define the task stack for the eventq_task_poll_receive */
+#define RECEIVE_TASK_POLL_PRIO     (4)
+struct os_task eventq_task_poll_r;
+os_stack_t eventq_task_stack_poll_r[POLL_STACK_SIZE ];
+
+/* Setting the data for the poll timeout */
+/* Define the task stack for the eventq_task_poll_timeout_send */
+#define SEND_TASK_POLL_TIMEOUT_PRIO        (5)
+struct os_task eventq_task_poll_timeout_s;
+os_stack_t eventq_task_stack_poll_timeout_s[POLL_STACK_SIZE];
+
+/* Define the task stack for the eventq_task_poll_receive */
+#define RECEIVE_TASK_POLL_TIMEOUT_PRIO     (6)
+struct os_task eventq_task_poll_timeout_r;
+os_stack_t eventq_task_stack_poll_timeout_r[POLL_STACK_SIZE];
+
+/* Setting the data for the poll single */
+/* Define the task stack for the eventq_task_poll_single_send */
+#define SEND_TASK_POLL_SINGLE_PRIO        (7)
+struct os_task eventq_task_poll_single_s;
+os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE];
+
+/* Define the task stack for the eventq_task_poll_single_receive */
+#define RECEIVE_TASK_POLL_SINGLE_PRIO     (8)
+struct os_task eventq_task_poll_single_r;
+os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE];
+
+/* This is the task function  to send data */
+void
+eventq_task_send(void *arg)
+{
+    int i;
+
+    g_event.ev_queued = 0;
+    g_event.ev_type = my_event_type;
+    g_event.ev_arg = NULL;
+
+    os_eventq_put(&my_eventq, &g_event);
+
+    os_time_delay(OS_TICKS_PER_SEC / 2);
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        m_event[i].ev_type = i + 2;
+        m_event[i].ev_arg = NULL;
+
+        /* Put and send */
+        os_eventq_put(&multi_eventq[i], &m_event[i]);
+        os_time_delay(OS_TICKS_PER_SEC / 2);
+    }
+
+    /* This task sleeps until the receive task completes the test. */
+    os_time_delay(1000000);
+}
+
+/* This is the task function is the receiving function */
+void
+eventq_task_receive(void *arg)
+{
+    struct os_event *event;
+    int i;
+
+    event = os_eventq_get(&my_eventq);
+    TEST_ASSERT(event->ev_type == my_event_type);
+
+    /* Receiving multi event from the send task */
+    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
+        event = os_eventq_get(&multi_eventq[i]);
+        TEST_ASSERT(event->ev_type == i + 2);
+    }
+
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+}
+
+void
+eventq_task_poll_send(void *arg)
+{
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    int i;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        m_event[i].ev_type = i + 10;
+        m_event[i].ev_arg = NULL;
+
+        /* Put and send */
+        os_eventq_put(eventqs[i], &m_event[i]);
+        os_time_delay(OS_TICKS_PER_SEC / 2);
+    }
+
+    /* This task sleeps until the receive task completes the test. */
+    os_time_delay(1000000);
+}
+
+void
+eventq_task_poll_receive(void *arg)
+{
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    struct os_event *event;
+    int i;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
+
+    /* Recieving using the os_eventq_poll*/
+    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
+        event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
+        TEST_ASSERT(event->ev_type == i +10);
+    }
+
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+
+}
+
+/* Sending with a time failure */
+void
+eventq_task_poll_timeout_send(void *arg)
+{
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    int i;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+         os_time_delay(OS_TICKS_PER_SEC);
+
+        /* Put and send */
+        os_eventq_put(eventqs[i], &m_event[i]);
+        os_time_delay(OS_TICKS_PER_SEC / 2);
+    }
+
+    /* This task sleeps until the receive task completes the test. */
+    os_time_delay(1000000);
+    
+}
+
+/* Receiving multiple event queues with a time failure */
+void
+eventq_task_poll_timeout_receive(void *arg)
+{
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    struct os_event *event;
+    int i;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
+
+    /* Recieving using the os_eventq_poll_timeout*/
+    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
+        event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_TICKS_PER_SEC / 5);
+        TEST_ASSERT(event == NULL);
+    }
+
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+
+}
+
+/* Sending a single event to poll */
+void
+eventq_task_poll_single_send(void *arg)
+{
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    int i;
+    int position = 2;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
+
+    /* Put and send */
+    os_eventq_put(eventqs[position], &m_event[position]);
+    os_time_delay(OS_TICKS_PER_SEC / 2);
+
+    /* This task sleeps until the receive task completes the test. */
+    os_time_delay(1000000);
+}
+
+/* Recieving the single event */
+void
+eventq_task_poll_single_receive(void *arg)
+{
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    struct os_event *event;
+    int i;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        eventqs[i] = &multi_eventq[i];
+    }
+
+    /* Recieving using the os_eventq_poll*/
+    event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
+    TEST_ASSERT(event->ev_type == 20);
+
+    /* Finishes the test when OS has been started */
+    os_test_restart();
+}
+
+TEST_CASE(event_test_sr)
+{
+    int i;
+
+    /* Initializing the OS */
+    os_init();
+    /* Initialize the task */
+    os_task_init(&eventq_task_s, "eventq_task_s", eventq_task_send, NULL,
+        SEND_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_s, MY_STACK_SIZE);
+
+    /* Receive events and check whether the eevnts are correctly received */
+    os_task_init(&eventq_task_r, "eventq_task_r", eventq_task_receive, NULL,
+        RECEIVE_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_r,
+        MY_STACK_SIZE);
+
+    os_eventq_init(&my_eventq);
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+    }
+
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
+/* To test for the basic function of os_eventq_poll() */
+TEST_CASE(event_test_poll_sr)
+{
+    int i;
+
+    /* Initializing the OS */
+    os_init();
+    /* Initialize the task */
+    os_task_init(&eventq_task_poll_s, "eventq_task_poll_s", eventq_task_poll_send,
+        NULL, SEND_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_s, 
+        POLL_STACK_SIZE);
+
+    /* Receive events and check whether the eevnts are correctly received */
+    os_task_init(&eventq_task_poll_r, "eventq_task_r", eventq_task_poll_receive,
+        NULL, RECEIVE_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_r,
+        POLL_STACK_SIZE);
+
+    /* Initializing the eventqs. */
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+    }
+
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
+/* Test case for poll timeout */
+TEST_CASE(event_test_poll_timeout_sr)
+{
+    int i;
+
+    /* Initializing the OS */
+    os_init();
+    /* Initialize the task */
+    os_task_init(&eventq_task_poll_timeout_s, "eventq_task_poll_timeout_s", 
+        eventq_task_poll_timeout_send, NULL, SEND_TASK_POLL_TIMEOUT_PRIO,
+        OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_s, POLL_STACK_SIZE);
+
+    /* Receive events and check whether the eevnts are correctly received */
+    os_task_init(&eventq_task_poll_timeout_r, "eventq_task_timeout_r",
+        eventq_task_poll_timeout_receive, NULL, RECEIVE_TASK_POLL_TIMEOUT_PRIO,
+        OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_r, POLL_STACK_SIZE);
+
+    /* Initializing the eventqs. */
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+
+        m_event[i].ev_type = i + 10;
+        m_event[i].ev_arg = NULL;
+    }
+
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
+/* The case for poll single */
+/* Test case for poll timeout */
+TEST_CASE(event_test_poll_single_sr)
+{
+    int i;
+
+    /* Initializing the OS */
+    os_init();
+    /* Initialize the task */
+    os_task_init(&eventq_task_poll_single_s, "eventq_task_poll_single_s", 
+        eventq_task_poll_single_send, NULL, SEND_TASK_POLL_SINGLE_PRIO,
+        OS_WAIT_FOREVER, eventq_task_stack_poll_single_s, POLL_STACK_SIZE);
+
+    /* Receive events and check whether the eevnts are correctly received */
+    os_task_init(&eventq_task_poll_single_r, "eventq_task_single_r",
+        eventq_task_poll_single_receive, NULL, RECEIVE_TASK_POLL_SINGLE_PRIO,
+        OS_WAIT_FOREVER, eventq_task_stack_poll_single_r, POLL_STACK_SIZE);
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+
+        m_event[i].ev_type = 10 * i;
+        m_event[i].ev_arg = NULL;
+    }
+
+    /* Does not return until OS_restart is called */
+    os_start();
+
+}
+
+/**
+ * Tests eventq_poll() with a timeout of 0.  This should not involve the
+ * scheduler at all, so it should work without starting the OS.
+ */
+TEST_CASE(event_test_poll_0timo)
+{
+    struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+    struct os_event *evp;
+    struct os_event ev;
+    int i;
+
+    for (i = 0; i < SIZE_MULTI_EVENT; i++){
+        os_eventq_init(&multi_eventq[i]);
+        eventqs[i] = &multi_eventq[i];
+    }
+
+    evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
+    TEST_ASSERT(evp == NULL);
+
+    /* Ensure no eventq thinks a task is waiting on it. */
+    for (i = 0; i < SIZE_MULTI_EVENT; i++) {
+        TEST_ASSERT(eventqs[i]->evq_task == NULL);
+    }
+
+    /* Put an event on one of the queues. */
+    memset(&ev, 0, sizeof ev);
+    ev.ev_type = 1;
+    os_eventq_put(eventqs[3], &ev);
+
+    evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
+    TEST_ASSERT(evp == &ev);
+}
+
+TEST_SUITE(os_eventq_test_suite)
+{
+    event_test_sr();
+    event_test_poll_sr();
+    event_test_poll_timeout_sr();
+    event_test_poll_single_sr();
+    event_test_poll_0timo();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/kernel/os/test/src/mbuf_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mbuf_test.c b/kernel/os/test/src/mbuf_test.c
new file mode 100644
index 0000000..dd4121d
--- /dev/null
+++ b/kernel/os/test/src/mbuf_test.c
@@ -0,0 +1,420 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+
+#include <string.h>
+
+/* 
+ * NOTE: currently, the buffer size cannot be changed as some tests are
+ * hard-coded for this size.
+ */
+#define MBUF_TEST_POOL_BUF_SIZE     (256)
+#define MBUF_TEST_POOL_BUF_COUNT    (10)
+
+#define MBUF_TEST_DATA_LEN          (1024)
+
+static os_membuf_t os_mbuf_membuf[OS_MEMPOOL_SIZE(MBUF_TEST_POOL_BUF_SIZE,
+        MBUF_TEST_POOL_BUF_COUNT)];
+
+static struct os_mbuf_pool os_mbuf_pool;
+static struct os_mempool os_mbuf_mempool;
+static uint8_t os_mbuf_test_data[MBUF_TEST_DATA_LEN];
+
+static void
+os_mbuf_test_setup(void)
+{
+    int rc;
+    int i;
+
+    rc = os_mempool_init(&os_mbuf_mempool, MBUF_TEST_POOL_BUF_COUNT,
+            MBUF_TEST_POOL_BUF_SIZE, &os_mbuf_membuf[0], "mbuf_pool");
+    TEST_ASSERT_FATAL(rc == 0, "Error creating memory pool %d", rc);
+
+    rc = os_mbuf_pool_init(&os_mbuf_pool, &os_mbuf_mempool,
+            MBUF_TEST_POOL_BUF_SIZE, MBUF_TEST_POOL_BUF_COUNT);
+    TEST_ASSERT_FATAL(rc == 0, "Error creating mbuf pool %d", rc);
+
+    for (i = 0; i < sizeof os_mbuf_test_data; i++) {
+        os_mbuf_test_data[i] = i;
+    }
+}
+
+static void
+os_mbuf_test_misc_assert_sane(struct os_mbuf *om, void *data,
+                              int buflen, int pktlen, int pkthdr_len)
+{
+    uint8_t *data_min;
+    uint8_t *data_max;
+    int totlen;
+    int i;
+
+    TEST_ASSERT_FATAL(om != NULL);
+
+    if (OS_MBUF_IS_PKTHDR(om)) {
+        TEST_ASSERT(OS_MBUF_PKTLEN(om) == pktlen);
+    }
+
+    totlen = 0;
+    for (i = 0; om != NULL; i++) {
+        if (i == 0) {
+            TEST_ASSERT(om->om_len == buflen);
+            TEST_ASSERT(om->om_pkthdr_len == pkthdr_len);
+        }
+
+        data_min = om->om_databuf + om->om_pkthdr_len;
+        data_max = om->om_databuf + om->om_omp->omp_databuf_len - om->om_len;
+        TEST_ASSERT(om->om_data >= data_min && om->om_data <= data_max);
+
+        if (data != NULL) {
+            TEST_ASSERT(memcmp(om->om_data, data + totlen, om->om_len) == 0);
+        }
+
+        totlen += om->om_len;
+        om = SLIST_NEXT(om, om_next);
+    }
+
+    TEST_ASSERT(totlen == pktlen);
+}
+
+
+TEST_CASE(os_mbuf_test_alloc)
+{
+    struct os_mbuf *m;
+    int rc;
+
+    os_mbuf_test_setup();
+
+    m = os_mbuf_get(&os_mbuf_pool, 0);
+    TEST_ASSERT_FATAL(m != NULL, "Error allocating mbuf");
+
+    rc = os_mbuf_free(m);
+    TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf %d", rc);
+}
+
+TEST_CASE(os_mbuf_test_get_pkthdr)
+{
+    struct os_mbuf *m;
+ 
+    os_mbuf_test_setup();
+
+#if (MBUF_TEST_POOL_BUF_SIZE <= 256)
+    m = os_mbuf_get_pkthdr(&os_mbuf_pool, MBUF_TEST_POOL_BUF_SIZE - 1);
+    TEST_ASSERT_FATAL(m == NULL, "Error: should not have returned mbuf");
+#endif
+
+    m = os_mbuf_get(&os_mbuf_pool, MBUF_TEST_POOL_BUF_SIZE);
+    TEST_ASSERT_FATAL(m == NULL, "Error: should not have returned mbuf");
+}
+
+
+TEST_CASE(os_mbuf_test_dup)
+{
+    struct os_mbuf *om;
+    struct os_mbuf *om2;
+    struct os_mbuf *dup;
+    int rc;
+
+    os_mbuf_test_setup();
+
+    /* Test first allocating and duplicating a single mbuf */
+    om = os_mbuf_get(&os_mbuf_pool, 0);
+    TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf");
+
+    rc = os_mbuf_append(om, os_mbuf_test_data, 200);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 0);
+
+    dup = os_mbuf_dup(om);
+    TEST_ASSERT_FATAL(dup != NULL, "NULL mbuf returned from dup");
+    TEST_ASSERT_FATAL(dup != om, "duplicate matches original.");
+    os_mbuf_test_misc_assert_sane(dup, os_mbuf_test_data, 200, 200, 0);
+
+    rc = os_mbuf_free(om);
+    TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf om %d", rc);
+
+    rc = os_mbuf_free(dup);
+    TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf dup %d", rc);
+
+    om = os_mbuf_get(&os_mbuf_pool, 0);
+    TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf");
+    rc = os_mbuf_append(om, os_mbuf_test_data, 200);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 0);
+
+    om2 = os_mbuf_get(&os_mbuf_pool, 0);
+    TEST_ASSERT_FATAL(om2 != NULL, "Error allocating mbuf");
+    rc = os_mbuf_append(om2, os_mbuf_test_data + 200, 200);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_test_misc_assert_sane(om2, os_mbuf_test_data + 200, 200, 200, 0);
+
+    os_mbuf_concat(om, om2);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 400, 0);
+
+    dup = os_mbuf_dup(om);
+    TEST_ASSERT_FATAL(dup != NULL, "NULL mbuf returned from dup");
+    TEST_ASSERT_FATAL(dup != om, "Duplicate matches original");
+    TEST_ASSERT_FATAL(SLIST_NEXT(dup, om_next) != NULL,
+            "NULL chained element, duplicate should match original");
+
+    os_mbuf_test_misc_assert_sane(dup, os_mbuf_test_data, 200, 400, 0);
+
+    rc = os_mbuf_free_chain(om);
+    TEST_ASSERT_FATAL(rc == 0, "Cannot free mbuf chain %d", rc);
+
+    rc = os_mbuf_free_chain(dup);
+    TEST_ASSERT_FATAL(rc == 0, "Cannot free mbuf chain %d", rc);
+}
+
+TEST_CASE(os_mbuf_test_append)
+{
+    struct os_mbuf *om;
+    int rc;
+    uint8_t databuf[] = {0xa, 0xb, 0xc, 0xd};
+    uint8_t cmpbuf[] = {0xff, 0xff, 0xff, 0xff};
+
+    os_mbuf_test_setup();
+
+    om = os_mbuf_get(&os_mbuf_pool, 0);
+    TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf");
+    os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 0);
+
+    rc = os_mbuf_append(om, databuf, sizeof(databuf));
+    TEST_ASSERT_FATAL(rc == 0, "Cannot add %d bytes to mbuf",
+            sizeof(databuf));
+    os_mbuf_test_misc_assert_sane(om, databuf, sizeof databuf, sizeof databuf,
+                                  0);
+
+    memcpy(cmpbuf, OS_MBUF_DATA(om, uint8_t *), om->om_len);
+    TEST_ASSERT_FATAL(memcmp(cmpbuf, databuf, sizeof(databuf)) == 0,
+            "Databuf doesn't match cmpbuf");
+}
+
+TEST_CASE(os_mbuf_test_extend)
+{
+    struct os_mbuf *om;
+    void *v;
+
+    os_mbuf_test_setup();
+
+    /*** Series of successful extensions. */
+    om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om != NULL);
+
+    TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 222);
+    TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
+    os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 18);
+
+    v = os_mbuf_extend(om, 20);
+    TEST_ASSERT(v != NULL);
+    TEST_ASSERT(v == om->om_data);
+    TEST_ASSERT(om->om_len == 20);
+
+    TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 202);
+    TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
+    os_mbuf_test_misc_assert_sane(om, NULL, 20, 20, 18);
+
+    v = os_mbuf_extend(om, 100);
+    TEST_ASSERT(v != NULL);
+    TEST_ASSERT(v == om->om_data + 20);
+    TEST_ASSERT(om->om_len == 120);
+
+    TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 102);
+    TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
+    os_mbuf_test_misc_assert_sane(om, NULL, 120, 120, 18);
+
+    v = os_mbuf_extend(om, 101);
+    TEST_ASSERT(v != NULL);
+    TEST_ASSERT(v == om->om_data + 120);
+    TEST_ASSERT(om->om_len == 221);
+
+    TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 1);
+    TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
+    os_mbuf_test_misc_assert_sane(om, NULL, 221, 221, 18);
+
+    v = os_mbuf_extend(om, 1);
+    TEST_ASSERT(v != NULL);
+    TEST_ASSERT(v == om->om_data + 221);
+    TEST_ASSERT(om->om_len == 222);
+
+    TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
+    TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
+    os_mbuf_test_misc_assert_sane(om, NULL, 222, 222, 18);
+
+    /* Overflow into next buffer. */
+    v = os_mbuf_extend(om, 1);
+    TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
+    TEST_ASSERT(SLIST_NEXT(om, om_next) != NULL);
+
+    TEST_ASSERT(v == SLIST_NEXT(om, om_next)->om_data);
+    TEST_ASSERT(om->om_len == 222);
+    TEST_ASSERT(SLIST_NEXT(om, om_next)->om_len == 1);
+    os_mbuf_test_misc_assert_sane(om, NULL, 222, 223, 18);
+
+    /*** Attempt to extend by an amount larger than max buf size fails. */
+    v = os_mbuf_extend(om, 257);
+    TEST_ASSERT(v == NULL);
+    TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
+    TEST_ASSERT(SLIST_NEXT(om, om_next) != NULL);
+
+    TEST_ASSERT(om->om_len == 222);
+    TEST_ASSERT(SLIST_NEXT(om, om_next)->om_len == 1);
+    os_mbuf_test_misc_assert_sane(om, NULL, 222, 223, 18);
+}
+
+TEST_CASE(os_mbuf_test_pullup)
+{
+    struct os_mbuf *om;
+    struct os_mbuf *om2;
+    int rc;
+
+    os_mbuf_test_setup();
+
+    /*** Free when too much os_mbuf_test_data is requested. */
+    om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om != NULL);
+
+    om = os_mbuf_pullup(om, 1);
+    TEST_ASSERT(om == NULL);
+
+    /*** No effect when all os_mbuf_test_data is already at the start. */
+    om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om != NULL);
+
+    rc = os_mbuf_append(om, os_mbuf_test_data, 1);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, 18);
+
+    om = os_mbuf_pullup(om, 1);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, 18);
+
+    /*** Spread os_mbuf_test_data across four mbufs. */
+    om2 = os_mbuf_get(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om2 != NULL);
+    rc = os_mbuf_append(om2, os_mbuf_test_data + 1, 1);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_concat(om, om2);
+
+    om2 = os_mbuf_get(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om2 != NULL);
+    rc = os_mbuf_append(om2, os_mbuf_test_data + 2, 1);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_concat(om, om2);
+
+    om2 = os_mbuf_get(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om2 != NULL);
+    rc = os_mbuf_append(om2, os_mbuf_test_data + 3, 1);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_concat(om, om2);
+
+    TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(om) == 4);
+
+    om = os_mbuf_pullup(om, 4);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 4, 4, 18);
+
+    os_mbuf_free_chain(om);
+
+    /*** Require an allocation. */
+    om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om != NULL);
+
+    om->om_data += 100;
+    rc = os_mbuf_append(om, os_mbuf_test_data, 100);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    om2 = os_mbuf_get(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om2 != NULL);
+    rc = os_mbuf_append(om2, os_mbuf_test_data + 100, 100);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_concat(om, om2);
+
+    om = os_mbuf_pullup(om, 200);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 18);
+
+    /*** Partial pullup. */
+    om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om != NULL);
+
+    om->om_data += 100;
+    rc = os_mbuf_append(om, os_mbuf_test_data, 100);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    om2 = os_mbuf_get(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om2 != NULL);
+    rc = os_mbuf_append(om2, os_mbuf_test_data + 100, 100);
+    TEST_ASSERT_FATAL(rc == 0);
+    os_mbuf_concat(om, om2);
+
+    om = os_mbuf_pullup(om, 150);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 150, 200, 18);
+}
+
+TEST_CASE(os_mbuf_test_adj)
+{
+    struct os_mbuf *om;
+    int rc;
+
+    os_mbuf_test_setup();
+
+    om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
+    TEST_ASSERT_FATAL(om != NULL);
+
+    rc = os_mbuf_append(om, os_mbuf_test_data, sizeof os_mbuf_test_data);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 222,
+                                  sizeof os_mbuf_test_data, 18);
+
+    /* Remove from the front. */
+    os_mbuf_adj(om, 10);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, 212,
+                                  sizeof os_mbuf_test_data - 10, 18);
+
+    /* Remove from the back. */
+    os_mbuf_adj(om, -10);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, 212,
+                                  sizeof os_mbuf_test_data - 20, 18);
+
+    /* Remove entire first buffer. */
+    os_mbuf_adj(om, 212);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 222, 0,
+                                  sizeof os_mbuf_test_data - 232, 18);
+
+    /* Remove next buffer. */
+    os_mbuf_adj(om, 256);
+    os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 478, 0,
+                                  sizeof os_mbuf_test_data - 488, 18);
+
+    /* Remove more data than is present. */
+    os_mbuf_adj(om, 1000);
+    os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 18);
+}
+
+TEST_SUITE(os_mbuf_test_suite)
+{
+    os_mbuf_test_alloc();
+    os_mbuf_test_dup();
+    os_mbuf_test_append();
+    os_mbuf_test_pullup();
+    os_mbuf_test_extend();
+    os_mbuf_test_adj();
+    os_mbuf_test_get_pkthdr();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/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
new file mode 100644
index 0000000..cd17c90
--- /dev/null
+++ b/kernel/os/test/src/mempool_test.c
@@ -0,0 +1,227 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <stdio.h>
+#include <string.h>
+#include "testutil/testutil.h"
+#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
+int alignment = 8;
+#endif
+
+/* Test memory pool structure */
+struct os_mempool g_TstMempool;
+
+/* Test memory pool buffer */
+os_membuf_t TstMembuf[OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE)];
+
+/* Array of block pointers. */
+void *block_array[MEMPOOL_TEST_MAX_BLOCKS];
+
+int verbose = 0;
+
+static int
+mempool_test_get_pool_size(int num_blocks, int block_size)
+{
+    int mem_pool_size;
+
+#if OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4
+    mem_pool_size = (num_blocks * ((block_size + 3)/4) * sizeof(os_membuf_t));
+#else
+    mem_pool_size = (num_blocks * ((block_size + 7)/8) * sizeof(os_membuf_t));
+#endif
+
+    return mem_pool_size;
+}
+
+static 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 == 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");
+
+    /* 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");
+}
+
+/**
+ * os mempool test 
+ *  
+ * Main test loop for memory pool testing. 
+ * 
+ * @return int 
+ */
+TEST_CASE(os_mempool_test_case)
+{
+    mempool_test(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE);
+}
+
+TEST_SUITE(os_mempool_test_suite)
+{
+    os_mempool_test_case();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/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
new file mode 100644
index 0000000..d23f099
--- /dev/null
+++ b/kernel/os/test/src/mutex_test.c
@@ -0,0 +1,407 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/time.h>
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os/os_test.h"
+#include "os/os_cfg.h"
+#include "os/os_mutex.h"
+#include "os_test_priv.h"
+
+#ifdef ARCH_sim
+#define MUTEX_TEST_STACK_SIZE   1024
+#else
+#define MUTEX_TEST_STACK_SIZE   256
+#endif
+
+struct os_task task14;
+os_stack_t stack14[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
+
+struct os_task task15;
+os_stack_t stack15[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
+
+struct os_task task16;
+os_stack_t stack16[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
+
+struct os_task task17;
+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)
+
+volatile int g_task14_val;
+volatile int g_task15_val;
+volatile int g_task16_val;
+volatile int g_task17_val;
+struct os_mutex g_mutex1;
+struct os_mutex g_mutex2;
+
+static volatile int g_mutex_test;
+
+/**
+ * mutex test basic 
+ *  
+ * Basic mutex tests
+ * 
+ * @return int 
+ */
+static void
+mutex_test_basic_handler(void *arg)
+{
+    struct os_mutex *mu;
+    struct os_task *t;
+    os_error_t err;
+
+    mu = &g_mutex1;
+    t = os_sched_get_current_task();
+
+    /* Test some error cases */
+    TEST_ASSERT(os_mutex_init(NULL)     == OS_INVALID_PARM);
+    TEST_ASSERT(os_mutex_release(NULL)  == OS_INVALID_PARM);
+    TEST_ASSERT(os_mutex_pend(NULL, 0)  == OS_INVALID_PARM);
+
+    /* Get the mutex */
+    err = os_mutex_pend(mu, 0);
+    TEST_ASSERT(err == 0,
+                "Did not get free mutex immediately (err=%d)", err);
+
+    /* Check mutex internals */
+    TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 1 &&
+                mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
+                "Mutex internals not correct after getting mutex\n"
+                "Mutex: owner=%p prio=%u level=%u head=%p\n"
+                "Task: task=%p prio=%u",
+                mu->mu_owner, mu->mu_prio, mu->mu_level, 
+                SLIST_FIRST(&mu->mu_head),
+                t, t->t_prio);
+
+    /* Get the mutex again; should be level 2 */
+    err = os_mutex_pend(mu, 0);
+    TEST_ASSERT(err == 0, "Did not get my mutex immediately (err=%d)", err);
+
+    /* Check mutex internals */
+    TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 2 &&
+                mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
+                "Mutex internals not correct after getting mutex\n"
+                "Mutex: owner=%p prio=%u level=%u head=%p\n"
+                "Task: task=%p prio=%u",
+                mu->mu_owner, mu->mu_prio, mu->mu_level, 
+                SLIST_FIRST(&mu->mu_head), t, t->t_prio);
+
+    /* Release mutex */
+    err = os_mutex_release(mu);
+    TEST_ASSERT(err == 0, "Could not release mutex I own (err=%d)", err);
+
+    /* Check mutex internals */
+    TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 1 &&
+                mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
+                "Error: mutex internals not correct after getting mutex\n"
+                "Mutex: owner=%p prio=%u level=%u head=%p\n"
+                "Task: task=%p prio=%u",
+                mu->mu_owner, mu->mu_prio, mu->mu_level, 
+                SLIST_FIRST(&mu->mu_head), t, t->t_prio);
+
+    /* Release it again */
+    err = os_mutex_release(mu);
+    TEST_ASSERT(err == 0, "Could not release mutex I own (err=%d)", err);
+
+    /* Check mutex internals */
+    TEST_ASSERT(mu->mu_owner == NULL && mu->mu_level == 0 &&
+                mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
+                "Mutex internals not correct after getting mutex\n"
+                "Mutex: owner=%p prio=%u level=%u head=%p\n"
+                "Task: task=%p prio=%u",
+                mu->mu_owner, mu->mu_prio, mu->mu_level, 
+                SLIST_FIRST(&mu->mu_head), t, t->t_prio);
+
+    os_test_restart();
+}
+
+static void 
+mutex_test1_task14_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);
+
+    for (iters = 0; iters < 3; iters++) {
+        os_time_delay(OS_TICKS_PER_SEC / 10);
+
+        g_task14_val = 1;
+
+        err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC / 10);
+        TEST_ASSERT(err == OS_OK);
+        TEST_ASSERT(g_task16_val == 1);
+
+        os_time_delay(OS_TICKS_PER_SEC / 10);
+    }
+
+    os_test_restart();
+}
+
+static void 
+mutex_test2_task14_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);
+
+    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;
+        os_time_delay(OS_TICKS_PER_SEC / 10);
+
+        /* 
+         * Task17 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);
+        }
+
+        if (g_mutex_test == 4) {
+            os_time_delay(150);
+        }
+
+        os_mutex_release(&g_mutex1);
+        os_time_delay(OS_TICKS_PER_SEC / 10);
+    }
+
+    os_test_restart();
+}
+
+static void 
+task15_handler(void *arg) 
+{
+    os_error_t err;
+    struct os_task *t;
+
+    if (g_mutex_test == 1) {
+        while (1) {
+            t = os_sched_get_current_task();
+            TEST_ASSERT(t->t_func == task15_handler);
+
+            os_time_delay(OS_TICKS_PER_SEC / 20);
+            while (1) {
+                /* Wait here forever */
+            }
+        }
+    } else {
+        if (g_mutex_test == 2) {
+            /* Sleep for 3 seconds */
+            t = os_sched_get_current_task();
+            os_time_delay(OS_TICKS_PER_SEC / 2);
+        } else if (g_mutex_test == 3) {
+            /* Sleep for 3 seconds */
+            t = os_sched_get_current_task();
+            os_time_delay(OS_TICKS_PER_SEC / 33);
+        }
+
+        while (1) {
+            t = os_sched_get_current_task();
+            TEST_ASSERT(t->t_func == task15_handler);
+
+            err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
+            if (g_mutex_test == 4) {
+                TEST_ASSERT(err == OS_TIMEOUT);
+            } else {
+                TEST_ASSERT(err == OS_OK);
+            }
+
+            os_time_delay(OS_TICKS_PER_SEC / 10);
+        }
+    }
+}
+
+static void 
+task16_handler(void *arg) 
+{
+    os_error_t err;
+    struct os_task *t;
+
+    if (g_mutex_test == 1) {
+        while (1) {
+            t = os_sched_get_current_task();
+            TEST_ASSERT(t->t_func == task16_handler);
+
+            /* Get mutex 1 */
+            err = os_mutex_pend(&g_mutex1, OS_TIMEOUT_NEVER);
+            TEST_ASSERT(err == OS_OK);
+
+            while (g_task14_val != 1) {
+                /* Wait till task 1 wakes up and sets val. */
+            }
+
+            g_task16_val = 1;
+
+            err = os_mutex_release(&g_mutex1);
+            TEST_ASSERT(err == OS_OK);
+        }
+    } else {
+        if (g_mutex_test == 2) {
+            /* Sleep for 3 seconds */
+            t = os_sched_get_current_task();
+            os_time_delay(OS_TICKS_PER_SEC / 33);
+        } else if (g_mutex_test == 3) {
+            /* Sleep for 3 seconds */
+            t = os_sched_get_current_task();
+            os_time_delay(OS_TICKS_PER_SEC / 20);
+        }
+
+        while (1) {
+            t = os_sched_get_current_task();
+            TEST_ASSERT(t->t_func == task16_handler);
+
+            err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
+            if (g_mutex_test == 4) {
+                TEST_ASSERT(err == OS_TIMEOUT);
+            } else {
+                TEST_ASSERT(err == OS_OK);
+            }
+
+            if (err == OS_OK) {
+                err = os_mutex_release(&g_mutex1);
+                TEST_ASSERT(err == OS_OK);
+            }
+
+            os_time_delay(OS_TICKS_PER_SEC * 10);
+        }
+    }
+}
+
+static void 
+task17_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);
+
+        if (g_mutex_test == 5) {
+            err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC / 10);
+        } else {
+            err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
+            TEST_ASSERT((t->t_flags & OS_TASK_FLAG_MUTEX_WAIT) == 0);
+        }
+
+        if (g_mutex_test == 4 || g_mutex_test == 5) {
+            TEST_ASSERT(err == OS_TIMEOUT);
+        } else {
+            TEST_ASSERT(err == OS_OK);
+        }
+
+        if (err == OS_OK) {
+            err = os_mutex_release(&g_mutex1);
+            TEST_ASSERT(err == OS_OK);
+        }
+
+        os_time_delay(OS_TICKS_PER_SEC * 10);
+    }
+}
+
+TEST_CASE(os_mutex_test_basic)
+{
+    os_init();
+
+    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_start();
+}
+
+TEST_CASE(os_mutex_test_case_1)
+{
+    int rc;
+
+    os_init();
+
+    g_mutex_test = 1;
+    g_task14_val = 0;
+    g_task15_val = 0;
+    g_task16_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(&task15, "task15", task15_handler, NULL, TASK15_PRIO, 
+            OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+
+    os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO, 
+            OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+
+    os_start();
+}
+
+TEST_CASE(os_mutex_test_case_2)
+{
+    os_init();
+
+    g_mutex_test = 2;
+    g_task14_val = 0;
+    g_task15_val = 0;
+    g_task16_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(&task15, "task15", task15_handler, NULL, TASK15_PRIO, 
+            OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+
+    os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO, 
+            OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+
+    os_task_init(&task17, "task17", task17_handler, NULL, TASK17_PRIO, 
+            OS_WAIT_FOREVER, stack17, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
+ 
+    os_start();
+}
+
+TEST_SUITE(os_mutex_test_suite)
+{
+    os_mutex_test_basic();
+    os_mutex_test_case_1();
+    os_mutex_test_case_2();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/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
new file mode 100644
index 0000000..e9d041b
--- /dev/null
+++ b/kernel/os/test/src/os_test.c
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <stddef.h>
+#include "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+#include "os/os_test.h"
+#include "os_test_priv.h"
+
+int
+os_test_all(void)
+{
+    os_mempool_test_suite();
+    os_mutex_test_suite();
+    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)
+{
+    tu_config.tc_print_results = 1;
+    tu_init();
+
+    os_test_all();
+
+    return tu_any_failed;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a7432f4/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
new file mode 100644
index 0000000..e923a6f
--- /dev/null
+++ b/kernel/os/test/src/os_test_priv.h
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_OS_TEST_PRIV_
+#define H_OS_TEST_PRIV_
+
+void os_test_restart(void);
+
+int os_mempool_test_suite(void);
+int os_mbuf_test_suite(void);
+int os_mutex_test_suite(void);
+int os_sem_test_suite(void);
+int os_eventq_test_suite(void);
+int os_callout_test_suite(void);
+
+#endif