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/10/17 23:59:30 UTC

[04/16] incubator-mynewt-core git commit: Unit test infrastructure

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..aeb3a8f
--- /dev/null
+++ b/kernel/os/test/src/sem_test.h
@@ -0,0 +1,79 @@
+/**
+ * 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 _SEM_TEST_H
+#define  _SEM_TEST_H
+
+#include <stdio.h>
+#include <string.h>
+#include "sysinit/sysinit.h"
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+
+#ifdef __cplusplus
+#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);
+void sem_test_sleep_task_handler(void *arg);
+void sem_test_pend_release_loop(int delay, int timeout, int itvl);
+void sem_test_basic_handler(void *arg);
+void sem_test_1_task1_handler(void *arg);
+void sem_test_1_task2_handler(void *arg);
+void sem_test_1_task3_handler(void *arg);
+void sem_test_2_task2_handler(void *arg);
+void sem_test_2_task3_handler(void *arg);
+void sem_test_2_task4_handler(void *arg);
+void sem_test_3_task2_handler(void *arg);
+void sem_test_3_task3_handler(void *arg);
+void sem_test_3_task4_handler(void *arg);
+void sem_test_4_task2_handler(void *arg);
+void sem_test_4_task3_handler(void *arg);
+void sem_test_4_task4_handler(void *arg); 
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*  _SEM_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/event_test_poll_0timo.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_0timo.c b/kernel/os/test/src/testcases/event_test_poll_0timo.c
new file mode 100644
index 0000000..33772cc
--- /dev/null
+++ b/kernel/os/test/src/testcases/event_test_poll_0timo.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 "os_test_priv.h"
+
+/**
+ * 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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/event_test_poll_single_sr.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_single_sr.c b/kernel/os/test/src/testcases/event_test_poll_single_sr.c
new file mode 100644
index 0000000..a0b54ac
--- /dev/null
+++ b/kernel/os/test/src/testcases/event_test_poll_single_sr.c
@@ -0,0 +1,49 @@
+/**
+ * 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_test_priv.h"
+
+/* The case for poll single */
+/* Test case for poll timeout */
+TEST_CASE(event_test_poll_single_sr)
+{
+    int i;
+
+    /* Initializing the OS */
+    sysinit();
+    /* 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();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/event_test_poll_sr.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_sr.c b/kernel/os/test/src/testcases/event_test_poll_sr.c
new file mode 100644
index 0000000..d6539b1
--- /dev/null
+++ b/kernel/os/test/src/testcases/event_test_poll_sr.c
@@ -0,0 +1,46 @@
+/**
+ * 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_test_priv.h"
+
+/* To test for the basic function of os_eventq_poll() */
+TEST_CASE(event_test_poll_sr)
+{
+    int i;
+
+    /* Initializing the OS */
+    sysinit();
+    /* 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();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c b/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
new file mode 100644
index 0000000..87eafe2
--- /dev/null
+++ b/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
@@ -0,0 +1,49 @@
+/**
+ * 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_test_priv.h"
+
+/* Test case for poll timeout */
+TEST_CASE(event_test_poll_timeout_sr)
+{
+    int i;
+
+    /* Initializing the OS */
+    sysinit();
+    /* 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();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/event_test_src.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_src.c b/kernel/os/test/src/testcases/event_test_src.c
new file mode 100644
index 0000000..c4936f0
--- /dev/null
+++ b/kernel/os/test/src/testcases/event_test_src.c
@@ -0,0 +1,45 @@
+/**
+ * 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_test_priv.h"
+
+TEST_CASE(event_test_sr)
+{
+    int i;
+
+    /* Initializing the OS */
+    sysinit();
+    /* 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();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/ob_mbuf_test_adj.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/ob_mbuf_test_adj.c b/kernel/os/test/src/testcases/ob_mbuf_test_adj.c
new file mode 100644
index 0000000..ceb72ed
--- /dev/null
+++ b/kernel/os/test/src/testcases/ob_mbuf_test_adj.c
@@ -0,0 +1,60 @@
+/**
+ * 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_test_priv.h"
+
+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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/ob_mbuf_test_pullup.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/ob_mbuf_test_pullup.c b/kernel/os/test/src/testcases/ob_mbuf_test_pullup.c
new file mode 100644
index 0000000..e320c81
--- /dev/null
+++ b/kernel/os/test/src/testcases/ob_mbuf_test_pullup.c
@@ -0,0 +1,106 @@
+/**
+ * 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_test_priv.h"
+
+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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/os_callout_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test.c b/kernel/os/test/src/testcases/os_callout_test.c
new file mode 100644
index 0000000..172ab69
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_callout_test.c
@@ -0,0 +1,46 @@
+/**
+ * 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_test_priv.h"
+
+/* Test case to test the basics of the callout */
+TEST_CASE(callout_test)
+{
+
+    /* Initializing the OS */
+    sysinit();
+    
+    /* 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();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/os_callout_test_speak.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test_speak.c b/kernel/os/test/src/testcases/os_callout_test_speak.c
new file mode 100644
index 0000000..25e8d39
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_callout_test_speak.c
@@ -0,0 +1,45 @@
+/**
+ * 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_test_priv.h"
+
+/* Test case to test case for speak and listen */
+TEST_CASE(callout_test_speak)
+{
+    /* Initializing the OS */
+    sysinit();
+    
+    /* 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();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/os_callout_test_stop.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test_stop.c b/kernel/os/test/src/testcases/os_callout_test_stop.c
new file mode 100644
index 0000000..598dd2e
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_callout_test_stop.c
@@ -0,0 +1,51 @@
+/**
+ * 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_test_priv.h"
+
+/* Test case of the callout_task_stop */
+TEST_CASE(callout_test_stop)
+{
+    int k;
+    /* Initializing the OS */
+    sysinit();
+
+    /* 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();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/os_mbuf_test_alloc.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mbuf_test_alloc.c b/kernel/os/test/src/testcases/os_mbuf_test_alloc.c
new file mode 100644
index 0000000..aae24cc
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mbuf_test_alloc.c
@@ -0,0 +1,33 @@
+/**
+ * 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_test_priv.h"
+
+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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/os_mbuf_test_append.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mbuf_test_append.c b/kernel/os/test/src/testcases/os_mbuf_test_append.c
new file mode 100644
index 0000000..4f8dfe2
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mbuf_test_append.c
@@ -0,0 +1,43 @@
+/**
+ * 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_test_priv.h"
+
+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");
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/os_mbuf_test_dup.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mbuf_test_dup.c b/kernel/os/test/src/testcases/os_mbuf_test_dup.c
new file mode 100644
index 0000000..f0ce017
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mbuf_test_dup.c
@@ -0,0 +1,77 @@
+/**
+ * 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_test_priv.h"
+
+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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/os_mbuf_test_extend.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mbuf_test_extend.c b/kernel/os/test/src/testcases/os_mbuf_test_extend.c
new file mode 100644
index 0000000..981de69
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mbuf_test_extend.c
@@ -0,0 +1,91 @@
+/**
+ * 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_test_priv.h"
+
+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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/testcases/os_mbuf_test_get_pkghdr.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_mbuf_test_get_pkghdr.c b/kernel/os/test/src/testcases/os_mbuf_test_get_pkghdr.c
new file mode 100644
index 0000000..40787f7
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mbuf_test_get_pkghdr.c
@@ -0,0 +1,34 @@
+/**
+ * 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_test_priv.h"
+
+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");
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..98d78cc
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mempool_test_case.c
@@ -0,0 +1,31 @@
+/**
+ * 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_test_priv.h"
+
+/**
+ * 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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..234c961
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mutex_test_basic.c
@@ -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.
+ */
+#include "os_test_priv.h"
+
+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_start();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..f1c5c1d
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mutex_test_case_1.c
@@ -0,0 +1,48 @@
+/**
+ * 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_test_priv.h"
+
+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;
+
+    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();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..eee1d89
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_mutex_test_case_2.c
@@ -0,0 +1,46 @@
+/**
+ * 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_test_priv.h"
+
+TEST_CASE(os_mutex_test_case_2)
+{
+    sysinit();
+
+    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();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..4a91192
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_sem_test_basic.c
@@ -0,0 +1,34 @@
+/**
+ * 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_test_priv.h"
+
+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_start();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..8e33087
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_sem_test_case_1.c
@@ -0,0 +1,42 @@
+/**
+ * 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_test_priv.h"
+
+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));
+
+    os_task_init(&task2, "task2", sem_test_1_task2_handler, NULL,
+                 TASK2_PRIO, OS_WAIT_FOREVER, stack2,
+                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+
+    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_start();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..2836b66
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_sem_test_case_2.c
@@ -0,0 +1,45 @@
+/**
+ * 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_test_priv.h"
+
+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));
+
+    os_task_init(&task2, "task2", sem_test_2_task2_handler, NULL,
+                 TASK2_PRIO, OS_WAIT_FOREVER, stack2,
+                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+
+    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(&task4, "task4", sem_test_2_task4_handler, NULL, TASK4_PRIO,
+            OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+
+    os_start();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..6f10409
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_sem_test_case_3.c
@@ -0,0 +1,45 @@
+/**
+ * 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_test_priv.h"
+
+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));
+
+    os_task_init(&task2, "task2", sem_test_3_task2_handler, NULL,
+                 TASK2_PRIO, OS_WAIT_FOREVER, stack2,
+                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+
+    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(&task4, "task4", sem_test_3_task4_handler, NULL, TASK4_PRIO,
+            OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+
+    os_start();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
new file mode 100644
index 0000000..6ec6f93
--- /dev/null
+++ b/kernel/os/test/src/testcases/os_sem_test_case_4.c
@@ -0,0 +1,45 @@
+/**
+ * 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_test_priv.h"
+
+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));
+
+    os_task_init(&task2, "task2", sem_test_4_task2_handler, NULL,
+                 TASK2_PRIO, OS_WAIT_FOREVER, stack2,
+                 OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+
+    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(&task4, "task4", sem_test_4_task4_handler, NULL, TASK4_PRIO,
+                 OS_WAIT_FOREVER, stack4, OS_STACK_ALIGN(SEM_TEST_STACK_SIZE));
+
+    os_start();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/net/ip/mn_socket/test/src/mn_sock_test.c
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/test/src/mn_sock_test.c b/net/ip/mn_socket/test/src/mn_sock_test.c
index 4af9b1d..0f56db5 100644
--- a/net/ip/mn_socket/test/src/mn_sock_test.c
+++ b/net/ip/mn_socket/test/src/mn_sock_test.c
@@ -27,13 +27,12 @@
 
 #include "mn_socket/mn_socket.h"
 #include "mn_socket/arch/sim/native_sock.h"
+#include "mn_sock_test.h"
 
 #define TEST_STACK_SIZE 4096
 #define TEST_PRIO 22
-static os_stack_t test_stack[OS_STACK_ALIGN(TEST_STACK_SIZE)];
-static struct os_task test_task;
-
-static struct os_sem test_sem;
+os_stack_t test_stack[OS_STACK_ALIGN(TEST_STACK_SIZE)];
+struct os_task test_task;
 
 #define MB_CNT 10
 #define MB_SZ  512
@@ -41,856 +40,51 @@ static uint8_t test_mbuf_area[MB_CNT * MB_SZ];
 static struct os_mempool test_mbuf_mpool;
 static struct os_mbuf_pool test_mbuf_pool;
 
-TEST_CASE(inet_pton_test)
-{
-    int rc;
-    uint8_t addr[8];
-    struct test_vec {
-        char *str;
-        uint8_t cmp[4];
-    };
-    struct test_vec ok_vec[] = {
-        { "1.1.1.1", { 1, 1, 1, 1 } },
-        { "1.2.3.4", { 1, 2, 3, 4 } },
-        { "010.001.255.255", { 10, 1, 255, 255 } },
-        { "001.002.005.006", { 1, 2, 5, 6 } }
-    };
-    struct test_vec invalid_vec[] = {
-        { "a.b.c.d" },
-        { "1a.b3.4.2" },
-        { "1.3.4.2a" },
-        { "1111.3.4.2" },
-        { "3.256.1.0" },
-    };
-    int i;
-
-    for (i = 0; i < sizeof(ok_vec) / sizeof(ok_vec[0]); i++) {
-        memset(addr, 0xa5, sizeof(addr));
-        rc = mn_inet_pton(MN_PF_INET, ok_vec[i].str, addr);
-        TEST_ASSERT(rc == 1);
-        TEST_ASSERT(!memcmp(ok_vec[i].cmp, addr, sizeof(uint32_t)));
-        TEST_ASSERT(addr[5] == 0xa5);
-    }
-    for (i = 0; i < sizeof(invalid_vec) / sizeof(invalid_vec[0]); i++) {
-        rc = mn_inet_pton(MN_PF_INET, invalid_vec[i].str, addr);
-        TEST_ASSERT(rc == 0);
-    }
-}
-
-TEST_CASE(inet_ntop_test)
-{
-    const char *rstr;
-    char addr[48];
-    struct test_vec {
-        char *str;
-        uint8_t cmp[4];
-    };
-    struct test_vec ok_vec[] = {
-        { "1.1.1.1", { 1, 1, 1, 1 } },
-        { "1.2.3.4", { 1, 2, 3, 4 } },
-        { "255.1.255.255", { 255, 1, 255, 255 } },
-        { "1.2.5.6", { 1, 2, 5, 6 } }
-    };
-    int i;
-
-    for (i = 0; i < sizeof(ok_vec) / sizeof(ok_vec[0]); i++) {
-        memset(addr, 0xa5, sizeof(addr));
-        rstr = mn_inet_ntop(MN_PF_INET, ok_vec[i].cmp, addr, sizeof(addr));
-        TEST_ASSERT(rstr);
-        TEST_ASSERT(!strcmp(ok_vec[i].str, addr));
-    }
-    rstr = mn_inet_ntop(MN_PF_INET, ok_vec[0].cmp, addr, 1);
-    TEST_ASSERT(rstr == NULL);
-
-    /* does not have space to null terminate */
-    rstr = mn_inet_ntop(MN_PF_INET, ok_vec[0].cmp, addr, 7);
-    TEST_ASSERT(rstr == NULL);
-}
-
-void
-sock_open_close(void)
-{
-    struct mn_socket *sock;
-    int rc;
-
-    rc = mn_socket(&sock, MN_PF_INET, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(sock);
-    TEST_ASSERT(rc == 0);
-    mn_close(sock);
-
-    rc = mn_socket(&sock, MN_PF_INET, MN_SOCK_STREAM, 0);
-    TEST_ASSERT(sock);
-    TEST_ASSERT(rc == 0);
-    mn_close(sock);
-
-    rc = mn_socket(&sock, MN_PF_INET6, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(sock);
-    TEST_ASSERT(rc == 0);
-    mn_close(sock);
-
-    rc = mn_socket(&sock, MN_PF_INET6, MN_SOCK_STREAM, 0);
-    TEST_ASSERT(sock);
-    TEST_ASSERT(rc == 0);
-    mn_close(sock);
-}
-
-void
-sock_listen(void)
-{
-    struct mn_socket *sock;
-    struct mn_sockaddr_in msin;
-    int rc;
-
-    rc = mn_socket(&sock, MN_PF_INET, MN_SOCK_STREAM, 0);
-    TEST_ASSERT(rc == 0);
-
-    msin.msin_family = MN_PF_INET;
-    msin.msin_len = sizeof(msin);
-    msin.msin_port = htons(12444);
-
-    mn_inet_pton(MN_PF_INET, "127.0.0.1", &msin.msin_addr);
-
-    rc = mn_bind(sock, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_listen(sock, 2);
-    TEST_ASSERT(rc == 0);
-
-    mn_close(sock);
-}
-
-void
-stc_writable(void *cb_arg, int err)
-{
-    int *i;
-
-    TEST_ASSERT(err == 0);
-    i = (int *)cb_arg;
-    *i = *i + 1;
-}
-
-int
-stc_newconn(void *cb_arg, struct mn_socket *new)
-{
-    struct mn_socket **r_sock;
-
-    r_sock = cb_arg;
-    *r_sock = new;
-
-    os_sem_release(&test_sem);
-    return 0;
-}
-
-void
-sock_tcp_connect(void)
-{
-    struct mn_socket *listen_sock;
-    struct mn_socket *sock;
-    struct mn_sockaddr_in msin;
-    struct mn_sockaddr_in msin2;
-    int rc;
-    union mn_socket_cb listen_cbs = {
-        .listen.newconn = stc_newconn,
-    };
-    union mn_socket_cb sock_cbs = {
-        .socket.writable = stc_writable
-    };
-    int connected = 0;
-    struct mn_socket *new_sock = NULL;
-
-    rc = mn_socket(&listen_sock, MN_PF_INET, MN_SOCK_STREAM, 0);
-    TEST_ASSERT(rc == 0);
-
-    msin.msin_family = MN_PF_INET;
-    msin.msin_len = sizeof(msin);
-    msin.msin_port = htons(12445);
-
-    mn_inet_pton(MN_PF_INET, "127.0.0.1", &msin.msin_addr);
-
-    mn_socket_set_cbs(listen_sock, &new_sock, &listen_cbs);
-    rc = mn_bind(listen_sock, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_listen(listen_sock, 2);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_socket(&sock, MN_PF_INET, MN_SOCK_STREAM, 0);
-    TEST_ASSERT(rc == 0);
-
-    mn_socket_set_cbs(sock, &connected, &sock_cbs);
-
-    rc = mn_connect(sock, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(connected == 1);
-    TEST_ASSERT(new_sock != NULL);
-
-    /*
-     * Check endpoint data matches
-     */
-    rc = mn_getsockname(sock, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-    rc = mn_getpeername(new_sock, (struct mn_sockaddr *)&msin2);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(!memcmp(&msin, &msin2, sizeof(msin)));
-
-    rc = mn_getsockname(new_sock, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-    rc = mn_getpeername(sock, (struct mn_sockaddr *)&msin2);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(!memcmp(&msin, &msin2, sizeof(msin)));
-
-
-    if (new_sock) {
-        mn_close(new_sock);
-    }
-    mn_close(sock);
-    mn_close(listen_sock);
-}
-
-void
-sud_readable(void *cb_arg, int err)
-{
-    os_sem_release(&test_sem);
-}
-
-void
-sock_udp_data(void)
-{
-    struct mn_socket *sock1;
-    struct mn_socket *sock2;
-    struct mn_sockaddr_in msin;
-    struct mn_sockaddr_in msin2;
-    int rc;
-    union mn_socket_cb sock_cbs = {
-        .socket.readable = sud_readable
-    };
-    struct os_mbuf *m;
-    char data[] = "1234567890";
-
-    rc = mn_socket(&sock1, MN_PF_INET, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(rc == 0);
-    mn_socket_set_cbs(sock1, NULL, &sock_cbs);
-
-    rc = mn_socket(&sock2, MN_PF_INET, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(rc == 0);
-    mn_socket_set_cbs(sock2, NULL, &sock_cbs);
-
-    msin.msin_family = MN_PF_INET;
-    msin.msin_len = sizeof(msin);
-    msin.msin_port = htons(12445);
-
-    mn_inet_pton(MN_PF_INET, "127.0.0.1", &msin.msin_addr);
-
-    rc = mn_bind(sock1, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    msin2.msin_family = MN_PF_INET;
-    msin2.msin_len = sizeof(msin2);
-    msin2.msin_port = 0;
-    msin2.msin_addr.s_addr = 0;
-    rc = mn_bind(sock2, (struct mn_sockaddr *)&msin2);
-    TEST_ASSERT(rc == 0);
-
-    m = os_msys_get(sizeof(data), 0);
-    TEST_ASSERT(m);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
-    TEST_ASSERT(rc == 0);
-    rc = mn_sendto(sock2, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Wait for the packet.
-     */
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_recvfrom(sock1, &m, (struct mn_sockaddr *)&msin2);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(m != NULL);
-    TEST_ASSERT(msin2.msin_family == MN_AF_INET);
-    TEST_ASSERT(msin2.msin_len == sizeof(msin2));
-    TEST_ASSERT(msin2.msin_port != 0);
-    TEST_ASSERT(msin2.msin_addr.s_addr != 0);
-
-    if (m) {
-        TEST_ASSERT(OS_MBUF_IS_PKTHDR(m));
-        TEST_ASSERT(OS_MBUF_PKTLEN(m) == sizeof(data));
-        TEST_ASSERT(m->om_len == sizeof(data));
-        TEST_ASSERT(!memcmp(m->om_data, data, sizeof(data)));
-    }
-
-    rc = mn_sendto(sock1, m, (struct mn_sockaddr *)&msin2);
-    TEST_ASSERT(rc == 0);
-
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_recvfrom(sock2, &m, (struct mn_sockaddr *)&msin2);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(m != NULL);
-    if (m) {
-        TEST_ASSERT(OS_MBUF_IS_PKTHDR(m));
-        TEST_ASSERT(OS_MBUF_PKTLEN(m) == sizeof(data));
-        TEST_ASSERT(m->om_len == sizeof(data));
-        TEST_ASSERT(!memcmp(m->om_data, data, sizeof(data)));
-        os_mbuf_free_chain(m);
-    }
-
-    mn_close(sock1);
-    mn_close(sock2);
-}
-
-void
-std_writable(void *cb_arg, int err)
-{
-    int *i;
-
-    TEST_ASSERT(err == 0);
-    i = (int *)cb_arg;
-    if (i) {
-        *i = *i + 1;
-    }
-}
-
-void
-std_readable(void *cb_arg, int err)
-{
-    os_sem_release(&test_sem);
-}
-
-static union mn_socket_cb sud_sock_cbs = {
-    .socket.writable = std_writable,
-    .socket.readable = std_readable
-};
-
-int
-std_newconn(void *cb_arg, struct mn_socket *new)
-{
-    struct mn_socket **r_sock;
-
-    r_sock = cb_arg;
-    *r_sock = new;
-
-    mn_socket_set_cbs(new, NULL, &sud_sock_cbs);
-
-    os_sem_release(&test_sem);
-    return 0;
-}
-
-void
-sock_tcp_data(void)
-{
-    struct mn_socket *listen_sock;
-    struct mn_socket *sock;
-    struct mn_sockaddr_in msin;
-    int rc;
-    union mn_socket_cb listen_cbs = {
-        .listen.newconn = std_newconn,
-    };
-    int connected = 0;
-    struct mn_socket *new_sock = NULL;
-    struct os_mbuf *m;
-    char data[] = "1234567890";
-
-    rc = mn_socket(&listen_sock, MN_PF_INET, MN_SOCK_STREAM, 0);
-    TEST_ASSERT(rc == 0);
-
-    msin.msin_family = MN_PF_INET;
-    msin.msin_len = sizeof(msin);
-    msin.msin_port = htons(12447);
-
-    mn_inet_pton(MN_PF_INET, "127.0.0.1", &msin.msin_addr);
-
-    mn_socket_set_cbs(listen_sock, &new_sock, &listen_cbs);
-    rc = mn_bind(listen_sock, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_listen(listen_sock, 2);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_socket(&sock, MN_PF_INET, MN_SOCK_STREAM, 0);
-    TEST_ASSERT(rc == 0);
-
-    mn_socket_set_cbs(sock, &connected, &sud_sock_cbs);
-
-    rc = mn_connect(sock, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(connected == 1);
-    TEST_ASSERT(new_sock != NULL);
-
-    m = os_msys_get(sizeof(data), 0);
-    TEST_ASSERT(m);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
-    TEST_ASSERT(rc == 0);
-    rc = mn_sendto(new_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Wait for the packet.
-     */
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == 0);
-
-    memset(&msin, 0, sizeof(msin));
-    rc = mn_recvfrom(sock, &m, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(m != NULL);
-    TEST_ASSERT(msin.msin_family == MN_AF_INET);
-    TEST_ASSERT(msin.msin_len == sizeof(msin));
-    TEST_ASSERT(msin.msin_port != 0);
-    TEST_ASSERT(msin.msin_addr.s_addr != 0);
-    os_mbuf_free_chain(m);
-
-    if (new_sock) {
-        mn_close(new_sock);
-    }
-    mn_close(sock);
-    mn_close(listen_sock);
-}
-
-void
-sock_itf_list(void)
-{
-    struct mn_itf itf;
-    struct mn_itf_addr itf_addr;
-    int if_cnt = 0;
-    int seen_127;
-    struct mn_in_addr addr127;
-    char addr_str[64];
-    int rc;
-
-    mn_inet_pton(MN_PF_INET, "127.0.0.1", &addr127);
-
-    memset(&itf, 0, sizeof(itf));
-
-    while (1) {
-        rc = mn_itf_getnext(&itf);
-        if (rc) {
-            break;
-        }
-        printf("%d: %x %s\n", itf.mif_idx, itf.mif_flags, itf.mif_name);
-        memset(&itf_addr, 0, sizeof(itf_addr));
-        while (1) {
-            rc = mn_itf_addr_getnext(&itf, &itf_addr);
-            if (rc) {
-                break;
-            }
-            if (itf_addr.mifa_family == MN_AF_INET &&
-              !memcmp(&itf_addr.mifa_addr, &addr127, sizeof(addr127))) {
-                seen_127 = 1;
-            }
-            addr_str[0] = '\0';
-            mn_inet_ntop(itf_addr.mifa_family, &itf_addr.mifa_addr,
-              addr_str, sizeof(addr_str));
-            printf(" %s/%d\n", addr_str, itf_addr.mifa_plen);
-        }
-        if_cnt++;
-    }
-    TEST_ASSERT(if_cnt > 0);
-    TEST_ASSERT(seen_127);
-}
-
-static int
-first_ll_addr(struct mn_sockaddr_in6 *ra)
-{
-    struct mn_itf itf;
-    struct mn_itf_addr itf_addr;
-    int rc;
-    struct mn_in6_addr *addr;
-
-    memset(&itf, 0, sizeof(itf));
-    addr = (struct mn_in6_addr *)&itf_addr.mifa_addr;
-    while (1) {
-        rc = mn_itf_getnext(&itf);
-        if (rc) {
-            break;
-        }
-        memset(&itf_addr, 0, sizeof(itf_addr));
-        while (1) {
-            rc = mn_itf_addr_getnext(&itf, &itf_addr);
-            if (rc) {
-                break;
-            }
-            if (itf_addr.mifa_family == MN_AF_INET6 &&
-              addr->s_addr[0] == 0xfe && addr->s_addr[1] == 0x80) {
-                memset(ra, 0, sizeof(*ra));
-                ra->msin6_family = MN_AF_INET6;
-                ra->msin6_len = sizeof(*ra);
-                ra->msin6_scope_id = itf.mif_idx;
-                memcpy(&ra->msin6_addr, addr, sizeof(*addr));
-                return 0;
-            }
-        }
-    }
-    return -1;
-}
-
-void
-sul_readable(void *cb_arg, int err)
-{
-    os_sem_release(&test_sem);
-}
-
-void
-sock_udp_ll(void)
-{
-    struct mn_socket *sock1;
-    struct mn_socket *sock2;
-    struct mn_sockaddr_in6 msin;
-    struct mn_sockaddr_in6 msin2;
-    int rc;
-    union mn_socket_cb sock_cbs = {
-        .socket.readable = sul_readable
-    };
-    struct os_mbuf *m;
-    char data[] = "1234567890";
-
-    rc = mn_socket(&sock1, MN_PF_INET6, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(rc == 0);
-    mn_socket_set_cbs(sock1, NULL, &sock_cbs);
-
-    rc = mn_socket(&sock2, MN_PF_INET6, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(rc == 0);
-    mn_socket_set_cbs(sock2, NULL, &sock_cbs);
-
-    rc = first_ll_addr(&msin);
-    if (rc != 0) {
-        printf("No ipv6 address present?\n");
-        return;
-    }
-    msin.msin6_port = htons(12445);
-
-    rc = mn_bind(sock1, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_getsockname(sock1, (struct mn_sockaddr *)&msin2);
-    TEST_ASSERT(rc == 0);
-
-    m = os_msys_get(sizeof(data), 0);
-    TEST_ASSERT(m);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
-    TEST_ASSERT(rc == 0);
-    rc = mn_sendto(sock2, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin2);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Wait for the packet.
-     */
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_recvfrom(sock1, &m, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(m != NULL);
-
-    if (m) {
-        TEST_ASSERT(OS_MBUF_IS_PKTHDR(m));
-        TEST_ASSERT(OS_MBUF_PKTLEN(m) == sizeof(data));
-        TEST_ASSERT(m->om_len == sizeof(data));
-        TEST_ASSERT(!memcmp(m->om_data, data, sizeof(data)));
-        os_mbuf_free_chain(m);
-    }
-
-    mn_close(sock1);
-    mn_close(sock2);
-}
-
-static int
-sock_find_multicast_if(void)
-{
-    struct mn_itf itf;
-
-    memset(&itf, 0, sizeof(itf));
-
-    while (1) {
-        if (mn_itf_getnext(&itf)) {
-            break;
-        }
-        if ((itf.mif_flags & MN_ITF_F_UP) == 0) {
-            continue;
-        }
-        if (itf.mif_flags & MN_ITF_F_MULTICAST) {
-            return itf.mif_idx;
-        }
-    }
-    return -1;
-}
-
-void
-sum4_readable(void *cb_arg, int err)
-{
-    os_sem_release(&test_sem);
-}
-
-static void
-sock_udp_mcast_v4(void)
-{
-    int loop_if_idx;
-    struct mn_socket *rx_sock;
-    struct mn_socket *tx_sock;
-    struct mn_sockaddr_in msin;
-    union mn_socket_cb sock_cbs = {
-        .socket.readable = sum4_readable
-    };
-    struct os_mbuf *m;
-    char data[] = "1234567890";
-    int rc;
-    struct mn_mreq mreq;
-    loop_if_idx = sock_find_multicast_if();
-    TEST_ASSERT(loop_if_idx > 0);
-
-    msin.msin_family = MN_AF_INET;
-    msin.msin_len = sizeof(msin);
-    msin.msin_port = htons(44344);
-    memset(&msin.msin_addr, 0, sizeof(msin.msin_addr));
-
-    rc = mn_socket(&rx_sock, MN_PF_INET, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(rc == 0);
-    mn_socket_set_cbs(rx_sock, NULL, &sock_cbs);
-
-    rc = mn_bind(rx_sock, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_socket(&tx_sock, MN_PF_INET, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_setsockopt(tx_sock, MN_SO_LEVEL, MN_MCAST_IF, &loop_if_idx);
-    TEST_ASSERT(rc == 0);
-
-    m = os_msys_get(sizeof(data), 0);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * multicast tgt
-     */
-    mn_inet_pton(MN_PF_INET, "224.0.2.241", &msin.msin_addr);
-
-    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
+TEST_CASE_DECL(inet_pton_test)
+TEST_CASE_DECL(inet_ntop_test)
+TEST_CASE_DECL(socket_tests)
 
-    /*
-     * RX socket has not joined group yet.
-     */
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC / 2);
-    TEST_ASSERT(rc == OS_TIMEOUT);
-
-    mreq.mm_idx = loop_if_idx;
-    mreq.mm_family = MN_AF_INET;
-    mreq.mm_addr.v4.s_addr = msin.msin_addr.s_addr;
-
-    /*
-     * Now join it.
-     */
-    rc = mn_setsockopt(rx_sock, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &mreq);
-    TEST_ASSERT(rc == 0);
-
-    m = os_msys_get(sizeof(data), 0);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_recvfrom(rx_sock, &m, NULL);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(m != NULL);
-    TEST_ASSERT(!memcmp(m->om_data, data, sizeof(data)));
-    os_mbuf_free_chain(m);
-
-    /*
-     * Then leave
-     */
-    rc = mn_setsockopt(rx_sock, MN_SO_LEVEL, MN_MCAST_LEAVE_GROUP, &mreq);
-    TEST_ASSERT(rc == 0);
-
-    m = os_msys_get(sizeof(data), 0);
-    TEST_ASSERT(m);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin);
-    TEST_ASSERT(rc == 0);
-
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == OS_TIMEOUT);
-
-    mn_close(rx_sock);
-    mn_close(tx_sock);
-}
-
-static void
-sock_udp_mcast_v6(void)
+TEST_SUITE(mn_socket_test_all)
 {
-    int loop_if_idx;
-    struct mn_socket *rx_sock;
-    struct mn_socket *tx_sock;
-    struct mn_sockaddr_in6 msin6;
-    union mn_socket_cb sock_cbs = {
-        .socket.readable = sum4_readable
-    };
-    struct os_mbuf *m;
-    char data[] = "1234567890";
     int rc;
-    struct mn_mreq mreq;
-    uint8_t mcast_addr[16] = {
-        0xff, 2, 0, 0,
-        0, 0, 0, 0,
-        0, 0, 0, 0,
-        0, 0, 0, 2
-    };
-
-    loop_if_idx = sock_find_multicast_if();
-    TEST_ASSERT(loop_if_idx > 0);
-
-    msin6.msin6_family = MN_AF_INET6;
-    msin6.msin6_len = sizeof(msin6);
-    msin6.msin6_port = htons(44344);
-    memset(&msin6.msin6_addr, 0, sizeof(msin6.msin6_addr));
-
-    rc = mn_socket(&rx_sock, MN_PF_INET6, MN_SOCK_DGRAM, 0);
-    TEST_ASSERT(rc == 0);
-    mn_socket_set_cbs(rx_sock, NULL, &sock_cbs);
-
-    rc = mn_bind(rx_sock, (struct mn_sockaddr *)&msin6);
-    TEST_ASSERT(rc == 0);
 
-    rc = mn_socket(&tx_sock, MN_PF_INET6, MN_SOCK_DGRAM, 0);
+    rc = os_mempool_init(&test_mbuf_mpool, MB_CNT, MB_SZ,
+                         test_mbuf_area, "mb");
     TEST_ASSERT(rc == 0);
-
-    rc = mn_setsockopt(tx_sock, MN_SO_LEVEL, MN_MCAST_IF, &loop_if_idx);
-    TEST_ASSERT(rc == 0);
-
-    m = os_msys_get(sizeof(data), 0);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
+    rc = os_mbuf_pool_init(&test_mbuf_pool, &test_mbuf_mpool,
+                           MB_CNT, MB_CNT);
     TEST_ASSERT(rc == 0);
-
-    /*
-     * multicast tgt
-     */
-    memcpy(&msin6.msin6_addr, mcast_addr, sizeof(mcast_addr));
-
-    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin6);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * RX socket has not joined group yet.
-     */
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC / 2);
-    TEST_ASSERT(rc == OS_TIMEOUT);
-
-    mreq.mm_idx = loop_if_idx;
-    mreq.mm_family = MN_AF_INET6;
-    memcpy(&mreq.mm_addr.v6.s_addr, msin6.msin6_addr.s_addr,
-      sizeof(msin6.msin6_addr.s_addr));
-
-    /*
-     * Now join it.
-     */
-    rc = mn_setsockopt(rx_sock, MN_SO_LEVEL, MN_MCAST_JOIN_GROUP, &mreq);
-    TEST_ASSERT(rc == 0);
-
-    m = os_msys_get(sizeof(data), 0);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin6);
-    TEST_ASSERT(rc == 0);
-
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_recvfrom(rx_sock, &m, NULL);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(m != NULL);
-    TEST_ASSERT(!memcmp(m->om_data, data, sizeof(data)));
-    os_mbuf_free_chain(m);
-
-    /*
-     * Then leave
-     */
-    rc = mn_setsockopt(rx_sock, MN_SO_LEVEL, MN_MCAST_LEAVE_GROUP, &mreq);
-    TEST_ASSERT(rc == 0);
-
-    m = os_msys_get(sizeof(data), 0);
-    TEST_ASSERT(m);
-    rc = os_mbuf_copyinto(m, 0, data, sizeof(data));
-    TEST_ASSERT(rc == 0);
-
-    rc = mn_sendto(tx_sock, (struct os_mbuf *)m, (struct mn_sockaddr *)&msin6);
+    rc = os_msys_register(&test_mbuf_pool);
     TEST_ASSERT(rc == 0);
 
-    rc = os_sem_pend(&test_sem, OS_TICKS_PER_SEC);
-    TEST_ASSERT(rc == OS_TIMEOUT);
-
-    mn_close(rx_sock);
-    mn_close(tx_sock);
+    inet_pton_test();
+    inet_ntop_test();
+    socket_tests();
 }
 
 void
-mn_socket_test_handler(void *arg)
-{
-    sock_open_close();
-    sock_listen();
-    sock_tcp_connect();
-    sock_udp_data();
-    sock_tcp_data();
-    sock_itf_list();
-    sock_udp_ll();
-    sock_udp_mcast_v4();
-    sock_udp_mcast_v6();
-    tu_restart();
-}
-
-TEST_CASE(socket_tests)
-{
-    sysinit();
-    native_sock_init();
-
-    os_sem_init(&test_sem, 0);
-
-    os_task_init(&test_task, "mn_socket_test", mn_socket_test_handler, NULL,
-      TEST_PRIO, OS_WAIT_FOREVER, test_stack, TEST_STACK_SIZE);
-    os_start();
-}
-
-TEST_SUITE(mn_socket_test_all)
+mn_socket_test_init()
 {
     int rc;
 
-    rc = os_mempool_init(&test_mbuf_mpool, MB_CNT, MB_SZ, test_mbuf_area, "mb");
+    rc = os_mempool_init(&test_mbuf_mpool, MB_CNT, MB_SZ,
+                         test_mbuf_area, "mb");
     TEST_ASSERT(rc == 0);
-    rc = os_mbuf_pool_init(&test_mbuf_pool, &test_mbuf_mpool, MB_CNT, MB_CNT);
+    rc = os_mbuf_pool_init(&test_mbuf_pool, &test_mbuf_mpool,
+                           MB_CNT, MB_CNT);
     TEST_ASSERT(rc == 0);
     rc = os_msys_register(&test_mbuf_pool);
     TEST_ASSERT(rc == 0);
-
-    inet_pton_test();
-    inet_ntop_test();
-
-    socket_tests();
 }
 
 #if MYNEWT_VAL(SELFTEST)
-
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
+    tu_suite_set_init_cb((void*)mn_socket_test_init, NULL);
     mn_socket_test_all();
-
-    return tu_any_failed;
 }
 #endif
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/net/ip/mn_socket/test/src/mn_sock_test.h
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/test/src/mn_sock_test.h b/net/ip/mn_socket/test/src/mn_sock_test.h
new file mode 100644
index 0000000..035c890
--- /dev/null
+++ b/net/ip/mn_socket/test/src/mn_sock_test.h
@@ -0,0 +1,42 @@
+/**
+ * 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 _MN_SOCK_TEST_H
+#define _MN_SOCK_TEST_H
+
+#include <stdio.h>
+#include <string.h>
+
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "os/os.h"
+#include "testutil/testutil.h"
+
+#include "mn_socket/mn_socket.h"
+#include "mn_socket/arch/sim/native_sock.h"
+
+#define TEST_STACK_SIZE 4096
+#define TEST_PRIO 22
+extern os_stack_t test_stack[];
+struct os_task test_task;
+
+struct os_sem test_sem;
+
+void mn_socket_test_handler(void *arg);
+
+#endif /* _MN_SOCK_TEST_H */