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:27 UTC

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

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop c76c68095 -> 7aa94c51a


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/case.c
----------------------------------------------------------------------
diff --git a/test/testutil/src/case.c b/test/testutil/src/case.c
index 614b142..ed589ab 100644
--- a/test/testutil/src/case.c
+++ b/test/testutil/src/case.c
@@ -30,8 +30,6 @@ int tu_case_failed;
 int tu_case_idx;
 
 const char *tu_case_name;
-tu_post_test_fn_t *tu_case_post_test_cb;
-void *tu_case_post_test_cb_arg;
 
 #define TU_CASE_BUF_SZ      1024
 
@@ -84,6 +82,38 @@ tu_case_set_name(const char *name)
     tu_case_name = name;
 }
 
+/**
+ * Configures a callback that gets executed at the end of each test.
+ * This callback is cleared when the current test completes.
+ *
+ * @param cb -  The callback to execute at the end of each test case.
+ * @param cb_arg - An optional argument that gets passed to the
+ *                                  callback.
+ */
+/*
+ * Called to initialize test (after tu_suite_pre_cb and before 
+ */
+void
+tu_case_set_init_cb(tu_init_test_fn_t *cb, void *cb_arg)
+{
+    tc_config.tc_case_init_cb = cb;
+    tc_config.tc_case_init_arg = cb_arg;
+}
+
+void
+tu_case_set_pre_cb(tu_pre_test_fn_t *cb, void *cb_arg)
+{
+    tc_config.tc_case_pre_test_cb = cb;
+    tc_config.tc_case_pre_arg = cb_arg;
+}
+
+void
+tu_case_set_post_cb(tu_post_test_fn_t *cb, void *cb_arg)
+{
+    tc_config.tc_case_post_test_cb = cb;
+    tc_config.tc_case_post_arg = cb_arg;
+}
+
 void
 tu_case_init(const char *name)
 {
@@ -92,8 +122,8 @@ tu_case_init(const char *name)
 
     tu_case_set_name(name);
 
-    if (tu_config.tc_case_init_cb != NULL) {
-        tu_config.tc_case_init_cb(tu_config.tc_case_init_arg);
+    if (tc_config.tc_case_init_cb != NULL) {
+        tc_config.tc_case_init_cb(tc_config.tc_case_init_arg);
     }
 }
 
@@ -101,13 +131,68 @@ void
 tu_case_complete(void)
 {
     tu_case_idx++;
+    tu_case_set_pre_cb(NULL, NULL);
+    tu_case_set_post_cb(NULL, NULL);
+}
+
+void
+tu_case_pre_test(void)
+{
+    if (tc_config.tc_case_pre_test_cb != NULL) {
+        tc_config.tc_case_pre_test_cb(tc_config.tc_case_pre_arg);
+    }
 }
 
 void
 tu_case_post_test(void)
 {
-    if (tu_case_post_test_cb != NULL) {
-        tu_case_post_test_cb(tu_case_post_test_cb_arg);
+    if (tc_config.tc_case_post_test_cb != NULL) {
+        tc_config.tc_case_post_test_cb(tc_config.tc_case_post_arg);
+    }
+}
+
+void
+tu_case_pass(void)
+{
+#if MYNEWT_VAL(SELFTEST)
+    if (ts_config.ts_print_results) {
+        printf("[pass] %s/%s\n", tu_suite_name, tu_case_name);
+        if (tu_case_buf_len > 0) {
+            printf("%s", tu_case_buf);
+        }
+        fflush(stdout);
+    }
+#endif
+
+    tu_case_reported = 1;
+    tu_case_failed = 0;
+
+    if (ts_config.ts_case_pass_cb != NULL) {
+        ts_config.ts_case_pass_cb(tu_case_buf, tu_case_buf_len,
+                                  ts_config.ts_case_pass_arg);
+    }
+}
+
+void
+tu_case_fail(void)
+{
+    tu_case_reported = 1;
+    tu_case_failed = 1;
+    tu_suite_failed = 1;
+    tu_any_failed = 1;
+
+#if MYNEWT_VAL(SELFTEST)
+    if (ts_config.ts_print_results) {
+        printf("[FAIL] %s/%s %s", tu_suite_name, tu_case_name, tu_case_buf);
+        fflush(stdout);
+    }
+#endif
+
+    tu_case_post_test();
+
+    if (ts_config.ts_case_fail_cb != NULL) {
+        ts_config.ts_case_fail_cb(tu_case_buf, tu_case_buf_len,
+                                  ts_config.ts_case_fail_arg);
     }
 }
 
@@ -119,14 +204,16 @@ tu_case_write_fail_buf(void)
     tu_suite_failed = 1;
     tu_any_failed = 1;
 
-    if (tu_config.tc_print_results) {
+#if MYNEWT_VAL(SELFTEST)
+    if (ts_config.ts_print_results) {
         printf("[FAIL] %s/%s %s", tu_suite_name, tu_case_name, tu_case_buf);
         fflush(stdout);
     }
+#endif
 
-    if (tu_config.tc_case_fail_cb != NULL) {
-        tu_config.tc_case_fail_cb(tu_case_buf, tu_case_buf_len,
-                                  tu_config.tc_case_fail_arg);
+    if (ts_config.ts_case_fail_cb != NULL) {
+        ts_config.ts_case_fail_cb(tu_case_buf, tu_case_buf_len,
+                                  ts_config.ts_case_fail_arg);
     }
 }
 
@@ -151,19 +238,22 @@ tu_case_append_assert_msg(const char *expr)
 static void
 tu_case_write_pass_buf(void)
 {
-    if (tu_config.tc_print_results) {
+
+#if MYNEWT_VAL(SELFTEST)
+    if (ts_config.ts_print_results) {
         printf("[pass] %s/%s\n", tu_suite_name, tu_case_name);
         if (tu_case_buf_len > 0) {
             printf("%s", tu_case_buf);
         }
         fflush(stdout);
     }
+#endif
 
     tu_case_reported = 1;
 
-    if (tu_config.tc_case_pass_cb != NULL) {
-        tu_config.tc_case_pass_cb(tu_case_buf, tu_case_buf_len,
-                                  tu_config.tc_case_pass_arg);
+    if (ts_config.ts_case_pass_cb != NULL) {
+        ts_config.ts_case_pass_cb(tu_case_buf, tu_case_buf_len,
+                                  ts_config.ts_case_pass_arg);
     }
 }
 
@@ -192,7 +282,7 @@ tu_case_fail_assert(int fatal, const char *file, int line,
     va_list ap;
     int rc;
 
-    if (tu_config.tc_system_assert) {
+    if (ts_config.ts_system_assert) {
         assert(0);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/suite.c
----------------------------------------------------------------------
diff --git a/test/testutil/src/suite.c b/test/testutil/src/suite.c
index 93ca639..4db0f1c 100644
--- a/test/testutil/src/suite.c
+++ b/test/testutil/src/suite.c
@@ -30,27 +30,71 @@ tu_suite_set_name(const char *name)
     tu_suite_name = name;
 }
 
+void
+tu_suite_set_init_cb(tu_init_test_fn_t *cb, void *cb_arg)
+{
+    ts_config.ts_suite_init_cb = cb;
+    ts_config.ts_suite_init_arg = cb_arg;
+}
+
 /**
- * Configures a callback that gets executed at the end of each test case in the
- * current suite.  This is useful when there are some checks that should be
- * performed at the end of each test (e.g., verify no memory leaks).  This
- * callback is cleared when the current suite completes.
+ * Configures a callback that gets executed at the end of each test
+ * case in the current suite.  This is useful when there are some
+ * checks that should be performed at the end of each test
+ * (e.g., verify no memory leaks).  This callback is cleared when the
+ * current suite completes.
  *
- * @param cb                    The callback to execute at the end of each test
- *                                  case.
- * @param cb_arg                An optional argument that gets passed to the
+ * @param cb -  The callback to execute at the end of each test case.
+ * @param cb_arg - An optional argument that gets passed to the
  *                                  callback.
  */
 void
+tu_suite_set_pre_test_cb(tu_pre_test_fn_t *cb, void *cb_arg)
+{
+    ts_config.ts_case_pre_test_cb = cb;
+    ts_config.ts_case_pre_arg = cb_arg;
+}
+
+void
+tu_suite_pre_test(void)
+{
+    if (ts_config.ts_case_pre_test_cb != NULL) {
+        ts_config.ts_case_pre_test_cb(ts_config.ts_case_pre_arg);
+    }
+}
+
+void
 tu_suite_set_post_test_cb(tu_post_test_fn_t *cb, void *cb_arg)
 {
-    tu_case_post_test_cb = cb;
-    tu_case_post_test_cb_arg = cb_arg;
+    ts_config.ts_case_post_test_cb = cb;
+    ts_config.ts_case_post_arg = cb_arg;
+}
+
+void
+tu_suite_post_test(void)
+{
+    if (ts_config.ts_case_post_test_cb != NULL) {
+        ts_config.ts_case_post_test_cb(ts_config.ts_case_post_arg);
+    }
+}
+
+void
+tu_suite_set_pass_cb(tu_case_report_fn_t *cb, void *cb_arg) {
+    ts_config.ts_case_pass_cb = cb;
+    ts_config.ts_case_pass_arg = cb_arg;
+}
+
+void
+tu_suite_set_fail_cb(tu_case_report_fn_t *cb, void *cb_arg) {
+    ts_config.ts_case_fail_cb = cb;
+    ts_config.ts_case_fail_arg = cb_arg;
 }
 
 void
 tu_suite_complete(void)
 {
+    tu_suite_set_init_cb(NULL, NULL);
+    tu_suite_set_pre_test_cb(NULL, NULL);
     tu_suite_set_post_test_cb(NULL, NULL);
 }
 
@@ -61,7 +105,7 @@ tu_suite_init(const char *name)
 
     tu_suite_set_name(name);
 
-    if (tu_config.tc_suite_init_cb != NULL) {
-        tu_config.tc_suite_init_cb(tu_config.tc_suite_init_arg);
+    if (ts_config.ts_suite_init_cb != NULL) {
+        ts_config.ts_suite_init_cb(ts_config.ts_suite_init_arg);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/testutil.c
----------------------------------------------------------------------
diff --git a/test/testutil/src/testutil.c b/test/testutil/src/testutil.c
index 9cf382b..ff1a277 100644
--- a/test/testutil/src/testutil.c
+++ b/test/testutil/src/testutil.c
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #include <assert.h>
 #include "sysinit/sysinit.h"
 #include "os/os.h"
@@ -24,7 +23,15 @@
 #include "testutil/testutil.h"
 #include "testutil_priv.h"
 
-struct tu_config tu_config;
+#include <errno.h>
+#include <unistd.h>
+
+struct tc_config tc_config;
+struct tc_config *tc_current_config = &tc_config;
+
+struct ts_config ts_config;
+struct ts_config *ts_current_config = &ts_config;
+
 int tu_any_failed;
 int tu_first_idx;
 
@@ -37,14 +44,44 @@ tu_init(void)
 }
 
 void
+tu_arch_restart(void)
+{
+#if MYNEWT_VAL(SELFTEST)
+    os_arch_os_stop();
+    tu_case_abort();
+#else
+    system_reset();
+#endif
+}
+
+int
+tu_parse_args(int argc, char **argv)
+{
+    int ch;
+
+    while ((ch = getopt(argc, argv, "s")) != -1) {
+        switch (ch) {
+        case 's':
+            ts_config.ts_system_assert = 1;
+            break;
+
+        default:
+            return EINVAL;
+        }
+    }
+
+    return 0;
+}
+
+void
 tu_restart(void)
 {
     tu_case_write_pass_auto();
 
     tu_first_idx = tu_case_idx + 1;
 
-    if (tu_config.tc_restart_cb != NULL) {
-        tu_config.tc_restart_cb(tu_config.tc_restart_arg);
+    if (ts_config.ts_restart_cb != NULL) {
+        ts_config.ts_restart_cb(ts_config.ts_restart_arg);
     }
 
     tu_arch_restart();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/util/cbmem/test/src/cbmem_test.c
----------------------------------------------------------------------
diff --git a/util/cbmem/test/src/cbmem_test.c b/util/cbmem/test/src/cbmem_test.c
index 755908c..35e587e 100644
--- a/util/cbmem/test/src/cbmem_test.c
+++ b/util/cbmem/test/src/cbmem_test.c
@@ -18,15 +18,16 @@
  */
 #include <stdio.h>
 #include <string.h>
-
+#include <assert.h>
+#include <stddef.h>
+#include "syscfg/syscfg.h"
 #include "testutil/testutil.h"
 #include "cbmem/cbmem.h"
-
-#define CBMEM1_BUF_SIZE (64 * 1024)
+#include "cbmem_test.h"
 
 struct cbmem cbmem1;
 uint8_t cbmem1_buf[CBMEM1_BUF_SIZE];
-uint8_t cbmem1_entry[1024];
+uint8_t cbmem1_entry[CBMEM1_ENTRY_SIZE];
 
 /*
  * Things to test.
@@ -35,8 +36,8 @@ uint8_t cbmem1_entry[1024];
  * - Reading through all entries.
  */
 
-static void
-setup_cbmem1(void)
+void
+setup_cbmem1(void *arg)
 {
     int i;
     int rc;
@@ -59,7 +60,7 @@ setup_cbmem1(void)
     }
 }
 
-static int
+int
 cbmem_test_case_1_walk(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr,
         void *arg)
 {
@@ -79,98 +80,29 @@ cbmem_test_case_1_walk(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr,
     return (0);
 }
 
-TEST_CASE(cbmem_test_case_1)
-{
-    int i;
-    int rc;
-
-    /* i starts at 2, for the 2 overwritten entries. */
-    i = 2;
-    rc = cbmem_walk(&cbmem1, cbmem_test_case_1_walk, &i);
-    TEST_ASSERT_FATAL(rc == 0, "Could not walk cbmem tree!  rc = %d", rc);
-    TEST_ASSERT_FATAL(i == 65,
-            "Did not go through every element of walk, %d processed", i - 2);
-
-}
+TEST_CASE_DECL(cbmem_test_case_1)
+TEST_CASE_DECL(cbmem_test_case_2)
+TEST_CASE_DECL(cbmem_test_case_3)
 
-TEST_CASE(cbmem_test_case_2)
+TEST_SUITE(cbmem_test_suite)
 {
-    struct cbmem_entry_hdr *hdr;
-    struct cbmem_iter iter;
-    uint8_t i;
-    uint8_t val;
-    int rc;
-
-    i = 2;
-    cbmem_iter_start(&cbmem1, &iter);
-    while (1) {
-        hdr = cbmem_iter_next(&cbmem1, &iter);
-        if (hdr == NULL) {
-            break;
-        }
-
-        rc = cbmem_read(&cbmem1, hdr, &val, 0, sizeof(val));
-        TEST_ASSERT_FATAL(rc == 1, "Couldn't read 1 byte from cbmem");
-        TEST_ASSERT_FATAL(val == i, "Entry index does not match %d vs %d",
-                val, i);
-
-        i++;
-    }
-
-    /* i starts at 2, for the 2 overwritten entries */
-    TEST_ASSERT_FATAL(i == 65,
-            "Did not iterate through all 63 elements of CBMEM1, processed %d",
-            i - 2);
+    cbmem_test_case_1();
+    cbmem_test_case_2();
+    cbmem_test_case_3();
 }
 
-TEST_CASE(cbmem_test_case_3)
+#if MYNEWT_VAL(SELFTEST)
+
+int
+main(int argc, char **argv)
 {
-    struct cbmem_entry_hdr *hdr;
-    struct cbmem_iter iter;
-    uint16_t off;
-    uint16_t len;
-    uint8_t buf[128];
-    int i;
-    int rc;
+    ts_config.ts_print_results = 1;
+    tu_init();
 
-    i = 0;
-    cbmem_iter_start(&cbmem1, &iter);
-    while (1) {
-        hdr = cbmem_iter_next(&cbmem1, &iter);
-        if (hdr == NULL) {
-            break;
-        }
-
-        /* first ensure we can read the entire entry */
-        off = 0;
-        len = 0;
-        while (1) {
-            rc = cbmem_read(&cbmem1, hdr, buf, off, sizeof(buf));
-            TEST_ASSERT_FATAL(rc >= 0,
-                    "Error reading from buffer rc=%d, off=%d,len=%d", rc, off,
-                    sizeof(buf));
-            if (rc == 0) {
-                break;
-            }
-            off += rc;
-            len += rc;
-        }
-        TEST_ASSERT_FATAL(len == 1024,
-                "Couldn't read full entry, expected %d got %d", 1024, len);
-        i++;
-
-        /* go apesh*t, and read data out of bounds, see what we get. */
-        rc = cbmem_read(&cbmem1, hdr, buf, 2048, sizeof(buf));
-        TEST_ASSERT_FATAL(rc < 0,
-                "Reading invalid should return error, instead %d returned.",
-                rc);
-    }
-}
+    tu_suite_set_init_cb(setup_cbmem1, NULL);
+    cbmem_test_suite();
 
-TEST_SUITE(cbmem_test_suite)
-{
-    setup_cbmem1();
-    cbmem_test_case_1();
-    cbmem_test_case_2();
-    cbmem_test_case_3();
+    return tu_any_failed;
 }
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/util/cbmem/test/src/cbmem_test.h
----------------------------------------------------------------------
diff --git a/util/cbmem/test/src/cbmem_test.h b/util/cbmem/test/src/cbmem_test.h
new file mode 100644
index 0000000..612e5e5
--- /dev/null
+++ b/util/cbmem/test/src/cbmem_test.h
@@ -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.
+ */
+#ifndef __CBMEM_TEST_H
+#define __CBMEM_TEST_H
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <stddef.h>
+#include "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+#include "cbmem/cbmem.h"
+
+#define CBMEM1_BUF_SIZE (64 * 1024)
+#define CBMEM1_ENTRY_SIZE 1024
+
+struct cbmem cbmem1;
+uint8_t cbmem1_buf[CBMEM1_BUF_SIZE];
+uint8_t cbmem1_entry[CBMEM1_ENTRY_SIZE];
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int cbmem_test_case_1_walk(struct cbmem *cbmem,
+                           struct cbmem_entry_hdr *hdr, void *arg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CBMEM_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/util/cbmem/test/src/testcases/cbmem_test_case_1.c
----------------------------------------------------------------------
diff --git a/util/cbmem/test/src/testcases/cbmem_test_case_1.c b/util/cbmem/test/src/testcases/cbmem_test_case_1.c
new file mode 100644
index 0000000..ef9b3b4
--- /dev/null
+++ b/util/cbmem/test/src/testcases/cbmem_test_case_1.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 "cbmem_test.h"
+
+TEST_CASE(cbmem_test_case_1)
+{
+    int i;
+    int rc;
+
+    /* i starts at 2, for the 2 overwritten entries. */
+    i = 2;
+    rc = cbmem_walk(&cbmem1, cbmem_test_case_1_walk, &i);
+    TEST_ASSERT_FATAL(rc == 0, "Could not walk cbmem tree!  rc = %d", rc);
+    TEST_ASSERT_FATAL(i == 65,
+            "Did not go through every element of walk, %d processed", i - 2);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/util/cbmem/test/src/testcases/cbmem_test_case_2.c
----------------------------------------------------------------------
diff --git a/util/cbmem/test/src/testcases/cbmem_test_case_2.c b/util/cbmem/test/src/testcases/cbmem_test_case_2.c
new file mode 100644
index 0000000..fd9885e
--- /dev/null
+++ b/util/cbmem/test/src/testcases/cbmem_test_case_2.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 "cbmem_test.h"
+
+TEST_CASE(cbmem_test_case_2)
+{
+    struct cbmem_entry_hdr *hdr;
+    struct cbmem_iter iter;
+    uint8_t i;
+    uint8_t val;
+    int rc;
+
+    i = 2;
+    cbmem_iter_start(&cbmem1, &iter);
+    while (1) {
+        hdr = cbmem_iter_next(&cbmem1, &iter);
+        if (hdr == NULL) {
+            break;
+        }
+
+        rc = cbmem_read(&cbmem1, hdr, &val, 0, sizeof(val));
+        TEST_ASSERT_FATAL(rc == 1, "Couldn't read 1 byte from cbmem");
+        TEST_ASSERT_FATAL(val == i, "Entry index does not match %d vs %d",
+                val, i);
+
+        i++;
+    }
+
+    /* i starts at 2, for the 2 overwritten entries */
+    TEST_ASSERT_FATAL(i == 65,
+            "Did not iterate through all 63 elements of CBMEM1, processed %d",
+            i - 2);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/util/cbmem/test/src/testcases/cbmem_test_case_3.c
----------------------------------------------------------------------
diff --git a/util/cbmem/test/src/testcases/cbmem_test_case_3.c b/util/cbmem/test/src/testcases/cbmem_test_case_3.c
new file mode 100644
index 0000000..d554959
--- /dev/null
+++ b/util/cbmem/test/src/testcases/cbmem_test_case_3.c
@@ -0,0 +1,63 @@
+/**
+ * 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 "cbmem_test.h"
+
+TEST_CASE(cbmem_test_case_3)
+{
+    struct cbmem_entry_hdr *hdr;
+    struct cbmem_iter iter;
+    uint16_t off;
+    uint16_t len;
+    uint8_t buf[128];
+    int i;
+    int rc;
+
+    i = 0;
+    cbmem_iter_start(&cbmem1, &iter);
+    while (1) {
+        hdr = cbmem_iter_next(&cbmem1, &iter);
+        if (hdr == NULL) {
+            break;
+        }
+
+        /* first ensure we can read the entire entry */
+        off = 0;
+        len = 0;
+        while (1) {
+            rc = cbmem_read(&cbmem1, hdr, buf, off, sizeof(buf));
+            TEST_ASSERT_FATAL(rc >= 0,
+                    "Error reading from buffer rc=%d, off=%d,len=%d", rc, off,
+                    sizeof(buf));
+            if (rc == 0) {
+                break;
+            }
+            off += rc;
+            len += rc;
+        }
+        TEST_ASSERT_FATAL(len == 1024,
+                "Couldn't read full entry, expected %d got %d", 1024, len);
+        i++;
+
+        /* go apesh*t, and read data out of bounds, see what we get. */
+        rc = cbmem_read(&cbmem1, hdr, buf, 2048, sizeof(buf));
+        TEST_ASSERT_FATAL(rc < 0,
+                "Reading invalid should return error, instead %d returned.",
+                rc);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/util/cbmem/test/src/util_test.c
----------------------------------------------------------------------
diff --git a/util/cbmem/test/src/util_test.c b/util/cbmem/test/src/util_test.c
deleted file mode 100644
index d34f6c9..0000000
--- a/util/cbmem/test/src/util_test.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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 "util_test_priv.h"
-
-int
-util_test_all(void)
-{
-    cbmem_test_suite();
-    return tu_case_failed;
-}
-
-#if MYNEWT_VAL(SELFTEST)
-
-int
-main(int argc, char **argv)
-{
-    tu_config.tc_print_results = 1;
-    tu_init();
-
-    util_test_all();
-    return tu_any_failed;
-}
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/util/cbmem/test/src/util_test_priv.h
----------------------------------------------------------------------
diff --git a/util/cbmem/test/src/util_test_priv.h b/util/cbmem/test/src/util_test_priv.h
deleted file mode 100644
index 38d3ed1..0000000
--- a/util/cbmem/test/src/util_test_priv.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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 __UTIL_TEST_PRIV_
-#define __UTIL_TEST_PRIV_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int cbmem_test_suite(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif


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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/arch/sim/nffs_test_priv.h
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/arch/sim/nffs_test_priv.h b/fs/nffs/test/src/arch/sim/nffs_test_priv.h
deleted file mode 100644
index e0b7ff0..0000000
--- a/fs/nffs/test/src/arch/sim/nffs_test_priv.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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_NFFS_TEST_PRIV_
-#define H_NFFS_TEST_PRIV_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct nffs_test_block_desc {
-    const char *data;
-    int data_len;
-};
-
-struct nffs_test_file_desc {
-    const char *filename;
-    int is_dir;
-    const char *contents;
-    int contents_len;
-    struct nffs_test_file_desc *children;
-};
-
-int nffs_test(void);
-
-extern const struct nffs_test_file_desc *nffs_test_system_01;
-extern const struct nffs_test_file_desc *nffs_test_system_01_rm_1014_mk10;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-


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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_empty_file.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_empty_file.c b/sys/config/test-nffs/src/testcases/config_test_empty_file.c
new file mode 100644
index 0000000..ab16095
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_empty_file.c
@@ -0,0 +1,56 @@
+/**
+ * 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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_empty_file)
+{
+    int rc;
+    struct conf_file cf_mfg;
+    struct conf_file cf_running;
+    const char cf_mfg_test[] = "";
+    const char cf_running_test[] = "\n\n";
+
+    config_wipe_srcs();
+
+    cf_mfg.cf_name = "/config/mfg";
+    cf_running.cf_name = "/config/running";
+
+    rc = conf_file_src(&cf_mfg);
+    TEST_ASSERT(rc == 0);
+    rc = conf_file_src(&cf_running);
+
+    /*
+     * No files
+     */
+    conf_load();
+
+    rc = fs_mkdir("/config");
+    TEST_ASSERT(rc == 0);
+
+    rc = fsutil_write_file("/config/mfg", cf_mfg_test, sizeof(cf_mfg_test));
+    TEST_ASSERT(rc == 0);
+
+    rc = fsutil_write_file("/config/running", cf_running_test,
+      sizeof(cf_running_test));
+    TEST_ASSERT(rc == 0);
+
+    conf_load();
+    config_wipe_srcs();
+    ctest_clear_call_state();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_getset_bytes.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_getset_bytes.c b/sys/config/test-nffs/src/testcases/config_test_getset_bytes.c
new file mode 100644
index 0000000..7d684a3
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_getset_bytes.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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_getset_bytes)
+{
+    char orig[32];
+    char bytes[32];
+    char str[48];
+    char *ret;
+    int j, i;
+    int tmp;
+    int rc;
+
+    for (j = 1; j < sizeof(orig); j++) {
+        for (i = 0; i < j; i++) {
+            orig[i] = i + j + 1;
+        }
+        ret = conf_str_from_bytes(orig, j, str, sizeof(str));
+        TEST_ASSERT(ret);
+        tmp = strlen(str);
+        TEST_ASSERT(tmp < sizeof(str));
+
+        memset(bytes, 0, sizeof(bytes));
+        tmp = sizeof(bytes);
+
+        tmp = sizeof(bytes);
+        rc = conf_bytes_from_str(str, bytes, &tmp);
+        TEST_ASSERT(rc == 0);
+        TEST_ASSERT(tmp == j);
+        TEST_ASSERT(!memcmp(orig, bytes, j));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_getset_int.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_getset_int.c b/sys/config/test-nffs/src/testcases/config_test_getset_int.c
new file mode 100644
index 0000000..c1305a2
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_getset_int.c
@@ -0,0 +1,40 @@
+/**
+ * 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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_getset_int)
+{
+    char name[80];
+    char tmp[64], *str;
+    int rc;
+
+    strcpy(name, "myfoo/mybar");
+    rc = conf_set_value(name, "42");
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_set_called == 1);
+    TEST_ASSERT(val8 == 42);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/mybar");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str);
+    TEST_ASSERT(test_get_called == 1);
+    TEST_ASSERT(!strcmp("42", tmp));
+    ctest_clear_call_state();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_getset_unknown.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_getset_unknown.c b/sys/config/test-nffs/src/testcases/config_test_getset_unknown.c
new file mode 100644
index 0000000..323047f
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_getset_unknown.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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_getset_unknown)
+{
+    char name[80];
+    char tmp[64], *str;
+    int rc;
+
+    strcpy(name, "foo/bar");
+    rc = conf_set_value(name, "tmp");
+    TEST_ASSERT(rc != 0);
+    TEST_ASSERT(ctest_get_call_state() == 0);
+
+    strcpy(name, "foo/bar");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str == NULL);
+    TEST_ASSERT(ctest_get_call_state() == 0);
+
+    strcpy(name, "myfoo/bar");
+    rc = conf_set_value(name, "tmp");
+    TEST_ASSERT(rc == OS_ENOENT);
+    TEST_ASSERT(test_set_called == 1);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/bar");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str == NULL);
+    TEST_ASSERT(test_get_called == 1);
+    ctest_clear_call_state();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_insert.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_insert.c b/sys/config/test-nffs/src/testcases/config_test_insert.c
new file mode 100644
index 0000000..125cfb6
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_insert.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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_insert)
+{
+    int rc;
+
+    rc = conf_register(&config_test_handler);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_insert2.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_insert2.c b/sys/config/test-nffs/src/testcases/config_test_insert2.c
new file mode 100644
index 0000000..cf61f98
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_insert2.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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_insert2)
+{
+    int rc;
+
+    rc = conf_register(&c2_test_handler);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_insert3.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_insert3.c b/sys/config/test-nffs/src/testcases/config_test_insert3.c
new file mode 100644
index 0000000..2d321cb
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_insert3.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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_insert3)
+{
+    int rc;
+
+    rc = conf_register(&c3_test_handler);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_multiple_in_file.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_multiple_in_file.c b/sys/config/test-nffs/src/testcases/config_test_multiple_in_file.c
new file mode 100644
index 0000000..eccb2c1
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_multiple_in_file.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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_multiple_in_file)
+{
+    int rc;
+    struct conf_file cf_mfg;
+    const char cf_mfg_test1[] =
+      "myfoo/mybar=1\n"
+      "myfoo/mybar=14";
+    const char cf_mfg_test2[] =
+      "myfoo/mybar=1\n"
+      "myfoo/mybar=15\n"
+      "\n";
+
+    config_wipe_srcs();
+
+    cf_mfg.cf_name = "/config/mfg";
+    rc = conf_file_src(&cf_mfg);
+    TEST_ASSERT(rc == 0);
+
+    rc = fsutil_write_file("/config/mfg", cf_mfg_test1, sizeof(cf_mfg_test1));
+    TEST_ASSERT(rc == 0);
+
+    conf_load();
+    TEST_ASSERT(test_set_called);
+    TEST_ASSERT(val8 == 14);
+
+    rc = fsutil_write_file("/config/mfg", cf_mfg_test2, sizeof(cf_mfg_test2));
+    TEST_ASSERT(rc == 0);
+
+    conf_load();
+    TEST_ASSERT(test_set_called);
+    TEST_ASSERT(val8 == 15);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_save_in_file.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_save_in_file.c b/sys/config/test-nffs/src/testcases/config_test_save_in_file.c
new file mode 100644
index 0000000..c6ad07f
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_save_in_file.c
@@ -0,0 +1,50 @@
+/**
+ * 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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_save_in_file)
+{
+    int rc;
+    struct conf_file cf;
+
+    config_wipe_srcs();
+
+    rc = fs_mkdir("/config");
+    TEST_ASSERT(rc == 0 || rc == FS_EEXIST);
+
+    cf.cf_name = "/config/blah";
+    rc = conf_file_src(&cf);
+    TEST_ASSERT(rc == 0);
+    rc = conf_file_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    val8 = 8;
+    rc = conf_save();
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_test_file_strstr(cf.cf_name, "myfoo/mybar=8\n");
+    TEST_ASSERT(rc == 0);
+
+    val8 = 43;
+    rc = conf_save();
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_test_file_strstr(cf.cf_name, "myfoo/mybar=43\n");
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_save_one_file.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_save_one_file.c b/sys/config/test-nffs/src/testcases/config_test_save_one_file.c
new file mode 100644
index 0000000..feb2376
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_save_one_file.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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_save_one_file)
+{
+    int rc;
+    struct conf_file cf;
+
+    config_wipe_srcs();
+    rc = fs_mkdir("/config");
+    TEST_ASSERT(rc == 0 || rc == FS_EEXIST);
+
+    cf.cf_name = "/config/blah";
+    rc = conf_file_src(&cf);
+    TEST_ASSERT(rc == 0);
+    rc = conf_file_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    val8 = 33;
+    rc = conf_save();
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_save_one("myfoo/mybar", "42");
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 42);
+
+    rc = conf_save_one("myfoo/mybar", "44");
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 44);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_small_file.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_small_file.c b/sys/config/test-nffs/src/testcases/config_test_small_file.c
new file mode 100644
index 0000000..5b3acc7
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_small_file.c
@@ -0,0 +1,56 @@
+/**
+ * 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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_small_file)
+{
+    int rc;
+    struct conf_file cf_mfg;
+    struct conf_file cf_running;
+    const char cf_mfg_test[] = "myfoo/mybar=1";
+    const char cf_running_test[] = " myfoo/mybar = 8 ";
+
+    config_wipe_srcs();
+
+    cf_mfg.cf_name = "/config/mfg";
+    cf_running.cf_name = "/config/running";
+
+    rc = conf_file_src(&cf_mfg);
+    TEST_ASSERT(rc == 0);
+    rc = conf_file_src(&cf_running);
+
+    rc = fsutil_write_file("/config/mfg", cf_mfg_test, sizeof(cf_mfg_test));
+    TEST_ASSERT(rc == 0);
+
+    conf_load();
+    TEST_ASSERT(test_set_called);
+    TEST_ASSERT(val8 == 1);
+
+    ctest_clear_call_state();
+
+    rc = fsutil_write_file("/config/running", cf_running_test,
+      sizeof(cf_running_test));
+    TEST_ASSERT(rc == 0);
+
+    conf_load();
+    TEST_ASSERT(test_set_called);
+    TEST_ASSERT(val8 == 8);
+
+    ctest_clear_call_state();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/syscfg.yml
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/syscfg.yml b/sys/config/test-nffs/syscfg.yml
new file mode 100644
index 0000000..19ea6cb
--- /dev/null
+++ b/sys/config/test-nffs/syscfg.yml
@@ -0,0 +1,5 @@
+# Package: sys/config/test-nffs
+
+syscfg.vals:
+    CONFIG_NFFS: 1
+    CONFIG_FCB_FLASH_AREA: 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/config/test/pkg.yml b/sys/config/test/pkg.yml
deleted file mode 100644
index 44efb51..0000000
--- a/sys/config/test/pkg.yml
+++ /dev/null
@@ -1,32 +0,0 @@
-# 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: sys/config/test
-pkg.type: unittest
-pkg.description: "Config unit tests."
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-
-pkg.deps: 
-    - test/testutil
-    - sys/config
-
-pkg.deps.SELFTEST:
-    - fs/nffs
-    - fs/fcb
-    - sys/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/src/conf_test.c
----------------------------------------------------------------------
diff --git a/sys/config/test/src/conf_test.c b/sys/config/test/src/conf_test.c
deleted file mode 100644
index 3c432c4..0000000
--- a/sys/config/test/src/conf_test.c
+++ /dev/null
@@ -1,953 +0,0 @@
-/**
- * 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 <os/os.h>
-#include <testutil/testutil.h>
-#include <nffs/nffs.h>
-#include <fs/fs.h>
-#include <fs/fsutil.h>
-#include <fcb/fcb.h>
-#include "config/config.h"
-#include "config/config_file.h"
-#include "config/config_fcb.h"
-#include "config_test.h"
-#include "config_priv.h"
-
-static uint8_t val8;
-int c2_var_count = 1;
-static char val_string[64][CONF_MAX_VAL_LEN];
-
-static uint32_t val32;
-
-static int test_get_called;
-static int test_set_called;
-static int test_commit_called;
-static int test_export_block;
-
-static char *ctest_handle_get(int argc, char **argv, char *val,
-  int val_len_max);
-static int ctest_handle_set(int argc, char **argv, char *val);
-static int ctest_handle_commit(void);
-static int ctest_handle_export(void (*cb)(char *name, char *value),
-  enum conf_export_tgt tgt);
-static char *c2_handle_get(int argc, char **argv, char *val,
-  int val_len_max);
-static int c2_handle_set(int argc, char **argv, char *val);
-static int c2_handle_export(void (*cb)(char *name, char *value),
-  enum conf_export_tgt tgt);
-static char *c3_handle_get(int argc, char **argv, char *val,
-  int val_len_max);
-static int c3_handle_set(int argc, char **argv, char *val);
-static int c3_handle_export(void (*cb)(char *name, char *value),
-  enum conf_export_tgt tgt);
-
-struct conf_handler config_test_handler = {
-    .ch_name = "myfoo",
-    .ch_get = ctest_handle_get,
-    .ch_set = ctest_handle_set,
-    .ch_commit = ctest_handle_commit,
-    .ch_export = ctest_handle_export
-};
-
-static char *
-ctest_handle_get(int argc, char **argv, char *val, int val_len_max)
-{
-    test_get_called = 1;
-    if (argc == 1 && !strcmp(argv[0], "mybar")) {
-        return conf_str_from_value(CONF_INT8, &val8, val, val_len_max);
-    }
-    return NULL;
-}
-
-static int
-ctest_handle_set(int argc, char **argv, char *val)
-{
-    uint8_t newval;
-    int rc;
-
-    test_set_called = 1;
-    if (argc == 1 && !strcmp(argv[0], "mybar")) {
-        rc = CONF_VALUE_SET(val, CONF_INT8, newval);
-        TEST_ASSERT(rc == 0);
-        val8 = newval;
-        return 0;
-    }
-    return OS_ENOENT;
-}
-
-static int
-ctest_handle_commit(void)
-{
-    test_commit_called = 1;
-    return 0;
-}
-
-static int
-ctest_handle_export(void (*cb)(char *name, char *value),
-  enum conf_export_tgt tgt)
-{
-    char value[32];
-
-    if (test_export_block) {
-        return 0;
-    }
-    conf_str_from_value(CONF_INT8, &val8, value, sizeof(value));
-    cb("myfoo/mybar", value);
-
-    return 0;
-}
-
-struct conf_handler c2_test_handler = {
-    .ch_name = "2nd",
-    .ch_get = c2_handle_get,
-    .ch_set = c2_handle_set,
-    .ch_commit = NULL,
-    .ch_export = c2_handle_export
-};
-
-char *
-c2_var_find(char *name)
-{
-    int idx = 0;
-    int len;
-    char *eptr;
-
-    len = strlen(name);
-    TEST_ASSERT(!strncmp(name, "string", 6));
-    TEST_ASSERT(len > 6);
-
-    idx = strtoul(&name[6], &eptr, 10);
-    TEST_ASSERT(*eptr == '\0');
-    TEST_ASSERT(idx < c2_var_count);
-    return val_string[idx];
-}
-
-static char *
-c2_handle_get(int argc, char **argv, char *val, int val_len_max)
-{
-    int len;
-    char *valptr;
-
-    if (argc == 1) {
-        valptr = c2_var_find(argv[0]);
-        if (!valptr) {
-            return NULL;
-        }
-        len = strlen(val_string[0]);
-        if (len > val_len_max) {
-            len = val_len_max;
-        }
-        strncpy(val, valptr, len);
-    }
-    return NULL;
-}
-
-static int
-c2_handle_set(int argc, char **argv, char *val)
-{
-    char *valptr;
-
-    if (argc == 1) {
-        valptr = c2_var_find(argv[0]);
-        if (!valptr) {
-            return OS_ENOENT;
-        }
-        if (val) {
-            strncpy(valptr, val, sizeof(val_string[0]));
-        } else {
-            memset(valptr, 0, sizeof(val_string[0]));
-        }
-        return 0;
-    }
-    return OS_ENOENT;
-}
-
-static int
-c2_handle_export(void (*cb)(char *name, char *value),
-  enum conf_export_tgt tgt)
-{
-    int i;
-    char name[32];
-
-    for (i = 0; i < c2_var_count; i++) {
-        snprintf(name, sizeof(name), "2nd/string%d", i);
-        cb(name, val_string[i]);
-    }
-    return 0;
-}
-
-struct conf_handler c3_test_handler = {
-    .ch_name = "3",
-    .ch_get = c3_handle_get,
-    .ch_set = c3_handle_set,
-    .ch_commit = NULL,
-    .ch_export = c3_handle_export
-};
-
-static char *
-c3_handle_get(int argc, char **argv, char *val, int val_len_max)
-{
-    if (argc == 1 && !strcmp(argv[0], "v")) {
-        return conf_str_from_value(CONF_INT32, &val32, val, val_len_max);
-    }
-    return NULL;
-}
-
-static int
-c3_handle_set(int argc, char **argv, char *val)
-{
-    uint32_t newval;
-    int rc;
-
-    if (argc == 1 && !strcmp(argv[0], "v")) {
-        rc = CONF_VALUE_SET(val, CONF_INT32, newval);
-        TEST_ASSERT(rc == 0);
-        val32 = newval;
-        return 0;
-    }
-    return OS_ENOENT;
-}
-
-static int
-c3_handle_export(void (*cb)(char *name, char *value),
-  enum conf_export_tgt tgt)
-{
-    char value[32];
-
-    conf_str_from_value(CONF_INT32, &val32, value, sizeof(value));
-    cb("3/v", value);
-
-    return 0;
-}
-
-static void
-ctest_clear_call_state(void)
-{
-    test_get_called = 0;
-    test_set_called = 0;
-    test_commit_called = 0;
-}
-
-static int
-ctest_get_call_state(void)
-{
-    return test_get_called + test_set_called + test_commit_called;
-}
-
-TEST_CASE(config_empty_lookups)
-{
-    int rc;
-    char name[80];
-    char tmp[64], *str;
-
-    strcpy(name, "foo/bar");
-    rc = conf_set_value(name, "tmp");
-    TEST_ASSERT(rc != 0);
-
-    strcpy(name, "foo/bar");
-    str = conf_get_value(name, tmp, sizeof(tmp));
-    TEST_ASSERT(str == NULL);
-}
-
-TEST_CASE(config_test_insert)
-{
-    int rc;
-
-    rc = conf_register(&config_test_handler);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(config_test_insert2)
-{
-    int rc;
-
-    rc = conf_register(&c2_test_handler);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(config_test_getset_unknown)
-{
-    char name[80];
-    char tmp[64], *str;
-    int rc;
-
-    strcpy(name, "foo/bar");
-    rc = conf_set_value(name, "tmp");
-    TEST_ASSERT(rc != 0);
-    TEST_ASSERT(ctest_get_call_state() == 0);
-
-    strcpy(name, "foo/bar");
-    str = conf_get_value(name, tmp, sizeof(tmp));
-    TEST_ASSERT(str == NULL);
-    TEST_ASSERT(ctest_get_call_state() == 0);
-
-    strcpy(name, "myfoo/bar");
-    rc = conf_set_value(name, "tmp");
-    TEST_ASSERT(rc == OS_ENOENT);
-    TEST_ASSERT(test_set_called == 1);
-    ctest_clear_call_state();
-
-    strcpy(name, "myfoo/bar");
-    str = conf_get_value(name, tmp, sizeof(tmp));
-    TEST_ASSERT(str == NULL);
-    TEST_ASSERT(test_get_called == 1);
-    ctest_clear_call_state();
-}
-
-TEST_CASE(config_test_getset_int)
-{
-    char name[80];
-    char tmp[64], *str;
-    int rc;
-
-    strcpy(name, "myfoo/mybar");
-    rc = conf_set_value(name, "42");
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(test_set_called == 1);
-    TEST_ASSERT(val8 == 42);
-    ctest_clear_call_state();
-
-    strcpy(name, "myfoo/mybar");
-    str = conf_get_value(name, tmp, sizeof(tmp));
-    TEST_ASSERT(str);
-    TEST_ASSERT(test_get_called == 1);
-    TEST_ASSERT(!strcmp("42", tmp));
-    ctest_clear_call_state();
-}
-
-TEST_CASE(config_test_getset_bytes)
-{
-    char orig[32];
-    char bytes[32];
-    char str[48];
-    char *ret;
-    int j, i;
-    int tmp;
-    int rc;
-
-    for (j = 1; j < sizeof(orig); j++) {
-        for (i = 0; i < j; i++) {
-            orig[i] = i + j + 1;
-        }
-        ret = conf_str_from_bytes(orig, j, str, sizeof(str));
-        TEST_ASSERT(ret);
-        tmp = strlen(str);
-        TEST_ASSERT(tmp < sizeof(str));
-
-        memset(bytes, 0, sizeof(bytes));
-        tmp = sizeof(bytes);
-
-        tmp = sizeof(bytes);
-        rc = conf_bytes_from_str(str, bytes, &tmp);
-        TEST_ASSERT(rc == 0);
-        TEST_ASSERT(tmp == j);
-        TEST_ASSERT(!memcmp(orig, bytes, j));
-    }
-}
-
-TEST_CASE(config_test_commit)
-{
-    char name[80];
-    int rc;
-
-    strcpy(name, "bar");
-    rc = conf_commit(name);
-    TEST_ASSERT(rc);
-    TEST_ASSERT(ctest_get_call_state() == 0);
-
-    rc = conf_commit(NULL);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(test_commit_called == 1);
-    ctest_clear_call_state();
-
-    strcpy(name, "myfoo");
-    rc = conf_commit(name);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(test_commit_called == 1);
-    ctest_clear_call_state();
-}
-
-static const struct nffs_area_desc config_nffs[] = {
-    { 0x00000000, 16 * 1024 },
-    { 0x00004000, 16 * 1024 },
-    { 0x00008000, 16 * 1024 },
-    { 0x0000c000, 16 * 1024 },
-    { 0, 0 }
-};
-
-TEST_CASE(config_setup_nffs)
-{
-    int rc;
-
-    rc = nffs_init();
-    TEST_ASSERT_FATAL(rc == 0);
-    rc = nffs_format(config_nffs);
-    TEST_ASSERT_FATAL(rc == 0);
-}
-
-static void config_wipe_srcs(void)
-{
-    SLIST_INIT(&conf_load_srcs);
-    conf_save_dst = NULL;
-}
-
-static void config_wipe_fcb(struct flash_area *fa, int cnt)
-{
-    int i;
-
-    for (i = 0; i < cnt; i++) {
-        flash_area_erase(&fa[i], 0, fa[i].fa_size);
-    }
-}
-
-TEST_CASE(config_test_empty_file)
-{
-    int rc;
-    struct conf_file cf_mfg;
-    struct conf_file cf_running;
-    const char cf_mfg_test[] = "";
-    const char cf_running_test[] = "\n\n";
-
-    config_wipe_srcs();
-
-    cf_mfg.cf_name = "/config/mfg";
-    cf_running.cf_name = "/config/running";
-
-    rc = conf_file_src(&cf_mfg);
-    TEST_ASSERT(rc == 0);
-    rc = conf_file_src(&cf_running);
-
-    /*
-     * No files
-     */
-    conf_load();
-
-    rc = fs_mkdir("/config");
-    TEST_ASSERT(rc == 0);
-
-    rc = fsutil_write_file("/config/mfg", cf_mfg_test, sizeof(cf_mfg_test));
-    TEST_ASSERT(rc == 0);
-
-    rc = fsutil_write_file("/config/running", cf_running_test,
-      sizeof(cf_running_test));
-    TEST_ASSERT(rc == 0);
-
-    conf_load();
-    config_wipe_srcs();
-    ctest_clear_call_state();
-}
-
-TEST_CASE(config_test_small_file)
-{
-    int rc;
-    struct conf_file cf_mfg;
-    struct conf_file cf_running;
-    const char cf_mfg_test[] = "myfoo/mybar=1";
-    const char cf_running_test[] = " myfoo/mybar = 8 ";
-
-    config_wipe_srcs();
-
-    cf_mfg.cf_name = "/config/mfg";
-    cf_running.cf_name = "/config/running";
-
-    rc = conf_file_src(&cf_mfg);
-    TEST_ASSERT(rc == 0);
-    rc = conf_file_src(&cf_running);
-
-    rc = fsutil_write_file("/config/mfg", cf_mfg_test, sizeof(cf_mfg_test));
-    TEST_ASSERT(rc == 0);
-
-    conf_load();
-    TEST_ASSERT(test_set_called);
-    TEST_ASSERT(val8 == 1);
-
-    ctest_clear_call_state();
-
-    rc = fsutil_write_file("/config/running", cf_running_test,
-      sizeof(cf_running_test));
-    TEST_ASSERT(rc == 0);
-
-    conf_load();
-    TEST_ASSERT(test_set_called);
-    TEST_ASSERT(val8 == 8);
-
-    ctest_clear_call_state();
-}
-
-TEST_CASE(config_test_multiple_in_file)
-{
-    int rc;
-    struct conf_file cf_mfg;
-    const char cf_mfg_test1[] =
-      "myfoo/mybar=1\n"
-      "myfoo/mybar=14";
-    const char cf_mfg_test2[] =
-      "myfoo/mybar=1\n"
-      "myfoo/mybar=15\n"
-      "\n";
-
-    config_wipe_srcs();
-
-    cf_mfg.cf_name = "/config/mfg";
-    rc = conf_file_src(&cf_mfg);
-    TEST_ASSERT(rc == 0);
-
-    rc = fsutil_write_file("/config/mfg", cf_mfg_test1, sizeof(cf_mfg_test1));
-    TEST_ASSERT(rc == 0);
-
-    conf_load();
-    TEST_ASSERT(test_set_called);
-    TEST_ASSERT(val8 == 14);
-
-    rc = fsutil_write_file("/config/mfg", cf_mfg_test2, sizeof(cf_mfg_test2));
-    TEST_ASSERT(rc == 0);
-
-    conf_load();
-    TEST_ASSERT(test_set_called);
-    TEST_ASSERT(val8 == 15);
-}
-
-int
-conf_test_file_strstr(const char *fname, char *string)
-{
-    int rc;
-    uint32_t len;
-    uint32_t rlen;
-    char *buf;
-    struct fs_file *file;
-
-    rc = fs_open(fname, FS_ACCESS_READ, &file);
-    if (rc) {
-        return rc;
-    }
-    rc = fs_filelen(file, &len);
-    fs_close(file);
-    if (rc) {
-        return rc;
-    }
-
-    buf = (char *)malloc(len + 1);
-    TEST_ASSERT(buf);
-
-    rc = fsutil_read_file(fname, 0, len, buf, &rlen);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(rlen == len);
-    buf[rlen] = '\0';
-
-    if (strstr(buf, string)) {
-        return 0;
-    } else {
-        return -1;
-    }
-}
-
-TEST_CASE(config_test_save_in_file)
-{
-    int rc;
-    struct conf_file cf;
-
-    config_wipe_srcs();
-
-    rc = fs_mkdir("/config");
-    TEST_ASSERT(rc == 0 || rc == FS_EEXIST);
-
-    cf.cf_name = "/config/blah";
-    rc = conf_file_src(&cf);
-    TEST_ASSERT(rc == 0);
-    rc = conf_file_dst(&cf);
-    TEST_ASSERT(rc == 0);
-
-    val8 = 8;
-    rc = conf_save();
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_test_file_strstr(cf.cf_name, "myfoo/mybar=8\n");
-    TEST_ASSERT(rc == 0);
-
-    val8 = 43;
-    rc = conf_save();
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_test_file_strstr(cf.cf_name, "myfoo/mybar=43\n");
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(config_test_save_one_file)
-{
-    int rc;
-    struct conf_file cf;
-
-    config_wipe_srcs();
-    rc = fs_mkdir("/config");
-    TEST_ASSERT(rc == 0 || rc == FS_EEXIST);
-
-    cf.cf_name = "/config/blah";
-    rc = conf_file_src(&cf);
-    TEST_ASSERT(rc == 0);
-    rc = conf_file_dst(&cf);
-    TEST_ASSERT(rc == 0);
-
-    val8 = 33;
-    rc = conf_save();
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_save_one("myfoo/mybar", "42");
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_load();
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(val8 == 42);
-
-    rc = conf_save_one("myfoo/mybar", "44");
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_load();
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(val8 == 44);
-}
-
-struct flash_area fcb_areas[] = {
-    [0] = {
-        .fa_off = 0x00000000,
-        .fa_size = 16 * 1024
-    },
-    [1] = {
-        .fa_off = 0x00004000,
-        .fa_size = 16 * 1024
-    },
-    [2] = {
-        .fa_off = 0x00008000,
-        .fa_size = 16 * 1024
-    },
-    [3] = {
-        .fa_off = 0x0000c000,
-        .fa_size = 16 * 1024
-    }
-};
-
-TEST_CASE(config_test_empty_fcb)
-{
-    int rc;
-    struct conf_fcb cf;
-
-    config_wipe_srcs();
-    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
-
-    cf.cf_fcb.f_sectors = fcb_areas;
-    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
-
-    rc = conf_fcb_src(&cf);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * No values
-     */
-    conf_load();
-
-    config_wipe_srcs();
-    ctest_clear_call_state();
-}
-
-TEST_CASE(config_test_save_1_fcb)
-{
-    int rc;
-    struct conf_fcb cf;
-
-    config_wipe_srcs();
-
-    cf.cf_fcb.f_sectors = fcb_areas;
-    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
-
-    rc = conf_fcb_src(&cf);
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_fcb_dst(&cf);
-    TEST_ASSERT(rc == 0);
-
-    val8 = 33;
-    rc = conf_save();
-    TEST_ASSERT(rc == 0);
-
-    val8 = 0;
-
-    rc = conf_load();
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(val8 == 33);
-}
-
-static void config_test_fill_area(char test_value[64][CONF_MAX_VAL_LEN],
-  int iteration)
-{
-      int i, j;
-
-      for (j = 0; j < 64; j++) {
-          for (i = 0; i < CONF_MAX_VAL_LEN; i++) {
-              test_value[j][i] = ((j * 2) + i + iteration) % 10 + '0';
-          }
-          test_value[j][sizeof(test_value[j]) - 1] = '\0';
-      }
-}
-
-TEST_CASE(config_test_save_2_fcb)
-{
-    int rc;
-    struct conf_fcb cf;
-    char test_value[64][CONF_MAX_VAL_LEN];
-    int i;
-
-    config_wipe_srcs();
-
-    cf.cf_fcb.f_sectors = fcb_areas;
-    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
-
-    rc = conf_fcb_src(&cf);
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_fcb_dst(&cf);
-    TEST_ASSERT(rc == 0);
-
-    config_test_fill_area(test_value, 0);
-    memcpy(val_string, test_value, sizeof(val_string));
-
-    val8 = 42;
-    rc = conf_save();
-    TEST_ASSERT(rc == 0);
-
-    val8 = 0;
-    memset(val_string[0], 0, sizeof(val_string[0]));
-    rc = conf_load();
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(val8 == 42);
-    TEST_ASSERT(!strcmp(val_string[0], test_value[0]));
-    test_export_block = 1;
-
-    /*
-     * Now add the number of settings to max. Keep adjusting the test_data,
-     * check that rollover happens when it's supposed to.
-     */
-    c2_var_count = 64;
-
-    for (i = 0; i < 32; i++) {
-        config_test_fill_area(test_value, i);
-        memcpy(val_string, test_value, sizeof(val_string));
-
-        rc = conf_save();
-        TEST_ASSERT(rc == 0);
-
-        memset(val_string, 0, sizeof(val_string));
-
-        val8 = 0;
-        rc = conf_load();
-        TEST_ASSERT(rc == 0);
-        TEST_ASSERT(!memcmp(val_string, test_value, sizeof(val_string)));
-        TEST_ASSERT(val8 == 42);
-    }
-    c2_var_count = 0;
-}
-
-TEST_CASE(config_test_insert3)
-{
-    int rc;
-
-    rc = conf_register(&c3_test_handler);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(config_test_save_3_fcb)
-{
-    int rc;
-    struct conf_fcb cf;
-    int i;
-
-    config_wipe_srcs();
-    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
-
-    cf.cf_fcb.f_sectors = fcb_areas;
-    cf.cf_fcb.f_sector_cnt = 4;
-
-    rc = conf_fcb_src(&cf);
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_fcb_dst(&cf);
-    TEST_ASSERT(rc == 0);
-
-    for (i = 0; i < 4096; i++) {
-        val32 = i;
-
-        rc = conf_save();
-        TEST_ASSERT(rc == 0);
-
-        val32 = 0;
-
-        rc = conf_load();
-        TEST_ASSERT(rc == 0);
-        TEST_ASSERT(val32 == i);
-    }
-}
-
-TEST_CASE(config_test_compress_reset)
-{
-    int rc;
-    struct conf_fcb cf;
-    struct flash_area *fa;
-    char test_value[64][CONF_MAX_VAL_LEN];
-    int elems[4];
-    int i;
-
-    config_wipe_srcs();
-    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
-
-    cf.cf_fcb.f_sectors = fcb_areas;
-    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
-
-    rc = conf_fcb_src(&cf);
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_fcb_dst(&cf);
-    TEST_ASSERT(rc == 0);
-
-    c2_var_count = 1;
-    memset(elems, 0, sizeof(elems));
-
-    for (i = 0; ; i++) {
-        config_test_fill_area(test_value, i);
-        memcpy(val_string, test_value, sizeof(val_string));
-
-        rc = conf_save();
-        TEST_ASSERT(rc == 0);
-
-        if (cf.cf_fcb.f_active.fe_area == &fcb_areas[2]) {
-            /*
-             * Started using space just before scratch.
-             */
-            break;
-        }
-        memset(val_string, 0, sizeof(val_string));
-
-        rc = conf_load();
-        TEST_ASSERT(rc == 0);
-        TEST_ASSERT(!memcmp(val_string, test_value, CONF_MAX_VAL_LEN));
-    }
-
-    fa = cf.cf_fcb.f_active.fe_area;
-    rc = fcb_append_to_scratch(&cf.cf_fcb);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(fcb_free_sector_cnt(&cf.cf_fcb) == 0);
-    TEST_ASSERT(fa != cf.cf_fcb.f_active.fe_area);
-
-    config_wipe_srcs();
-
-    memset(&cf, 0, sizeof(cf));
-
-    cf.cf_fcb.f_sectors = fcb_areas;
-    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
-
-    rc = conf_fcb_src(&cf);
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_fcb_dst(&cf);
-    TEST_ASSERT(rc == 0);
-
-    TEST_ASSERT(fcb_free_sector_cnt(&cf.cf_fcb) == 1);
-    TEST_ASSERT(fa == cf.cf_fcb.f_active.fe_area);
-
-    c2_var_count = 0;
-}
-
-TEST_CASE(config_test_save_one_fcb)
-{
-    int rc;
-    struct conf_fcb cf;
-
-    config_wipe_srcs();
-    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
-
-    cf.cf_fcb.f_sectors = fcb_areas;
-    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
-
-    rc = conf_fcb_src(&cf);
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_fcb_dst(&cf);
-    TEST_ASSERT(rc == 0);
-
-    val8 = 33;
-    rc = conf_save();
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_save_one("myfoo/mybar", "42");
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_load();
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(val8 == 42);
-
-    rc = conf_save_one("myfoo/mybar", "44");
-    TEST_ASSERT(rc == 0);
-
-    rc = conf_load();
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(val8 == 44);
-}
-
-TEST_SUITE(config_test_all)
-{
-    /*
-     * Config tests.
-     */
-    config_empty_lookups();
-    config_test_insert();
-    config_test_getset_unknown();
-    config_test_getset_int();
-    config_test_getset_bytes();
-
-    config_test_commit();
-
-    /*
-     * NFFS as backing storage.
-     */
-    config_setup_nffs();
-    config_test_empty_file();
-    config_test_small_file();
-    config_test_multiple_in_file();
-
-    config_test_save_in_file();
-
-    config_test_save_one_file();
-
-    /*
-     * FCB as backing storage.
-     */
-    config_test_empty_fcb();
-    config_test_save_1_fcb();
-
-    config_test_insert2();
-
-    config_test_save_2_fcb();
-
-    config_test_insert3();
-    config_test_save_3_fcb();
-
-    config_test_compress_reset();
-
-    config_test_save_one_fcb();
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/src/conf_test.h
----------------------------------------------------------------------
diff --git a/sys/config/test/src/conf_test.h b/sys/config/test/src/conf_test.h
deleted file mode 100644
index e88a1f6..0000000
--- a/sys/config/test/src/conf_test.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * 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 _CONF_TEST_H_
-#define _CONF_TEST_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void config_test_all(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _CONF_TEST_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/src/conf_test_suite.c
----------------------------------------------------------------------
diff --git a/sys/config/test/src/conf_test_suite.c b/sys/config/test/src/conf_test_suite.c
deleted file mode 100644
index 65360c3..0000000
--- a/sys/config/test/src/conf_test_suite.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 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 "syscfg/syscfg.h"
-#include "os/os.h"
-#include "testutil/testutil.h"
-#include "config/config.h"
-#include "config_test.h"
-
-#if MYNEWT_VAL(SELFTEST)
-
-int
-main(int argc, char **argv)
-{
-    tu_config.tc_print_results = 1;
-    tu_init();
-
-    conf_init();
-    config_test_all();
-
-    return tu_any_failed;
-}
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/src/config_test.h
----------------------------------------------------------------------
diff --git a/sys/config/test/src/config_test.h b/sys/config/test/src/config_test.h
deleted file mode 100644
index fb515f8..0000000
--- a/sys/config/test/src/config_test.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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 _CONFIG_TEST_H_
-#define _CONFIG_TEST_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int config_test_all();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test/syscfg.yml
----------------------------------------------------------------------
diff --git a/sys/config/test/syscfg.yml b/sys/config/test/syscfg.yml
deleted file mode 100644
index f6bcf48..0000000
--- a/sys/config/test/syscfg.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-# Package: sys/config/test
-
-syscfg.vals:
-    CONFIG_NFFS: 1
-    CONFIG_FCB: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/flash_map/test/src/flash_map_test.c
----------------------------------------------------------------------
diff --git a/sys/flash_map/test/src/flash_map_test.c b/sys/flash_map/test/src/flash_map_test.c
index d1a5aa2..3409ec8 100644
--- a/sys/flash_map/test/src/flash_map_test.c
+++ b/sys/flash_map/test/src/flash_map_test.c
@@ -29,126 +29,8 @@
 #include "hal/hal_flash.h"
 #include "hal/hal_flash_int.h"
 
-/*
- * Test flash_area_to_sectors()
- */
-TEST_CASE(flash_map_test_case_1)
-{
-    const struct flash_area *fa;
-    int areas_checked = 0;
-    int i, j, rc;
-    const struct hal_flash *hf;
-    struct flash_area my_secs[32];
-    int my_sec_cnt;
-    uint32_t end;
-
-    sysinit();
-
-    for (i = 0; i < 8; i++) {
-        rc = flash_area_open(i, &fa);
-        if (rc) {
-            continue;
-        }
-
-        hf = bsp_flash_dev(fa->fa_device_id);
-        TEST_ASSERT_FATAL(hf != NULL, "bsp_flash_dev");
-
-        rc = flash_area_to_sectors(i, &my_sec_cnt, my_secs);
-        TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed");
-
-        end = fa->fa_off;
-        for (j = 0; j < my_sec_cnt; j++) {
-            TEST_ASSERT_FATAL(end == my_secs[j].fa_off, "Non contiguous area");
-            TEST_ASSERT_FATAL(my_secs[j].fa_device_id == fa->fa_device_id,
-              "Sectors not in same flash?");
-            end = my_secs[j].fa_off + my_secs[j].fa_size;
-        }
-        if (my_sec_cnt) {
-            areas_checked++;
-            TEST_ASSERT_FATAL(my_secs[my_sec_cnt - 1].fa_off +
-              my_secs[my_sec_cnt - 1].fa_size == fa->fa_off + fa->fa_size,
-              "Last sector not in the end");
-        }
-    }
-    TEST_ASSERT_FATAL(areas_checked != 0, "No flash map areas to check!");
-}
-
-/*
- * Test flash_erase
- */
-TEST_CASE(flash_map_test_case_2)
-{
-    const struct flash_area *fa;
-    struct flash_area secs[32];
-    int sec_cnt;
-    int i;
-    int rc;
-    uint32_t off;
-    uint8_t wd[256];
-    uint8_t rd[256];
-
-    sysinit();
-
-    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fa);
-    TEST_ASSERT_FATAL(rc == 0, "flash_area_open() fail");
-
-    rc = flash_area_to_sectors(FLASH_AREA_IMAGE_0, &sec_cnt, secs);
-    TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed");
-
-    /*
-     * First erase the area so it's ready for use.
-     */
-    for (i = 0; i < sec_cnt; i++) {
-        rc = hal_flash_erase_sector(secs[i].fa_device_id, secs[i].fa_off);
-        TEST_ASSERT_FATAL(rc == 0, "hal_flash_erase_sector() failed");
-    }
-    TEST_ASSERT_FATAL(rc == 0, "read data != write data");
-
-    memset(wd, 0xa5, sizeof(wd));
-
-    /* write stuff to beginning of every sector */
-    off = 0;
-    for (i = 0; i < sec_cnt; i++) {
-        rc = flash_area_write(fa, off, wd, sizeof(wd));
-        TEST_ASSERT_FATAL(rc == 0, "flash_area_write() fail");
-
-        /* read it back via hal_flash_Read() */
-        rc = hal_flash_read(fa->fa_device_id, fa->fa_off + off, rd, sizeof(rd));
-        TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
-
-        rc = memcmp(wd, rd, sizeof(wd));
-        TEST_ASSERT_FATAL(rc == 0, "read data != write data");
-
-        /* write stuff to end of area */
-        rc = hal_flash_write(fa->fa_device_id,
-          fa->fa_off + off + secs[i].fa_size - sizeof(wd), wd, sizeof(wd));
-        TEST_ASSERT_FATAL(rc == 0, "hal_flash_write() fail");
-
-        /* and read it back */
-        memset(rd, 0, sizeof(rd));
-        rc = flash_area_read(fa, off + secs[i].fa_size - sizeof(rd),
-          rd, sizeof(rd));
-        TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
-
-        rc = memcmp(wd, rd, sizeof(rd));
-        TEST_ASSERT_FATAL(rc == 0, "read data != write data");
-
-        off += secs[i].fa_size;
-    }
-    /* erase it */
-    rc = flash_area_erase(fa, 0, fa->fa_size);
-    TEST_ASSERT_FATAL(rc == 0, "read data != write data");
-
-    /* should read back ff all throughout*/
-    memset(wd, 0xff, sizeof(wd));
-    for (off = 0; off < fa->fa_size; off += sizeof(rd)) {
-         rc = flash_area_read(fa, off, rd, sizeof(rd));
-         TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
-
-         rc = memcmp(wd, rd, sizeof(rd));
-         TEST_ASSERT_FATAL(rc == 0, "area not erased");
-    }
-}
+TEST_CASE_DECL(flash_map_test_case_1)
+TEST_CASE_DECL(flash_map_test_case_2)
 
 TEST_SUITE(flash_map_test_suite)
 {
@@ -157,16 +39,14 @@ TEST_SUITE(flash_map_test_suite)
 }
 
 #if MYNEWT_VAL(SELFTEST)
-
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     flash_map_test_suite();
 
     return tu_any_failed;
 }
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/flash_map/test/src/flash_map_test.h
----------------------------------------------------------------------
diff --git a/sys/flash_map/test/src/flash_map_test.h b/sys/flash_map/test/src/flash_map_test.h
new file mode 100644
index 0000000..c1d6e8d
--- /dev/null
+++ b/sys/flash_map/test/src/flash_map_test.h
@@ -0,0 +1,44 @@
+/**
+ * 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 _FLASH_MAP_TEST_H
+#define _FLASH_MAP_TEST_H
+#include <stdio.h>
+#include <string.h>
+
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "sysflash/sysflash.h"
+#include "os/os.h"
+#include "testutil/testutil.h"
+#include "flash_map/flash_map.h"
+#include "hal/hal_bsp.h"
+#include "hal/hal_flash.h"
+#include "hal/hal_flash_int.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+/* This space intentionally left blank */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FLASH_MAP_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/flash_map/test/src/testcases/flash_map_test_case_1.c
----------------------------------------------------------------------
diff --git a/sys/flash_map/test/src/testcases/flash_map_test_case_1.c b/sys/flash_map/test/src/testcases/flash_map_test_case_1.c
new file mode 100644
index 0000000..f46ba1e
--- /dev/null
+++ b/sys/flash_map/test/src/testcases/flash_map_test_case_1.c
@@ -0,0 +1,63 @@
+/**
+ * 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 "flash_map_test.h"
+
+/*
+ * Test flash_area_to_sectors()
+ */
+TEST_CASE(flash_map_test_case_1)
+{
+    const struct flash_area *fa;
+    int areas_checked = 0;
+    int i, j, rc;
+    const struct hal_flash *hf;
+    struct flash_area my_secs[32];
+    int my_sec_cnt;
+    uint32_t end;
+
+    sysinit();
+
+    for (i = 0; i < 8; i++) {
+        rc = flash_area_open(i, &fa);
+        if (rc) {
+            continue;
+        }
+
+        hf = bsp_flash_dev(fa->fa_device_id);
+        TEST_ASSERT_FATAL(hf != NULL, "bsp_flash_dev");
+
+        rc = flash_area_to_sectors(i, &my_sec_cnt, my_secs);
+        TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed");
+
+        end = fa->fa_off;
+        for (j = 0; j < my_sec_cnt; j++) {
+            TEST_ASSERT_FATAL(end == my_secs[j].fa_off, "Non contiguous area");
+            TEST_ASSERT_FATAL(my_secs[j].fa_device_id == fa->fa_device_id,
+              "Sectors not in same flash?");
+            end = my_secs[j].fa_off + my_secs[j].fa_size;
+        }
+        if (my_sec_cnt) {
+            areas_checked++;
+            TEST_ASSERT_FATAL(my_secs[my_sec_cnt - 1].fa_off +
+              my_secs[my_sec_cnt - 1].fa_size == fa->fa_off + fa->fa_size,
+              "Last sector not in the end");
+        }
+    }
+    TEST_ASSERT_FATAL(areas_checked != 0, "No flash map areas to check!");
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/flash_map/test/src/testcases/flash_map_test_case_2.c
----------------------------------------------------------------------
diff --git a/sys/flash_map/test/src/testcases/flash_map_test_case_2.c b/sys/flash_map/test/src/testcases/flash_map_test_case_2.c
new file mode 100644
index 0000000..559f56d
--- /dev/null
+++ b/sys/flash_map/test/src/testcases/flash_map_test_case_2.c
@@ -0,0 +1,96 @@
+/**
+ * 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 "flash_map_test.h"
+
+/*
+ * Test flash_erase
+ */
+TEST_CASE(flash_map_test_case_2)
+{
+    const struct flash_area *fa;
+    struct flash_area secs[32];
+    int sec_cnt;
+    int i;
+    int rc;
+    uint32_t off;
+    uint8_t wd[256];
+    uint8_t rd[256];
+
+    sysinit();
+
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fa);
+    TEST_ASSERT_FATAL(rc == 0, "flash_area_open() fail");
+
+    rc = flash_area_to_sectors(FLASH_AREA_IMAGE_0, &sec_cnt, secs);
+    TEST_ASSERT_FATAL(rc == 0, "flash_area_to_sectors failed");
+
+    /*
+     * First erase the area so it's ready for use.
+     */
+    for (i = 0; i < sec_cnt; i++) {
+        rc = hal_flash_erase_sector(secs[i].fa_device_id, secs[i].fa_off);
+        TEST_ASSERT_FATAL(rc == 0, "hal_flash_erase_sector() failed");
+    }
+    TEST_ASSERT_FATAL(rc == 0, "read data != write data");
+
+    memset(wd, 0xa5, sizeof(wd));
+
+    /* write stuff to beginning of every sector */
+    off = 0;
+    for (i = 0; i < sec_cnt; i++) {
+        rc = flash_area_write(fa, off, wd, sizeof(wd));
+        TEST_ASSERT_FATAL(rc == 0, "flash_area_write() fail");
+
+        /* read it back via hal_flash_Read() */
+        rc = hal_flash_read(fa->fa_device_id, fa->fa_off + off, rd, sizeof(rd));
+        TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
+
+        rc = memcmp(wd, rd, sizeof(wd));
+        TEST_ASSERT_FATAL(rc == 0, "read data != write data");
+
+        /* write stuff to end of area */
+        rc = hal_flash_write(fa->fa_device_id,
+          fa->fa_off + off + secs[i].fa_size - sizeof(wd), wd, sizeof(wd));
+        TEST_ASSERT_FATAL(rc == 0, "hal_flash_write() fail");
+
+        /* and read it back */
+        memset(rd, 0, sizeof(rd));
+        rc = flash_area_read(fa, off + secs[i].fa_size - sizeof(rd),
+          rd, sizeof(rd));
+        TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
+
+        rc = memcmp(wd, rd, sizeof(rd));
+        TEST_ASSERT_FATAL(rc == 0, "read data != write data");
+
+        off += secs[i].fa_size;
+    }
+    /* erase it */
+    rc = flash_area_erase(fa, 0, fa->fa_size);
+    TEST_ASSERT_FATAL(rc == 0, "read data != write data");
+
+    /* should read back ff all throughout*/
+    memset(wd, 0xff, sizeof(wd));
+    for (off = 0; off < fa->fa_size; off += sizeof(rd)) {
+         rc = flash_area_read(fa, off, rd, sizeof(rd));
+         TEST_ASSERT_FATAL(rc == 0, "hal_flash_read() fail");
+
+         rc = memcmp(wd, rd, sizeof(rd));
+         TEST_ASSERT_FATAL(rc == 0, "area not erased");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/log_test.c
----------------------------------------------------------------------
diff --git a/sys/log/test/src/log_test.c b/sys/log/test/src/log_test.c
index b0f71ad..ff411e8 100644
--- a/sys/log/test/src/log_test.c
+++ b/sys/log/test/src/log_test.c
@@ -24,7 +24,7 @@
 #include "fcb/fcb.h"
 #include "log/log.h"
 
-static struct flash_area fcb_areas[] = {
+struct flash_area fcb_areas[] = {
     [0] = {
         .fa_off = 0x00000000,
         .fa_size = 16 * 1024
@@ -34,52 +34,18 @@ static struct flash_area fcb_areas[] = {
         .fa_size = 16 * 1024
     }
 };
-static struct fcb log_fcb;
-static struct log my_log;
+struct fcb log_fcb;
+struct log my_log;
 
-static char *str_logs[] = {
+char *str_logs[] = {
     "testdata",
     "1testdata2",
     NULL
 };
-static int str_idx = 0;
-static int str_max_idx = 0;
+int str_idx = 0;
+int str_max_idx = 0;
 
-TEST_CASE(log_setup_fcb)
-{
-    int rc;
-    int i;
-
-    log_fcb.f_sectors = fcb_areas;
-    log_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
-    log_fcb.f_magic = 0x7EADBADF;
-    log_fcb.f_version = 0;
-
-    for (i = 0; i < log_fcb.f_sector_cnt; i++) {
-        rc = flash_area_erase(&fcb_areas[i], 0, fcb_areas[i].fa_size);
-        TEST_ASSERT(rc == 0);
-    }
-    rc = fcb_init(&log_fcb);
-    TEST_ASSERT(rc == 0);
-
-    log_register("log", &my_log, &log_fcb_handler, &log_fcb);
-}
-
-TEST_CASE(log_append_fcb)
-{
-    char *str;
-
-    while (1) {
-        str = str_logs[str_max_idx];
-        if (!str) {
-            break;
-        }
-        log_printf(&my_log, 0, 0, str, strlen(str));
-        str_max_idx++;
-    }
-}
-
-static int
+int
 log_test_walk1(struct log *log, void *arg, void *dptr, uint16_t len)
 {
     int rc;
@@ -107,17 +73,7 @@ log_test_walk1(struct log *log, void *arg, void *dptr, uint16_t len)
     return 0;
 }
 
-TEST_CASE(log_walk_fcb)
-{
-    int rc;
-
-    str_idx = 0;
-
-    rc = log_walk(&my_log, log_test_walk1, NULL);
-    TEST_ASSERT(rc == 0);
-}
-
-static int
+int
 log_test_walk2(struct log *log, void *arg, void *dptr, uint16_t len)
 {
     TEST_ASSERT(0);
@@ -135,6 +91,11 @@ TEST_CASE(log_flush_fcb)
     TEST_ASSERT(rc == 0);
 }
 
+TEST_CASE_DECL(log_setup_fcb)
+TEST_CASE_DECL(log_append_fcb)
+TEST_CASE_DECL(log_walk_fcb)
+TEST_CASE_DECL(log_flush_fcb)
+
 TEST_SUITE(log_test_all)
 {
     log_setup_fcb();
@@ -148,7 +109,7 @@ TEST_SUITE(log_test_all)
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     log_init();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/log_test.h
----------------------------------------------------------------------
diff --git a/sys/log/test/src/log_test.h b/sys/log/test/src/log_test.h
new file mode 100644
index 0000000..36e5bfe
--- /dev/null
+++ b/sys/log/test/src/log_test.h
@@ -0,0 +1,54 @@
+/**
+ * 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 _LOG_TEST_H
+#define _LOG_TEST_H
+#include <string.h>
+
+#include "syscfg/syscfg.h"
+#include "os/os.h"
+#include "testutil/testutil.h"
+#include "fcb/fcb.h"
+#include "log/log.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+#define FCB_FLASH_AREAS 2
+
+extern struct flash_area fcb_areas[FCB_FLASH_AREAS];
+
+extern struct fcb log_fcb;
+extern struct log my_log;
+
+#define FCB_STR_LOGS_CNT 3
+
+extern char *str_logs[FCB_STR_LOGS_CNT];
+
+extern int str_idx;
+extern int str_max_idx;
+
+int log_test_walk1(struct log *log, void *arg, void *dptr, uint16_t len);
+int log_test_walk2(struct log *log, void *arg, void *dptr, uint16_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LOG_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/testcases/log_append_fcb.c
----------------------------------------------------------------------
diff --git a/sys/log/test/src/testcases/log_append_fcb.c b/sys/log/test/src/testcases/log_append_fcb.c
new file mode 100644
index 0000000..9db6371
--- /dev/null
+++ b/sys/log/test/src/testcases/log_append_fcb.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 "log_test.h"
+
+TEST_CASE(log_append_fcb)
+{
+    char *str;
+
+    while (1) {
+        str = str_logs[str_max_idx];
+        if (!str) {
+            break;
+        }
+        log_printf(&my_log, 0, 0, str, strlen(str));
+        str_max_idx++;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/testcases/log_setup_fcb.c
----------------------------------------------------------------------
diff --git a/sys/log/test/src/testcases/log_setup_fcb.c b/sys/log/test/src/testcases/log_setup_fcb.c
new file mode 100644
index 0000000..fde174d
--- /dev/null
+++ b/sys/log/test/src/testcases/log_setup_fcb.c
@@ -0,0 +1,39 @@
+/**
+ * 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 "log_test.h"
+
+TEST_CASE(log_setup_fcb)
+{
+    int rc;
+    int i;
+
+    log_fcb.f_sectors = fcb_areas;
+    log_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
+    log_fcb.f_magic = 0x7EADBADF;
+    log_fcb.f_version = 0;
+
+    for (i = 0; i < log_fcb.f_sector_cnt; i++) {
+        rc = flash_area_erase(&fcb_areas[i], 0, fcb_areas[i].fa_size);
+        TEST_ASSERT(rc == 0);
+    }
+    rc = fcb_init(&log_fcb);
+    TEST_ASSERT(rc == 0);
+
+    log_register("log", &my_log, &log_fcb_handler, &log_fcb);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/log/test/src/testcases/log_walk_fcb.c
----------------------------------------------------------------------
diff --git a/sys/log/test/src/testcases/log_walk_fcb.c b/sys/log/test/src/testcases/log_walk_fcb.c
new file mode 100644
index 0000000..d3288b6
--- /dev/null
+++ b/sys/log/test/src/testcases/log_walk_fcb.c
@@ -0,0 +1,29 @@
+/**
+ * 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 "log_test.h"
+
+TEST_CASE(log_walk_fcb)
+{
+    int rc;
+
+    str_idx = 0;
+
+    rc = log_walk(&my_log, log_test_walk1, NULL);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/include/testutil/testutil.h
----------------------------------------------------------------------
diff --git a/test/testutil/include/testutil/testutil.h b/test/testutil/include/testutil/testutil.h
index 1579b84..13df0ab 100644
--- a/test/testutil/include/testutil/testutil.h
+++ b/test/testutil/include/testutil/testutil.h
@@ -29,63 +29,142 @@
 extern "C" {
 #endif
 
-/*****************************************************************************
- * Public declarations                                                       *
- *****************************************************************************/
+/*
+ * General execution flow of test suites and cases (more to come XXX)
+ *
+ * TEST_SUITE
+ *      tu_suite_init
+ *          tu_suite_pre_test
+ *              tu_case_init
+ *              tu_case_pre_test
+ *                  TEST_CASE
+ *              tu_case_post_test
+ *              tu_case_pass/tu_case_fail
+ *              tu_case_complete
+ *          tu_suite_post_test
+ *      tu_suite_complete
+ */
 
-typedef void tu_case_init_fn_t(void *arg);
 typedef void tu_case_report_fn_t(char *msg, int msg_len, void *arg);
-typedef void tu_suite_init_fn_t(void *arg);
-typedef void tu_restart_fn_t(void *arg);
-
-struct tu_config {
-    int tc_print_results;
-    int tc_system_assert;
+typedef void tu_suite_restart_fn_t(void *arg);
 
-    tu_case_init_fn_t *tc_case_init_cb;
-    void *tc_case_init_arg;
+typedef void tu_pre_test_fn_t(void *arg);
+typedef void tu_post_test_fn_t(void *arg);
 
-    tu_case_report_fn_t *tc_case_fail_cb;
-    void *tc_case_fail_arg;
+typedef void tu_init_test_fn_t(void *arg);
+typedef void tu_pre_test_fn_t(void *arg);
+typedef void tu_post_test_fn_t(void *arg);
 
-    tu_case_report_fn_t *tc_case_pass_cb;
-    void *tc_case_pass_arg;
+/*
+ * Private declarations - Test Suite configuration
+ */
+void tu_suite_set_init_cb(tu_init_test_fn_t *cb, void *cb_arg);
+void tu_suite_set_pre_test_cb(tu_pre_test_fn_t *cb, void *cb_arg);
+void tu_suite_set_post_test_cb(tu_post_test_fn_t *cb, void *cb_arg);
+void tu_suite_set_pass_cb(tu_case_report_fn_t *cb, void *cb_arg);
+void tu_suite_set_fail_cb(tu_case_report_fn_t *cb, void *cb_arg);
 
-    tu_suite_init_fn_t *tc_suite_init_cb;
-    void *tc_suite_init_arg;
+void tu_suite_init(const char *name);
+void tu_suite_pre_test(void);
+void tu_suite_post_test(void);
+void tu_suite_complete(void);
 
-    tu_restart_fn_t *tc_restart_cb;
-    void *tc_restart_arg;
+struct ts_config {
+    int ts_print_results;
+    int ts_system_assert;
+
+    /*
+     * Called prior to the first test in the suite
+     */
+    tu_init_test_fn_t *ts_suite_init_cb;
+    void *ts_suite_init_arg;
+
+    /*
+     * Called before every test in the suite
+     */
+    tu_pre_test_fn_t *ts_case_pre_test_cb;
+    void *ts_case_pre_arg;
+
+    /*
+     * Called after every test in the suite
+     */
+    tu_post_test_fn_t *ts_case_post_test_cb;
+    void *ts_case_post_arg;
+
+    /*
+     * Called after test returns success
+     */
+    tu_case_report_fn_t *ts_case_pass_cb;
+    void *ts_case_pass_arg;
+
+    /*
+     * Called after test fails (primarily thoough a failed test assert
+     */
+    tu_case_report_fn_t *ts_case_fail_cb;
+    void *ts_case_fail_arg;
+
+    /*
+     * restart after running the test suite
+     */
+    tu_suite_restart_fn_t *ts_restart_cb;
+    void *ts_restart_arg;
 };
 
-extern struct tu_config tu_config;
-extern const char *tu_suite_name;
-extern const char *tu_case_name;
-extern int tu_first_idx;
-
-typedef void tu_post_test_fn_t(void *arg);
-
-void tu_suite_set_post_test_cb(tu_post_test_fn_t *cb, void *cb_arg);
 int tu_parse_args(int argc, char **argv);
 int tu_init(void);
 void tu_restart(void);
 
-/*****************************************************************************
- * Private declarations                                                      *
- *****************************************************************************/
+/*
+ * Public declarations - test case configuration
+ */
 
-void tu_suite_complete(void);
-void tu_suite_init(const char *name);
+void tu_case_set_init_cb(tu_init_test_fn_t *cb, void *cb_arg);
+void tu_case_set_pre_cb(tu_pre_test_fn_t *cb, void *cb_arg);
+void tu_case_set_post_cb(tu_post_test_fn_t *cb, void *cb_arg);
+
+struct tc_config {
+    /*
+     * Called to initialize the test case
+     */
+    tu_init_test_fn_t *tc_case_init_cb;
+    void *tc_case_init_arg;
+
+    /*
+     * Called prior to the test case start
+     */
+    tu_pre_test_fn_t *tc_case_pre_test_cb;
+    void *tc_case_pre_arg;
+
+    /*
+     * Called after the test case completes
+     */
+    tu_post_test_fn_t *tc_case_post_test_cb;
+    void *tc_case_post_arg;
+};
 
 void tu_case_init(const char *name);
 void tu_case_complete(void);
+void tu_case_pass(void);
+void tu_case_fail(void);
 void tu_case_fail_assert(int fatal, const char *file, int line,
                          const char *expr, const char *format, ...);
 void tu_case_write_pass_auto(void);
 void tu_case_pass_manual(const char *file, int line,
                          const char *format, ...);
+void tu_case_pre_test(void);
 void tu_case_post_test(void);
 
+void tu_case_complete(void);
+
+extern struct tc_config tc_config;
+extern struct tc_config *tc_current_config;
+extern struct ts_config ts_config;
+extern struct ts_config *ts_current_config;
+
+extern const char *tu_suite_name;
+extern const char *tu_case_name;
+extern int tu_first_idx;
+
 extern int tu_any_failed;
 extern int tu_suite_failed;
 extern int tu_case_reported;
@@ -93,48 +172,57 @@ extern int tu_case_failed;
 extern int tu_case_idx;
 extern jmp_buf tu_case_jb;
 
-#define TEST_SUITE(suite_name)                                                \
-    static void TEST_SUITE_##suite_name(void);                                \
-                                                                              \
-    int                                                                       \
-    suite_name(void)                                                          \
-    {                                                                         \
-        tu_suite_init(#suite_name);                                           \
-        TEST_SUITE_##suite_name();                                            \
-        tu_suite_complete();                                                  \
-                                                                              \
-        return tu_suite_failed;                                               \
-    }                                                                         \
-                                                                              \
-    static void                                                               \
+#define TEST_SUITE(suite_name)                               \
+static void                                                  \
+TEST_SUITE_##suite_name(void);                               \
+                                                             \
+    int                                                      \
+    suite_name(void)                                         \
+    {                                                        \
+        tu_suite_init(#suite_name);                          \
+        TEST_SUITE_##suite_name();                           \
+        tu_suite_complete();                                 \
+                                                             \
+        return tu_suite_failed;                              \
+    }                                                        \
+                                                             \
+    static void                                              \
     TEST_SUITE_##suite_name(void)
 
-/* for creating multiple files with test cases all belonging to the same
- * suite */
-#define TEST_CASE_DECL(case_name)  int case_name(void);
-
-#define TEST_CASE(case_name)                                                  \
-    static void TEST_CASE_##case_name(void);                                  \
-                                                                              \
-    int                                                                       \
-    case_name(void)                                                           \
-    {                                                                         \
-        if (tu_case_idx >= tu_first_idx) {                                    \
-            tu_case_init(#case_name);                                         \
-                                                                              \
-            if (setjmp(tu_case_jb) == 0) {                                    \
-                TEST_CASE_##case_name();                                      \
-                tu_case_post_test();                                          \
-                tu_case_write_pass_auto();                                    \
-            }                                                                 \
-        }                                                                     \
-                                                                              \
-        tu_case_complete();                                                   \
-                                                                              \
-        return tu_case_failed;                                                \
-    }                                                                         \
-                                                                              \
-    static void                                                               \
+/*
+ * for creating multiple files with test cases
+ * all belonging to the same suite
+ */
+#define TEST_CASE_DECL(case_name)                            \
+    int case_name(void);
+
+/*
+ * Unit test definition.
+ */
+#define TEST_CASE(case_name)                                  \
+    static void TEST_CASE_##case_name(void);                  \
+                                                              \
+    int                                                       \
+    case_name(void)                                           \
+    {                                                         \
+        tu_suite_pre_test();                                  \
+        if (tu_case_idx >= tu_first_idx) {                    \
+            tu_case_init(#case_name);                         \
+                                                              \
+            tu_case_pre_test();                               \
+            if (setjmp(tu_case_jb) == 0) {                    \
+                TEST_CASE_##case_name();                      \
+                tu_case_post_test();                          \
+                tu_case_pass();                               \
+            }                                                 \
+            tu_case_complete();                               \
+        }                                                     \
+        tu_suite_post_test();                                 \
+                                                              \
+        return tu_case_failed;                                \
+    }                                                         \
+                                                              \
+    static void                                               \
     TEST_CASE_##case_name(void)
 
 #define FIRST_AUX(first, ...) first
@@ -152,21 +240,22 @@ extern jmp_buf tu_case_jb;
 #define XSTR(s) STR(s)
 #define STR(s) #s
 
-#define TEST_ASSERT_FULL(fatal, expr, ...) do                                 \
-{                                                                             \
-    if (!(expr)) {                                                            \
-        tu_case_fail_assert((fatal), __FILE__, __LINE__, XSTR(expr),          \
-                            __VA_ARGS__);                                     \
-    }                                                                         \
+#define TEST_ASSERT_FULL(fatal, expr, ...) do                 \
+{                                                             \
+    if (!(expr)) {                                            \
+        tu_case_fail_assert((fatal), __FILE__,                \
+                            __LINE__, XSTR(expr),             \
+                            __VA_ARGS__);                     \
+    }                                                         \
 } while (0)
 
-#define TEST_ASSERT(...)                                                      \
+#define TEST_ASSERT(...)                                      \
     TEST_ASSERT_FULL(0, FIRST(__VA_ARGS__), REST_OR_0(__VA_ARGS__))
 
-#define TEST_ASSERT_FATAL(...)                                                \
+#define TEST_ASSERT_FATAL(...)                                \
     TEST_ASSERT_FULL(1, FIRST(__VA_ARGS__), REST_OR_0(__VA_ARGS__))
 
-#define TEST_PASS(...)                                                        \
+#define TEST_PASS(...)                                        \
     tu_case_pass_manual(__FILE__, __LINE__, __VA_ARGS__);
 
 #if MYNEWT_VAL(TEST)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/arch/cortex_m4/testutil_arch_arm.c
----------------------------------------------------------------------
diff --git a/test/testutil/src/arch/cortex_m4/testutil_arch_arm.c b/test/testutil/src/arch/cortex_m4/testutil_arch_arm.c
deleted file mode 100644
index 52ace63..0000000
--- a/test/testutil/src/arch/cortex_m4/testutil_arch_arm.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * 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 "hal/hal_system.h"
-#include "testutil_priv.h"
-
-void
-tu_arch_restart(void)
-{
-    system_reset();
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/arch/sim/testutil_arch_sim.c
----------------------------------------------------------------------
diff --git a/test/testutil/src/arch/sim/testutil_arch_sim.c b/test/testutil/src/arch/sim/testutil_arch_sim.c
deleted file mode 100644
index 2d90501..0000000
--- a/test/testutil/src/arch/sim/testutil_arch_sim.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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/os_arch.h"
-#include "os/os_test.h"
-#include "testutil_priv.h"
-
-void
-tu_arch_restart(void)
-{
-    os_arch_os_stop();
-    tu_case_abort();
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/test/testutil/src/arch/sim/tu_args.c
----------------------------------------------------------------------
diff --git a/test/testutil/src/arch/sim/tu_args.c b/test/testutil/src/arch/sim/tu_args.c
deleted file mode 100644
index 75a2900..0000000
--- a/test/testutil/src/arch/sim/tu_args.c
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <errno.h>
-#include <unistd.h>
-
-#include "testutil/testutil.h"
-
-int
-tu_parse_args(int argc, char **argv)
-{
-    int ch;
-
-    while ((ch = getopt(argc, argv, "s")) != -1) {
-        switch (ch) {
-        case 's':
-            tu_config.tc_system_assert = 1;
-            break;
-
-        default:
-            return EINVAL;
-        }
-    }
-
-    return 0;
-}



[16/16] incubator-mynewt-core git commit: Fix some minor unit test merge issues.

Posted by cc...@apache.org.
Fix some minor unit test merge issues.


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

Branch: refs/heads/develop
Commit: 7aa94c51a3749dda2a66e6e3f7a39546a1f4ee9c
Parents: 914236c
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Oct 17 17:00:19 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Oct 17 17:00:19 2016 -0700

----------------------------------------------------------------------
 boot/bootutil/test/src/boot_test.h              |   8 +-
 boot/bootutil/test/src/boot_test_utils.c        | 143 ++++++++++++++++++-
 .../test/src/testcases/boot_test_no_hash.c      |   2 +-
 .../test/src/testcases/boot_test_nv_bs_10.c     |   2 +-
 .../test/src/testcases/boot_test_nv_bs_11.c     |   2 +-
 .../src/testcases/boot_test_nv_bs_11_2areas.c   |   7 +-
 .../test/src/testcases/boot_test_nv_ns_01.c     |   4 +-
 .../test/src/testcases/boot_test_revert.c       |   7 +-
 .../src/testcases/boot_test_revert_continue.c   |   8 +-
 .../test/src/testcases/boot_test_vb_ns_11.c     |   4 +-
 .../test/src/testcases/boot_test_vm_ns_01.c     |   2 +-
 .../src/testcases/boot_test_vm_ns_11_2areas.c   |   2 +-
 .../test/src/testcases/boot_test_vm_ns_11_b.c   |   2 +-
 net/ip/mn_socket/test/src/mn_sock_test.c        |   2 +
 14 files changed, 165 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/boot_test.h
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test.h b/boot/bootutil/test/src/boot_test.h
index 25e2da2..e883c8f 100644
--- a/boot/bootutil/test/src/boot_test.h
+++ b/boot/bootutil/test/src/boot_test.h
@@ -31,15 +31,14 @@
 #include "hal/hal_flash.h"
 #include "flash_map/flash_map.h"
 #include "bootutil/image.h"
-#include "bootutil/loader.h"
-#include "bootutil/bootutil_misc.h"
-#include "../../src/bootutil_priv.h"
+#include "bootutil/bootutil.h"
+#include "bootutil_priv.h"
 #include "testutil/testutil.h"
 
 #include "mbedtls/sha256.h"
 
 #ifdef __cplusplus
-#extern "C" {
+extern "C" {
 #endif
 
 #define BOOT_TEST_HEADER_SIZE       0x200
@@ -66,6 +65,7 @@ void boot_test_util_swap_areas(int area_idx1, int area_idx2);
 void boot_test_util_write_image(const struct image_header *hdr,
                                        int slot);
 void boot_test_util_write_hash(const struct image_header *hdr, int slot);
+void boot_test_util_mark_revert(void);
 void boot_test_util_verify_area(const struct flash_area *area_desc,
                                        const struct image_header *hdr,
                                        uint32_t image_addr, int img_msb);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/boot_test_utils.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test_utils.c b/boot/bootutil/test/src/boot_test_utils.c
index 160e81d..3040604 100644
--- a/boot/bootutil/test/src/boot_test_utils.c
+++ b/boot/bootutil/test/src/boot_test_utils.c
@@ -42,6 +42,8 @@ struct boot_test_img_addrs boot_test_img_addrs[] = {
     { 0, 0x80000 },
 };
 
+#define BOOT_TEST_AREA_IDX_SCRATCH 6
+
 uint8_t
 boot_test_util_byte_at(int img_msb, uint32_t image_offset)
 {
@@ -73,7 +75,6 @@ boot_test_util_init_flash(void)
     }
 }
 
-
 void
 boot_test_util_copy_area(int from_area_idx, int to_area_idx)
 {
@@ -106,12 +107,38 @@ boot_test_util_copy_area(int from_area_idx, int to_area_idx)
     free(buf);
 }
 
+static uint32_t
+boot_test_util_area_write_size(int dst_idx, uint32_t off, uint32_t size)
+{
+    const struct flash_area *desc;
+    int64_t diff;
+    uint32_t trailer_start;
+
+    if (dst_idx != BOOT_TEST_AREA_IDX_SCRATCH - 1) {
+        return size;
+    }
+
+    /* Don't include trailer in copy to second slot. */
+    desc = boot_test_area_descs + dst_idx;
+    trailer_start = desc->fa_size - boot_status_sz(1);
+    diff = off + size - trailer_start;
+    if (diff > 0) {
+        if (diff > size) {
+            size = 0;
+        } else {
+            size -= diff;
+        }
+    }
+
+    return size;
+}
 
 void
 boot_test_util_swap_areas(int area_idx1, int area_idx2)
 {
     const struct flash_area *area_desc1;
     const struct flash_area *area_desc2;
+    uint32_t size;
     void *buf1;
     void *buf2;
     int rc;
@@ -139,17 +166,18 @@ boot_test_util_swap_areas(int area_idx1, int area_idx2)
     rc = flash_area_erase(area_desc2, 0, area_desc2->fa_size);
     TEST_ASSERT(rc == 0);
 
-    rc = flash_area_write(area_desc1, 0, buf2, area_desc1->fa_size);
+    size = boot_test_util_area_write_size(area_idx1, 0, area_desc1->fa_size);
+    rc = flash_area_write(area_desc1, 0, buf2, size);
     TEST_ASSERT(rc == 0);
 
-    rc = flash_area_write(area_desc2, 0, buf1, area_desc2->fa_size);
+    size = boot_test_util_area_write_size(area_idx2, 0, area_desc2->fa_size);
+    rc = flash_area_write(area_desc2, 0, buf1, size);
     TEST_ASSERT(rc == 0);
 
     free(buf1);
     free(buf2);
 }
 
-
 void
 boot_test_util_write_image(const struct image_header *hdr, int slot)
 {
@@ -235,6 +263,37 @@ boot_test_util_write_hash(const struct image_header *hdr, int slot)
 }
 
 void
+boot_test_util_write_bit(int flash_area_id, struct boot_img_trailer *bit)
+{
+    const struct flash_area *fap;
+    int rc;
+
+    /* XXX: This function only works by chance.  It requires that the boot
+     * loader have have been run once already so that its global state has been
+     * populated.
+     */
+
+    rc = flash_area_open(flash_area_id, &fap);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    rc = flash_area_write(fap, fap->fa_size - sizeof *bit, bit, sizeof *bit);
+    TEST_ASSERT_FATAL(rc == 0);
+}
+
+void
+boot_test_util_mark_revert(void)
+{
+    struct boot_img_trailer bit_slot0 = {
+        .bit_copy_start = BOOT_IMG_MAGIC,
+        .bit_copy_done = 0x01,
+        .bit_img_ok = 0xff,
+        ._pad = 0xffff,
+    };
+
+    boot_test_util_write_bit(FLASH_AREA_IMAGE_0, &bit_slot0);
+}
+
+void
 boot_test_util_verify_area(const struct flash_area *area_desc,
                            const struct image_header *hdr,
                            uint32_t image_addr, int img_msb)
@@ -322,7 +381,7 @@ boot_test_util_verify_status_clear(void)
     rc = flash_area_read(fap, fap->fa_size - sizeof(bit), &bit, sizeof(bit));
     TEST_ASSERT(rc == 0);
 
-    TEST_ASSERT(bit.bit_copy_start != BOOT_MAGIC_SWAP_TEMP ||
+    TEST_ASSERT(bit.bit_copy_start != BOOT_IMG_MAGIC ||
       bit.bit_copy_done != 0xff);
 }
 
@@ -359,3 +418,77 @@ boot_test_util_verify_flash(const struct image_header *hdr0, int orig_slot_0,
         area_idx++;
     }
 }
+
+void
+boot_test_util_verify_all(const struct boot_req *req, int expected_swap_type,
+                          const struct image_header *hdr0,
+                          const struct image_header *hdr1)
+{
+    const struct image_header *slot0hdr;
+    const struct image_header *slot1hdr;
+    struct boot_rsp rsp;
+    int orig_slot_0;
+    int orig_slot_1;
+    int num_swaps;
+    int rc;
+    int i;
+
+    TEST_ASSERT_FATAL(req != NULL);
+    TEST_ASSERT_FATAL(hdr0 != NULL || hdr1 != NULL);
+
+    num_swaps = 0;
+    for (i = 0; i < 3; i++) {
+        rc = boot_go(req, &rsp);
+        TEST_ASSERT_FATAL(rc == 0);
+
+        if (expected_swap_type != BOOT_SWAP_TYPE_NONE) {
+            num_swaps++;
+        }
+
+        if (num_swaps % 2 == 0) {
+            if (hdr0 != NULL) {
+                slot0hdr = hdr0;
+                slot1hdr = hdr1;
+            } else {
+                slot0hdr = hdr1;
+                slot1hdr = hdr0;
+            }
+            orig_slot_0 = 0;
+            orig_slot_1 = 1;
+        } else {
+            if (hdr1 != NULL) {
+                slot0hdr = hdr1;
+                slot1hdr = hdr0;
+            } else {
+                slot0hdr = hdr0;
+                slot1hdr = hdr1;
+            }
+            orig_slot_0 = 1;
+            orig_slot_1 = 0;
+        }
+
+        TEST_ASSERT(memcmp(rsp.br_hdr, slot0hdr, sizeof *slot0hdr) == 0);
+        TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
+        TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
+
+        boot_test_util_verify_flash(slot0hdr, orig_slot_0,
+                                    slot1hdr, orig_slot_1);
+        boot_test_util_verify_status_clear();
+
+        if (expected_swap_type != BOOT_SWAP_TYPE_NONE) {
+            switch (expected_swap_type) {
+            case BOOT_SWAP_TYPE_TEST:
+                expected_swap_type = BOOT_SWAP_TYPE_REVERT;
+                break;
+
+            case BOOT_SWAP_TYPE_REVERT:
+                expected_swap_type = BOOT_SWAP_TYPE_NONE;
+                break;
+
+            default:
+                TEST_ASSERT_FATAL(0);
+                break;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_no_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_no_hash.c b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
index 339753e..0ce1a54 100644
--- a/boot/bootutil/test/src/testcases/boot_test_no_hash.c
+++ b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
@@ -53,7 +53,7 @@ TEST_CASE(boot_test_no_hash)
     boot_test_util_write_image(&hdr1, 1);
 
     rc = boot_set_pending(1);
-    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(rc == 0);
 
     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c b/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
index cced9fb..bb7bc9c 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
@@ -41,7 +41,7 @@ TEST_CASE(boot_test_nv_bs_10)
     boot_test_util_write_image(&hdr, 0);
     boot_test_util_write_hash(&hdr, 0);
     boot_test_util_swap_areas(boot_test_slot_areas[1],
-      BOOT_TEST_AREA_IDX_SCRATCH);
+                              BOOT_TEST_AREA_IDX_SCRATCH);
 
     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
index 3312ec4..86146b1 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
@@ -65,5 +65,5 @@ TEST_CASE(boot_test_nv_bs_11)
     rc = boot_write_status(&status);
     TEST_ASSERT(rc == 0);
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
index 11a8a6f..e427f36 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
@@ -54,12 +54,11 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
     boot_test_util_write_hash(&hdr0, 0);
     boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr1, 1);
-
-    boot_test_util_swap_areas(2, 5);
-
     rc = boot_set_pending(1);
     TEST_ASSERT_FATAL(rc == 0);
 
+    boot_test_util_swap_areas(2, 5);
+
     status.idx = 1;
     status.elem_sz = 1;
     status.state = 0;
@@ -67,5 +66,5 @@ TEST_CASE(boot_test_nv_bs_11_2areas)
     rc = boot_write_status(&status);
     TEST_ASSERT_FATAL(rc == 0);
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
index c887eca..00a1967 100644
--- a/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
@@ -41,5 +41,7 @@ TEST_CASE(boot_test_nv_ns_01)
     boot_test_util_write_image(&hdr, 1);
     boot_test_util_write_hash(&hdr, 1);
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
+    boot_set_pending(1);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, NULL, &hdr);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_revert.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_revert.c b/boot/bootutil/test/src/testcases/boot_test_revert.c
index d49d42d..f564f7c 100644
--- a/boot/bootutil/test/src/testcases/boot_test_revert.c
+++ b/boot/bootutil/test/src/testcases/boot_test_revert.c
@@ -20,8 +20,7 @@
 
 TEST_CASE(boot_test_revert)
 {
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
+    struct image_header hdr0 = { .ih_magic = IMAGE_MAGIC,
         .ih_tlv_size = 4 + 32,
         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
         .ih_img_size = 5 * 1024,
@@ -53,7 +52,7 @@ TEST_CASE(boot_test_revert)
     boot_test_util_write_hash(&hdr1, 1);
 
     /* Indicate that the image in slot 0 is being tested. */
-    boot_set_copy_done();
+    boot_test_util_mark_revert();
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, &hdr0, &hdr1);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_revert_continue.c b/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
index ec4f56c..4abd87f 100644
--- a/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
+++ b/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
@@ -55,10 +55,10 @@ TEST_CASE(boot_test_revert_continue)
     boot_test_util_write_image(&hdr1, 1);
     boot_test_util_write_hash(&hdr1, 1);
 
-    boot_test_util_swap_areas(2, 5);
-
     /* Indicate that the image in slot 0 is being tested. */
-    boot_set_copy_done();
+    boot_test_util_mark_revert();
+
+    boot_test_util_swap_areas(2, 5);
 
     status.idx = 1;
     status.elem_sz = 1;
@@ -67,5 +67,5 @@ TEST_CASE(boot_test_revert_continue)
     rc = boot_write_status(&status);
     TEST_ASSERT_FATAL(rc == 0);
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, &hdr0, &hdr1);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
index 38fa8f9..0ac7480 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
@@ -55,7 +55,7 @@ TEST_CASE(boot_test_vb_ns_11)
     boot_test_util_write_hash(&hdr1, 1);
 
     rc = boot_set_pending(1);
-    TEST_ASSERT_FATAL(rc == 0);
+    TEST_ASSERT(rc == 0);
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
index ac31824..b749f87 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
@@ -46,5 +46,5 @@ TEST_CASE(boot_test_vm_ns_01)
     rc = boot_set_pending(1);
     TEST_ASSERT(rc == 0);
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, NULL, &hdr);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
index 84e6a91..6f75c31 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
@@ -57,5 +57,5 @@ TEST_CASE(boot_test_vm_ns_11_2areas)
     rc = boot_set_pending(1);
     TEST_ASSERT(rc == 0);
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
index f4df74a..88d9e74 100644
--- a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
@@ -57,5 +57,5 @@ TEST_CASE(boot_test_vm_ns_11_b)
     rc = boot_set_pending(1);
     TEST_ASSERT(rc == 0);
 
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7aa94c51/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 0f56db5..e52d012 100644
--- a/net/ip/mn_socket/test/src/mn_sock_test.c
+++ b/net/ip/mn_socket/test/src/mn_sock_test.c
@@ -86,5 +86,7 @@ main(int argc, char **argv)
 
     tu_suite_set_init_cb((void*)mn_socket_test_init, NULL);
     mn_socket_test_all();
+
+    return 0;
 }
 #endif


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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/net/ip/mn_socket/test/src/mn_sock_util.c
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/test/src/mn_sock_util.c b/net/ip/mn_socket/test/src/mn_sock_util.c
new file mode 100644
index 0000000..19ffe71
--- /dev/null
+++ b/net/ip/mn_socket/test/src/mn_sock_util.c
@@ -0,0 +1,775 @@
+/**
+ * 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 "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"
+
+struct os_sem test_sem;
+
+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);
+
+    /*
+     * 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)
+{
+    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);
+    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
+     */
+    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);
+    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);
+}
+
+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();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/net/ip/mn_socket/test/src/testcases/inet_ntop_test.c
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/test/src/testcases/inet_ntop_test.c b/net/ip/mn_socket/test/src/testcases/inet_ntop_test.c
new file mode 100644
index 0000000..7ef13d5
--- /dev/null
+++ b/net/ip/mn_socket/test/src/testcases/inet_ntop_test.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 "mn_sock_test.h"
+
+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);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/net/ip/mn_socket/test/src/testcases/inet_pton_test.c
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/test/src/testcases/inet_pton_test.c b/net/ip/mn_socket/test/src/testcases/inet_pton_test.c
new file mode 100644
index 0000000..f1413d6
--- /dev/null
+++ b/net/ip/mn_socket/test/src/testcases/inet_pton_test.c
@@ -0,0 +1,55 @@
+/**
+ * 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 "mn_sock_test.h"
+
+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);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/net/ip/mn_socket/test/src/testcases/socket_tests.c
----------------------------------------------------------------------
diff --git a/net/ip/mn_socket/test/src/testcases/socket_tests.c b/net/ip/mn_socket/test/src/testcases/socket_tests.c
new file mode 100644
index 0000000..5bbc0f7
--- /dev/null
+++ b/net/ip/mn_socket/test/src/testcases/socket_tests.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 "mn_sock_test.h"
+
+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();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/net/nimble/host/test/src/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test.c b/net/nimble/host/test/src/ble_hs_test.c
index e1f4dad..2b0239c 100644
--- a/net/nimble/host/test/src/ble_hs_test.c
+++ b/net/nimble/host/test/src/ble_hs_test.c
@@ -29,7 +29,7 @@
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_parse_args(argc, argv);
 
     tu_init();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/include/config/config_fcb.h
----------------------------------------------------------------------
diff --git a/sys/config/include/config/config_fcb.h b/sys/config/include/config/config_fcb.h
index b2ed7a2..807af24 100644
--- a/sys/config/include/config/config_fcb.h
+++ b/sys/config/include/config/config_fcb.h
@@ -30,8 +30,8 @@ struct conf_fcb {
     struct fcb cf_fcb;
 };
 
-int conf_fcb_src(struct conf_fcb *fcb);
-int conf_fcb_dst(struct conf_fcb *fcb);
+extern int conf_fcb_src(struct conf_fcb *cf);
+extern int conf_fcb_dst(struct conf_fcb *cf);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/pkg.yml b/sys/config/test-fcb/pkg.yml
new file mode 100644
index 0000000..c5cd984
--- /dev/null
+++ b/sys/config/test-fcb/pkg.yml
@@ -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.
+#
+pkg.name: sys/config/test-fcb
+pkg.type: unittest
+pkg.description: "Config unit tests for fcb."
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps: 
+    - test/testutil
+    - sys/config
+
+pkg.deps.SELFTEST:
+    - fs/fcb
+    - sys/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/conf_test_fcb.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/conf_test_fcb.c b/sys/config/test-fcb/src/conf_test_fcb.c
new file mode 100644
index 0000000..f2cae7d
--- /dev/null
+++ b/sys/config/test-fcb/src/conf_test_fcb.c
@@ -0,0 +1,363 @@
+/**
+ * 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 <os/os.h>
+#include <flash_map/flash_map.h>
+#include <testutil/testutil.h>
+#include <fcb/fcb.h>
+#include "config/config.h"
+#include "config/config_file.h"
+#include "config/config_fcb.h"
+#include "config_priv.h"
+#include "conf_test_fcb.h"
+
+uint8_t val8;
+int c2_var_count = 1;
+
+char val_string[CONF_TEST_FCB_VAL_STR_CNT][CONF_MAX_VAL_LEN];
+
+uint32_t val32;
+
+int test_get_called;
+int test_set_called;
+int test_commit_called;
+int test_export_block;
+
+char *ctest_handle_get(int argc, char **argv, char *val,
+  int val_len_max);
+int ctest_handle_set(int argc, char **argv, char *val);
+int ctest_handle_commit(void);
+int ctest_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt);
+char *c2_handle_get(int argc, char **argv, char *val,
+  int val_len_max);
+int c2_handle_set(int argc, char **argv, char *val);
+int c2_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt);
+char *c3_handle_get(int argc, char **argv, char *val,
+  int val_len_max);
+int c3_handle_set(int argc, char **argv, char *val);
+int c3_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt);
+
+struct conf_handler config_test_handler = {
+    .ch_name = "myfoo",
+    .ch_get = ctest_handle_get,
+    .ch_set = ctest_handle_set,
+    .ch_commit = ctest_handle_commit,
+    .ch_export = ctest_handle_export
+};
+
+char *
+ctest_handle_get(int argc, char **argv, char *val, int val_len_max)
+{
+    test_get_called = 1;
+    if (argc == 1 && !strcmp(argv[0], "mybar")) {
+        return conf_str_from_value(CONF_INT8, &val8, val, val_len_max);
+    }
+    return NULL;
+}
+
+int
+ctest_handle_set(int argc, char **argv, char *val)
+{
+    uint8_t newval;
+    int rc;
+
+    test_set_called = 1;
+    if (argc == 1 && !strcmp(argv[0], "mybar")) {
+        rc = CONF_VALUE_SET(val, CONF_INT8, newval);
+        TEST_ASSERT(rc == 0);
+        val8 = newval;
+        return 0;
+    }
+    return OS_ENOENT;
+}
+
+int
+ctest_handle_commit(void)
+{
+    test_commit_called = 1;
+    return 0;
+}
+
+int
+ctest_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt)
+{
+    char value[32];
+
+    if (test_export_block) {
+        return 0;
+    }
+    conf_str_from_value(CONF_INT8, &val8, value, sizeof(value));
+    cb("myfoo/mybar", value);
+
+    return 0;
+}
+
+struct conf_handler c2_test_handler = {
+    .ch_name = "2nd",
+    .ch_get = c2_handle_get,
+    .ch_set = c2_handle_set,
+    .ch_commit = NULL,
+    .ch_export = c2_handle_export
+};
+
+char *
+c2_var_find(char *name)
+{
+    int idx = 0;
+    int len;
+    char *eptr;
+
+    len = strlen(name);
+    TEST_ASSERT(!strncmp(name, "string", 6));
+    TEST_ASSERT(len > 6);
+
+    idx = strtoul(&name[6], &eptr, 10);
+    TEST_ASSERT(*eptr == '\0');
+    TEST_ASSERT(idx < c2_var_count);
+    return val_string[idx];
+}
+
+char *
+c2_handle_get(int argc, char **argv, char *val, int val_len_max)
+{
+    int len;
+    char *valptr;
+
+    if (argc == 1) {
+        valptr = c2_var_find(argv[0]);
+        if (!valptr) {
+            return NULL;
+        }
+        len = strlen(val_string[0]);
+        if (len > val_len_max) {
+            len = val_len_max;
+        }
+        strncpy(val, valptr, len);
+    }
+    return NULL;
+}
+
+int
+c2_handle_set(int argc, char **argv, char *val)
+{
+    char *valptr;
+
+    if (argc == 1) {
+        valptr = c2_var_find(argv[0]);
+        if (!valptr) {
+            return OS_ENOENT;
+        }
+        if (val) {
+            strncpy(valptr, val, sizeof(val_string[0]));
+        } else {
+            memset(valptr, 0, sizeof(val_string[0]));
+        }
+        return 0;
+    }
+    return OS_ENOENT;
+}
+
+int
+c2_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt)
+{
+    int i;
+    char name[32];
+
+    for (i = 0; i < c2_var_count; i++) {
+        snprintf(name, sizeof(name), "2nd/string%d", i);
+        cb(name, val_string[i]);
+    }
+    return 0;
+}
+
+struct conf_handler c3_test_handler = {
+    .ch_name = "3",
+    .ch_get = c3_handle_get,
+    .ch_set = c3_handle_set,
+    .ch_commit = NULL,
+    .ch_export = c3_handle_export
+};
+
+char *
+c3_handle_get(int argc, char **argv, char *val, int val_len_max)
+{
+    if (argc == 1 && !strcmp(argv[0], "v")) {
+        return conf_str_from_value(CONF_INT32, &val32, val, val_len_max);
+    }
+    return NULL;
+}
+
+int
+c3_handle_set(int argc, char **argv, char *val)
+{
+    uint32_t newval;
+    int rc;
+
+    if (argc == 1 && !strcmp(argv[0], "v")) {
+        rc = CONF_VALUE_SET(val, CONF_INT32, newval);
+        TEST_ASSERT(rc == 0);
+        val32 = newval;
+        return 0;
+    }
+    return OS_ENOENT;
+}
+
+int
+c3_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt)
+{
+    char value[32];
+
+    conf_str_from_value(CONF_INT32, &val32, value, sizeof(value));
+    cb("3/v", value);
+
+    return 0;
+}
+
+void
+ctest_clear_call_state(void)
+{
+    test_get_called = 0;
+    test_set_called = 0;
+    test_commit_called = 0;
+}
+
+int
+ctest_get_call_state(void)
+{
+    return test_get_called + test_set_called + test_commit_called;
+}
+
+void config_wipe_srcs(void)
+{
+    SLIST_INIT(&conf_load_srcs);
+    conf_save_dst = NULL;
+}
+
+void config_wipe_fcb(struct flash_area *fa, int cnt)
+{
+    int i;
+
+    for (i = 0; i < cnt; i++) {
+        flash_area_erase(&fa[i], 0, fa[i].fa_size);
+    }
+}
+
+struct flash_area fcb_areas[] = {
+    [0] = {
+        .fa_off = 0x00000000,
+        .fa_size = 16 * 1024
+    },
+    [1] = {
+        .fa_off = 0x00004000,
+        .fa_size = 16 * 1024
+    },
+    [2] = {
+        .fa_off = 0x00008000,
+        .fa_size = 16 * 1024
+    },
+    [3] = {
+        .fa_off = 0x0000c000,
+        .fa_size = 16 * 1024
+    }
+};
+
+void
+config_test_fill_area(
+          char test_value[CONF_TEST_FCB_VAL_STR_CNT][CONF_MAX_VAL_LEN],
+          int iteration)
+{
+      int i, j;
+
+      for (j = 0; j < 64; j++) {
+          for (i = 0; i < CONF_MAX_VAL_LEN; i++) {
+              test_value[j][i] = ((j * 2) + i + iteration) % 10 + '0';
+          }
+          test_value[j][sizeof(test_value[j]) - 1] = '\0';
+      }
+}
+
+TEST_CASE_DECL(config_empty_lookups)
+TEST_CASE_DECL(config_test_insert)
+TEST_CASE_DECL(config_test_getset_unknown)
+TEST_CASE_DECL(config_test_getset_int)
+TEST_CASE_DECL(config_test_getset_bytes)
+TEST_CASE_DECL(config_test_commit)
+TEST_CASE_DECL(config_test_empty_fcb)
+TEST_CASE_DECL(config_test_save_1_fcb)
+TEST_CASE_DECL(config_test_insert2)
+TEST_CASE_DECL(config_test_save_2_fcb)
+TEST_CASE_DECL(config_test_insert3)
+TEST_CASE_DECL(config_test_save_3_fcb)
+TEST_CASE_DECL(config_test_compress_reset)
+TEST_CASE_DECL(config_test_save_one_fcb)
+
+TEST_SUITE(config_test_all)
+{
+    /*
+     * Config tests.
+     */
+    config_empty_lookups();
+    config_test_insert();
+    config_test_getset_unknown();
+    config_test_getset_int();
+    config_test_getset_bytes();
+
+    config_test_commit();
+
+    /*
+     * FCB as backing storage.
+     */
+    config_test_empty_fcb();
+    config_test_save_1_fcb();
+
+    config_test_insert2();
+
+    config_test_save_2_fcb();
+
+    config_test_insert3();
+    config_test_save_3_fcb();
+
+    config_test_compress_reset();
+
+    config_test_save_one_fcb();
+}
+
+#if MYNEWT_VAL(SELFTEST)
+
+int
+main(int argc, char **argv)
+{
+    ts_config.ts_print_results = 1;
+    tu_init();
+
+    conf_init();
+    config_test_all();
+
+    return tu_any_failed;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/conf_test_fcb.h
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/conf_test_fcb.h b/sys/config/test-fcb/src/conf_test_fcb.h
new file mode 100644
index 0000000..618ae19
--- /dev/null
+++ b/sys/config/test-fcb/src/conf_test_fcb.h
@@ -0,0 +1,90 @@
+/**
+ * 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 _CONF_TEST_FCB_H
+#define _CONF_TEST_FCB_H
+
+#include <stdio.h>
+#include <string.h>
+#include <syscfg/syscfg.h>
+#include <os/os.h>
+#include <flash_map/flash_map.h>
+#include <testutil/testutil.h>
+#include <fcb/fcb.h>
+#include <config/config.h>
+#include <config/config_fcb.h>
+#include "config_priv.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+uint8_t val8;
+int c2_var_count;
+
+#define CONF_TEST_FCB_VAL_STR_CNT   64
+
+extern char val_string[CONF_TEST_FCB_VAL_STR_CNT][CONF_MAX_VAL_LEN];
+
+#define CONF_TEST_FCB_FLASH_CNT   4
+
+extern struct flash_area fcb_areas[CONF_TEST_FCB_FLASH_CNT];
+
+uint32_t val32;
+
+int test_get_called;
+int test_set_called;
+int test_commit_called;
+int test_export_block;
+
+void ctest_clear_call_state(void);
+int ctest_get_call_state(void);
+void config_wipe_srcs(void);
+extern void config_test_fill_area(
+        char test_value[CONF_TEST_FCB_VAL_STR_CNT][CONF_MAX_VAL_LEN],
+        int iteration);
+
+void config_wipe_fcb(struct flash_area *fa, int cnt);
+
+char *ctest_handle_get(int argc, char **argv, char *val, int val_len_max);
+int ctest_handle_set(int argc, char **argv, char *val);
+int ctest_handle_commit(void);
+int ctest_handle_export(void (*cb)(char *name, char *value),
+                        enum conf_export_tgt tgt);
+
+char *c2_handle_get(int argc, char **argv, char *val, int val_len_max);
+int c2_handle_set(int argc, char **argv, char *val);
+int c2_handle_export(void (*cb)(char *name, char *value),
+                     enum conf_export_tgt tgt);
+
+char *c3_handle_get(int argc, char **argv, char *val, int val_len_max);
+int c3_handle_set(int argc, char **argv, char *val);
+int c3_handle_export(void (*cb)(char *name, char *value),
+                     enum conf_export_tgt tgt);
+
+struct conf_handler config_test_handler;
+
+struct conf_handler c2_test_handler;
+
+struct conf_handler c3_test_handler;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CONF_TEST_FCB_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_empty_lookups.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_empty_lookups.c b/sys/config/test-fcb/src/testcases/config_empty_lookups.c
new file mode 100644
index 0000000..768f083
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_empty_lookups.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 "conf_test_fcb.h"
+
+TEST_CASE(config_empty_lookups)
+{
+    int rc;
+    char name[80];
+    char tmp[64], *str;
+
+    strcpy(name, "foo/bar");
+    rc = conf_set_value(name, "tmp");
+    TEST_ASSERT(rc != 0);
+
+    strcpy(name, "foo/bar");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str == NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_commit.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_commit.c b/sys/config/test-fcb/src/testcases/config_test_commit.c
new file mode 100644
index 0000000..4078bff
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_commit.c
@@ -0,0 +1,41 @@
+/**
+ * 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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_commit)
+{
+    char name[80];
+    int rc;
+
+    strcpy(name, "bar");
+    rc = conf_commit(name);
+    TEST_ASSERT(rc);
+    TEST_ASSERT(ctest_get_call_state() == 0);
+
+    rc = conf_commit(NULL);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_commit_called == 1);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo");
+    rc = conf_commit(name);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_commit_called == 1);
+    ctest_clear_call_state();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_compress_reset.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_compress_reset.c b/sys/config/test-fcb/src/testcases/config_test_compress_reset.c
new file mode 100644
index 0000000..2d16e6a
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_compress_reset.c
@@ -0,0 +1,88 @@
+/**
+ * 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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_compress_reset)
+{
+    int rc;
+    struct conf_fcb cf;
+    struct flash_area *fa;
+    char test_value[CONF_TEST_FCB_VAL_STR_CNT][CONF_MAX_VAL_LEN];
+    int elems[4];
+    int i;
+
+    config_wipe_srcs();
+    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
+
+    cf.cf_fcb.f_sectors = fcb_areas;
+    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
+
+    rc = conf_fcb_src(&cf);
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_fcb_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    c2_var_count = 1;
+    memset(elems, 0, sizeof(elems));
+
+    for (i = 0; ; i++) {
+        config_test_fill_area(test_value, i);
+        memcpy(val_string, test_value, sizeof(val_string));
+
+        rc = conf_save();
+        TEST_ASSERT(rc == 0);
+
+        if (cf.cf_fcb.f_active.fe_area == &fcb_areas[2]) {
+            /*
+             * Started using space just before scratch.
+             */
+            break;
+        }
+        memset(val_string, 0, sizeof(val_string));
+
+        rc = conf_load();
+        TEST_ASSERT(rc == 0);
+        TEST_ASSERT(!memcmp(val_string, test_value, CONF_MAX_VAL_LEN));
+    }
+
+    fa = cf.cf_fcb.f_active.fe_area;
+    rc = fcb_append_to_scratch(&cf.cf_fcb);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(fcb_free_sector_cnt(&cf.cf_fcb) == 0);
+    TEST_ASSERT(fa != cf.cf_fcb.f_active.fe_area);
+
+    config_wipe_srcs();
+
+    memset(&cf, 0, sizeof(cf));
+
+    cf.cf_fcb.f_sectors = fcb_areas;
+    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
+
+    rc = conf_fcb_src(&cf);
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_fcb_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(fcb_free_sector_cnt(&cf.cf_fcb) == 1);
+    TEST_ASSERT(fa == cf.cf_fcb.f_active.fe_area);
+
+    c2_var_count = 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_empty_fcb.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_empty_fcb.c b/sys/config/test-fcb/src/testcases/config_test_empty_fcb.c
new file mode 100644
index 0000000..5c62e47
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_empty_fcb.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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_empty_fcb)
+{
+    int rc;
+    struct conf_fcb cf;
+
+    config_wipe_srcs();
+    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
+
+    cf.cf_fcb.f_sectors = fcb_areas;
+    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
+
+    rc = conf_fcb_src(&cf);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * No values
+     */
+    conf_load();
+
+    config_wipe_srcs();
+    ctest_clear_call_state();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_getset_bytes.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_getset_bytes.c b/sys/config/test-fcb/src/testcases/config_test_getset_bytes.c
new file mode 100644
index 0000000..f545794
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_getset_bytes.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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_getset_bytes)
+{
+    char orig[32];
+    char bytes[32];
+    char str[48];
+    char *ret;
+    int j, i;
+    int tmp;
+    int rc;
+
+    for (j = 1; j < sizeof(orig); j++) {
+        for (i = 0; i < j; i++) {
+            orig[i] = i + j + 1;
+        }
+        ret = conf_str_from_bytes(orig, j, str, sizeof(str));
+        TEST_ASSERT(ret);
+        tmp = strlen(str);
+        TEST_ASSERT(tmp < sizeof(str));
+
+        memset(bytes, 0, sizeof(bytes));
+        tmp = sizeof(bytes);
+
+        tmp = sizeof(bytes);
+        rc = conf_bytes_from_str(str, bytes, &tmp);
+        TEST_ASSERT(rc == 0);
+        TEST_ASSERT(tmp == j);
+        TEST_ASSERT(!memcmp(orig, bytes, j));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_getset_int.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_getset_int.c b/sys/config/test-fcb/src/testcases/config_test_getset_int.c
new file mode 100644
index 0000000..fbf841e
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_getset_int.c
@@ -0,0 +1,40 @@
+/**
+ * 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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_getset_int)
+{
+    char name[80];
+    char tmp[64], *str;
+    int rc;
+
+    strcpy(name, "myfoo/mybar");
+    rc = conf_set_value(name, "42");
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_set_called == 1);
+    TEST_ASSERT(val8 == 42);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/mybar");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str);
+    TEST_ASSERT(test_get_called == 1);
+    TEST_ASSERT(!strcmp("42", tmp));
+    ctest_clear_call_state();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_getset_unknown.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_getset_unknown.c b/sys/config/test-fcb/src/testcases/config_test_getset_unknown.c
new file mode 100644
index 0000000..60e1309
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_getset_unknown.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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_getset_unknown)
+{
+    char name[80];
+    char tmp[64], *str;
+    int rc;
+
+    strcpy(name, "foo/bar");
+    rc = conf_set_value(name, "tmp");
+    TEST_ASSERT(rc != 0);
+    TEST_ASSERT(ctest_get_call_state() == 0);
+
+    strcpy(name, "foo/bar");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str == NULL);
+    TEST_ASSERT(ctest_get_call_state() == 0);
+
+    strcpy(name, "myfoo/bar");
+    rc = conf_set_value(name, "tmp");
+    TEST_ASSERT(rc == OS_ENOENT);
+    TEST_ASSERT(test_set_called == 1);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo/bar");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str == NULL);
+    TEST_ASSERT(test_get_called == 1);
+    ctest_clear_call_state();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_insert.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_insert.c b/sys/config/test-fcb/src/testcases/config_test_insert.c
new file mode 100644
index 0000000..7ff5ef3
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_insert.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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_insert)
+{
+    int rc;
+
+    rc = conf_register(&config_test_handler);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_insert2.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_insert2.c b/sys/config/test-fcb/src/testcases/config_test_insert2.c
new file mode 100644
index 0000000..a667447
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_insert2.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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_insert2)
+{
+    int rc;
+
+    rc = conf_register(&c2_test_handler);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_insert3.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_insert3.c b/sys/config/test-fcb/src/testcases/config_test_insert3.c
new file mode 100644
index 0000000..db72c46
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_insert3.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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_insert3)
+{
+    int rc;
+
+    rc = conf_register(&c3_test_handler);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_save_1_fcb.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_save_1_fcb.c b/sys/config/test-fcb/src/testcases/config_test_save_1_fcb.c
new file mode 100644
index 0000000..4579b8a
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_save_1_fcb.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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_save_1_fcb)
+{
+    int rc;
+    struct conf_fcb cf;
+
+    config_wipe_srcs();
+
+    cf.cf_fcb.f_sectors = fcb_areas;
+    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
+
+    rc = conf_fcb_src(&cf);
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_fcb_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    val8 = 33;
+    rc = conf_save();
+    TEST_ASSERT(rc == 0);
+
+    val8 = 0;
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 33);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_save_2_fcb.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_save_2_fcb.c b/sys/config/test-fcb/src/testcases/config_test_save_2_fcb.c
new file mode 100644
index 0000000..4cf4b1a
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_save_2_fcb.c
@@ -0,0 +1,76 @@
+/**
+ * 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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_save_2_fcb)
+{
+    int rc;
+    struct conf_fcb cf;
+    char test_value[CONF_TEST_FCB_VAL_STR_CNT][CONF_MAX_VAL_LEN];
+    int i;
+
+    config_wipe_srcs();
+
+    cf.cf_fcb.f_sectors = fcb_areas;
+    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
+
+    rc = conf_fcb_src(&cf);
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_fcb_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    config_test_fill_area(test_value, 0);
+    memcpy(val_string, test_value, sizeof(val_string));
+
+    val8 = 42;
+    rc = conf_save();
+    TEST_ASSERT(rc == 0);
+
+    val8 = 0;
+    memset(val_string[0], 0, sizeof(val_string[0]));
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 42);
+    TEST_ASSERT(!strcmp(val_string[0], test_value[0]));
+    test_export_block = 1;
+
+    /*
+     * Now add the number of settings to max. Keep adjusting the test_data,
+     * check that rollover happens when it's supposed to.
+     */
+    c2_var_count = 64;
+
+    for (i = 0; i < 32; i++) {
+        config_test_fill_area(test_value, i);
+        memcpy(val_string, test_value, sizeof(val_string));
+
+        rc = conf_save();
+        TEST_ASSERT(rc == 0);
+
+        memset(val_string, 0, sizeof(val_string));
+
+        val8 = 0;
+        rc = conf_load();
+        TEST_ASSERT(rc == 0);
+        TEST_ASSERT(!memcmp(val_string, test_value, sizeof(val_string)));
+        TEST_ASSERT(val8 == 42);
+    }
+    c2_var_count = 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_save_3_fcb.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_save_3_fcb.c b/sys/config/test-fcb/src/testcases/config_test_save_3_fcb.c
new file mode 100644
index 0000000..69de5f1
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_save_3_fcb.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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_save_3_fcb)
+{
+    int rc;
+    struct conf_fcb cf;
+    int i;
+
+    config_wipe_srcs();
+    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
+
+    cf.cf_fcb.f_sectors = fcb_areas;
+    cf.cf_fcb.f_sector_cnt = 4;
+
+    rc = conf_fcb_src(&cf);
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_fcb_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    for (i = 0; i < 4096; i++) {
+        val32 = i;
+
+        rc = conf_save();
+        TEST_ASSERT(rc == 0);
+
+        val32 = 0;
+
+        rc = conf_load();
+        TEST_ASSERT(rc == 0);
+        TEST_ASSERT(val32 == i);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/src/testcases/config_test_save_one_fcb.c
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/src/testcases/config_test_save_one_fcb.c b/sys/config/test-fcb/src/testcases/config_test_save_one_fcb.c
new file mode 100644
index 0000000..25932fa
--- /dev/null
+++ b/sys/config/test-fcb/src/testcases/config_test_save_one_fcb.c
@@ -0,0 +1,55 @@
+/**
+ * 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 "conf_test_fcb.h"
+
+TEST_CASE(config_test_save_one_fcb)
+{
+    int rc;
+    struct conf_fcb cf;
+
+    config_wipe_srcs();
+    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
+
+    cf.cf_fcb.f_sectors = fcb_areas;
+    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
+
+    rc = conf_fcb_src(&cf);
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_fcb_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    val8 = 33;
+    rc = conf_save();
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_save_one("myfoo/mybar", "42");
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 42);
+
+    rc = conf_save_one("myfoo/mybar", "44");
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 44);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-fcb/syscfg.yml
----------------------------------------------------------------------
diff --git a/sys/config/test-fcb/syscfg.yml b/sys/config/test-fcb/syscfg.yml
new file mode 100644
index 0000000..bb352e4
--- /dev/null
+++ b/sys/config/test-fcb/syscfg.yml
@@ -0,0 +1,4 @@
+# Package: sys/config/test-fcb
+
+syscfg.vals:
+    CONFIG_FCB: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/pkg.yml
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/pkg.yml b/sys/config/test-nffs/pkg.yml
new file mode 100644
index 0000000..87f6161
--- /dev/null
+++ b/sys/config/test-nffs/pkg.yml
@@ -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.
+#
+pkg.name: sys/config/test-nffs
+pkg.type: unittest
+pkg.description: "Config unit tests for nffs."
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps: 
+    - test/testutil
+    - sys/config
+
+pkg.deps.SELFTEST:
+    - fs/nffs
+    - sys/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/conf_test_nffs.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/conf_test_nffs.c b/sys/config/test-nffs/src/conf_test_nffs.c
new file mode 100644
index 0000000..bd4706f
--- /dev/null
+++ b/sys/config/test-nffs/src/conf_test_nffs.c
@@ -0,0 +1,367 @@
+/**
+ * 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 <os/os.h>
+#include <testutil/testutil.h>
+#include <nffs/nffs.h>
+#include <fs/fs.h>
+#include <fs/fsutil.h>
+#include "config/config.h"
+#include "config/config_file.h"
+#include "config_priv.h"
+
+uint8_t val8;
+int c2_var_count = 1;
+char val_string[64][CONF_MAX_VAL_LEN];
+
+uint32_t val32;
+
+int test_get_called;
+int test_set_called;
+int test_commit_called;
+int test_export_block;
+
+char *ctest_handle_get(int argc, char **argv, char *val,
+  int val_len_max);
+int ctest_handle_set(int argc, char **argv, char *val);
+int ctest_handle_commit(void);
+int ctest_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt);
+char *c2_handle_get(int argc, char **argv, char *val,
+  int val_len_max);
+int c2_handle_set(int argc, char **argv, char *val);
+int c2_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt);
+char *c3_handle_get(int argc, char **argv, char *val,
+  int val_len_max);
+int c3_handle_set(int argc, char **argv, char *val);
+int c3_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt);
+
+struct conf_handler config_test_handler = {
+    .ch_name = "myfoo",
+    .ch_get = ctest_handle_get,
+    .ch_set = ctest_handle_set,
+    .ch_commit = ctest_handle_commit,
+    .ch_export = ctest_handle_export
+};
+
+char *
+ctest_handle_get(int argc, char **argv, char *val, int val_len_max)
+{
+    test_get_called = 1;
+    if (argc == 1 && !strcmp(argv[0], "mybar")) {
+        return conf_str_from_value(CONF_INT8, &val8, val, val_len_max);
+    }
+    return NULL;
+}
+
+int
+ctest_handle_set(int argc, char **argv, char *val)
+{
+    uint8_t newval;
+    int rc;
+
+    test_set_called = 1;
+    if (argc == 1 && !strcmp(argv[0], "mybar")) {
+        rc = CONF_VALUE_SET(val, CONF_INT8, newval);
+        TEST_ASSERT(rc == 0);
+        val8 = newval;
+        return 0;
+    }
+    return OS_ENOENT;
+}
+
+int
+ctest_handle_commit(void)
+{
+    test_commit_called = 1;
+    return 0;
+}
+
+int
+ctest_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt)
+{
+    char value[32];
+
+    if (test_export_block) {
+        return 0;
+    }
+    conf_str_from_value(CONF_INT8, &val8, value, sizeof(value));
+    cb("myfoo/mybar", value);
+
+    return 0;
+}
+
+struct conf_handler c2_test_handler = {
+    .ch_name = "2nd",
+    .ch_get = c2_handle_get,
+    .ch_set = c2_handle_set,
+    .ch_commit = NULL,
+    .ch_export = c2_handle_export
+};
+
+char *
+c2_var_find(char *name)
+{
+    int idx = 0;
+    int len;
+    char *eptr;
+
+    len = strlen(name);
+    TEST_ASSERT(!strncmp(name, "string", 6));
+    TEST_ASSERT(len > 6);
+
+    idx = strtoul(&name[6], &eptr, 10);
+    TEST_ASSERT(*eptr == '\0');
+    TEST_ASSERT(idx < c2_var_count);
+    return val_string[idx];
+}
+
+char *
+c2_handle_get(int argc, char **argv, char *val, int val_len_max)
+{
+    int len;
+    char *valptr;
+
+    if (argc == 1) {
+        valptr = c2_var_find(argv[0]);
+        if (!valptr) {
+            return NULL;
+        }
+        len = strlen(val_string[0]);
+        if (len > val_len_max) {
+            len = val_len_max;
+        }
+        strncpy(val, valptr, len);
+    }
+    return NULL;
+}
+
+int
+c2_handle_set(int argc, char **argv, char *val)
+{
+    char *valptr;
+
+    if (argc == 1) {
+        valptr = c2_var_find(argv[0]);
+        if (!valptr) {
+            return OS_ENOENT;
+        }
+        if (val) {
+            strncpy(valptr, val, sizeof(val_string[0]));
+        } else {
+            memset(valptr, 0, sizeof(val_string[0]));
+        }
+        return 0;
+    }
+    return OS_ENOENT;
+}
+
+int
+c2_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt)
+{
+    int i;
+    char name[32];
+
+    for (i = 0; i < c2_var_count; i++) {
+        snprintf(name, sizeof(name), "2nd/string%d", i);
+        cb(name, val_string[i]);
+    }
+    return 0;
+}
+
+struct conf_handler c3_test_handler = {
+    .ch_name = "3",
+    .ch_get = c3_handle_get,
+    .ch_set = c3_handle_set,
+    .ch_commit = NULL,
+    .ch_export = c3_handle_export
+};
+
+char *
+c3_handle_get(int argc, char **argv, char *val, int val_len_max)
+{
+    if (argc == 1 && !strcmp(argv[0], "v")) {
+        return conf_str_from_value(CONF_INT32, &val32, val, val_len_max);
+    }
+    return NULL;
+}
+
+int
+c3_handle_set(int argc, char **argv, char *val)
+{
+    uint32_t newval;
+    int rc;
+
+    if (argc == 1 && !strcmp(argv[0], "v")) {
+        rc = CONF_VALUE_SET(val, CONF_INT32, newval);
+        TEST_ASSERT(rc == 0);
+        val32 = newval;
+        return 0;
+    }
+    return OS_ENOENT;
+}
+
+int
+c3_handle_export(void (*cb)(char *name, char *value),
+  enum conf_export_tgt tgt)
+{
+    char value[32];
+
+    conf_str_from_value(CONF_INT32, &val32, value, sizeof(value));
+    cb("3/v", value);
+
+    return 0;
+}
+
+void
+ctest_clear_call_state(void)
+{
+    test_get_called = 0;
+    test_set_called = 0;
+    test_commit_called = 0;
+}
+
+int
+ctest_get_call_state(void)
+{
+    return test_get_called + test_set_called + test_commit_called;
+}
+
+const struct nffs_area_desc config_nffs[] = {
+    { 0x00000000, 16 * 1024 },
+    { 0x00004000, 16 * 1024 },
+    { 0x00008000, 16 * 1024 },
+    { 0x0000c000, 16 * 1024 },
+    { 0, 0 }
+};
+
+void
+config_wipe_srcs(void)
+{
+    SLIST_INIT(&conf_load_srcs);
+    conf_save_dst = NULL;
+}
+
+int
+conf_test_file_strstr(const char *fname, char *string)
+{
+    int rc;
+    uint32_t len;
+    uint32_t rlen;
+    char *buf;
+    struct fs_file *file;
+
+    rc = fs_open(fname, FS_ACCESS_READ, &file);
+    if (rc) {
+        return rc;
+    }
+    rc = fs_filelen(file, &len);
+    fs_close(file);
+    if (rc) {
+        return rc;
+    }
+
+    buf = (char *)malloc(len + 1);
+    TEST_ASSERT(buf);
+
+    rc = fsutil_read_file(fname, 0, len, buf, &rlen);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(rlen == len);
+    buf[rlen] = '\0';
+
+    if (strstr(buf, string)) {
+        return 0;
+    } else {
+        return -1;
+    }
+}
+
+void config_test_fill_area(char test_value[64][CONF_MAX_VAL_LEN],
+  int iteration)
+{
+      int i, j;
+
+      for (j = 0; j < 64; j++) {
+          for (i = 0; i < CONF_MAX_VAL_LEN; i++) {
+              test_value[j][i] = ((j * 2) + i + iteration) % 10 + '0';
+          }
+          test_value[j][sizeof(test_value[j]) - 1] = '\0';
+      }
+}
+
+TEST_CASE_DECL(config_empty_lookups)
+TEST_CASE_DECL(config_test_insert)
+TEST_CASE_DECL(config_test_getset_unknown)
+TEST_CASE_DECL(config_test_getset_int)
+TEST_CASE_DECL(config_test_getset_bytes)
+TEST_CASE_DECL(config_test_commit)
+TEST_CASE_DECL(config_setup_nffs)
+TEST_CASE_DECL(config_test_empty_file)
+TEST_CASE_DECL(config_test_small_file)
+TEST_CASE_DECL(config_test_multiple_in_file)
+TEST_CASE_DECL(config_test_save_in_file)
+TEST_CASE_DECL(config_test_save_one_file)
+
+TEST_SUITE(config_test_all)
+{
+    /*
+     * Config tests.
+     */
+    config_empty_lookups();
+    config_test_insert();
+    config_test_getset_unknown();
+    config_test_getset_int();
+    config_test_getset_bytes();
+
+    config_test_commit();
+
+    /*
+     * NFFS as backing storage.
+     */
+    config_setup_nffs();
+    config_test_empty_file();
+    config_test_small_file();
+    config_test_multiple_in_file();
+
+    config_test_save_in_file();
+
+    config_test_save_one_file();
+}
+
+#if MYNEWT_VAL(SELFTEST)
+
+int
+main(int argc, char **argv)
+{
+    ts_config.ts_print_results = 1;
+    tu_init();
+
+    conf_init();
+    config_test_all();
+
+    return tu_any_failed;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/conf_test_nffs.h
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/conf_test_nffs.h b/sys/config/test-nffs/src/conf_test_nffs.h
new file mode 100644
index 0000000..eb9ee81
--- /dev/null
+++ b/sys/config/test-nffs/src/conf_test_nffs.h
@@ -0,0 +1,87 @@
+/**
+ * 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 _CONF_TEST_H_
+#define _CONF_TEST_H_
+
+#include <stdio.h>
+#include <string.h>
+
+#include "syscfg/syscfg.h"
+
+#include <os/os.h>
+#include <testutil/testutil.h>
+#include <nffs/nffs.h>
+#include <fs/fs.h>
+#include <fs/fsutil.h>
+#include "config/config.h"
+#include "config/config_file.h"
+#include "config_priv.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+uint8_t val8;
+int c2_var_count;
+char val_string[64][CONF_MAX_VAL_LEN];
+
+uint32_t val32;
+
+int test_get_called;
+int test_set_called;
+int test_commit_called;
+int test_export_block;
+
+char *ctest_handle_get(int argc, char **argv, char *val, int val_len_max);
+int ctest_handle_set(int argc, char **argv, char *val);
+int ctest_handle_commit(void);
+int ctest_handle_export(void (*cb)(char *name, char *value),
+                        enum conf_export_tgt tgt);
+int ctest_get_call_state(void);
+void ctest_clear_call_state(void);
+
+void config_wipe_srcs(void);
+
+int conf_test_file_strstr(const char *fname, char *string);
+
+char *c2_handle_get(int argc, char **argv, char *val, int val_len_max);
+int c2_handle_set(int argc, char **argv, char *val);
+int c2_handle_export(void (*cb)(char *name, char *value),
+                     enum conf_export_tgt tgt);
+
+char *c3_handle_get(int argc, char **argv, char *val, int val_len_max);
+int c3_handle_set(int argc, char **argv, char *val);
+int c3_handle_export(void (*cb)(char *name, char *value),
+                     enum conf_export_tgt tgt);
+
+struct conf_handler config_test_handler;
+
+struct conf_handler c2_test_handler;
+
+struct conf_handler c3_test_handler;
+
+extern struct nffs_area_desc config_nffs[];
+
+void config_test_all(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CONF_TEST_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_empty_lookups.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_empty_lookups.c b/sys/config/test-nffs/src/testcases/config_empty_lookups.c
new file mode 100644
index 0000000..d20a419
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_empty_lookups.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 "conf_test_nffs.h"
+
+TEST_CASE(config_empty_lookups)
+{
+    int rc;
+    char name[80];
+    char tmp[64], *str;
+
+    strcpy(name, "foo/bar");
+    rc = conf_set_value(name, "tmp");
+    TEST_ASSERT(rc != 0);
+
+    strcpy(name, "foo/bar");
+    str = conf_get_value(name, tmp, sizeof(tmp));
+    TEST_ASSERT(str == NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_setup_nffs.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_setup_nffs.c b/sys/config/test-nffs/src/testcases/config_setup_nffs.c
new file mode 100644
index 0000000..5453a4e
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_setup_nffs.c
@@ -0,0 +1,29 @@
+/**
+ * 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 "conf_test_nffs.h"
+
+TEST_CASE(config_setup_nffs)
+{
+    int rc;
+
+    rc = nffs_init();
+    TEST_ASSERT_FATAL(rc == 0);
+    rc = nffs_format(config_nffs);
+    TEST_ASSERT_FATAL(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/sys/config/test-nffs/src/testcases/config_test_commit.c
----------------------------------------------------------------------
diff --git a/sys/config/test-nffs/src/testcases/config_test_commit.c b/sys/config/test-nffs/src/testcases/config_test_commit.c
new file mode 100644
index 0000000..03cab12
--- /dev/null
+++ b/sys/config/test-nffs/src/testcases/config_test_commit.c
@@ -0,0 +1,41 @@
+/**
+ * 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 "conf_test_nffs.h"
+
+TEST_CASE(config_test_commit)
+{
+    char name[80];
+    int rc;
+
+    strcpy(name, "bar");
+    rc = conf_commit(name);
+    TEST_ASSERT(rc);
+    TEST_ASSERT(ctest_get_call_state() == 0);
+
+    rc = conf_commit(NULL);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_commit_called == 1);
+    ctest_clear_call_state();
+
+    strcpy(name, "myfoo");
+    rc = conf_commit(name);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(test_commit_called == 1);
+    ctest_clear_call_state();
+}



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

Posted by cc...@apache.org.
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 */


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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/testcases/json_simple_encode.c
----------------------------------------------------------------------
diff --git a/encoding/json/test/src/testcases/json_simple_encode.c b/encoding/json/test/src/testcases/json_simple_encode.c
new file mode 100644
index 0000000..9e6ceba
--- /dev/null
+++ b/encoding/json/test/src/testcases/json_simple_encode.c
@@ -0,0 +1,85 @@
+/**
+ * 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 "test_json.h"
+
+TEST_CASE(test_json_simple_encode)
+{
+    struct json_encoder encoder;
+    struct json_value value;
+    int rc;
+
+    /* reset the state of the internal test */
+    buf_index = 0;
+    memset(&encoder, 0, sizeof(encoder));
+
+    encoder.je_write = test_write;
+    encoder.je_arg= NULL;
+
+    rc = json_encode_object_start(&encoder);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_BOOL(&value, 1);
+    rc = json_encode_object_entry(&encoder, "KeyBool", &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_INT(&value, -1234);
+    rc = json_encode_object_entry(&encoder, "KeyInt", &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_UINT(&value, 1353214);
+    rc = json_encode_object_entry(&encoder, "KeyUint", &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_STRING(&value, "foobar");
+    rc = json_encode_object_entry(&encoder, "KeyString", &value);
+    TEST_ASSERT(rc == 0);
+
+    /* we'll decode later differently */
+    JSON_VALUE_STRINGN(&value, "foobarlongstring", 10);
+    rc = json_encode_object_entry(&encoder, "KeyStringN", &value);
+    TEST_ASSERT(rc == 0);
+
+    rc = json_encode_array_name(&encoder, "KeyIntArr");
+    TEST_ASSERT(rc == 0);
+
+    rc = json_encode_array_start(&encoder);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_INT(&value, 153);
+    rc = json_encode_array_value(&encoder, &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_INT(&value, 2532);
+    rc = json_encode_array_value(&encoder, &value);
+    TEST_ASSERT(rc == 0);
+
+    JSON_VALUE_INT(&value, -322);
+    rc = json_encode_array_value(&encoder, &value);
+    TEST_ASSERT(rc == 0);
+
+    rc = json_encode_array_finish(&encoder);
+    TEST_ASSERT(rc == 0);
+
+    rc = json_encode_object_finish(&encoder);
+    TEST_ASSERT(rc == 0);
+
+    /* does it match what we expect it to */
+    rc = strcmp(bigbuf, output);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/fcb_test.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/fcb_test.c b/fs/fcb/test/src/fcb_test.c
index 47df15c..e91609e 100644
--- a/fs/fcb/test/src/fcb_test.c
+++ b/fs/fcb/test/src/fcb_test.c
@@ -27,9 +27,11 @@
 #include "fcb/fcb.h"
 #include "fcb/../../src/fcb_priv.h"
 
-static struct fcb test_fcb;
+#include "fcb_test.h"
 
-static struct flash_area test_fcb_area[] = {
+struct fcb test_fcb;
+
+struct flash_area test_fcb_area[] = {
     [0] = {
         .fa_device_id = 0,
         .fa_off = 0,
@@ -52,7 +54,7 @@ static struct flash_area test_fcb_area[] = {
     }
 };
 
-static void
+void
 fcb_test_wipe(void)
 {
     int i;
@@ -66,78 +68,20 @@ fcb_test_wipe(void)
     }
 }
 
-TEST_CASE(fcb_test_len)
-{
-    uint8_t buf[3];
-    uint16_t len;
-    uint16_t len2;
-    int rc;
-
-    for (len = 0; len < FCB_MAX_LEN; len++) {
-        rc = fcb_put_len(buf, len);
-        TEST_ASSERT(rc == 1 || rc == 2);
-
-        rc = fcb_get_len(buf, &len2);
-        TEST_ASSERT(rc == 1 || rc == 2);
-
-        TEST_ASSERT(len == len2);
-    }
-}
-
-TEST_CASE(fcb_test_init)
-{
-    int rc;
-    struct fcb *fcb;
-
-    fcb = &test_fcb;
-    memset(fcb, 0, sizeof(*fcb));
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == FCB_ERR_ARGS);
-
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == FCB_ERR_ARGS);
-
-    fcb->f_sector_cnt = 2;
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-}
-
-static int
+int
 fcb_test_empty_walk_cb(struct fcb_entry *loc, void *arg)
 {
     TEST_ASSERT(0);
     return 0;
 }
 
-TEST_CASE(fcb_test_empty_walk)
-{
-    int rc;
-    struct fcb *fcb;
-
-    fcb_test_wipe();
-    fcb = &test_fcb;
-    memset(fcb, 0, sizeof(*fcb));
-
-    fcb->f_sector_cnt = 2;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    rc = fcb_walk(fcb, 0, fcb_test_empty_walk_cb, NULL);
-    TEST_ASSERT(rc == 0);
-}
-
-static uint8_t
+uint8_t
 fcb_test_append_data(int msg_len, int off)
 {
     return (msg_len ^ off);
 }
 
-static int
+int
 fcb_test_data_walk_cb(struct fcb_entry *loc, void *arg)
 {
     uint16_t len;
@@ -160,94 +104,7 @@ fcb_test_data_walk_cb(struct fcb_entry *loc, void *arg)
     return 0;
 }
 
-TEST_CASE(fcb_test_append)
-{
-    int rc;
-    struct fcb *fcb;
-    struct fcb_entry loc;
-    uint8_t test_data[128];
-    int i;
-    int j;
-    int var_cnt;
-
-    fcb_test_wipe();
-    fcb = &test_fcb;
-    memset(fcb, 0, sizeof(*fcb));
-    fcb->f_sector_cnt = 2;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    for (i = 0; i < sizeof(test_data); i++) {
-        for (j = 0; j < i; j++) {
-            test_data[j] = fcb_test_append_data(i, j);
-        }
-        rc = fcb_append(fcb, i, &loc);
-        TEST_ASSERT_FATAL(rc == 0);
-        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data, i);
-        TEST_ASSERT(rc == 0);
-        rc = fcb_append_finish(fcb, &loc);
-        TEST_ASSERT(rc == 0);
-    }
-
-    var_cnt = 0;
-    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(var_cnt == sizeof(test_data));
-}
-
-TEST_CASE(fcb_test_append_too_big)
-{
-    struct fcb *fcb;
-    int rc;
-    int len;
-    struct fcb_entry elem_loc;
-
-    fcb_test_wipe();
-    fcb = &test_fcb;
-    memset(fcb, 0, sizeof(*fcb));
-    fcb->f_sector_cnt = 2;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Max element which fits inside sector is
-     * sector size - (disk header + crc + 1-2 bytes of length).
-     */
-    len = fcb->f_active.fe_area->fa_size;
-
-    rc = fcb_append(fcb, len, &elem_loc);
-    TEST_ASSERT(rc != 0);
-
-    len--;
-    rc = fcb_append(fcb, len, &elem_loc);
-    TEST_ASSERT(rc != 0);
-
-    len -= sizeof(struct fcb_disk_area);
-    rc = fcb_append(fcb, len, &elem_loc);
-    TEST_ASSERT(rc != 0);
-
-    len = fcb->f_active.fe_area->fa_size -
-      (sizeof(struct fcb_disk_area) + 1 + 2);
-    rc = fcb_append(fcb, len, &elem_loc);
-    TEST_ASSERT(rc == 0);
-
-    rc = fcb_append_finish(fcb, &elem_loc);
-    TEST_ASSERT(rc == 0);
-
-    rc = fcb_elem_info(fcb, &elem_loc);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(elem_loc.fe_data_len == len);
-}
-
-struct append_arg {
-    int *elem_cnts;
-};
-
-static int
+int
 fcb_test_cnt_elems_cb(struct fcb_entry *loc, void *arg)
 {
     struct append_arg *aa = (struct append_arg *)arg;
@@ -258,410 +115,34 @@ fcb_test_cnt_elems_cb(struct fcb_entry *loc, void *arg)
     return 0;
 }
 
-TEST_CASE(fcb_test_append_fill)
-{
-    struct fcb *fcb;
-    int rc;
-    int i;
-    struct fcb_entry loc;
-    uint8_t test_data[128];
-    int elem_cnts[2] = {0, 0};
-    int aa_together_cnts[2];
-    struct append_arg aa_together = {
-        .elem_cnts = aa_together_cnts
-    };
-    int aa_separate_cnts[2];
-    struct append_arg aa_separate = {
-        .elem_cnts = aa_separate_cnts
-    };
-
-    fcb_test_wipe();
-    fcb = &test_fcb;
-    memset(fcb, 0, sizeof(*fcb));
-    fcb->f_sector_cnt = 2;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    for (i = 0; i < sizeof(test_data); i++) {
-        test_data[i] = fcb_test_append_data(sizeof(test_data), i);
-    }
-
-    while (1) {
-        rc = fcb_append(fcb, sizeof(test_data), &loc);
-        if (rc == FCB_ERR_NOSPACE) {
-            break;
-        }
-        if (loc.fe_area == &test_fcb_area[0]) {
-            elem_cnts[0]++;
-        } else if (loc.fe_area == &test_fcb_area[1]) {
-            elem_cnts[1]++;
-        } else {
-            TEST_ASSERT(0);
-        }
-
-        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
-          sizeof(test_data));
-        TEST_ASSERT(rc == 0);
-
-        rc = fcb_append_finish(fcb, &loc);
-        TEST_ASSERT(rc == 0);
-    }
-    TEST_ASSERT(elem_cnts[0] > 0);
-    TEST_ASSERT(elem_cnts[0] == elem_cnts[1]);
-
-    memset(&aa_together_cnts, 0, sizeof(aa_together_cnts));
-    rc = fcb_walk(fcb, NULL, fcb_test_cnt_elems_cb, &aa_together);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(aa_together.elem_cnts[0] == elem_cnts[0]);
-    TEST_ASSERT(aa_together.elem_cnts[1] == elem_cnts[1]);
-
-    memset(&aa_separate_cnts, 0, sizeof(aa_separate_cnts));
-    rc = fcb_walk(fcb, &test_fcb_area[0], fcb_test_cnt_elems_cb,
-      &aa_separate);
-    TEST_ASSERT(rc == 0);
-    rc = fcb_walk(fcb, &test_fcb_area[1], fcb_test_cnt_elems_cb,
-      &aa_separate);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(aa_separate.elem_cnts[0] == elem_cnts[0]);
-    TEST_ASSERT(aa_separate.elem_cnts[1] == elem_cnts[1]);
-
-}
-
-TEST_CASE(fcb_test_reset)
-{
-    struct fcb *fcb;
-    int rc;
-    int i;
-    struct fcb_entry loc;
-    uint8_t test_data[128];
-    int var_cnt;
-
-    fcb_test_wipe();
-    fcb = &test_fcb;
-    memset(fcb, 0, sizeof(*fcb));
-    fcb->f_sector_cnt = 2;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    var_cnt = 0;
-    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(var_cnt == 0);
-
-    rc = fcb_append(fcb, 32, &loc);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * No ready ones yet. CRC should not match.
-     */
-    var_cnt = 0;
-    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(var_cnt == 0);
-
-    for (i = 0; i < sizeof(test_data); i++) {
-        test_data[i] = fcb_test_append_data(32, i);
-    }
-    rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data, 32);
-    TEST_ASSERT(rc == 0);
-
-    rc = fcb_append_finish(fcb, &loc);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * one entry
-     */
-    var_cnt = 32;
-    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(var_cnt == 33);
-
-    /*
-     * Pretend reset
-     */
-    memset(fcb, 0, sizeof(*fcb));
-    fcb->f_sector_cnt = 2;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    var_cnt = 32;
-    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(var_cnt == 33);
-
-    rc = fcb_append(fcb, 33, &loc);
-    TEST_ASSERT(rc == 0);
-
-    for (i = 0; i < sizeof(test_data); i++) {
-        test_data[i] = fcb_test_append_data(33, i);
-    }
-    rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data, 33);
-    TEST_ASSERT(rc == 0);
-
-    rc = fcb_append_finish(fcb, &loc);
-    TEST_ASSERT(rc == 0);
-
-    var_cnt = 32;
-    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(var_cnt == 34);
-
-    /*
-     * Add partial one, make sure that we survive reset then.
-     */
-    rc = fcb_append(fcb, 34, &loc);
-    TEST_ASSERT(rc == 0);
-
-    memset(fcb, 0, sizeof(*fcb));
-    fcb->f_sector_cnt = 2;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Walk should skip that.
-     */
-    var_cnt = 32;
-    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(var_cnt == 34);
-
-    /* Add a 3rd one, should go behind corrupt entry */
-    rc = fcb_append(fcb, 34, &loc);
-    TEST_ASSERT(rc == 0);
-
-    for (i = 0; i < sizeof(test_data); i++) {
-        test_data[i] = fcb_test_append_data(34, i);
-    }
-    rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data, 34);
-    TEST_ASSERT(rc == 0);
-
-    rc = fcb_append_finish(fcb, &loc);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Walk should skip corrupt entry, but report the next one.
-     */
-    var_cnt = 32;
-    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(var_cnt == 35);
-}
-
-TEST_CASE(fcb_test_rotate)
-{
-    struct fcb *fcb;
-    int rc;
-    int old_id;
-    struct fcb_entry loc;
-    uint8_t test_data[128];
-    int elem_cnts[2] = {0, 0};
-    int cnts[2];
-    struct append_arg aa_arg = {
-        .elem_cnts = cnts
-    };
-
-    fcb_test_wipe();
-    fcb = &test_fcb;
-    memset(fcb, 0, sizeof(*fcb));
-    fcb->f_sector_cnt = 2;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    old_id = fcb->f_active_id;
-    rc = fcb_rotate(fcb);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(fcb->f_active_id == old_id + 1);
-
-    /*
-     * Now fill up the
-     */
-    while (1) {
-        rc = fcb_append(fcb, sizeof(test_data), &loc);
-        if (rc == FCB_ERR_NOSPACE) {
-            break;
-        }
-        if (loc.fe_area == &test_fcb_area[0]) {
-            elem_cnts[0]++;
-        } else if (loc.fe_area == &test_fcb_area[1]) {
-            elem_cnts[1]++;
-        } else {
-            TEST_ASSERT(0);
-        }
-
-        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
-          sizeof(test_data));
-        TEST_ASSERT(rc == 0);
-
-        rc = fcb_append_finish(fcb, &loc);
-        TEST_ASSERT(rc == 0);
-    }
-    TEST_ASSERT(elem_cnts[0] > 0 && elem_cnts[0] == elem_cnts[1]);
-
-    old_id = fcb->f_active_id;
-    rc = fcb_rotate(fcb);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(fcb->f_active_id == old_id); /* no new area created */
-
-    memset(cnts, 0, sizeof(cnts));
-    rc = fcb_walk(fcb, NULL, fcb_test_cnt_elems_cb, &aa_arg);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(aa_arg.elem_cnts[0] == elem_cnts[0] ||
-      aa_arg.elem_cnts[1] == elem_cnts[1]);
-    TEST_ASSERT(aa_arg.elem_cnts[0] == 0 || aa_arg.elem_cnts[1] == 0);
-
-    /*
-     * One sector is full. The other one should have one entry in it.
-     */
-    rc = fcb_append(fcb, sizeof(test_data), &loc);
-    TEST_ASSERT(rc == 0);
-
-    rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
-      sizeof(test_data));
-    TEST_ASSERT(rc == 0);
-
-    rc = fcb_append_finish(fcb, &loc);
-    TEST_ASSERT(rc == 0);
-
-    old_id = fcb->f_active_id;
-    rc = fcb_rotate(fcb);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(fcb->f_active_id == old_id);
-
-    memset(cnts, 0, sizeof(cnts));
-    rc = fcb_walk(fcb, NULL, fcb_test_cnt_elems_cb, &aa_arg);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(aa_arg.elem_cnts[0] == 1 || aa_arg.elem_cnts[1] == 1);
-    TEST_ASSERT(aa_arg.elem_cnts[0] == 0 || aa_arg.elem_cnts[1] == 0);
-}
-
-TEST_CASE(fcb_test_multiple_scratch)
-{
-    struct fcb *fcb;
-    int rc;
-    struct fcb_entry loc;
-    uint8_t test_data[128];
-    int elem_cnts[4];
-    int idx;
-    int cnts[4];
-    struct append_arg aa_arg = {
-        .elem_cnts = cnts
-    };
-
-    fcb_test_wipe();
-    fcb = &test_fcb;
-    memset(fcb, 0, sizeof(*fcb));
-    fcb->f_sector_cnt = 4;
-    fcb->f_scratch_cnt = 1;
-    fcb->f_sectors = test_fcb_area;
-
-    rc = fcb_init(fcb);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Now fill up everything. We should be able to get 3 of the sectors
-     * full.
-     */
-    memset(elem_cnts, 0, sizeof(elem_cnts));
-    while (1) {
-        rc = fcb_append(fcb, sizeof(test_data), &loc);
-        if (rc == FCB_ERR_NOSPACE) {
-            break;
-        }
-        idx = loc.fe_area - &test_fcb_area[0];
-        elem_cnts[idx]++;
-
-        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
-          sizeof(test_data));
-        TEST_ASSERT(rc == 0);
-
-        rc = fcb_append_finish(fcb, &loc);
-        TEST_ASSERT(rc == 0);
-    }
-
-    TEST_ASSERT(elem_cnts[0] > 0);
-    TEST_ASSERT(elem_cnts[0] == elem_cnts[1] && elem_cnts[0] == elem_cnts[2]);
-    TEST_ASSERT(elem_cnts[3] == 0);
-
-    /*
-     * Ask to use scratch block, then fill it up.
-     */
-    rc = fcb_append_to_scratch(fcb);
-    TEST_ASSERT(rc == 0);
-
-    while (1) {
-        rc = fcb_append(fcb, sizeof(test_data), &loc);
-        if (rc == FCB_ERR_NOSPACE) {
-            break;
-        }
-        idx = loc.fe_area - &test_fcb_area[0];
-        elem_cnts[idx]++;
-
-        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
-          sizeof(test_data));
-        TEST_ASSERT(rc == 0);
-
-        rc = fcb_append_finish(fcb, &loc);
-        TEST_ASSERT(rc == 0);
-    }
-    TEST_ASSERT(elem_cnts[3] == elem_cnts[0]);
-
-    /*
-     * Rotate
-     */
-    rc = fcb_rotate(fcb);
-    TEST_ASSERT(rc == 0);
-
-    memset(&cnts, 0, sizeof(cnts));
-    rc = fcb_walk(fcb, NULL, fcb_test_cnt_elems_cb, &aa_arg);
-    TEST_ASSERT(rc == 0);
-
-    TEST_ASSERT(cnts[0] == 0);
-    TEST_ASSERT(cnts[1] > 0);
-    TEST_ASSERT(cnts[1] == cnts[2] && cnts[1] == cnts[3]);
-
-    rc = fcb_append_to_scratch(fcb);
-    TEST_ASSERT(rc == 0);
-    rc = fcb_append_to_scratch(fcb);
-    TEST_ASSERT(rc != 0);
-}
+TEST_CASE_DECL(fcb_test_len)
+TEST_CASE_DECL(fcb_test_init)
+TEST_CASE_DECL(fcb_test_empty_walk)
+TEST_CASE_DECL(fcb_test_append)
+TEST_CASE_DECL(fcb_test_append_too_big)
+TEST_CASE_DECL(fcb_test_append_fill)
+TEST_CASE_DECL(fcb_test_reset)
+TEST_CASE_DECL(fcb_test_rotate)
+TEST_CASE_DECL(fcb_test_multiple_scratch)
 
 TEST_SUITE(fcb_test_all)
 {
     fcb_test_len();
-
     fcb_test_init();
-
     fcb_test_empty_walk();
-
     fcb_test_append();
-
     fcb_test_append_too_big();
-
     fcb_test_append_fill();
-
     fcb_test_reset();
-
     fcb_test_rotate();
-
     fcb_test_multiple_scratch();
 }
 
 #if MYNEWT_VAL(SELFTEST)
-
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     fcb_test_all();
@@ -669,4 +150,3 @@ main(int argc, char **argv)
     return tu_any_failed;
 }
 #endif
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/fcb_test.h
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/fcb_test.h b/fs/fcb/test/src/fcb_test.h
new file mode 100644
index 0000000..c0ab6c0
--- /dev/null
+++ b/fs/fcb/test/src/fcb_test.h
@@ -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.
+ */
+#ifndef _FCB_TEST_H
+#define _FCB_TEST_H
+
+#include <stdio.h>
+#include <string.h>
+
+#include "syscfg/syscfg.h"
+#include "os/os.h"
+#include "testutil/testutil.h"
+
+#include "fcb/fcb.h"
+#include "fcb/../../src/fcb_priv.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+extern struct fcb test_fcb;
+
+extern struct flash_area test_fcb_area[];
+
+struct append_arg {
+    int *elem_cnts;
+};
+
+void fcb_test_wipe(void);
+int fcb_test_empty_walk_cb(struct fcb_entry *loc, void *arg);
+uint8_t fcb_test_append_data(int msg_len, int off);
+int fcb_test_data_walk_cb(struct fcb_entry *loc, void *arg);
+int fcb_test_cnt_elems_cb(struct fcb_entry *loc, void *arg);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _FCB_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_append.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_append.c b/fs/fcb/test/src/testcases/fcb_test_append.c
new file mode 100644
index 0000000..cba39cd
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_append.c
@@ -0,0 +1,56 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_append)
+{
+    int rc;
+    struct fcb *fcb;
+    struct fcb_entry loc;
+    uint8_t test_data[128];
+    int i;
+    int j;
+    int var_cnt;
+
+    fcb_test_wipe();
+    fcb = &test_fcb;
+    memset(fcb, 0, sizeof(*fcb));
+    fcb->f_sector_cnt = 2;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    for (i = 0; i < sizeof(test_data); i++) {
+        for (j = 0; j < i; j++) {
+            test_data[j] = fcb_test_append_data(i, j);
+        }
+        rc = fcb_append(fcb, i, &loc);
+        TEST_ASSERT_FATAL(rc == 0);
+        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data, i);
+        TEST_ASSERT(rc == 0);
+        rc = fcb_append_finish(fcb, &loc);
+        TEST_ASSERT(rc == 0);
+    }
+
+    var_cnt = 0;
+    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(var_cnt == sizeof(test_data));
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_append_fill.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_append_fill.c b/fs/fcb/test/src/testcases/fcb_test_append_fill.c
new file mode 100644
index 0000000..e07f3fc
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_append_fill.c
@@ -0,0 +1,90 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_append_fill)
+{
+    struct fcb *fcb;
+    int rc;
+    int i;
+    struct fcb_entry loc;
+    uint8_t test_data[128];
+    int elem_cnts[2] = {0, 0};
+    int aa_together_cnts[2];
+    struct append_arg aa_together = {
+        .elem_cnts = aa_together_cnts
+    };
+    int aa_separate_cnts[2];
+    struct append_arg aa_separate = {
+        .elem_cnts = aa_separate_cnts
+    };
+
+    fcb_test_wipe();
+    fcb = &test_fcb;
+    memset(fcb, 0, sizeof(*fcb));
+    fcb->f_sector_cnt = 2;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    for (i = 0; i < sizeof(test_data); i++) {
+        test_data[i] = fcb_test_append_data(sizeof(test_data), i);
+    }
+
+    while (1) {
+        rc = fcb_append(fcb, sizeof(test_data), &loc);
+        if (rc == FCB_ERR_NOSPACE) {
+            break;
+        }
+        if (loc.fe_area == &test_fcb_area[0]) {
+            elem_cnts[0]++;
+        } else if (loc.fe_area == &test_fcb_area[1]) {
+            elem_cnts[1]++;
+        } else {
+            TEST_ASSERT(0);
+        }
+
+        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
+          sizeof(test_data));
+        TEST_ASSERT(rc == 0);
+
+        rc = fcb_append_finish(fcb, &loc);
+        TEST_ASSERT(rc == 0);
+    }
+    TEST_ASSERT(elem_cnts[0] > 0);
+    TEST_ASSERT(elem_cnts[0] == elem_cnts[1]);
+
+    memset(&aa_together_cnts, 0, sizeof(aa_together_cnts));
+    rc = fcb_walk(fcb, NULL, fcb_test_cnt_elems_cb, &aa_together);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(aa_together.elem_cnts[0] == elem_cnts[0]);
+    TEST_ASSERT(aa_together.elem_cnts[1] == elem_cnts[1]);
+
+    memset(&aa_separate_cnts, 0, sizeof(aa_separate_cnts));
+    rc = fcb_walk(fcb, &test_fcb_area[0], fcb_test_cnt_elems_cb,
+      &aa_separate);
+    TEST_ASSERT(rc == 0);
+    rc = fcb_walk(fcb, &test_fcb_area[1], fcb_test_cnt_elems_cb,
+      &aa_separate);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(aa_separate.elem_cnts[0] == elem_cnts[0]);
+    TEST_ASSERT(aa_separate.elem_cnts[1] == elem_cnts[1]);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_append_too_big.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_append_too_big.c b/fs/fcb/test/src/testcases/fcb_test_append_too_big.c
new file mode 100644
index 0000000..0000add
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_append_too_big.c
@@ -0,0 +1,65 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_append_too_big)
+{
+    struct fcb *fcb;
+    int rc;
+    int len;
+    struct fcb_entry elem_loc;
+
+    fcb_test_wipe();
+    fcb = &test_fcb;
+    memset(fcb, 0, sizeof(*fcb));
+    fcb->f_sector_cnt = 2;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * Max element which fits inside sector is
+     * sector size - (disk header + crc + 1-2 bytes of length).
+     */
+    len = fcb->f_active.fe_area->fa_size;
+
+    rc = fcb_append(fcb, len, &elem_loc);
+    TEST_ASSERT(rc != 0);
+
+    len--;
+    rc = fcb_append(fcb, len, &elem_loc);
+    TEST_ASSERT(rc != 0);
+
+    len -= sizeof(struct fcb_disk_area);
+    rc = fcb_append(fcb, len, &elem_loc);
+    TEST_ASSERT(rc != 0);
+
+    len = fcb->f_active.fe_area->fa_size -
+      (sizeof(struct fcb_disk_area) + 1 + 2);
+    rc = fcb_append(fcb, len, &elem_loc);
+    TEST_ASSERT(rc == 0);
+
+    rc = fcb_append_finish(fcb, &elem_loc);
+    TEST_ASSERT(rc == 0);
+
+    rc = fcb_elem_info(fcb, &elem_loc);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(elem_loc.fe_data_len == len);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_empty_walk.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_empty_walk.c b/fs/fcb/test/src/testcases/fcb_test_empty_walk.c
new file mode 100644
index 0000000..3a73782
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_empty_walk.c
@@ -0,0 +1,38 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_empty_walk)
+{
+    int rc;
+    struct fcb *fcb;
+
+    fcb_test_wipe();
+    fcb = &test_fcb;
+    memset(fcb, 0, sizeof(*fcb));
+
+    fcb->f_sector_cnt = 2;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    rc = fcb_walk(fcb, 0, fcb_test_empty_walk_cb, NULL);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_init.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_init.c b/fs/fcb/test/src/testcases/fcb_test_init.c
new file mode 100644
index 0000000..0e9bdd4
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_init.c
@@ -0,0 +1,40 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_init)
+{
+    int rc;
+    struct fcb *fcb;
+
+    fcb = &test_fcb;
+    memset(fcb, 0, sizeof(*fcb));
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == FCB_ERR_ARGS);
+
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == FCB_ERR_ARGS);
+
+    fcb->f_sector_cnt = 2;
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_len.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_len.c b/fs/fcb/test/src/testcases/fcb_test_len.c
new file mode 100644
index 0000000..2ab7065
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_len.c
@@ -0,0 +1,37 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_len)
+{
+    uint8_t buf[3];
+    uint16_t len;
+    uint16_t len2;
+    int rc;
+
+    for (len = 0; len < FCB_MAX_LEN; len++) {
+        rc = fcb_put_len(buf, len);
+        TEST_ASSERT(rc == 1 || rc == 2);
+
+        rc = fcb_get_len(buf, &len2);
+        TEST_ASSERT(rc == 1 || rc == 2);
+
+        TEST_ASSERT(len == len2);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_multiple_scratch.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_multiple_scratch.c b/fs/fcb/test/src/testcases/fcb_test_multiple_scratch.c
new file mode 100644
index 0000000..b10e7e4
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_multiple_scratch.c
@@ -0,0 +1,110 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_multiple_scratch)
+{
+    struct fcb *fcb;
+    int rc;
+    struct fcb_entry loc;
+    uint8_t test_data[128];
+    int elem_cnts[4];
+    int idx;
+    int cnts[4];
+    struct append_arg aa_arg = {
+        .elem_cnts = cnts
+    };
+
+    fcb_test_wipe();
+    fcb = &test_fcb;
+    memset(fcb, 0, sizeof(*fcb));
+    fcb->f_sector_cnt = 4;
+    fcb->f_scratch_cnt = 1;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * Now fill up everything. We should be able to get 3 of the sectors
+     * full.
+     */
+    memset(elem_cnts, 0, sizeof(elem_cnts));
+    while (1) {
+        rc = fcb_append(fcb, sizeof(test_data), &loc);
+        if (rc == FCB_ERR_NOSPACE) {
+            break;
+        }
+        idx = loc.fe_area - &test_fcb_area[0];
+        elem_cnts[idx]++;
+
+        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
+          sizeof(test_data));
+        TEST_ASSERT(rc == 0);
+
+        rc = fcb_append_finish(fcb, &loc);
+        TEST_ASSERT(rc == 0);
+    }
+
+    TEST_ASSERT(elem_cnts[0] > 0);
+    TEST_ASSERT(elem_cnts[0] == elem_cnts[1] && elem_cnts[0] == elem_cnts[2]);
+    TEST_ASSERT(elem_cnts[3] == 0);
+
+    /*
+     * Ask to use scratch block, then fill it up.
+     */
+    rc = fcb_append_to_scratch(fcb);
+    TEST_ASSERT(rc == 0);
+
+    while (1) {
+        rc = fcb_append(fcb, sizeof(test_data), &loc);
+        if (rc == FCB_ERR_NOSPACE) {
+            break;
+        }
+        idx = loc.fe_area - &test_fcb_area[0];
+        elem_cnts[idx]++;
+
+        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
+          sizeof(test_data));
+        TEST_ASSERT(rc == 0);
+
+        rc = fcb_append_finish(fcb, &loc);
+        TEST_ASSERT(rc == 0);
+    }
+    TEST_ASSERT(elem_cnts[3] == elem_cnts[0]);
+
+    /*
+     * Rotate
+     */
+    rc = fcb_rotate(fcb);
+    TEST_ASSERT(rc == 0);
+
+    memset(&cnts, 0, sizeof(cnts));
+    rc = fcb_walk(fcb, NULL, fcb_test_cnt_elems_cb, &aa_arg);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(cnts[0] == 0);
+    TEST_ASSERT(cnts[1] > 0);
+    TEST_ASSERT(cnts[1] == cnts[2] && cnts[1] == cnts[3]);
+
+    rc = fcb_append_to_scratch(fcb);
+    TEST_ASSERT(rc == 0);
+    rc = fcb_append_to_scratch(fcb);
+    TEST_ASSERT(rc != 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_reset.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_reset.c b/fs/fcb/test/src/testcases/fcb_test_reset.c
new file mode 100644
index 0000000..d54bd1a
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_reset.c
@@ -0,0 +1,145 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_reset)
+{
+    struct fcb *fcb;
+    int rc;
+    int i;
+    struct fcb_entry loc;
+    uint8_t test_data[128];
+    int var_cnt;
+
+    fcb_test_wipe();
+    fcb = &test_fcb;
+    memset(fcb, 0, sizeof(*fcb));
+    fcb->f_sector_cnt = 2;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    var_cnt = 0;
+    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(var_cnt == 0);
+
+    rc = fcb_append(fcb, 32, &loc);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * No ready ones yet. CRC should not match.
+     */
+    var_cnt = 0;
+    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(var_cnt == 0);
+
+    for (i = 0; i < sizeof(test_data); i++) {
+        test_data[i] = fcb_test_append_data(32, i);
+    }
+    rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data, 32);
+    TEST_ASSERT(rc == 0);
+
+    rc = fcb_append_finish(fcb, &loc);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * one entry
+     */
+    var_cnt = 32;
+    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(var_cnt == 33);
+
+    /*
+     * Pretend reset
+     */
+    memset(fcb, 0, sizeof(*fcb));
+    fcb->f_sector_cnt = 2;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    var_cnt = 32;
+    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(var_cnt == 33);
+
+    rc = fcb_append(fcb, 33, &loc);
+    TEST_ASSERT(rc == 0);
+
+    for (i = 0; i < sizeof(test_data); i++) {
+        test_data[i] = fcb_test_append_data(33, i);
+    }
+    rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data, 33);
+    TEST_ASSERT(rc == 0);
+
+    rc = fcb_append_finish(fcb, &loc);
+    TEST_ASSERT(rc == 0);
+
+    var_cnt = 32;
+    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(var_cnt == 34);
+
+    /*
+     * Add partial one, make sure that we survive reset then.
+     */
+    rc = fcb_append(fcb, 34, &loc);
+    TEST_ASSERT(rc == 0);
+
+    memset(fcb, 0, sizeof(*fcb));
+    fcb->f_sector_cnt = 2;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * Walk should skip that.
+     */
+    var_cnt = 32;
+    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(var_cnt == 34);
+
+    /* Add a 3rd one, should go behind corrupt entry */
+    rc = fcb_append(fcb, 34, &loc);
+    TEST_ASSERT(rc == 0);
+
+    for (i = 0; i < sizeof(test_data); i++) {
+        test_data[i] = fcb_test_append_data(34, i);
+    }
+    rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data, 34);
+    TEST_ASSERT(rc == 0);
+
+    rc = fcb_append_finish(fcb, &loc);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * Walk should skip corrupt entry, but report the next one.
+     */
+    var_cnt = 32;
+    rc = fcb_walk(fcb, 0, fcb_test_data_walk_cb, &var_cnt);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(var_cnt == 35);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/fcb/test/src/testcases/fcb_test_rotate.c
----------------------------------------------------------------------
diff --git a/fs/fcb/test/src/testcases/fcb_test_rotate.c b/fs/fcb/test/src/testcases/fcb_test_rotate.c
new file mode 100644
index 0000000..398a96a
--- /dev/null
+++ b/fs/fcb/test/src/testcases/fcb_test_rotate.c
@@ -0,0 +1,108 @@
+/**
+ * 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 "fcb_test.h"
+
+TEST_CASE(fcb_test_rotate)
+{
+    struct fcb *fcb;
+    int rc;
+    int old_id;
+    struct fcb_entry loc;
+    uint8_t test_data[128];
+    int elem_cnts[2] = {0, 0};
+    int cnts[2];
+    struct append_arg aa_arg = {
+        .elem_cnts = cnts
+    };
+
+    fcb_test_wipe();
+    fcb = &test_fcb;
+    memset(fcb, 0, sizeof(*fcb));
+    fcb->f_sector_cnt = 2;
+    fcb->f_sectors = test_fcb_area;
+
+    rc = fcb_init(fcb);
+    TEST_ASSERT(rc == 0);
+
+    old_id = fcb->f_active_id;
+    rc = fcb_rotate(fcb);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(fcb->f_active_id == old_id + 1);
+
+    /*
+     * Now fill up the
+     */
+    while (1) {
+        rc = fcb_append(fcb, sizeof(test_data), &loc);
+        if (rc == FCB_ERR_NOSPACE) {
+            break;
+        }
+        if (loc.fe_area == &test_fcb_area[0]) {
+            elem_cnts[0]++;
+        } else if (loc.fe_area == &test_fcb_area[1]) {
+            elem_cnts[1]++;
+        } else {
+            TEST_ASSERT(0);
+        }
+
+        rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
+          sizeof(test_data));
+        TEST_ASSERT(rc == 0);
+
+        rc = fcb_append_finish(fcb, &loc);
+        TEST_ASSERT(rc == 0);
+    }
+    TEST_ASSERT(elem_cnts[0] > 0 && elem_cnts[0] == elem_cnts[1]);
+
+    old_id = fcb->f_active_id;
+    rc = fcb_rotate(fcb);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(fcb->f_active_id == old_id); /* no new area created */
+
+    memset(cnts, 0, sizeof(cnts));
+    rc = fcb_walk(fcb, NULL, fcb_test_cnt_elems_cb, &aa_arg);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(aa_arg.elem_cnts[0] == elem_cnts[0] ||
+      aa_arg.elem_cnts[1] == elem_cnts[1]);
+    TEST_ASSERT(aa_arg.elem_cnts[0] == 0 || aa_arg.elem_cnts[1] == 0);
+
+    /*
+     * One sector is full. The other one should have one entry in it.
+     */
+    rc = fcb_append(fcb, sizeof(test_data), &loc);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_write(loc.fe_area, loc.fe_data_off, test_data,
+      sizeof(test_data));
+    TEST_ASSERT(rc == 0);
+
+    rc = fcb_append_finish(fcb, &loc);
+    TEST_ASSERT(rc == 0);
+
+    old_id = fcb->f_active_id;
+    rc = fcb_rotate(fcb);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(fcb->f_active_id == old_id);
+
+    memset(cnts, 0, sizeof(cnts));
+    rc = fcb_walk(fcb, NULL, fcb_test_cnt_elems_cb, &aa_arg);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(aa_arg.elem_cnts[0] == 1 || aa_arg.elem_cnts[1] == 1);
+    TEST_ASSERT(aa_arg.elem_cnts[0] == 0 || aa_arg.elem_cnts[1] == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/src/nffs_priv.h
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_priv.h b/fs/nffs/src/nffs_priv.h
index 360194d..0de4420 100644
--- a/fs/nffs/src/nffs_priv.h
+++ b/fs/nffs/src/nffs_priv.h
@@ -511,6 +511,7 @@ int nffs_write_to_file(struct nffs_file *file, const void *data, int len);
 
 #define NFFS_FLASH_LOC_NONE  nffs_flash_loc(NFFS_AREA_ID_NONE, 0)
 
+#if 0
 #ifdef ARCH_sim
 #include <stdio.h>
 #define NFFS_LOG(lvl, ...) \
@@ -519,6 +520,10 @@ int nffs_write_to_file(struct nffs_file *file, const void *data, int len);
 #define NFFS_LOG(lvl, ...) \
     LOG_ ## lvl(&nffs_log, LOG_MODULE_NFFS, __VA_ARGS__)
 #endif
+#endif /* 0 */
+
+#define NFFS_LOG(lvl, ...) \
+    LOG_ ## lvl(&nffs_log, LOG_MODULE_NFFS, __VA_ARGS__)
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/syscfg.yml
----------------------------------------------------------------------
diff --git a/fs/nffs/syscfg.yml b/fs/nffs/syscfg.yml
index 657ab0c..98451b0 100644
--- a/fs/nffs/syscfg.yml
+++ b/fs/nffs/syscfg.yml
@@ -7,6 +7,7 @@ syscfg.defs:
         value:
         restrictions:
             - $notnull
+
     NFFS_DETECT_FAIL:
         description: 'TBD'
         value: 'NFFS_DETECT_FAIL_FORMAT'

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/arch/cortex_m4/nffs_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/arch/cortex_m4/nffs_test.c b/fs/nffs/test/src/arch/cortex_m4/nffs_test.c
deleted file mode 100644
index 654089b..0000000
--- a/fs/nffs/test/src/arch/cortex_m4/nffs_test.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * 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 "nffs/nffs_test.h"
-
-int
-nffs_test_all(void)
-{
-    return 0;
-}



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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/arch/sim/nffs_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/arch/sim/nffs_test.c b/fs/nffs/test/src/arch/sim/nffs_test.c
deleted file mode 100644
index 87afcfa..0000000
--- a/fs/nffs/test/src/arch/sim/nffs_test.c
+++ /dev/null
@@ -1,3251 +0,0 @@
-/**
- * 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 <stdlib.h>
-#include <errno.h>
-#include "syscfg/syscfg.h"
-#include "hal/hal_flash.h"
-#include "testutil/testutil.h"
-#include "fs/fs.h"
-#include "nffs/nffs.h"
-#include "nffs/nffs_test.h"
-#include "nffs_test_priv.h"
-#include "nffs_priv.h"
-
-int flash_native_memset(uint32_t offset, uint8_t c, uint32_t len);
-
-static const struct nffs_area_desc nffs_area_descs[] = {
-        { 0x00000000, 16 * 1024 },
-        { 0x00004000, 16 * 1024 },
-        { 0x00008000, 16 * 1024 },
-        { 0x0000c000, 16 * 1024 },
-        { 0x00010000, 64 * 1024 },
-        { 0x00020000, 128 * 1024 },
-        { 0x00040000, 128 * 1024 },
-        { 0x00060000, 128 * 1024 },
-        { 0x00080000, 128 * 1024 },
-        { 0x000a0000, 128 * 1024 },
-        { 0x000c0000, 128 * 1024 },
-        { 0x000e0000, 128 * 1024 },
-        { 0, 0 },
-};
-
-static void
-nffs_test_util_assert_ent_name(struct fs_dirent *dirent,
-                               const char *expected_name)
-{
-    char name[NFFS_FILENAME_MAX_LEN + 1];
-    uint8_t name_len;
-    int rc;
-
-    rc = fs_dirent_name(dirent, sizeof name, name, &name_len);
-    TEST_ASSERT(rc == 0);
-    if (rc == 0) {
-        TEST_ASSERT(strcmp(name, expected_name) == 0);
-    }
-}
-
-static void
-nffs_test_util_assert_file_len(struct fs_file *file, uint32_t expected)
-{
-    uint32_t len;
-    int rc;
-
-    rc = fs_filelen(file, &len);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(len == expected);
-}
-
-static void
-nffs_test_util_assert_cache_is_sane(const char *filename)
-{
-    struct nffs_cache_inode *cache_inode;
-    struct nffs_cache_block *cache_block;
-    struct fs_file *fs_file;
-    struct nffs_file *file;
-    uint32_t cache_start;
-    uint32_t cache_end;
-    uint32_t block_end;
-    int rc;
-
-    rc = fs_open(filename, FS_ACCESS_READ, &fs_file);
-    TEST_ASSERT(rc == 0);
-
-    file = (struct nffs_file *)fs_file;
-    rc = nffs_cache_inode_ensure(&cache_inode, file->nf_inode_entry);
-    TEST_ASSERT(rc == 0);
-
-    nffs_cache_inode_range(cache_inode, &cache_start, &cache_end);
-
-    if (TAILQ_EMPTY(&cache_inode->nci_block_list)) {
-        TEST_ASSERT(cache_start == 0 && cache_end == 0);
-    } else {
-        block_end = 0;  /* Pacify gcc. */
-        TAILQ_FOREACH(cache_block, &cache_inode->nci_block_list, ncb_link) {
-            if (cache_block == TAILQ_FIRST(&cache_inode->nci_block_list)) {
-                TEST_ASSERT(cache_block->ncb_file_offset == cache_start);
-            } else {
-                /* Ensure no gap between this block and its predecessor. */
-                TEST_ASSERT(cache_block->ncb_file_offset == block_end);
-            }
-
-            block_end = cache_block->ncb_file_offset +
-                        cache_block->ncb_block.nb_data_len;
-            if (cache_block == TAILQ_LAST(&cache_inode->nci_block_list,
-                                          nffs_cache_block_list)) {
-
-                TEST_ASSERT(block_end == cache_end);
-            }
-        }
-    }
-
-    rc = fs_close(fs_file);
-    TEST_ASSERT(rc == 0);
-}
-
-static void
-nffs_test_util_assert_contents(const char *filename, const char *contents,
-                               int contents_len)
-{
-    struct fs_file *file;
-    uint32_t bytes_read;
-    void *buf;
-    int rc;
-
-    rc = fs_open(filename, FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == 0);
-
-    buf = malloc(contents_len + 1);
-    TEST_ASSERT(buf != NULL);
-
-    rc = fs_read(file, contents_len + 1, buf, &bytes_read);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(bytes_read == contents_len);
-    TEST_ASSERT(memcmp(buf, contents, contents_len) == 0);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    free(buf);
-
-    nffs_test_util_assert_cache_is_sane(filename);
-}
-
-static int
-nffs_test_util_block_count(const char *filename)
-{
-    struct nffs_hash_entry *entry;
-    struct nffs_block block;
-    struct nffs_file *file;
-    struct fs_file *fs_file;
-    int count;
-    int rc;
-
-    rc = fs_open(filename, FS_ACCESS_READ, &fs_file);
-    TEST_ASSERT(rc == 0);
-
-    file = (struct nffs_file *)fs_file;
-    count = 0;
-    entry = file->nf_inode_entry->nie_last_block_entry;
-    while (entry != NULL) {
-        count++;
-        rc = nffs_block_from_hash_entry(&block, entry);
-        TEST_ASSERT(rc == 0);
-        TEST_ASSERT(block.nb_prev != entry);
-        entry = block.nb_prev;
-    }
-
-    rc = fs_close(fs_file);
-    TEST_ASSERT(rc == 0);
-
-    return count;
-}
-
-static void
-nffs_test_util_assert_block_count(const char *filename, int expected_count)
-{
-    int actual_count;
-
-    actual_count = nffs_test_util_block_count(filename);
-    TEST_ASSERT(actual_count == expected_count);
-}
-
-static void
-nffs_test_util_assert_cache_range(const char *filename,
-                                 uint32_t expected_cache_start,
-                                 uint32_t expected_cache_end)
-{
-    struct nffs_cache_inode *cache_inode;
-    struct nffs_file *file;
-    struct fs_file *fs_file;
-    uint32_t cache_start;
-    uint32_t cache_end;
-    int rc;
-
-    rc = fs_open(filename, FS_ACCESS_READ, &fs_file);
-    TEST_ASSERT(rc == 0);
-
-    file = (struct nffs_file *)fs_file;
-    rc = nffs_cache_inode_ensure(&cache_inode, file->nf_inode_entry);
-    TEST_ASSERT(rc == 0);
-
-    nffs_cache_inode_range(cache_inode, &cache_start, &cache_end);
-    TEST_ASSERT(cache_start == expected_cache_start);
-    TEST_ASSERT(cache_end == expected_cache_end);
-
-    rc = fs_close(fs_file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_cache_is_sane(filename);
-}
-
-static void
-nffs_test_util_create_file_blocks(const char *filename,
-                                 const struct nffs_test_block_desc *blocks,
-                                 int num_blocks)
-{
-    struct fs_file *file;
-    uint32_t total_len;
-    uint32_t offset;
-    char *buf;
-    int num_writes;
-    int rc;
-    int i;
-
-    rc = fs_open(filename, FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file);
-    TEST_ASSERT(rc == 0);
-
-    total_len = 0;
-    if (num_blocks <= 0) {
-        num_writes = 1;
-    } else {
-        num_writes = num_blocks;
-    }
-    for (i = 0; i < num_writes; i++) {
-        rc = fs_write(file, blocks[i].data, blocks[i].data_len);
-        TEST_ASSERT(rc == 0);
-
-        total_len += blocks[i].data_len;
-    }
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    buf = malloc(total_len);
-    TEST_ASSERT(buf != NULL);
-
-    offset = 0;
-    for (i = 0; i < num_writes; i++) {
-        memcpy(buf + offset, blocks[i].data, blocks[i].data_len);
-        offset += blocks[i].data_len;
-    }
-    TEST_ASSERT(offset == total_len);
-
-    nffs_test_util_assert_contents(filename, buf, total_len);
-    if (num_blocks > 0) {
-        nffs_test_util_assert_block_count(filename, num_blocks);
-    }
-
-    free(buf);
-}
-
-static void
-nffs_test_util_create_file(const char *filename, const char *contents,
-                           int contents_len)
-{
-    struct nffs_test_block_desc block;
-
-    block.data = contents;
-    block.data_len = contents_len;
-
-    nffs_test_util_create_file_blocks(filename, &block, 0);
-}
-
-static void
-nffs_test_util_append_file(const char *filename, const char *contents,
-                           int contents_len)
-{
-    struct fs_file *file;
-    int rc;
-
-    rc = fs_open(filename, FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_write(file, contents, contents_len);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-}
-
-static void
-nffs_test_copy_area(const struct nffs_area_desc *from,
-                    const struct nffs_area_desc *to)
-{
-    void *buf;
-    int rc;
-
-    TEST_ASSERT(from->nad_length == to->nad_length);
-
-    buf = malloc(from->nad_length);
-    TEST_ASSERT(buf != NULL);
-
-    rc = hal_flash_read(from->nad_flash_id, from->nad_offset, buf,
-                        from->nad_length);
-    TEST_ASSERT(rc == 0);
-
-    rc = hal_flash_erase(from->nad_flash_id, to->nad_offset, to->nad_length);
-    TEST_ASSERT(rc == 0);
-
-    rc = hal_flash_write(to->nad_flash_id, to->nad_offset, buf, to->nad_length);
-    TEST_ASSERT(rc == 0);
-
-    free(buf);
-}
-
-static void
-nffs_test_util_create_subtree(const char *parent_path,
-                             const struct nffs_test_file_desc *elem)
-{
-    char *path;
-    int rc;
-    int i;
-
-    if (parent_path == NULL) {
-        path = malloc(1);
-        TEST_ASSERT(path != NULL);
-        path[0] = '\0';
-    } else {
-        path = malloc(strlen(parent_path) + 1 + strlen(elem->filename) + 1);
-        TEST_ASSERT(path != NULL);
-
-        sprintf(path, "%s/%s", parent_path, elem->filename);
-    }
-
-    if (elem->is_dir) {
-        if (parent_path != NULL) {
-            rc = fs_mkdir(path);
-            TEST_ASSERT(rc == 0);
-        }
-
-        if (elem->children != NULL) {
-            for (i = 0; elem->children[i].filename != NULL; i++) {
-                nffs_test_util_create_subtree(path, elem->children + i);
-            }
-        }
-    } else {
-        nffs_test_util_create_file(path, elem->contents, elem->contents_len);
-    }
-
-    free(path);
-}
-
-static void
-nffs_test_util_create_tree(const struct nffs_test_file_desc *root_dir)
-{
-    nffs_test_util_create_subtree(NULL, root_dir);
-}
-
-#define NFFS_TEST_TOUCHED_ARR_SZ     (16 * 1024)
-static struct nffs_hash_entry
-    *nffs_test_touched_entries[NFFS_TEST_TOUCHED_ARR_SZ];
-static int nffs_test_num_touched_entries;
-
-/*
- * Recursively descend directory structure
- */
-static void
-nffs_test_assert_file(const struct nffs_test_file_desc *file,
-                     struct nffs_inode_entry *inode_entry,
-                     const char *path)
-{
-    const struct nffs_test_file_desc *child_file;
-    struct nffs_inode inode;
-    struct nffs_inode_entry *child_inode_entry;
-    char *child_path;
-    int child_filename_len;
-    int path_len;
-    int rc;
-
-    /*
-     * track of hash entries that have been examined
-     */
-    TEST_ASSERT(nffs_test_num_touched_entries < NFFS_TEST_TOUCHED_ARR_SZ);
-    nffs_test_touched_entries[nffs_test_num_touched_entries] =
-        &inode_entry->nie_hash_entry;
-    nffs_test_num_touched_entries++;
-
-    path_len = strlen(path);
-
-    rc = nffs_inode_from_entry(&inode, inode_entry);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * recursively examine each child of directory
-     */
-    if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
-        for (child_file = file->children;
-             child_file != NULL && child_file->filename != NULL;
-             child_file++) {
-
-            /*
-             * Construct full pathname for file
-             * Not null terminated
-             */
-            child_filename_len = strlen(child_file->filename);
-            child_path = malloc(path_len + 1 + child_filename_len + 1);
-            TEST_ASSERT(child_path != NULL);
-            memcpy(child_path, path, path_len);
-            child_path[path_len] = '/';
-            memcpy(child_path + path_len + 1, child_file->filename,
-                   child_filename_len);
-            child_path[path_len + 1 + child_filename_len] = '\0';
-
-            /*
-             * Verify child inode can be found using full pathname
-             */
-            rc = nffs_path_find_inode_entry(child_path, &child_inode_entry);
-            if (rc != 0) {
-                TEST_ASSERT(rc == 0);
-            }
-
-            nffs_test_assert_file(child_file, child_inode_entry, child_path);
-
-            free(child_path);
-        }
-    } else {
-        nffs_test_util_assert_contents(path, file->contents,
-                                       file->contents_len);
-    }
-}
-
-static void
-nffs_test_assert_branch_touched(struct nffs_inode_entry *inode_entry)
-{
-    struct nffs_inode_entry *child;
-    int i;
-
-    if (inode_entry == nffs_lost_found_dir) {
-        return;
-    }
-
-    for (i = 0; i < nffs_test_num_touched_entries; i++) {
-        if (nffs_test_touched_entries[i] == &inode_entry->nie_hash_entry) {
-            break;
-        }
-    }
-    TEST_ASSERT(i < nffs_test_num_touched_entries);
-    nffs_test_touched_entries[i] = NULL;
-
-    if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
-        SLIST_FOREACH(child, &inode_entry->nie_child_list, nie_sibling_next) {
-            nffs_test_assert_branch_touched(child);
-        }
-    }
-}
-
-static void
-nffs_test_assert_child_inode_present(struct nffs_inode_entry *child)
-{
-    const struct nffs_inode_entry *inode_entry;
-    const struct nffs_inode_entry *parent;
-    struct nffs_inode inode;
-    int rc;
-
-    /*
-     * Sucessfully read inode data from flash
-     */
-    rc = nffs_inode_from_entry(&inode, child);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Validate parent
-     */
-    parent = inode.ni_parent;
-    TEST_ASSERT(parent != NULL);
-    TEST_ASSERT(nffs_hash_id_is_dir(parent->nie_hash_entry.nhe_id));
-
-    /*
-     * Make sure inode is in parents child list
-     */
-    SLIST_FOREACH(inode_entry, &parent->nie_child_list, nie_sibling_next) {
-        if (inode_entry == child) {
-            return;
-        }
-    }
-
-    TEST_ASSERT(0);
-}
-
-static void
-nffs_test_assert_block_present(struct nffs_hash_entry *block_entry)
-{
-    const struct nffs_inode_entry *inode_entry;
-    struct nffs_hash_entry *cur;
-    struct nffs_block block;
-    int rc;
-
-    /*
-     * Successfully read block data from flash
-     */
-    rc = nffs_block_from_hash_entry(&block, block_entry);
-    TEST_ASSERT(rc == 0);
-
-    /*
-     * Validate owning inode
-     */
-    inode_entry = block.nb_inode_entry;
-    TEST_ASSERT(inode_entry != NULL);
-    TEST_ASSERT(nffs_hash_id_is_file(inode_entry->nie_hash_entry.nhe_id));
-
-    /*
-     * Validate that block is in owning inode's block chain
-     */
-    cur = inode_entry->nie_last_block_entry;
-    while (cur != NULL) {
-        if (cur == block_entry) {
-            return;
-        }
-
-        rc = nffs_block_from_hash_entry(&block, cur);
-        TEST_ASSERT(rc == 0);
-        cur = block.nb_prev;
-    }
-
-    TEST_ASSERT(0);
-}
-
-/*
- * Recursively verify that the children of each directory are sorted
- * on the directory children linked list by filename length
- */
-static void
-nffs_test_assert_children_sorted(struct nffs_inode_entry *inode_entry)
-{
-    struct nffs_inode_entry *child_entry;
-    struct nffs_inode_entry *prev_entry;
-    struct nffs_inode child_inode;
-    struct nffs_inode prev_inode;
-    int cmp;
-    int rc;
-
-    prev_entry = NULL;
-    SLIST_FOREACH(child_entry, &inode_entry->nie_child_list,
-                  nie_sibling_next) {
-        rc = nffs_inode_from_entry(&child_inode, child_entry);
-        TEST_ASSERT(rc == 0);
-
-        if (prev_entry != NULL) {
-            rc = nffs_inode_from_entry(&prev_inode, prev_entry);
-            TEST_ASSERT(rc == 0);
-
-            rc = nffs_inode_filename_cmp_flash(&prev_inode, &child_inode,
-                                               &cmp);
-            TEST_ASSERT(rc == 0);
-            TEST_ASSERT(cmp < 0);
-        }
-
-        if (nffs_hash_id_is_dir(child_entry->nie_hash_entry.nhe_id)) {
-            nffs_test_assert_children_sorted(child_entry);
-        }
-
-        prev_entry = child_entry;
-    }
-}
-
-static void
-nffs_test_assert_system_once(const struct nffs_test_file_desc *root_dir)
-{
-    struct nffs_inode_entry *inode_entry;
-    struct nffs_hash_entry *entry;
-    struct nffs_hash_entry *next;
-    int i;
-
-    nffs_test_num_touched_entries = 0;
-    nffs_test_assert_file(root_dir, nffs_root_dir, "");
-    nffs_test_assert_branch_touched(nffs_root_dir);
-
-    /* Ensure no orphaned inodes or blocks. */
-    NFFS_HASH_FOREACH(entry, i, next) {
-        TEST_ASSERT(entry->nhe_flash_loc != NFFS_FLASH_LOC_NONE);
-        if (nffs_hash_id_is_inode(entry->nhe_id)) {
-            inode_entry = (void *)entry;
-            TEST_ASSERT(inode_entry->nie_refcnt == 1);
-            if (entry->nhe_id == NFFS_ID_ROOT_DIR) {
-                TEST_ASSERT(inode_entry == nffs_root_dir);
-            } else {
-                nffs_test_assert_child_inode_present(inode_entry);
-            }
-        } else {
-            nffs_test_assert_block_present(entry);
-        }
-    }
-
-    /* Ensure proper sorting. */
-    nffs_test_assert_children_sorted(nffs_root_dir);
-}
-
-static void
-nffs_test_assert_system(const struct nffs_test_file_desc *root_dir,
-                        const struct nffs_area_desc *area_descs)
-{
-    int rc;
-
-    /* Ensure files are as specified, and that there are no other files or
-     * orphaned inodes / blocks.
-     */
-    nffs_test_assert_system_once(root_dir);
-
-    /* Force a garbage collection cycle. */
-    rc = nffs_gc(NULL);
-    TEST_ASSERT(rc == 0);
-
-    /* Ensure file system is still as expected. */
-    nffs_test_assert_system_once(root_dir);
-
-    /* Clear cached data and restore from flash (i.e, simulate a reboot). */
-    rc = nffs_misc_reset();
-    TEST_ASSERT(rc == 0);
-    rc = nffs_detect(area_descs);
-    TEST_ASSERT(rc == 0);
-
-    /* Ensure file system is still as expected. */
-    nffs_test_assert_system_once(root_dir);
-}
-
-static void
-nffs_test_assert_area_seqs(int seq1, int count1, int seq2, int count2)
-{
-    struct nffs_disk_area disk_area;
-    int cur1;
-    int cur2;
-    int rc;
-    int i;
-
-    cur1 = 0;
-    cur2 = 0;
-
-    for (i = 0; i < nffs_num_areas; i++) {
-        rc = nffs_flash_read(i, 0, &disk_area, sizeof disk_area);
-        TEST_ASSERT(rc == 0);
-        TEST_ASSERT(nffs_area_magic_is_set(&disk_area));
-        TEST_ASSERT(disk_area.nda_gc_seq == nffs_areas[i].na_gc_seq);
-        if (i == nffs_scratch_area_idx) {
-            TEST_ASSERT(disk_area.nda_id == NFFS_AREA_ID_NONE);
-        }
-
-        if (nffs_areas[i].na_gc_seq == seq1) {
-            cur1++;
-        } else if (nffs_areas[i].na_gc_seq == seq2) {
-            cur2++;
-        } else {
-            TEST_ASSERT(0);
-        }
-    }
-
-    TEST_ASSERT(cur1 == count1 && cur2 == count2);
-}
-
-static void
-nffs_test_mkdir(void)
-{
-    struct fs_file *file;
-    int rc;
-
-
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/a/b/c/d");
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    rc = fs_mkdir("asdf");
-    TEST_ASSERT(rc == FS_EINVAL);
-
-    rc = fs_mkdir("/a");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/a/b");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/a/b/c");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/a/b/c/d");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_open("/a/b/c/d/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "a",
-                .is_dir = 1,
-                .children = (struct nffs_test_file_desc[]) { {
-                    .filename = "b",
-                    .is_dir = 1,
-                    .children = (struct nffs_test_file_desc[]) { {
-                        .filename = "c",
-                        .is_dir = 1,
-                        .children = (struct nffs_test_file_desc[]) { {
-                            .filename = "d",
-                            .is_dir = 1,
-                            .children = (struct nffs_test_file_desc[]) { {
-                                .filename = "myfile.txt",
-                                .contents = NULL,
-                                .contents_len = 0,
-                            }, {
-                                .filename = NULL,
-                            } },
-                        }, {
-                            .filename = NULL,
-                        } },
-                    }, {
-                        .filename = NULL,
-                    } },
-                }, {
-                    .filename = NULL,
-                } },
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_unlink)
-{
-    struct fs_file *file0;
-    struct fs_file *file1;
-    struct fs_file *file2;
-    struct nffs_file *nfs_file;
-    uint8_t buf[64];
-    uint32_t bytes_read;
-    int initial_num_blocks;
-    int initial_num_inodes;
-    int rc;
-
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    initial_num_blocks = nffs_block_entry_pool.mp_num_free;
-    initial_num_inodes = nffs_inode_entry_pool.mp_num_free;
-
-    nffs_test_util_create_file("/file0.txt", "0", 1);
-
-    rc = fs_open("/file0.txt", FS_ACCESS_READ | FS_ACCESS_WRITE, &file0);
-    TEST_ASSERT(rc == 0);
-    nfs_file = (struct nffs_file *)file0;
-    TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 2);
-
-    rc = fs_unlink("/file0.txt");
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 1);
-
-    rc = fs_open("/file0.txt", FS_ACCESS_READ, &file2);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    rc = fs_write(file0, "00", 2);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_seek(file0, 0);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_read(file0, sizeof buf, buf, &bytes_read);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(bytes_read == 2);
-    TEST_ASSERT(memcmp(buf, "00", 2) == 0);
-
-    rc = fs_close(file0);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_open("/file0.txt", FS_ACCESS_READ, &file0);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    /* Ensure the file was fully removed from RAM. */
-    TEST_ASSERT(nffs_inode_entry_pool.mp_num_free == initial_num_inodes);
-    TEST_ASSERT(nffs_block_entry_pool.mp_num_free == initial_num_blocks);
-
-    /*** Nested unlink. */
-    rc = fs_mkdir("/mydir");
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_create_file("/mydir/file1.txt", "1", 2);
-
-    rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ | FS_ACCESS_WRITE, &file1);
-    TEST_ASSERT(rc == 0);
-    nfs_file = (struct nffs_file *)file1;
-    TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 2);
-
-    rc = fs_unlink("/mydir");
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 1);
-
-    rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ, &file2);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    rc = fs_write(file1, "11", 2);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_seek(file1, 0);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_read(file1, sizeof buf, buf, &bytes_read);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(bytes_read == 2);
-    TEST_ASSERT(memcmp(buf, "11", 2) == 0);
-
-    rc = fs_close(file1);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ, &file1);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-
-    /* Ensure the files and directories were fully removed from RAM. */
-    TEST_ASSERT(nffs_inode_entry_pool.mp_num_free == initial_num_inodes);
-    TEST_ASSERT(nffs_block_entry_pool.mp_num_free == initial_num_blocks);
-}
-
-TEST_CASE(nffs_test_rename)
-{
-    struct fs_file *file;
-    const char contents[] = "contents";
-    int rc;
-
-
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_rename("/nonexistent.txt", "/newname.txt");
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    /*** Rename file. */
-    nffs_test_util_create_file("/myfile.txt", contents, sizeof contents);
-
-    rc = fs_rename("/myfile.txt", "badname");
-    TEST_ASSERT(rc == FS_EINVAL);
-
-    rc = fs_rename("/myfile.txt", "/myfile2.txt");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_open("/myfile.txt", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    nffs_test_util_assert_contents("/myfile2.txt", contents, sizeof contents);
-
-    rc = fs_mkdir("/mydir");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/mydir/leafdir");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_rename("/myfile2.txt", "/mydir/myfile2.txt");
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/mydir/myfile2.txt", contents,
-                                  sizeof contents);
-
-    /*** Rename directory. */
-    rc = fs_rename("/mydir", "badname");
-    TEST_ASSERT(rc == FS_EINVAL);
-
-    /* Don't allow a directory to be moved into a descendent directory. */
-    rc = fs_rename("/mydir", "/mydir/leafdir/a");
-    TEST_ASSERT(rc == FS_EINVAL);
-
-    rc = fs_rename("/mydir", "/mydir2");
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/mydir2/myfile2.txt", contents,
-                                  sizeof contents);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "mydir2",
-                .is_dir = 1,
-                .children = (struct nffs_test_file_desc[]) { {
-                    .filename = "leafdir",
-                    .is_dir = 1,
-                }, {
-                    .filename = "myfile2.txt",
-                    .contents = "contents",
-                    .contents_len = 9,
-                }, {
-                    .filename = NULL,
-                } },
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_truncate)
-{
-    struct fs_file *file;
-    int rc;
-
-
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 0);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "abcdefgh", 8);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 8);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt", "abcdefgh", 8);
-
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 0);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "1234", 4);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 4);
-    TEST_ASSERT(fs_getpos(file) == 4);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt", "1234", 4);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = "1234",
-                .contents_len = 4,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_append)
-{
-    struct fs_file *file;
-    uint32_t len;
-    char c;
-    int rc;
-    int i;
-
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 0);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "abcdefgh", 8);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 8);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt", "abcdefgh", 8);
-
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 8);
-
-    /* File position should always be at the end of a file after an append.
-     * Seek to the middle prior to writing to test this.
-     */
-    rc = fs_seek(file, 2);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 2);
-
-    rc = fs_write(file, "ijklmnop", 8);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 16);
-    rc = fs_write(file, "qrstuvwx", 8);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 24);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt",
-                                  "abcdefghijklmnopqrstuvwx", 24);
-
-    rc = fs_mkdir("/mydir");
-    TEST_ASSERT_FATAL(rc == 0);
-    rc = fs_open("/mydir/gaga.txt", FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    /*** Repeated appends to a large file. */
-    for (i = 0; i < 1000; i++) {
-        rc = fs_filelen(file, &len);
-        TEST_ASSERT_FATAL(rc == 0);
-        TEST_ASSERT(len == i);
-
-        c = '0' + i % 10;
-        rc = fs_write(file, &c, 1);
-        TEST_ASSERT_FATAL(rc == 0);
-    }
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/mydir/gaga.txt",
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789"
-        "01234567890123456789012345678901234567890123456789",
-        1000);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = "abcdefghijklmnopqrstuvwx",
-                .contents_len = 24,
-            }, {
-                .filename = "mydir",
-                .is_dir = 1,
-                .children = (struct nffs_test_file_desc[]) { {
-                    .filename = "gaga.txt",
-                    .contents =
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    "01234567890123456789012345678901234567890123456789"
-    ,
-                    .contents_len = 1000,
-                }, {
-                    .filename = NULL,
-                } },
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_read)
-{
-    struct fs_file *file;
-    uint8_t buf[16];
-    uint32_t bytes_read;
-    int rc;
-
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file("/myfile.txt", "1234567890", 10);
-
-    rc = fs_open("/myfile.txt", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 10);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_read(file, 4, buf, &bytes_read);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(bytes_read == 4);
-    TEST_ASSERT(memcmp(buf, "1234", 4) == 0);
-    TEST_ASSERT(fs_getpos(file) == 4);
-
-    rc = fs_read(file, sizeof buf - 4, buf + 4, &bytes_read);
-    TEST_ASSERT(rc == 0);
-    TEST_ASSERT(bytes_read == 6);
-    TEST_ASSERT(memcmp(buf, "1234567890", 10) == 0);
-    TEST_ASSERT(fs_getpos(file) == 10);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(nffs_test_open)
-{
-    struct fs_file *file;
-    struct fs_dir *dir;
-    int rc;
-
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    /*** Fail to open an invalid path (not rooted). */
-    rc = fs_open("file", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == FS_EINVAL);
-
-    /*** Fail to open a directory (root directory). */
-    rc = fs_open("/", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == FS_EINVAL);
-
-    /*** Fail to open a nonexistent file for reading. */
-    rc = fs_open("/1234", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    /*** Fail to open a child of a nonexistent directory. */
-    rc = fs_open("/dir/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == FS_ENOENT);
-    rc = fs_opendir("/dir", &dir);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    rc = fs_mkdir("/dir");
-    TEST_ASSERT(rc == 0);
-
-    /*** Fail to open a directory. */
-    rc = fs_open("/dir", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == FS_EINVAL);
-
-    /*** Successfully open an existing file for reading. */
-    nffs_test_util_create_file("/dir/file.txt", "1234567890", 10);
-    rc = fs_open("/dir/file.txt", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == 0);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    /*** Successfully open an nonexistent file for writing. */
-    rc = fs_open("/dir/file2.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    /*** Ensure the file can be reopened. */
-    rc = fs_open("/dir/file.txt", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == 0);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(nffs_test_overwrite_one)
-{
-    struct fs_file *file;
-    int rc;
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_append_file("/myfile.txt", "abcdefgh", 8);
-
-    /*** Overwrite within one block (middle). */
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 3);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 3);
-
-    rc = fs_write(file, "12", 2);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 5);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt", "abc12fgh", 8);
-    nffs_test_util_assert_block_count("/myfile.txt", 1);
-
-    /*** Overwrite within one block (start). */
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "xy", 2);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 2);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt", "xyc12fgh", 8);
-    nffs_test_util_assert_block_count("/myfile.txt", 1);
-
-    /*** Overwrite within one block (end). */
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 6);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 6);
-
-    rc = fs_write(file, "<>", 2);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 8);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt", "xyc12f<>", 8);
-    nffs_test_util_assert_block_count("/myfile.txt", 1);
-
-    /*** Overwrite one block middle, extend. */
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 4);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 8);
-    TEST_ASSERT(fs_getpos(file) == 4);
-
-    rc = fs_write(file, "abcdefgh", 8);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 12);
-    TEST_ASSERT(fs_getpos(file) == 12);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt", "xyc1abcdefgh", 12);
-    nffs_test_util_assert_block_count("/myfile.txt", 1);
-
-    /*** Overwrite one block start, extend. */
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 12);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "abcdefghijklmnop", 16);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 16);
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents("/myfile.txt", "abcdefghijklmnop", 16);
-    nffs_test_util_assert_block_count("/myfile.txt", 1);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = "abcdefghijklmnop",
-                .contents_len = 16,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_overwrite_two)
-{
-    struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { {
-        .data = "abcdefgh",
-        .data_len = 8,
-    }, {
-        .data = "ijklmnop",
-        .data_len = 8,
-    } };
-
-    struct fs_file *file;
-    int rc;
-
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    /*** Overwrite two blocks (middle). */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 7);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 7);
-
-    rc = fs_write(file, "123", 3);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 10);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt", "abcdefg123klmnop", 16);
-    nffs_test_util_assert_block_count("/myfile.txt", 2);
-
-    /*** Overwrite two blocks (start). */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "ABCDEFGHIJ", 10);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 10);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt", "ABCDEFGHIJklmnop", 16);
-    nffs_test_util_assert_block_count("/myfile.txt", 2);
-
-    /*** Overwrite two blocks (end). */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 6);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 6);
-
-    rc = fs_write(file, "1234567890", 10);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 16);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt", "abcdef1234567890", 16);
-    nffs_test_util_assert_block_count("/myfile.txt", 2);
-
-    /*** Overwrite two blocks middle, extend. */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 6);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 6);
-
-    rc = fs_write(file, "1234567890!@#$", 14);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 20);
-    TEST_ASSERT(fs_getpos(file) == 20);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt", "abcdef1234567890!@#$", 20);
-    nffs_test_util_assert_block_count("/myfile.txt", 2);
-
-    /*** Overwrite two blocks start, extend. */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 16);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "1234567890!@#$%^&*()", 20);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 20);
-    TEST_ASSERT(fs_getpos(file) == 20);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt", "1234567890!@#$%^&*()", 20);
-    nffs_test_util_assert_block_count("/myfile.txt", 2);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = "1234567890!@#$%^&*()",
-                .contents_len = 20,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_overwrite_three)
-{
-    struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { {
-        .data = "abcdefgh",
-        .data_len = 8,
-    }, {
-        .data = "ijklmnop",
-        .data_len = 8,
-    }, {
-        .data = "qrstuvwx",
-        .data_len = 8,
-    } };
-
-    struct fs_file *file;
-    int rc;
-
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    /*** Overwrite three blocks (middle). */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 6);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 6);
-
-    rc = fs_write(file, "1234567890!@", 12);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 18);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt",
-                                   "abcdef1234567890!@stuvwx", 24);
-    nffs_test_util_assert_block_count("/myfile.txt", 3);
-
-    /*** Overwrite three blocks (start). */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "1234567890!@#$%^&*()", 20);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 20);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt",
-                                   "1234567890!@#$%^&*()uvwx", 24);
-    nffs_test_util_assert_block_count("/myfile.txt", 3);
-
-    /*** Overwrite three blocks (end). */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 6);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 6);
-
-    rc = fs_write(file, "1234567890!@#$%^&*", 18);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 24);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt",
-                                   "abcdef1234567890!@#$%^&*", 24);
-    nffs_test_util_assert_block_count("/myfile.txt", 3);
-
-    /*** Overwrite three blocks middle, extend. */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 6);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 6);
-
-    rc = fs_write(file, "1234567890!@#$%^&*()", 20);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 26);
-    TEST_ASSERT(fs_getpos(file) == 26);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt",
-                                   "abcdef1234567890!@#$%^&*()", 26);
-    nffs_test_util_assert_block_count("/myfile.txt", 3);
-
-    /*** Overwrite three blocks start, extend. */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_write(file, "1234567890!@#$%^&*()abcdefghij", 30);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 30);
-    TEST_ASSERT(fs_getpos(file) == 30);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt",
-                                   "1234567890!@#$%^&*()abcdefghij", 30);
-    nffs_test_util_assert_block_count("/myfile.txt", 3);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = "1234567890!@#$%^&*()abcdefghij",
-                .contents_len = 30,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_overwrite_many)
-{
-    struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { {
-        .data = "abcdefgh",
-        .data_len = 8,
-    }, {
-        .data = "ijklmnop",
-        .data_len = 8,
-    }, {
-        .data = "qrstuvwx",
-        .data_len = 8,
-    } };
-
-    struct fs_file *file;
-    int rc;
-
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    /*** Overwrite middle of first block. */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 3);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 3);
-
-    rc = fs_write(file, "12", 2);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 5);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt",
-                                   "abc12fghijklmnopqrstuvwx", 24);
-    nffs_test_util_assert_block_count("/myfile.txt", 3);
-
-    /*** Overwrite end of first block, start of second. */
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
-    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 0);
-
-    rc = fs_seek(file, 6);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 6);
-
-    rc = fs_write(file, "1234", 4);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_file_len(file, 24);
-    TEST_ASSERT(fs_getpos(file) == 10);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_contents( "/myfile.txt",
-                                   "abcdef1234klmnopqrstuvwx", 24);
-    nffs_test_util_assert_block_count("/myfile.txt", 3);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = "abcdef1234klmnopqrstuvwx",
-                .contents_len = 24,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_long_filename)
-{
-    int rc;
-
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file("/12345678901234567890.txt", "contents", 8);
-
-    rc = fs_mkdir("/longdir12345678901234567890");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_rename("/12345678901234567890.txt",
-                    "/longdir12345678901234567890/12345678901234567890.txt");
-    TEST_ASSERT(rc == 0);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "longdir12345678901234567890",
-                .is_dir = 1,
-                .children = (struct nffs_test_file_desc[]) { {
-                    .filename = "/12345678901234567890.txt",
-                    .contents = "contents",
-                    .contents_len = 8,
-                }, {
-                    .filename = NULL,
-                } },
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_large_write)
-{
-    static char data[NFFS_BLOCK_MAX_DATA_SZ_MAX * 5];
-    int rc;
-    int i;
-
-    static const struct nffs_area_desc area_descs_two[] = {
-        { 0x00020000, 128 * 1024 },
-        { 0x00040000, 128 * 1024 },
-        { 0, 0 },
-    };
-
-
-
-    /*** Setup. */
-    rc = nffs_format(area_descs_two);
-    TEST_ASSERT(rc == 0);
-
-    for (i = 0; i < sizeof data; i++) {
-        data[i] = i;
-    }
-
-    nffs_test_util_create_file("/myfile.txt", data, sizeof data);
-
-    /* Ensure large write was split across the appropriate number of data
-     * blocks.
-     */
-    TEST_ASSERT(nffs_test_util_block_count("/myfile.txt") ==
-           sizeof data / NFFS_BLOCK_MAX_DATA_SZ_MAX);
-
-    /* Garbage collect and then ensure the large file is still properly divided
-     * according to max data block size.
-     */
-    nffs_gc(NULL);
-    TEST_ASSERT(nffs_test_util_block_count("/myfile.txt") ==
-           sizeof data / NFFS_BLOCK_MAX_DATA_SZ_MAX);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = data,
-                .contents_len = sizeof data,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, area_descs_two);
-}
-
-TEST_CASE(nffs_test_many_children)
-{
-    int rc;
-
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file("/zasdf", NULL, 0);
-    nffs_test_util_create_file("/FfD", NULL, 0);
-    nffs_test_util_create_file("/4Zvv", NULL, 0);
-    nffs_test_util_create_file("/*(*2fs", NULL, 0);
-    nffs_test_util_create_file("/pzzd", NULL, 0);
-    nffs_test_util_create_file("/zasdf0", NULL, 0);
-    nffs_test_util_create_file("/23132.bin", NULL, 0);
-    nffs_test_util_create_file("/asldkfjaldskfadsfsdf.txt", NULL, 0);
-    nffs_test_util_create_file("/sdgaf", NULL, 0);
-    nffs_test_util_create_file("/939302**", NULL, 0);
-    rc = fs_mkdir("/dir");
-    nffs_test_util_create_file("/dir/itw82", NULL, 0);
-    nffs_test_util_create_file("/dir/124", NULL, 0);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) {
-                { "zasdf" },
-                { "FfD" },
-                { "4Zvv" },
-                { "*(*2fs" },
-                { "pzzd" },
-                { "zasdf0" },
-                { "23132.bin" },
-                { "asldkfjaldskfadsfsdf.txt" },
-                { "sdgaf" },
-                { "939302**" },
-                {
-                    .filename = "dir",
-                    .is_dir = 1,
-                    .children = (struct nffs_test_file_desc[]) {
-                        { "itw82" },
-                        { "124" },
-                        { NULL },
-                    },
-                },
-                { NULL },
-            }
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_gc)
-{
-    int rc;
-
-    static const struct nffs_area_desc area_descs_two[] = {
-        { 0x00020000, 128 * 1024 },
-        { 0x00040000, 128 * 1024 },
-        { 0, 0 },
-    };
-
-    struct nffs_test_block_desc blocks[8] = { {
-        .data = "1",
-        .data_len = 1,
-    }, {
-        .data = "2",
-        .data_len = 1,
-    }, {
-        .data = "3",
-        .data_len = 1,
-    }, {
-        .data = "4",
-        .data_len = 1,
-    }, {
-        .data = "5",
-        .data_len = 1,
-    }, {
-        .data = "6",
-        .data_len = 1,
-    }, {
-        .data = "7",
-        .data_len = 1,
-    }, {
-        .data = "8",
-        .data_len = 1,
-    } };
-
-
-    rc = nffs_format(area_descs_two);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 8);
-
-    nffs_gc(NULL);
-
-    nffs_test_util_assert_block_count("/myfile.txt", 1);
-}
-
-TEST_CASE(nffs_test_wear_level)
-{
-    int rc;
-    int i;
-    int j;
-
-    static const struct nffs_area_desc area_descs_uniform[] = {
-        { 0x00000000, 2 * 1024 },
-        { 0x00020000, 2 * 1024 },
-        { 0x00040000, 2 * 1024 },
-        { 0x00060000, 2 * 1024 },
-        { 0x00080000, 2 * 1024 },
-        { 0, 0 },
-    };
-
-
-    /*** Setup. */
-    rc = nffs_format(area_descs_uniform);
-    TEST_ASSERT(rc == 0);
-
-    /* Ensure areas rotate properly. */
-    for (i = 0; i < 255; i++) {
-        for (j = 0; j < nffs_num_areas; j++) {
-            nffs_test_assert_area_seqs(i, nffs_num_areas - j, i + 1, j);
-            nffs_gc(NULL);
-        }
-    }
-
-    /* Ensure proper rollover of sequence numbers. */
-    for (j = 0; j < nffs_num_areas; j++) {
-        nffs_test_assert_area_seqs(255, nffs_num_areas - j, 0, j);
-        nffs_gc(NULL);
-    }
-    for (j = 0; j < nffs_num_areas; j++) {
-        nffs_test_assert_area_seqs(0, nffs_num_areas - j, 1, j);
-        nffs_gc(NULL);
-    }
-}
-
-TEST_CASE(nffs_test_corrupt_scratch)
-{
-    int non_scratch_id;
-    int scratch_id;
-    int rc;
-
-    static const struct nffs_area_desc area_descs_two[] = {
-        { 0x00020000, 128 * 1024 },
-        { 0x00040000, 128 * 1024 },
-        { 0, 0 },
-    };
-
-
-    /*** Setup. */
-    rc = nffs_format(area_descs_two);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file("/myfile.txt", "contents", 8);
-
-    /* Copy the current contents of the non-scratch area to the scratch area.
-     * This will make the scratch area look like it only partially participated
-     * in a garbage collection cycle.
-     */
-    scratch_id = nffs_scratch_area_idx;
-    non_scratch_id = scratch_id ^ 1;
-    nffs_test_copy_area(area_descs_two + non_scratch_id,
-                       area_descs_two + nffs_scratch_area_idx);
-
-    /* Add some more data to the non-scratch area. */
-    rc = fs_mkdir("/mydir");
-    TEST_ASSERT(rc == 0);
-
-    /* Ensure the file system is successfully detected and valid, despite
-     * corruption.
-     */
-
-    rc = nffs_misc_reset();
-    TEST_ASSERT(rc == 0);
-
-    rc = nffs_detect(area_descs_two);
-    TEST_ASSERT(rc == 0);
-
-    TEST_ASSERT(nffs_scratch_area_idx == scratch_id);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "mydir",
-                .is_dir = 1,
-            }, {
-                .filename = "myfile.txt",
-                .contents = "contents",
-                .contents_len = 8,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, area_descs_two);
-}
-
-/*
- * This test no longer works with the current implementation. The
- * expectation is that intermediate blocks can be removed and the old
- * method of finding the last current block after restore will allow the
- * file to be salvaged. Instead, the file should be removed and all data
- * declared invalid.
- */
-TEST_CASE(nffs_test_incomplete_block)
-{
-    struct nffs_block block;
-    struct fs_file *fs_file;
-    struct nffs_file *file;
-    uint32_t flash_offset;
-    uint32_t area_offset;
-    uint8_t area_idx;
-    int rc;
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/mydir");
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file("/mydir/a", "aaaa", 4);
-    nffs_test_util_create_file("/mydir/b", "bbbb", 4);
-    nffs_test_util_create_file("/mydir/c", "cccc", 4);
-
-    /* Add a second block to the 'b' file. */
-    nffs_test_util_append_file("/mydir/b", "1234", 4);
-
-    /* Corrupt the 'b' file; make it look like the second block only got half
-     * written.
-     */
-    rc = fs_open("/mydir/b", FS_ACCESS_READ, &fs_file);
-    TEST_ASSERT(rc == 0);
-    file = (struct nffs_file *)fs_file;
-
-    rc = nffs_block_from_hash_entry(&block,
-                                   file->nf_inode_entry->nie_last_block_entry);
-    TEST_ASSERT(rc == 0);
-
-    nffs_flash_loc_expand(block.nb_hash_entry->nhe_flash_loc, &area_idx,
-                         &area_offset);
-    flash_offset = nffs_areas[area_idx].na_offset + area_offset;
-    /*
-     * Overwrite block data - the CRC check should pick this up
-     */
-    rc = flash_native_memset(
-            flash_offset + sizeof (struct nffs_disk_block) + 2, 0xff, 2);
-    TEST_ASSERT(rc == 0);
-
-    rc = nffs_misc_reset();
-    TEST_ASSERT(rc == 0);
-    rc = nffs_detect(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    /* OLD: The entire second block should be removed; the file should only
-     * contain the first block.
-     * Unless we can salvage the block, the entire file should probably be
-     * removed. This is a contrived example which generates bad data on the
-     * what happens to be the last block, but corruption can actually occur
-     * in any block. Sweep should be updated to search look for blocks that
-     * don't have a correct prev_id and then decide whether to delete the
-     * owning inode. XXX
-     */
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "mydir",
-                .is_dir = 1,
-                .children = (struct nffs_test_file_desc[]) { {
-                    .filename = "a",
-                    .contents = "aaaa",
-                    .contents_len = 4,
-#if 0
-/* keep this out until sweep updated to capture bad blocks XXX */
-                }, {
-                    .filename = "b",
-                    .contents = "bbbb",
-                    .contents_len = 4,
-#endif
-                }, {
-                    .filename = "c",
-                    .contents = "cccc",
-                    .contents_len = 4,
-                }, {
-                    .filename = NULL,
-                } },
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_corrupt_block)
-{
-    struct nffs_block block;
-    struct fs_file *fs_file;
-    struct nffs_file *file;
-    uint32_t flash_offset;
-    uint32_t area_offset;
-    uint8_t area_idx;
-    uint8_t off;    /* offset to corrupt */
-    int rc;
-    struct nffs_disk_block ndb;
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/mydir");
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file("/mydir/a", "aaaa", 4);
-    nffs_test_util_create_file("/mydir/b", "bbbb", 4);
-    nffs_test_util_create_file("/mydir/c", "cccc", 4);
-
-    /* Add a second block to the 'b' file. */
-    nffs_test_util_append_file("/mydir/b", "1234", 4);
-
-    /* Corrupt the 'b' file; overwrite the second block's magic number. */
-    rc = fs_open("/mydir/b", FS_ACCESS_READ, &fs_file);
-    TEST_ASSERT(rc == 0);
-    file = (struct nffs_file *)fs_file;
-
-    rc = nffs_block_from_hash_entry(&block,
-                                   file->nf_inode_entry->nie_last_block_entry);
-    TEST_ASSERT(rc == 0);
-
-    nffs_flash_loc_expand(block.nb_hash_entry->nhe_flash_loc, &area_idx,
-                         &area_offset);
-    flash_offset = nffs_areas[area_idx].na_offset + area_offset;
-
-    /*
-     * Overwriting the reserved16 field should invalidate the CRC
-     */
-    off = (char*)&ndb.reserved16 - (char*)&ndb;
-    rc = flash_native_memset(flash_offset + off, 0x43, 1);
-
-    TEST_ASSERT(rc == 0);
-
-    /* Write a fourth file. This file should get restored even though the
-     * previous object has an invalid magic number.
-     */
-    nffs_test_util_create_file("/mydir/d", "dddd", 4);
-
-    rc = nffs_misc_reset();
-    TEST_ASSERT(rc == 0);
-    rc = nffs_detect(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    /* The entire second block should be removed; the file should only contain
-     * the first block.
-     */
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "mydir",
-                .is_dir = 1,
-                .children = (struct nffs_test_file_desc[]) { {
-                    .filename = "a",
-                    .contents = "aaaa",
-                    .contents_len = 4,
-#if 0
-                /*
-                 * In the newer implementation without the find_file_ends
-                 * corrupted inodes are deleted rather than retained with
-                 * partial contents
-                 */
-                }, {
-                    .filename = "b",
-                    .contents = "bbbb",
-                    .contents_len = 4,
-#endif
-                }, {
-                    .filename = "c",
-                    .contents = "cccc",
-                    .contents_len = 4,
-                }, {
-                    .filename = "d",
-                    .contents = "dddd",
-                    .contents_len = 4,
-                }, {
-                    .filename = NULL,
-                } },
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_large_unlink)
-{
-    static char file_contents[1024 * 4];
-    char filename[256];
-    int rc;
-    int i;
-    int j;
-    int k;
-
-
-    /*** Setup. */
-    nffs_config.nc_num_inodes = 1024;
-    nffs_config.nc_num_blocks = 1024;
-
-    rc = nffs_init();
-    TEST_ASSERT(rc == 0);
-
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    for (i = 0; i < 5; i++) {
-        snprintf(filename, sizeof filename, "/dir0_%d", i);
-        rc = fs_mkdir(filename);
-        TEST_ASSERT(rc == 0);
-
-        for (j = 0; j < 5; j++) {
-            snprintf(filename, sizeof filename, "/dir0_%d/dir1_%d", i, j);
-            rc = fs_mkdir(filename);
-            TEST_ASSERT(rc == 0);
-
-            for (k = 0; k < 5; k++) {
-                snprintf(filename, sizeof filename,
-                         "/dir0_%d/dir1_%d/file2_%d", i, j, k);
-                nffs_test_util_create_file(filename, file_contents,
-                                          sizeof file_contents);
-            }
-        }
-
-        for (j = 0; j < 15; j++) {
-            snprintf(filename, sizeof filename, "/dir0_%d/file1_%d", i, j);
-            nffs_test_util_create_file(filename, file_contents,
-                                      sizeof file_contents);
-        }
-    }
-
-    for (i = 0; i < 5; i++) {
-        snprintf(filename, sizeof filename, "/dir0_%d", i);
-        rc = fs_unlink(filename);
-        TEST_ASSERT(rc == 0);
-    }
-
-    /* The entire file system should be empty. */
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_large_system)
-{
-    int rc;
-
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_create_tree(nffs_test_system_01);
-
-    nffs_test_assert_system(nffs_test_system_01, nffs_area_descs);
-
-    rc = fs_unlink("/lvl1dir-0000");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_unlink("/lvl1dir-0004");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/lvl1dir-0000");
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_assert_system(nffs_test_system_01_rm_1014_mk10, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_lost_found)
-{
-    char buf[32];
-    struct nffs_inode_entry *inode_entry;
-    uint32_t flash_offset;
-    uint32_t area_offset;
-    uint8_t area_idx;
-    int rc;
-    struct nffs_disk_inode ndi;
-    uint8_t off;    /* calculated offset for memset */
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_mkdir("/mydir");
-    TEST_ASSERT(rc == 0);
-    rc = fs_mkdir("/mydir/dir1");
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file("/mydir/file1", "aaaa", 4);
-    nffs_test_util_create_file("/mydir/dir1/file2", "bbbb", 4);
-
-    /* Corrupt the mydir inode. */
-    rc = nffs_path_find_inode_entry("/mydir", &inode_entry);
-    TEST_ASSERT(rc == 0);
-
-    snprintf(buf, sizeof buf, "%lu",
-             (unsigned long)inode_entry->nie_hash_entry.nhe_id);
-
-    nffs_flash_loc_expand(inode_entry->nie_hash_entry.nhe_flash_loc,
-                         &area_idx, &area_offset);
-    flash_offset = nffs_areas[area_idx].na_offset + area_offset;
-    /*
-     * Overwrite the sequence number - should be detected as CRC corruption
-     */
-    off = (char*)&ndi.ndi_seq - (char*)&ndi;
-    rc = flash_native_memset(flash_offset + off, 0xaa, 1);
-    TEST_ASSERT(rc == 0);
-
-    /* Clear cached data and restore from flash (i.e, simulate a reboot). */
-    rc = nffs_misc_reset();
-    TEST_ASSERT(rc == 0);
-    rc = nffs_detect(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    /* All contents should now be in the lost+found dir. */
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "lost+found",
-                .is_dir = 1,
-#if 0
-                .children = (struct nffs_test_file_desc[]) { {
-                    .filename = buf,
-                    .is_dir = 1,
-                    .children = (struct nffs_test_file_desc[]) { {
-                        .filename = "file1",
-                        .contents = "aaaa",
-                        .contents_len = 4,
-                    }, {
-                        .filename = "dir1",
-                        .is_dir = 1,
-                        .children = (struct nffs_test_file_desc[]) { {
-                            .filename = "file2",
-                            .contents = "bbbb",
-                            .contents_len = 4,
-                        }, {
-                            .filename = NULL,
-                        } },
-                    }, {
-                        .filename = NULL,
-                    } },
-                }, {
-                    .filename = NULL,
-                } },
-#endif
-            }, {
-                .filename = NULL,
-            } }
-    } };
-
-    nffs_test_assert_system(expected_system, nffs_area_descs);
-}
-
-TEST_CASE(nffs_test_cache_large_file)
-{
-    static char data[NFFS_BLOCK_MAX_DATA_SZ_MAX * 5];
-    struct fs_file *file;
-    uint8_t b;
-    int rc;
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_create_file("/myfile.txt", data, sizeof data);
-    nffs_cache_clear();
-
-    /* Opening a file should not cause any blocks to get cached. */
-    rc = fs_open("/myfile.txt", FS_ACCESS_READ, &file);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_cache_range("/myfile.txt", 0, 0);
-
-    /* Cache first block. */
-    rc = fs_seek(file, nffs_block_max_data_sz * 0);
-    TEST_ASSERT(rc == 0);
-    rc = fs_read(file, 1, &b, NULL);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_cache_range("/myfile.txt",
-                                     nffs_block_max_data_sz * 0,
-                                     nffs_block_max_data_sz * 1);
-
-    /* Cache second block. */
-    rc = fs_seek(file, nffs_block_max_data_sz * 1);
-    TEST_ASSERT(rc == 0);
-    rc = fs_read(file, 1, &b, NULL);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_cache_range("/myfile.txt",
-                                     nffs_block_max_data_sz * 0,
-                                     nffs_block_max_data_sz * 2);
-
-
-    /* Cache fourth block; prior cache should get erased. */
-    rc = fs_seek(file, nffs_block_max_data_sz * 3);
-    TEST_ASSERT(rc == 0);
-    rc = fs_read(file, 1, &b, NULL);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_cache_range("/myfile.txt",
-                                     nffs_block_max_data_sz * 3,
-                                     nffs_block_max_data_sz * 4);
-
-    /* Cache second and third blocks. */
-    rc = fs_seek(file, nffs_block_max_data_sz * 1);
-    TEST_ASSERT(rc == 0);
-    rc = fs_read(file, 1, &b, NULL);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_cache_range("/myfile.txt",
-                                     nffs_block_max_data_sz * 1,
-                                     nffs_block_max_data_sz * 4);
-
-    /* Cache fifth block. */
-    rc = fs_seek(file, nffs_block_max_data_sz * 4);
-    TEST_ASSERT(rc == 0);
-    rc = fs_read(file, 1, &b, NULL);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_cache_range("/myfile.txt",
-                                     nffs_block_max_data_sz * 1,
-                                     nffs_block_max_data_sz * 5);
-
-    rc = fs_close(file);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(nffs_test_readdir)
-{
-    struct fs_dirent *dirent;
-    struct fs_dir *dir;
-    int rc;
-
-    /*** Setup. */
-    rc = nffs_format(nffs_area_descs);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    rc = fs_mkdir("/mydir");
-    TEST_ASSERT_FATAL(rc == 0);
-
-    nffs_test_util_create_file("/mydir/b", "bbbb", 4);
-    nffs_test_util_create_file("/mydir/a", "aaaa", 4);
-    rc = fs_mkdir("/mydir/c");
-    TEST_ASSERT_FATAL(rc == 0);
-
-    /* Nonexistent directory. */
-    rc = fs_opendir("/asdf", &dir);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    /* Fail to opendir a file. */
-    rc = fs_opendir("/mydir/a", &dir);
-    TEST_ASSERT(rc == FS_EINVAL);
-
-    /* Real directory (with trailing slash). */
-    rc = fs_opendir("/mydir/", &dir);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_ent_name(dirent, "a");
-    TEST_ASSERT(fs_dirent_is_dir(dirent) == 0);
-
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_ent_name(dirent, "b");
-    TEST_ASSERT(fs_dirent_is_dir(dirent) == 0);
-
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_ent_name(dirent, "c");
-    TEST_ASSERT(fs_dirent_is_dir(dirent) == 1);
-
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    rc = fs_closedir(dir);
-    TEST_ASSERT(rc == 0);
-
-    /* Root directory. */
-    rc = fs_opendir("/", &dir);
-    TEST_ASSERT(rc == 0);
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_ent_name(dirent, "lost+found");
-    TEST_ASSERT(fs_dirent_is_dir(dirent) == 1);
-
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == 0);
-    nffs_test_util_assert_ent_name(dirent, "mydir");
-    TEST_ASSERT(fs_dirent_is_dir(dirent) == 1);
-
-    rc = fs_closedir(dir);
-    TEST_ASSERT(rc == 0);
-
-    /* Delete entries while iterating. */
-    rc = fs_opendir("/mydir", &dir);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_ent_name(dirent, "a");
-    TEST_ASSERT(fs_dirent_is_dir(dirent) == 0);
-
-    rc = fs_unlink("/mydir/b");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_unlink("/mydir/c");
-    TEST_ASSERT(rc == 0);
-
-    rc = fs_unlink("/mydir");
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_util_assert_ent_name(dirent, "c");
-    TEST_ASSERT(fs_dirent_is_dir(dirent) == 1);
-
-    rc = fs_readdir(dir, &dirent);
-    TEST_ASSERT(rc == FS_ENOENT);
-
-    rc = fs_closedir(dir);
-    TEST_ASSERT(rc == 0);
-
-    /* Ensure directory is gone. */
-    rc = fs_opendir("/mydir", &dir);
-    TEST_ASSERT(rc == FS_ENOENT);
-}
-
-TEST_CASE(nffs_test_split_file)
-{
-    static char data[24 * 1024];
-    int rc;
-    int i;
-
-    /*** Setup. */
-    static const struct nffs_area_desc area_descs_two[] = {
-            { 0x00000000, 16 * 1024 },
-            { 0x00004000, 16 * 1024 },
-            { 0x00008000, 16 * 1024 },
-            { 0, 0 },
-    };
-
-    rc = nffs_format(area_descs_two);
-    TEST_ASSERT(rc == 0);
-
-    for (i = 0; i < sizeof data; i++) {
-        data[i] = i;
-    }
-
-    for (i = 0; i < 256; i++) {
-        nffs_test_util_create_file("/myfile.txt", data, sizeof data);
-        rc = fs_unlink("/myfile.txt");
-        TEST_ASSERT(rc == 0);
-    }
-
-    nffs_test_util_create_file("/myfile.txt", data, sizeof data);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = data,
-                .contents_len = sizeof data,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, area_descs_two);
-}
-
-TEST_CASE(nffs_test_gc_on_oom)
-{
-    int rc;
-
-    /*** Setup. */
-    /* Ensure all areas are the same size. */
-    static const struct nffs_area_desc area_descs_two[] = {
-            { 0x00000000, 16 * 1024 },
-            { 0x00004000, 16 * 1024 },
-            { 0x00008000, 16 * 1024 },
-            { 0, 0 },
-    };
-
-    rc = nffs_format(area_descs_two);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    /* Leak block entries until only four are left. */
-    /* XXX: This is ridiculous.  Need to fix nffs configuration so that the
-     * caller passes a config object rather than writing to a global variable.
-     */
-    while (nffs_block_entry_pool.mp_num_free != 4) {
-        nffs_block_entry_alloc();
-    }
-
-    /*** Write 4 data blocks. */
-    struct nffs_test_block_desc blocks[4] = { {
-        .data = "1",
-        .data_len = 1,
-    }, {
-        .data = "2",
-        .data_len = 1,
-    }, {
-        .data = "3",
-        .data_len = 1,
-    }, {
-        .data = "4",
-        .data_len = 1,
-    } };
-
-    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 4);
-
-    TEST_ASSERT_FATAL(nffs_block_entry_pool.mp_num_free == 0);
-
-    /* Attempt another one-byte write.  This should trigger a garbage
-     * collection cycle, resulting in the four blocks being collated.  The
-     * fifth write consumes an additional block, resulting in 2 out of 4 blocks
-     * in use.
-     */
-    nffs_test_util_append_file("/myfile.txt", "5", 1);
-
-    TEST_ASSERT_FATAL(nffs_block_entry_pool.mp_num_free == 2);
-
-    struct nffs_test_file_desc *expected_system =
-        (struct nffs_test_file_desc[]) { {
-            .filename = "",
-            .is_dir = 1,
-            .children = (struct nffs_test_file_desc[]) { {
-                .filename = "myfile.txt",
-                .contents = "12345",
-                .contents_len = 5,
-            }, {
-                .filename = NULL,
-            } },
-    } };
-
-    nffs_test_assert_system(expected_system, area_descs_two);
-}
-
-TEST_SUITE(nffs_suite_cache)
-{
-    int rc;
-
-    memset(&nffs_config, 0, sizeof nffs_config);
-    nffs_config.nc_num_cache_inodes = 4;
-    nffs_config.nc_num_cache_blocks = 64;
-
-    rc = nffs_init();
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_cache_large_file();
-}
-
-static void
-nffs_test_gen(void)
-{
-    int rc;
-
-    rc = nffs_init();
-    TEST_ASSERT(rc == 0);
-
-    nffs_test_unlink();
-    nffs_test_mkdir();
-    nffs_test_rename();
-    nffs_test_truncate();
-    nffs_test_append();
-    nffs_test_read();
-    nffs_test_open();
-    nffs_test_overwrite_one();
-    nffs_test_overwrite_two();
-    nffs_test_overwrite_three();
-    nffs_test_overwrite_many();
-    nffs_test_long_filename();
-    nffs_test_large_write();
-    nffs_test_many_children();
-    nffs_test_gc();
-    nffs_test_wear_level();
-    nffs_test_corrupt_scratch();
-    nffs_test_incomplete_block();
-    nffs_test_corrupt_block();
-    nffs_test_large_unlink();
-    nffs_test_large_system();
-    nffs_test_lost_found();
-    nffs_test_readdir();
-    nffs_test_split_file();
-    nffs_test_gc_on_oom();
-}
-
-TEST_SUITE(gen_1_1)
-{
-    nffs_config.nc_num_cache_inodes = 1;
-    nffs_config.nc_num_cache_blocks = 1;
-    nffs_test_gen();
-}
-
-TEST_SUITE(gen_4_32)
-{
-    nffs_config.nc_num_cache_inodes = 4;
-    nffs_config.nc_num_cache_blocks = 32;
-    nffs_test_gen();
-}
-
-TEST_SUITE(gen_32_1024)
-{
-    nffs_config.nc_num_cache_inodes = 32;
-    nffs_config.nc_num_cache_blocks = 1024;
-    nffs_test_gen();
-}
-
-int
-nffs_test_all(void)
-{
-    nffs_config.nc_num_inodes = 1024 * 8;
-    nffs_config.nc_num_blocks = 1024 * 20;
-
-    gen_1_1();
-    gen_4_32();
-    gen_32_1024();
-    nffs_suite_cache();
-
-    return tu_any_failed;
-}
-
-void
-print_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
-{
-    struct nffs_inode inode;
-    char name[NFFS_FILENAME_MAX_LEN + 1];
-    uint32_t area_offset;
-    uint8_t area_idx;
-    int rc;
-
-    if (inode_entry == nffs_root_dir) {
-        printf("%*s/\n", indent, "");
-        return;
-    }
-
-    rc = nffs_inode_from_entry(&inode, inode_entry);
-    /*
-     * Dummy inode
-     */
-    if (rc == FS_ENOENT) {
-        printf("    DUMMY %d\n", rc);
-        return;
-    }
-
-    nffs_flash_loc_expand(inode_entry->nie_hash_entry.nhe_flash_loc,
-                         &area_idx, &area_offset);
-
-    rc = nffs_flash_read(area_idx,
-                         area_offset + sizeof (struct nffs_disk_inode),
-                         name, inode.ni_filename_len);
-
-    name[inode.ni_filename_len] = '\0';
-
-    printf("%*s%s\n", indent, "", name[0] == '\0' ? "/" : name);
-}
-
-void
-process_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
-{
-    struct nffs_inode_entry *child;
-
-    print_inode_entry(inode_entry, indent);
-
-    if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
-        SLIST_FOREACH(child, &inode_entry->nie_child_list, nie_sibling_next) {
-            process_inode_entry(child, indent + 2);
-        }
-    }
-}
-
-int
-print_nffs_flash_inode(struct nffs_area *area, uint32_t off)
-{
-    struct nffs_disk_inode ndi;
-    char filename[128];
-    int len;
-    int rc;
-
-    rc = hal_flash_read(area->na_flash_id, area->na_offset + off,
-                         &ndi, sizeof(ndi));
-    assert(rc == 0);
-
-    memset(filename, 0, sizeof(filename));
-    len = min(sizeof(filename) - 1, ndi.ndi_filename_len);
-    rc = hal_flash_read(area->na_flash_id, area->na_offset + off + sizeof(ndi),
-                         filename, len);
-
-    printf("  off %x %s id %x flen %d seq %d last %x prnt %x flgs %x %s\n",
-           off,
-           (nffs_hash_id_is_file(ndi.ndi_id) ? "File" :
-            (nffs_hash_id_is_dir(ndi.ndi_id) ? "Dir" : "???")),
-           ndi.ndi_id,
-           ndi.ndi_filename_len,
-           ndi.ndi_seq,
-           ndi.ndi_lastblock_id,
-           ndi.ndi_parent_id,
-           ndi.ndi_flags,
-           filename);
-    return sizeof(ndi) + ndi.ndi_filename_len;
-}
-
-int
-print_nffs_flash_block(struct nffs_area *area, uint32_t off)
-{
-    struct nffs_disk_block ndb;
-    int rc;
-
-    rc = hal_flash_read(area->na_flash_id, area->na_offset + off,
-                        &ndb, sizeof(ndb));
-    assert(rc == 0);
-
-    printf("  off %x Block id %x len %d seq %d prev %x own ino %x\n",
-           off,
-           ndb.ndb_id,
-           ndb.ndb_data_len,
-           ndb.ndb_seq,
-           ndb.ndb_prev_id,
-           ndb.ndb_inode_id);
-    return sizeof(ndb) + ndb.ndb_data_len;
-}
-
-int
-print_nffs_flash_object(struct nffs_area *area, uint32_t off)
-{
-    struct nffs_disk_object ndo;
-
-    hal_flash_read(area->na_flash_id, area->na_offset + off,
-                        &ndo.ndo_un_obj, sizeof(ndo.ndo_un_obj));
-
-    if (nffs_hash_id_is_inode(ndo.ndo_disk_inode.ndi_id)) {
-        return print_nffs_flash_inode(area, off);
-
-    } else if (nffs_hash_id_is_block(ndo.ndo_disk_block.ndb_id)) {
-        return print_nffs_flash_block(area, off);
-
-    } else if (ndo.ndo_disk_block.ndb_id == 0xffffffff) {
-        return area->na_length;
-
-    } else {
-        return 1;
-    }
-}
-
-void
-print_nffs_flash_areas(int verbose)
-{
-    struct nffs_area area;
-    struct nffs_disk_area darea;
-    int off;
-    int i;
-
-    for (i = 0; nffs_current_area_descs[i].nad_length != 0; i++) {
-        if (i > NFFS_MAX_AREAS) {
-            return;
-        }
-        area.na_offset = nffs_current_area_descs[i].nad_offset;
-        area.na_length = nffs_current_area_descs[i].nad_length;
-        area.na_flash_id = nffs_current_area_descs[i].nad_flash_id;
-        hal_flash_read(area.na_flash_id, area.na_offset, &darea, sizeof(darea));
-        area.na_id = darea.nda_id;
-        area.na_cur = nffs_areas[i].na_cur;
-        if (!nffs_area_magic_is_set(&darea)) {
-            printf("Area header corrupt!\n");
-        }
-        printf("area %d: id %d %x-%x cur %x len %d flashid %x gc-seq %d %s%s\n",
-               i, area.na_id, area.na_offset, area.na_offset + area.na_length,
-               area.na_cur, area.na_length, area.na_flash_id, darea.nda_gc_seq,
-               nffs_scratch_area_idx == i ? "(scratch)" : "",
-               !nffs_area_magic_is_set(&darea) ? "corrupt" : "");
-        if (verbose < 2) {
-            off = sizeof (struct nffs_disk_area);
-            while (off < area.na_length) {
-                off += print_nffs_flash_object(&area, off);
-            }
-        }
-    }
-}
-
-static int
-nffs_hash_fn(uint32_t id)
-{
-    return id % NFFS_HASH_SIZE;
-}
-
-void
-print_hashlist(struct nffs_hash_entry *he)
-{
-    struct nffs_hash_list *list;
-    int idx = nffs_hash_fn(he->nhe_id);
-    list = nffs_hash + idx;
-
-    SLIST_FOREACH(he, list, nhe_next) {
-        printf("hash_entry %s 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
-                   nffs_hash_id_is_inode(he->nhe_id) ? "inode" : "block",
-                   (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
-   }
-}
-
-void
-print_hash(void)
-{
-    int i;
-    struct nffs_hash_entry *he;
-    struct nffs_hash_entry *next;
-    struct nffs_inode ni;
-    struct nffs_disk_inode di;
-    struct nffs_block nb;
-    struct nffs_disk_block db;
-    uint32_t area_offset;
-    uint8_t area_idx;
-    int rc;
-
-    NFFS_HASH_FOREACH(he, i, next) {
-        if (nffs_hash_id_is_inode(he->nhe_id)) {
-            printf("hash_entry inode %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
-                   i, (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
-            if (he->nhe_id == NFFS_ID_ROOT_DIR) {
-                continue;
-            }
-            nffs_flash_loc_expand(he->nhe_flash_loc,
-                                  &area_idx, &area_offset);
-            rc = nffs_inode_read_disk(area_idx, area_offset, &di);
-            if (rc) {
-                printf("%d: fail inode read id 0x%x rc %d\n",
-               

<TRUNCATED>


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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/nffs_test_utils.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test_utils.c b/fs/nffs/test/src/nffs_test_utils.c
new file mode 100644
index 0000000..3b99b18
--- /dev/null
+++ b/fs/nffs/test/src/nffs_test_utils.c
@@ -0,0 +1,744 @@
+/**
+ * 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 <stdlib.h>
+#include <errno.h>
+#include "hal/hal_flash.h"
+#include "testutil/testutil.h"
+#include "fs/fs.h"
+#include "nffs/nffs.h"
+#include "nffs_test.h"
+#include "nffs_test_priv.h"
+#include "nffs_priv.h"
+
+#if 0
+#ifdef ARCH_sim
+const struct nffs_area_desc nffs_sim_area_descs[] = {
+        { 0x00000000, 16 * 1024 },
+        { 0x00004000, 16 * 1024 },
+        { 0x00008000, 16 * 1024 },
+        { 0x0000c000, 16 * 1024 },
+        { 0x00010000, 64 * 1024 },
+        { 0x00020000, 128 * 1024 },
+        { 0x00040000, 128 * 1024 },
+        { 0x00060000, 128 * 1024 },
+        { 0x00080000, 128 * 1024 },
+        { 0x000a0000, 128 * 1024 },
+        { 0x000c0000, 128 * 1024 },
+        { 0x000e0000, 128 * 1024 },
+        { 0, 0 },
+};
+#endif
+#endif
+
+void
+nffs_test_util_assert_ent_name(struct fs_dirent *dirent,
+                               const char *expected_name)
+{
+    char name[NFFS_FILENAME_MAX_LEN + 1];
+    uint8_t name_len;
+    int rc;
+
+    rc = fs_dirent_name(dirent, sizeof name, name, &name_len);
+    TEST_ASSERT(rc == 0);
+    if (rc == 0) {
+        TEST_ASSERT(strcmp(name, expected_name) == 0);
+    }
+}
+
+void
+nffs_test_util_assert_file_len(struct fs_file *file, uint32_t expected)
+{
+    uint32_t len;
+    int rc;
+
+    rc = fs_filelen(file, &len);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(len == expected);
+}
+
+void
+nffs_test_util_assert_cache_is_sane(const char *filename)
+{
+    struct nffs_cache_inode *cache_inode;
+    struct nffs_cache_block *cache_block;
+    struct fs_file *fs_file;
+    struct nffs_file *file;
+    uint32_t cache_start;
+    uint32_t cache_end;
+    uint32_t block_end;
+    int rc;
+
+    rc = fs_open(filename, FS_ACCESS_READ, &fs_file);
+    TEST_ASSERT(rc == 0);
+
+    file = (struct nffs_file *)fs_file;
+    rc = nffs_cache_inode_ensure(&cache_inode, file->nf_inode_entry);
+    TEST_ASSERT(rc == 0);
+
+    nffs_cache_inode_range(cache_inode, &cache_start, &cache_end);
+
+    if (TAILQ_EMPTY(&cache_inode->nci_block_list)) {
+        TEST_ASSERT(cache_start == 0 && cache_end == 0);
+    } else {
+        block_end = 0;  /* Pacify gcc. */
+        TAILQ_FOREACH(cache_block, &cache_inode->nci_block_list, ncb_link) {
+            if (cache_block == TAILQ_FIRST(&cache_inode->nci_block_list)) {
+                TEST_ASSERT(cache_block->ncb_file_offset == cache_start);
+            } else {
+                /* Ensure no gap between this block and its predecessor. */
+                TEST_ASSERT(cache_block->ncb_file_offset == block_end);
+            }
+
+            block_end = cache_block->ncb_file_offset +
+                        cache_block->ncb_block.nb_data_len;
+            if (cache_block == TAILQ_LAST(&cache_inode->nci_block_list,
+                                          nffs_cache_block_list)) {
+
+                TEST_ASSERT(block_end == cache_end);
+            }
+        }
+    }
+
+    rc = fs_close(fs_file);
+    TEST_ASSERT(rc == 0);
+}
+
+void
+nffs_test_util_assert_contents(const char *filename, const char *contents,
+                               int contents_len)
+{
+    struct fs_file *file;
+    uint32_t bytes_read;
+    void *buf;
+    int rc;
+
+    rc = fs_open(filename, FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == 0);
+
+    buf = malloc(contents_len + 1);
+    TEST_ASSERT(buf != NULL);
+
+    rc = fs_read(file, contents_len + 1, buf, &bytes_read);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(bytes_read == contents_len);
+    TEST_ASSERT(memcmp(buf, contents, contents_len) == 0);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    free(buf);
+
+    nffs_test_util_assert_cache_is_sane(filename);
+}
+
+int
+nffs_test_util_block_count(const char *filename)
+{
+    struct nffs_hash_entry *entry;
+    struct nffs_block block;
+    struct nffs_file *file;
+    struct fs_file *fs_file;
+    int count;
+    int rc;
+
+    rc = fs_open(filename, FS_ACCESS_READ, &fs_file);
+    TEST_ASSERT(rc == 0);
+
+    file = (struct nffs_file *)fs_file;
+    count = 0;
+    entry = file->nf_inode_entry->nie_last_block_entry;
+    while (entry != NULL) {
+        count++;
+        rc = nffs_block_from_hash_entry(&block, entry);
+        TEST_ASSERT(rc == 0);
+        TEST_ASSERT(block.nb_prev != entry);
+        entry = block.nb_prev;
+    }
+
+    rc = fs_close(fs_file);
+    TEST_ASSERT(rc == 0);
+
+    return count;
+}
+
+void
+nffs_test_util_assert_block_count(const char *filename, int expected_count)
+{
+    int actual_count;
+
+    actual_count = nffs_test_util_block_count(filename);
+    TEST_ASSERT(actual_count == expected_count);
+}
+
+void
+nffs_test_util_assert_cache_range(const char *filename,
+                                 uint32_t expected_cache_start,
+                                 uint32_t expected_cache_end)
+{
+    struct nffs_cache_inode *cache_inode;
+    struct nffs_file *file;
+    struct fs_file *fs_file;
+    uint32_t cache_start;
+    uint32_t cache_end;
+    int rc;
+
+    rc = fs_open(filename, FS_ACCESS_READ, &fs_file);
+    TEST_ASSERT(rc == 0);
+
+    file = (struct nffs_file *)fs_file;
+    rc = nffs_cache_inode_ensure(&cache_inode, file->nf_inode_entry);
+    TEST_ASSERT(rc == 0);
+
+    nffs_cache_inode_range(cache_inode, &cache_start, &cache_end);
+    TEST_ASSERT(cache_start == expected_cache_start);
+    TEST_ASSERT(cache_end == expected_cache_end);
+
+    rc = fs_close(fs_file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_cache_is_sane(filename);
+}
+
+void
+nffs_test_util_create_file_blocks(const char *filename,
+                                 const struct nffs_test_block_desc *blocks,
+                                 int num_blocks)
+{
+    struct fs_file *file;
+    uint32_t total_len;
+    uint32_t offset;
+    char *buf;
+    int num_writes;
+    int rc;
+    int i;
+
+    rc = fs_open(filename, FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file);
+    TEST_ASSERT(rc == 0);
+
+    total_len = 0;
+    if (num_blocks <= 0) {
+        num_writes = 1;
+    } else {
+        num_writes = num_blocks;
+    }
+    for (i = 0; i < num_writes; i++) {
+        rc = fs_write(file, blocks[i].data, blocks[i].data_len);
+        TEST_ASSERT(rc == 0);
+
+        total_len += blocks[i].data_len;
+    }
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    buf = malloc(total_len);
+    TEST_ASSERT(buf != NULL);
+
+    offset = 0;
+    for (i = 0; i < num_writes; i++) {
+        memcpy(buf + offset, blocks[i].data, blocks[i].data_len);
+        offset += blocks[i].data_len;
+    }
+    TEST_ASSERT(offset == total_len);
+
+    nffs_test_util_assert_contents(filename, buf, total_len);
+    if (num_blocks > 0) {
+        nffs_test_util_assert_block_count(filename, num_blocks);
+    }
+
+    free(buf);
+}
+
+void
+nffs_test_util_create_file(const char *filename, const char *contents,
+                           int contents_len)
+{
+    struct nffs_test_block_desc block;
+
+    block.data = contents;
+    block.data_len = contents_len;
+
+    nffs_test_util_create_file_blocks(filename, &block, 0);
+}
+
+void
+nffs_test_util_append_file(const char *filename, const char *contents,
+                           int contents_len)
+{
+    struct fs_file *file;
+    int rc;
+
+    rc = fs_open(filename, FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_write(file, contents, contents_len);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+}
+
+void
+nffs_test_copy_area(const struct nffs_area_desc *from,
+                    const struct nffs_area_desc *to)
+{
+    void *buf;
+    int rc;
+
+    TEST_ASSERT(from->nad_length == to->nad_length);
+
+    buf = malloc(from->nad_length);
+    TEST_ASSERT(buf != NULL);
+
+    rc = hal_flash_read(from->nad_flash_id, from->nad_offset, buf,
+                        from->nad_length);
+    TEST_ASSERT(rc == 0);
+
+    rc = hal_flash_erase(from->nad_flash_id, to->nad_offset, to->nad_length);
+    TEST_ASSERT(rc == 0);
+
+    rc = hal_flash_write(to->nad_flash_id, to->nad_offset, buf, to->nad_length);
+    TEST_ASSERT(rc == 0);
+
+    free(buf);
+}
+
+void
+nffs_test_util_create_subtree(const char *parent_path,
+                             const struct nffs_test_file_desc *elem)
+{
+    char *path;
+    int rc;
+    int i;
+
+    if (parent_path == NULL) {
+        path = malloc(1);
+        TEST_ASSERT(path != NULL);
+        path[0] = '\0';
+    } else {
+        path = malloc(strlen(parent_path) + 1 + strlen(elem->filename) + 1);
+        TEST_ASSERT(path != NULL);
+
+        sprintf(path, "%s/%s", parent_path, elem->filename);
+    }
+
+    if (elem->is_dir) {
+        if (parent_path != NULL) {
+            rc = fs_mkdir(path);
+            TEST_ASSERT(rc == 0);
+        }
+
+        if (elem->children != NULL) {
+            for (i = 0; elem->children[i].filename != NULL; i++) {
+                nffs_test_util_create_subtree(path, elem->children + i);
+            }
+        }
+    } else {
+        nffs_test_util_create_file(path, elem->contents, elem->contents_len);
+    }
+
+    free(path);
+}
+
+void
+nffs_test_util_create_tree(const struct nffs_test_file_desc *root_dir)
+{
+    nffs_test_util_create_subtree(NULL, root_dir);
+}
+
+#define NFFS_TEST_TOUCHED_ARR_SZ     (16 * 64)
+/*#define NFFS_TEST_TOUCHED_ARR_SZ     (16 * 1024)*/
+struct nffs_hash_entry
+    *nffs_test_touched_entries[NFFS_TEST_TOUCHED_ARR_SZ];
+int nffs_test_num_touched_entries;
+
+/*
+ * Recursively descend directory structure
+ */
+void
+nffs_test_assert_file(const struct nffs_test_file_desc *file,
+                     struct nffs_inode_entry *inode_entry,
+                     const char *path)
+{
+    const struct nffs_test_file_desc *child_file;
+    struct nffs_inode inode;
+    struct nffs_inode_entry *child_inode_entry;
+    char *child_path;
+    int child_filename_len;
+    int path_len;
+    int rc;
+
+    /*
+     * track of hash entries that have been examined
+     */
+    TEST_ASSERT(nffs_test_num_touched_entries < NFFS_TEST_TOUCHED_ARR_SZ);
+    nffs_test_touched_entries[nffs_test_num_touched_entries] =
+        &inode_entry->nie_hash_entry;
+    nffs_test_num_touched_entries++;
+
+    path_len = strlen(path);
+
+    rc = nffs_inode_from_entry(&inode, inode_entry);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * recursively examine each child of directory
+     */
+    if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
+        for (child_file = file->children;
+             child_file != NULL && child_file->filename != NULL;
+             child_file++) {
+
+            /*
+             * Construct full pathname for file
+             * Not null terminated
+             */
+            child_filename_len = strlen(child_file->filename);
+            child_path = malloc(path_len + 1 + child_filename_len + 1);
+            TEST_ASSERT(child_path != NULL);
+            memcpy(child_path, path, path_len);
+            child_path[path_len] = '/';
+            memcpy(child_path + path_len + 1, child_file->filename,
+                   child_filename_len);
+            child_path[path_len + 1 + child_filename_len] = '\0';
+
+            /*
+             * Verify child inode can be found using full pathname
+             */
+            rc = nffs_path_find_inode_entry(child_path, &child_inode_entry);
+            if (rc != 0) {
+                TEST_ASSERT(rc == 0);
+            }
+
+            nffs_test_assert_file(child_file, child_inode_entry, child_path);
+
+            free(child_path);
+        }
+    } else {
+        nffs_test_util_assert_contents(path, file->contents,
+                                       file->contents_len);
+    }
+}
+
+void
+nffs_test_assert_branch_touched(struct nffs_inode_entry *inode_entry)
+{
+    struct nffs_inode_entry *child;
+    int i;
+
+    if (inode_entry == nffs_lost_found_dir) {
+        return;
+    }
+
+    for (i = 0; i < nffs_test_num_touched_entries; i++) {
+        if (nffs_test_touched_entries[i] == &inode_entry->nie_hash_entry) {
+            break;
+        }
+    }
+    TEST_ASSERT(i < nffs_test_num_touched_entries);
+    nffs_test_touched_entries[i] = NULL;
+
+    if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
+        SLIST_FOREACH(child, &inode_entry->nie_child_list, nie_sibling_next) {
+            nffs_test_assert_branch_touched(child);
+        }
+    }
+}
+
+void
+nffs_test_assert_child_inode_present(struct nffs_inode_entry *child)
+{
+    const struct nffs_inode_entry *inode_entry;
+    const struct nffs_inode_entry *parent;
+    struct nffs_inode inode;
+    int rc;
+
+    /*
+     * Sucessfully read inode data from flash
+     */
+    rc = nffs_inode_from_entry(&inode, child);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * Validate parent
+     */
+    parent = inode.ni_parent;
+    TEST_ASSERT(parent != NULL);
+    TEST_ASSERT(nffs_hash_id_is_dir(parent->nie_hash_entry.nhe_id));
+
+    /*
+     * Make sure inode is in parents child list
+     */
+    SLIST_FOREACH(inode_entry, &parent->nie_child_list, nie_sibling_next) {
+        if (inode_entry == child) {
+            return;
+        }
+    }
+
+    TEST_ASSERT(0);
+}
+
+void
+nffs_test_assert_block_present(struct nffs_hash_entry *block_entry)
+{
+    const struct nffs_inode_entry *inode_entry;
+    struct nffs_hash_entry *cur;
+    struct nffs_block block;
+    int rc;
+
+    /*
+     * Successfully read block data from flash
+     */
+    rc = nffs_block_from_hash_entry(&block, block_entry);
+    TEST_ASSERT(rc == 0);
+
+    /*
+     * Validate owning inode
+     */
+    inode_entry = block.nb_inode_entry;
+    TEST_ASSERT(inode_entry != NULL);
+    TEST_ASSERT(nffs_hash_id_is_file(inode_entry->nie_hash_entry.nhe_id));
+
+    /*
+     * Validate that block is in owning inode's block chain
+     */
+    cur = inode_entry->nie_last_block_entry;
+    while (cur != NULL) {
+        if (cur == block_entry) {
+            return;
+        }
+
+        rc = nffs_block_from_hash_entry(&block, cur);
+        TEST_ASSERT(rc == 0);
+        cur = block.nb_prev;
+    }
+
+    TEST_ASSERT(0);
+}
+
+/*
+ * Recursively verify that the children of each directory are sorted
+ * on the directory children linked list by filename length
+ */
+void
+nffs_test_assert_children_sorted(struct nffs_inode_entry *inode_entry)
+{
+    struct nffs_inode_entry *child_entry;
+    struct nffs_inode_entry *prev_entry;
+    struct nffs_inode child_inode;
+    struct nffs_inode prev_inode;
+    int cmp;
+    int rc;
+
+    prev_entry = NULL;
+    SLIST_FOREACH(child_entry, &inode_entry->nie_child_list,
+                  nie_sibling_next) {
+        rc = nffs_inode_from_entry(&child_inode, child_entry);
+        TEST_ASSERT(rc == 0);
+
+        if (prev_entry != NULL) {
+            rc = nffs_inode_from_entry(&prev_inode, prev_entry);
+            TEST_ASSERT(rc == 0);
+
+            rc = nffs_inode_filename_cmp_flash(&prev_inode, &child_inode,
+                                               &cmp);
+            TEST_ASSERT(rc == 0);
+            TEST_ASSERT(cmp < 0);
+        }
+
+        if (nffs_hash_id_is_dir(child_entry->nie_hash_entry.nhe_id)) {
+            nffs_test_assert_children_sorted(child_entry);
+        }
+
+        prev_entry = child_entry;
+    }
+}
+
+void
+nffs_test_assert_system_once(const struct nffs_test_file_desc *root_dir)
+{
+    struct nffs_inode_entry *inode_entry;
+    struct nffs_hash_entry *entry;
+    struct nffs_hash_entry *next;
+    int i;
+
+    nffs_test_num_touched_entries = 0;
+    nffs_test_assert_file(root_dir, nffs_root_dir, "");
+    nffs_test_assert_branch_touched(nffs_root_dir);
+
+    /* Ensure no orphaned inodes or blocks. */
+    NFFS_HASH_FOREACH(entry, i, next) {
+        TEST_ASSERT(entry->nhe_flash_loc != NFFS_FLASH_LOC_NONE);
+        if (nffs_hash_id_is_inode(entry->nhe_id)) {
+            inode_entry = (void *)entry;
+            TEST_ASSERT(inode_entry->nie_refcnt == 1);
+            if (entry->nhe_id == NFFS_ID_ROOT_DIR) {
+                TEST_ASSERT(inode_entry == nffs_root_dir);
+            } else {
+                nffs_test_assert_child_inode_present(inode_entry);
+            }
+        } else {
+            nffs_test_assert_block_present(entry);
+        }
+    }
+
+    /* Ensure proper sorting. */
+    nffs_test_assert_children_sorted(nffs_root_dir);
+}
+
+void
+nffs_test_assert_system(const struct nffs_test_file_desc *root_dir,
+                        const struct nffs_area_desc *area_descs)
+{
+    int rc;
+
+    /* Ensure files are as specified, and that there are no other files or
+     * orphaned inodes / blocks.
+     */
+    nffs_test_assert_system_once(root_dir);
+
+    /* Force a garbage collection cycle. */
+    rc = nffs_gc(NULL);
+    TEST_ASSERT(rc == 0);
+
+    /* Ensure file system is still as expected. */
+    nffs_test_assert_system_once(root_dir);
+
+    /* Clear cached data and restore from flash (i.e, simulate a reboot). */
+    rc = nffs_misc_reset();
+    TEST_ASSERT(rc == 0);
+    rc = nffs_detect(area_descs);
+    TEST_ASSERT(rc == 0);
+
+    /* Ensure file system is still as expected. */
+    nffs_test_assert_system_once(root_dir);
+}
+
+void
+nffs_test_assert_area_seqs(int seq1, int count1, int seq2, int count2)
+{
+    struct nffs_disk_area disk_area;
+    int cur1;
+    int cur2;
+    int rc;
+    int i;
+
+    cur1 = 0;
+    cur2 = 0;
+
+    for (i = 0; i < nffs_num_areas; i++) {
+        rc = nffs_flash_read(i, 0, &disk_area, sizeof disk_area);
+        TEST_ASSERT(rc == 0);
+        TEST_ASSERT(nffs_area_magic_is_set(&disk_area));
+        TEST_ASSERT(disk_area.nda_gc_seq == nffs_areas[i].na_gc_seq);
+        if (i == nffs_scratch_area_idx) {
+            TEST_ASSERT(disk_area.nda_id == NFFS_AREA_ID_NONE);
+        }
+
+        if (nffs_areas[i].na_gc_seq == seq1) {
+            cur1++;
+        } else if (nffs_areas[i].na_gc_seq == seq2) {
+            cur2++;
+        } else {
+            TEST_ASSERT(0);
+        }
+    }
+
+    TEST_ASSERT(cur1 == count1 && cur2 == count2);
+}
+
+#if 0
+void
+nffs_test_mkdir(void)
+{
+    struct fs_file *file;
+    int rc;
+
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/a/b/c/d");
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    rc = fs_mkdir("asdf");
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    rc = fs_mkdir("/a");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/a/b");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/a/b/c");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/a/b/c/d");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_open("/a/b/c/d/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "a",
+                .is_dir = 1,
+                .children = (struct nffs_test_file_desc[]) { {
+                    .filename = "b",
+                    .is_dir = 1,
+                    .children = (struct nffs_test_file_desc[]) { {
+                        .filename = "c",
+                        .is_dir = 1,
+                        .children = (struct nffs_test_file_desc[]) { {
+                            .filename = "d",
+                            .is_dir = 1,
+                            .children = (struct nffs_test_file_desc[]) { {
+                                .filename = "myfile.txt",
+                                .contents = NULL,
+                                .contents_len = 0,
+                            }, {
+                                .filename = NULL,
+                            } },
+                        }, {
+                            .filename = NULL,
+                        } },
+                    }, {
+                        .filename = NULL,
+                    } },
+                }, {
+                    .filename = NULL,
+                } },
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/nffs_test_utils.h
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test_utils.h b/fs/nffs/test/src/nffs_test_utils.h
new file mode 100644
index 0000000..be4372a
--- /dev/null
+++ b/fs/nffs/test/src/nffs_test_utils.h
@@ -0,0 +1,92 @@
+/**
+ * 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_NFFS_TEST_UTILS_
+#define H_NFFS_TEST_UTILS_
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "hal/hal_flash.h"
+#include "testutil/testutil.h"
+#include "fs/fs.h"
+#include "nffs/nffs.h"
+#include "nffs_test.h"
+#include "nffs_test_priv.h"
+#include "nffs_priv.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+extern struct nffs_hash_entry *nffs_test_touched_entries;
+int nffs_test_num_touched_entries;
+
+extern int flash_native_memset(uint32_t offset, uint8_t c, uint32_t len);
+
+void nffs_test_util_assert_ent_name(struct fs_dirent *dirent,
+                                    const char *expected_name);
+void nffs_test_util_assert_file_len(struct fs_file *file, uint32_t expected);
+void nffs_test_util_assert_cache_is_sane(const char *filename);
+void nffs_test_util_assert_contents(const char *filename,
+                                    const char *contents, int contents_len);
+int nffs_test_util_block_count(const char *filename);
+void nffs_test_util_assert_block_count(const char *filename,
+                                       int expected_count);
+void nffs_test_util_assert_cache_range(const char *filename,
+                                       uint32_t expected_cache_start,
+                                       uint32_t expected_cache_end);
+void nffs_test_util_create_file_blocks(const char *filename,
+                                   const struct nffs_test_block_desc *blocks,
+                                   int num_blocks);
+void nffs_test_util_create_file(const char *filename, const char *contents,
+                                int contents_len);
+void nffs_test_util_append_file(const char *filename, const char *contents,
+                                int contents_len);
+void nffs_test_copy_area(const struct nffs_area_desc *from,
+                         const struct nffs_area_desc *to);
+void nffs_test_util_create_subtree(const char *parent_path,
+                                   const struct nffs_test_file_desc *elem);
+void nffs_test_util_create_tree(const struct nffs_test_file_desc *root_dir);
+
+/*
+ * Recursively descend directory structure
+ */
+void nffs_test_assert_file(const struct nffs_test_file_desc *file,
+                           struct nffs_inode_entry *inode_entry,
+                           const char *path);
+void nffs_test_assert_branch_touched(struct nffs_inode_entry *inode_entry);
+void nffs_test_assert_child_inode_present(struct nffs_inode_entry *child);
+void nffs_test_assert_block_present(struct nffs_hash_entry *block_entry);
+/*
+ * Recursively verify that the children of each directory are sorted
+ * on the directory children linked list by filename length
+ */
+void nffs_test_assert_children_sorted(struct nffs_inode_entry *inode_entry);
+void nffs_test_assert_system_once(const struct nffs_test_file_desc *root_dir);
+void nffs_test_assert_system(const struct nffs_test_file_desc *root_dir,
+                             const struct nffs_area_desc *area_descs);
+void nffs_test_assert_area_seqs(int seq1, int count1, int seq2, int count2);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_NFFS_TEST_UTILS_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/append_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/append_test.c b/fs/nffs/test/src/testcases/append_test.c
new file mode 100644
index 0000000..b676605
--- /dev/null
+++ b/fs/nffs/test/src/testcases/append_test.c
@@ -0,0 +1,169 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+void process_inode_entry(struct nffs_inode_entry *inode_entry, int indent);
+
+TEST_CASE(nffs_test_append)
+{
+    struct fs_file *file;
+    uint32_t len;
+    char c;
+    int rc;
+    int i;
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 0);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "abcdefgh", 8);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 8);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt", "abcdefgh", 8);
+
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 8);
+
+    /* File position should always be at the end of a file after an append.
+     * Seek to the middle prior to writing to test this.
+     */
+    rc = fs_seek(file, 2);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 2);
+
+    rc = fs_write(file, "ijklmnop", 8);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 16);
+    rc = fs_write(file, "qrstuvwx", 8);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 24);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt",
+                                  "abcdefghijklmnopqrstuvwx", 24);
+
+    rc = fs_mkdir("/mydir");
+    TEST_ASSERT_FATAL(rc == 0);
+    rc = fs_open("/mydir/gaga.txt", FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /*** Repeated appends to a large file. */
+    for (i = 0; i < 1000; i++) {
+        rc = fs_filelen(file, &len);
+        TEST_ASSERT_FATAL(rc == 0);
+
+        TEST_ASSERT(len == i);
+
+        if (i == 920) {
+            process_inode_entry(nffs_root_dir, 1);
+        }
+
+        c = '0' + i % 10;
+        rc = fs_write(file, &c, 1);
+        TEST_ASSERT_FATAL(rc == 0);
+    }
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/mydir/gaga.txt",
+        "01234567890123456789012345678901234567890123456789" /* 1 */
+        "01234567890123456789012345678901234567890123456789" /* 2 */
+        "01234567890123456789012345678901234567890123456789" /* 3 */
+        "01234567890123456789012345678901234567890123456789" /* 4 */
+        "01234567890123456789012345678901234567890123456789" /* 5 */
+        "01234567890123456789012345678901234567890123456789" /* 6 */
+        "01234567890123456789012345678901234567890123456789" /* 7 */
+        "01234567890123456789012345678901234567890123456789" /* 8 */
+        "01234567890123456789012345678901234567890123456789" /* 9 */
+        "01234567890123456789012345678901234567890123456789" /* 10 */
+        "01234567890123456789012345678901234567890123456789" /* 11 */
+        "01234567890123456789012345678901234567890123456789" /* 12 */
+        "01234567890123456789012345678901234567890123456789" /* 13 */
+        "01234567890123456789012345678901234567890123456789" /* 14 */
+        "01234567890123456789012345678901234567890123456789" /* 15 */
+        "01234567890123456789012345678901234567890123456789" /* 16 */
+        "01234567890123456789012345678901234567890123456789" /* 17 */
+        "01234567890123456789012345678901234567890123456789" /* 18 */
+        "01234567890123456789012345678901234567890123456789" /* 19 */
+        "01234567890123456789012345678901234567890123456789" /* 20 */
+        ,
+        1000);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = "abcdefghijklmnopqrstuvwx",
+                .contents_len = 24,
+            }, {
+                .filename = "mydir",
+                .is_dir = 1,
+                .children = (struct nffs_test_file_desc[]) { {
+                    .filename = "gaga.txt",
+                    .contents =
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    "01234567890123456789012345678901234567890123456789"
+    ,
+                    .contents_len = 1000,
+                }, {
+                    .filename = NULL,
+                } },
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/cache_large_file_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/cache_large_file_test.c b/fs/nffs/test/src/testcases/cache_large_file_test.c
new file mode 100644
index 0000000..e7e0591
--- /dev/null
+++ b/fs/nffs/test/src/testcases/cache_large_file_test.c
@@ -0,0 +1,89 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_cache_large_file)
+{
+    static char data[NFFS_BLOCK_MAX_DATA_SZ_MAX * 5];
+    struct fs_file *file;
+    uint8_t b;
+    int rc;
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file("/myfile.txt", data, sizeof data);
+    nffs_cache_clear();
+
+    /* Opening a file should not cause any blocks to get cached. */
+    rc = fs_open("/myfile.txt", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_cache_range("/myfile.txt", 0, 0);
+
+    /* Cache first block. */
+    rc = fs_seek(file, nffs_block_max_data_sz * 0);
+    TEST_ASSERT(rc == 0);
+    rc = fs_read(file, 1, &b, NULL);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_cache_range("/myfile.txt",
+                                     nffs_block_max_data_sz * 0,
+                                     nffs_block_max_data_sz * 1);
+
+    /* Cache second block. */
+    rc = fs_seek(file, nffs_block_max_data_sz * 1);
+    TEST_ASSERT(rc == 0);
+    rc = fs_read(file, 1, &b, NULL);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_cache_range("/myfile.txt",
+                                     nffs_block_max_data_sz * 0,
+                                     nffs_block_max_data_sz * 2);
+
+
+    /* Cache fourth block; prior cache should get erased. */
+    rc = fs_seek(file, nffs_block_max_data_sz * 3);
+    TEST_ASSERT(rc == 0);
+    rc = fs_read(file, 1, &b, NULL);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_cache_range("/myfile.txt",
+                                     nffs_block_max_data_sz * 3,
+                                     nffs_block_max_data_sz * 4);
+
+    /* Cache second and third blocks. */
+    rc = fs_seek(file, nffs_block_max_data_sz * 1);
+    TEST_ASSERT(rc == 0);
+    rc = fs_read(file, 1, &b, NULL);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_cache_range("/myfile.txt",
+                                     nffs_block_max_data_sz * 1,
+                                     nffs_block_max_data_sz * 4);
+
+    /* Cache fifth block. */
+    rc = fs_seek(file, nffs_block_max_data_sz * 4);
+    TEST_ASSERT(rc == 0);
+    rc = fs_read(file, 1, &b, NULL);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_cache_range("/myfile.txt",
+                                     nffs_block_max_data_sz * 1,
+                                     nffs_block_max_data_sz * 5);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/corrupt_block_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/corrupt_block_test.c b/fs/nffs/test/src/testcases/corrupt_block_test.c
new file mode 100644
index 0000000..8edfd42
--- /dev/null
+++ b/fs/nffs/test/src/testcases/corrupt_block_test.c
@@ -0,0 +1,121 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_corrupt_block)
+{
+    struct nffs_block block;
+    struct fs_file *fs_file;
+    struct nffs_file *file;
+    uint32_t flash_offset;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    uint8_t off;    /* offset to corrupt */
+    int rc;
+    struct nffs_disk_block ndb;
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/mydir");
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file("/mydir/a", "aaaa", 4);
+    nffs_test_util_create_file("/mydir/b", "bbbb", 4);
+    nffs_test_util_create_file("/mydir/c", "cccc", 4);
+
+    /* Add a second block to the 'b' file. */
+    nffs_test_util_append_file("/mydir/b", "1234", 4);
+
+    /* Corrupt the 'b' file; overwrite the second block's magic number. */
+    rc = fs_open("/mydir/b", FS_ACCESS_READ, &fs_file);
+    TEST_ASSERT(rc == 0);
+    file = (struct nffs_file *)fs_file;
+
+    rc = nffs_block_from_hash_entry(&block,
+                                   file->nf_inode_entry->nie_last_block_entry);
+    TEST_ASSERT(rc == 0);
+
+    nffs_flash_loc_expand(block.nb_hash_entry->nhe_flash_loc, &area_idx,
+                         &area_offset);
+    flash_offset = nffs_areas[area_idx].na_offset + area_offset;
+
+    /*
+     * Overwriting the reserved16 field should invalidate the CRC
+     */
+    off = (char*)&ndb.reserved16 - (char*)&ndb;
+    rc = flash_native_memset(flash_offset + off, 0x43, 1);
+
+    TEST_ASSERT(rc == 0);
+
+    /* Write a fourth file. This file should get restored even though the
+     * previous object has an invalid magic number.
+     */
+    nffs_test_util_create_file("/mydir/d", "dddd", 4);
+
+    rc = nffs_misc_reset();
+    TEST_ASSERT(rc == 0);
+    rc = nffs_detect(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    /* The entire second block should be removed; the file should only contain
+     * the first block.
+     */
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "mydir",
+                .is_dir = 1,
+                .children = (struct nffs_test_file_desc[]) { {
+                    .filename = "a",
+                    .contents = "aaaa",
+                    .contents_len = 4,
+#if 0
+                /*
+                 * In the newer implementation without the find_file_ends
+                 * corrupted inodes are deleted rather than retained with
+                 * partial contents
+                 */
+                }, {
+                    .filename = "b",
+                    .contents = "bbbb",
+                    .contents_len = 4,
+#endif
+                }, {
+                    .filename = "c",
+                    .contents = "cccc",
+                    .contents_len = 4,
+                }, {
+                    .filename = "d",
+                    .contents = "dddd",
+                    .contents_len = 4,
+                }, {
+                    .filename = NULL,
+                } },
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/corrupt_scratch_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/corrupt_scratch_test.c b/fs/nffs/test/src/testcases/corrupt_scratch_test.c
new file mode 100644
index 0000000..8f4b5af
--- /dev/null
+++ b/fs/nffs/test/src/testcases/corrupt_scratch_test.c
@@ -0,0 +1,83 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_corrupt_scratch)
+{
+    int non_scratch_id;
+    int scratch_id;
+    int rc;
+
+    static const struct nffs_area_desc area_descs_two[] = {
+        { 0x00020000, 128 * 1024 },
+        { 0x00040000, 128 * 1024 },
+        { 0, 0 },
+    };
+    nffs_current_area_descs = (struct nffs_area_desc*)area_descs_two;
+
+    /*** Setup. */
+    rc = nffs_format(area_descs_two);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file("/myfile.txt", "contents", 8);
+
+    /* Copy the current contents of the non-scratch area to the scratch area.
+     * This will make the scratch area look like it only partially
+     * participated in a garbage collection cycle.
+     */
+    scratch_id = nffs_scratch_area_idx;
+    non_scratch_id = scratch_id ^ 1;
+    nffs_test_copy_area(area_descs_two + non_scratch_id,
+                       area_descs_two + nffs_scratch_area_idx);
+
+    /* Add some more data to the non-scratch area. */
+    rc = fs_mkdir("/mydir");
+    TEST_ASSERT(rc == 0);
+
+    /* Ensure the file system is successfully detected and valid, despite
+     * corruption.
+     */
+
+    rc = nffs_misc_reset();
+    TEST_ASSERT(rc == 0);
+
+    rc = nffs_detect(area_descs_two);
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(nffs_scratch_area_idx == scratch_id);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "mydir",
+                .is_dir = 1,
+            }, {
+                .filename = "myfile.txt",
+                .contents = "contents",
+                .contents_len = 8,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, area_descs_two);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/gc_on_oom_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/gc_on_oom_test.c b/fs/nffs/test/src/testcases/gc_on_oom_test.c
new file mode 100644
index 0000000..32aeb5f
--- /dev/null
+++ b/fs/nffs/test/src/testcases/gc_on_oom_test.c
@@ -0,0 +1,88 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_gc_on_oom)
+{
+    int rc;
+
+    /*** Setup. */
+    /* Ensure all areas are the same size. */
+    static const struct nffs_area_desc area_descs_two[] = {
+            { 0x00000000, 16 * 1024 },
+            { 0x00004000, 16 * 1024 },
+            { 0x00008000, 16 * 1024 },
+            { 0, 0 },
+    };
+
+    rc = nffs_format(area_descs_two);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /* Leak block entries until only four are left. */
+    /* XXX: This is ridiculous.  Need to fix nffs configuration so that the
+     * caller passes a config object rather than writing to a global variable.
+     */
+    while (nffs_block_entry_pool.mp_num_free != 4) {
+        nffs_block_entry_alloc();
+    }
+
+    /*** Write 4 data blocks. */
+    struct nffs_test_block_desc blocks[4] = { {
+        .data = "1",
+        .data_len = 1,
+    }, {
+        .data = "2",
+        .data_len = 1,
+    }, {
+        .data = "3",
+        .data_len = 1,
+    }, {
+        .data = "4",
+        .data_len = 1,
+    } };
+
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 4);
+
+    TEST_ASSERT_FATAL(nffs_block_entry_pool.mp_num_free == 0);
+
+    /* Attempt another one-byte write.  This should trigger a garbage
+     * collection cycle, resulting in the four blocks being collated.  The
+     * fifth write consumes an additional block, resulting in 2 out of 4 blocks
+     * in use.
+     */
+    nffs_test_util_append_file("/myfile.txt", "5", 1);
+
+    TEST_ASSERT_FATAL(nffs_block_entry_pool.mp_num_free == 2);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = "12345",
+                .contents_len = 5,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, area_descs_two);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/gc_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/gc_test.c b/fs/nffs/test/src/testcases/gc_test.c
new file mode 100644
index 0000000..23e0642
--- /dev/null
+++ b/fs/nffs/test/src/testcases/gc_test.c
@@ -0,0 +1,67 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_gc)
+{
+    int rc;
+
+    static const struct nffs_area_desc area_descs_two[] = {
+        { 0x00020000, 128 * 1024 },
+        { 0x00040000, 128 * 1024 },
+        { 0, 0 },
+    };
+
+    struct nffs_test_block_desc blocks[8] = { {
+        .data = "1",
+        .data_len = 1,
+    }, {
+        .data = "2",
+        .data_len = 1,
+    }, {
+        .data = "3",
+        .data_len = 1,
+    }, {
+        .data = "4",
+        .data_len = 1,
+    }, {
+        .data = "5",
+        .data_len = 1,
+    }, {
+        .data = "6",
+        .data_len = 1,
+    }, {
+        .data = "7",
+        .data_len = 1,
+    }, {
+        .data = "8",
+        .data_len = 1,
+    } };
+
+
+    rc = nffs_format(area_descs_two);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 8);
+
+    nffs_gc(NULL);
+
+    nffs_test_util_assert_block_count("/myfile.txt", 1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/incomplete_block_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/incomplete_block_test.c b/fs/nffs/test/src/testcases/incomplete_block_test.c
new file mode 100644
index 0000000..4529e54
--- /dev/null
+++ b/fs/nffs/test/src/testcases/incomplete_block_test.c
@@ -0,0 +1,119 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+/*
+ * This test no longer works with the current implementation. The
+ * expectation is that intermediate blocks can be removed and the old
+ * method of finding the last current block after restore will allow the
+ * file to be salvaged. Instead, the file should be removed and all data
+ * declared invalid.
+ */
+TEST_CASE(nffs_test_incomplete_block)
+{
+    struct nffs_block block;
+    struct fs_file *fs_file;
+    struct nffs_file *file;
+    uint32_t flash_offset;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/mydir");
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file("/mydir/a", "aaaa", 4);
+    nffs_test_util_create_file("/mydir/b", "bbbb", 4);
+    nffs_test_util_create_file("/mydir/c", "cccc", 4);
+
+    /* Add a second block to the 'b' file. */
+    nffs_test_util_append_file("/mydir/b", "1234", 4);
+
+    /* Corrupt the 'b' file; make it look like the second block only got half
+     * written.
+     */
+    rc = fs_open("/mydir/b", FS_ACCESS_READ, &fs_file);
+    TEST_ASSERT(rc == 0);
+    file = (struct nffs_file *)fs_file;
+
+    rc = nffs_block_from_hash_entry(&block,
+                                   file->nf_inode_entry->nie_last_block_entry);
+    TEST_ASSERT(rc == 0);
+
+    nffs_flash_loc_expand(block.nb_hash_entry->nhe_flash_loc, &area_idx,
+                         &area_offset);
+    flash_offset = nffs_areas[area_idx].na_offset + area_offset;
+    /*
+     * Overwrite block data - the CRC check should pick this up
+     */
+    rc = flash_native_memset(
+            flash_offset + sizeof (struct nffs_disk_block) + 2, 0xff, 2);
+    TEST_ASSERT(rc == 0);
+
+    rc = nffs_misc_reset();
+    TEST_ASSERT(rc == 0);
+    rc = nffs_detect(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    /* OLD: The entire second block should be removed; the file should only
+     * contain the first block.
+     * Unless we can salvage the block, the entire file should probably be
+     * removed. This is a contrived example which generates bad data on the
+     * what happens to be the last block, but corruption can actually occur
+     * in any block. Sweep should be updated to search look for blocks that
+     * don't have a correct prev_id and then decide whether to delete the
+     * owning inode. XXX
+     */
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "mydir",
+                .is_dir = 1,
+                .children = (struct nffs_test_file_desc[]) { {
+                    .filename = "a",
+                    .contents = "aaaa",
+                    .contents_len = 4,
+#if 0
+/* keep this out until sweep updated to capture bad blocks XXX */
+                }, {
+                    .filename = "b",
+                    .contents = "bbbb",
+                    .contents_len = 4,
+#endif
+                }, {
+                    .filename = "c",
+                    .contents = "cccc",
+                    .contents_len = 4,
+                }, {
+                    .filename = NULL,
+                } },
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/large_system_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/large_system_test.c b/fs/nffs/test/src/testcases/large_system_test.c
new file mode 100644
index 0000000..6ca3ec1
--- /dev/null
+++ b/fs/nffs/test/src/testcases/large_system_test.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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_large_system)
+{
+    int rc;
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_create_tree(nffs_test_system_01);
+
+    nffs_test_assert_system(nffs_test_system_01, nffs_current_area_descs);
+
+    rc = fs_unlink("/lvl1dir-0000");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_unlink("/lvl1dir-0004");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/lvl1dir-0000");
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_assert_system(nffs_test_system_01_rm_1014_mk10, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/large_unlink_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/large_unlink_test.c b/fs/nffs/test/src/testcases/large_unlink_test.c
new file mode 100644
index 0000000..2626874
--- /dev/null
+++ b/fs/nffs/test/src/testcases/large_unlink_test.c
@@ -0,0 +1,80 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_large_unlink)
+{
+    static char file_contents[1024 * 4];
+    char filename[256];
+    int rc;
+    int i;
+    int j;
+    int k;
+
+    /*** Setup. */
+    nffs_config.nc_num_inodes = 1024;
+    nffs_config.nc_num_blocks = 1024;
+
+    rc = nffs_init();
+    TEST_ASSERT(rc == 0);
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    for (i = 0; i < 5; i++) {
+        snprintf(filename, sizeof filename, "/dir0_%d", i);
+        rc = fs_mkdir(filename);
+        TEST_ASSERT(rc == 0);
+
+        for (j = 0; j < 5; j++) {
+            snprintf(filename, sizeof filename, "/dir0_%d/dir1_%d", i, j);
+            rc = fs_mkdir(filename);
+            TEST_ASSERT(rc == 0);
+
+            for (k = 0; k < 5; k++) {
+                snprintf(filename, sizeof filename,
+                         "/dir0_%d/dir1_%d/file2_%d", i, j, k);
+                nffs_test_util_create_file(filename, file_contents,
+                                          sizeof file_contents);
+            }
+        }
+
+        for (j = 0; j < 15; j++) {
+            snprintf(filename, sizeof filename, "/dir0_%d/file1_%d", i, j);
+            nffs_test_util_create_file(filename, file_contents,
+                                      sizeof file_contents);
+        }
+    }
+
+    for (i = 0; i < 5; i++) {
+        snprintf(filename, sizeof filename, "/dir0_%d", i);
+        rc = fs_unlink(filename);
+        TEST_ASSERT(rc == 0);
+    }
+
+    /* The entire file system should be empty. */
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/large_write_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/large_write_test.c b/fs/nffs/test/src/testcases/large_write_test.c
new file mode 100644
index 0000000..8f653b5
--- /dev/null
+++ b/fs/nffs/test/src/testcases/large_write_test.c
@@ -0,0 +1,71 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_large_write)
+{
+    static char data[NFFS_BLOCK_MAX_DATA_SZ_MAX * 5];
+    int rc;
+    int i;
+
+    static const struct nffs_area_desc area_descs_two[] = {
+        { 0x00020000, 128 * 1024 },
+        { 0x00040000, 128 * 1024 },
+        { 0, 0 },
+    };
+
+    /*** Setup. */
+    rc = nffs_format(area_descs_two);
+    TEST_ASSERT(rc == 0);
+
+    for (i = 0; i < sizeof data; i++) {
+        data[i] = i;
+    }
+
+    nffs_test_util_create_file("/myfile.txt", data, sizeof data);
+
+    /* Ensure large write was split across the appropriate number of data
+     * blocks.
+     */
+    TEST_ASSERT(nffs_test_util_block_count("/myfile.txt") ==
+           sizeof data / NFFS_BLOCK_MAX_DATA_SZ_MAX);
+
+    /* Garbage collect and then ensure the large file is still properly divided
+     * according to max data block size.
+     */
+    nffs_gc(NULL);
+    TEST_ASSERT(nffs_test_util_block_count("/myfile.txt") ==
+           sizeof data / NFFS_BLOCK_MAX_DATA_SZ_MAX);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = data,
+                .contents_len = sizeof data,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, area_descs_two);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/long_filename_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/long_filename_test.c b/fs/nffs/test/src/testcases/long_filename_test.c
new file mode 100644
index 0000000..369d66c
--- /dev/null
+++ b/fs/nffs/test/src/testcases/long_filename_test.c
@@ -0,0 +1,59 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_long_filename)
+{
+    int rc;
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file("/12345678901234567890.txt", "contents", 8);
+
+    rc = fs_mkdir("/longdir12345678901234567890");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_rename("/12345678901234567890.txt",
+                    "/longdir12345678901234567890/12345678901234567890.txt");
+    TEST_ASSERT(rc == 0);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "longdir12345678901234567890",
+                .is_dir = 1,
+                .children = (struct nffs_test_file_desc[]) { {
+                    .filename = "/12345678901234567890.txt",
+                    .contents = "contents",
+                    .contents_len = 8,
+                }, {
+                    .filename = NULL,
+                } },
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/lost_found_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/lost_found_test.c b/fs/nffs/test/src/testcases/lost_found_test.c
new file mode 100644
index 0000000..c6cda5b
--- /dev/null
+++ b/fs/nffs/test/src/testcases/lost_found_test.c
@@ -0,0 +1,107 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_lost_found)
+{
+    char buf[32];
+    struct nffs_inode_entry *inode_entry;
+    uint32_t flash_offset;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+    struct nffs_disk_inode ndi;
+    uint8_t off;    /* calculated offset for memset */
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/mydir");
+    TEST_ASSERT(rc == 0);
+    rc = fs_mkdir("/mydir/dir1");
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file("/mydir/file1", "aaaa", 4);
+    nffs_test_util_create_file("/mydir/dir1/file2", "bbbb", 4);
+
+    /* Corrupt the mydir inode. */
+    rc = nffs_path_find_inode_entry("/mydir", &inode_entry);
+    TEST_ASSERT(rc == 0);
+
+    snprintf(buf, sizeof buf, "%lu",
+             (unsigned long)inode_entry->nie_hash_entry.nhe_id);
+
+    nffs_flash_loc_expand(inode_entry->nie_hash_entry.nhe_flash_loc,
+                         &area_idx, &area_offset);
+    flash_offset = nffs_areas[area_idx].na_offset + area_offset;
+    /*
+     * Overwrite the sequence number - should be detected as CRC corruption
+     */
+    off = (char*)&ndi.ndi_seq - (char*)&ndi;
+    rc = flash_native_memset(flash_offset + off, 0xaa, 1);
+    TEST_ASSERT(rc == 0);
+
+    /* Clear cached data and restore from flash (i.e, simulate a reboot). */
+    rc = nffs_misc_reset();
+    TEST_ASSERT(rc == 0);
+    rc = nffs_detect(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    /* All contents should now be in the lost+found dir. */
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "lost+found",
+                .is_dir = 1,
+#if 0
+                .children = (struct nffs_test_file_desc[]) { {
+                    .filename = buf,
+                    .is_dir = 1,
+                    .children = (struct nffs_test_file_desc[]) { {
+                        .filename = "file1",
+                        .contents = "aaaa",
+                        .contents_len = 4,
+                    }, {
+                        .filename = "dir1",
+                        .is_dir = 1,
+                        .children = (struct nffs_test_file_desc[]) { {
+                            .filename = "file2",
+                            .contents = "bbbb",
+                            .contents_len = 4,
+                        }, {
+                            .filename = NULL,
+                        } },
+                    }, {
+                        .filename = NULL,
+                    } },
+                }, {
+                    .filename = NULL,
+                } },
+#endif
+            }, {
+                .filename = NULL,
+            } }
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/many_children_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/many_children_test.c b/fs/nffs/test/src/testcases/many_children_test.c
new file mode 100644
index 0000000..4bc7cdd
--- /dev/null
+++ b/fs/nffs/test/src/testcases/many_children_test.c
@@ -0,0 +1,74 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_many_children)
+{
+    int rc;
+
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file("/zasdf", NULL, 0);
+    nffs_test_util_create_file("/FfD", NULL, 0);
+    nffs_test_util_create_file("/4Zvv", NULL, 0);
+    nffs_test_util_create_file("/*(*2fs", NULL, 0);
+    nffs_test_util_create_file("/pzzd", NULL, 0);
+    nffs_test_util_create_file("/zasdf0", NULL, 0);
+    nffs_test_util_create_file("/23132.bin", NULL, 0);
+    nffs_test_util_create_file("/asldkfjaldskfadsfsdf.txt", NULL, 0);
+    nffs_test_util_create_file("/sdgaf", NULL, 0);
+    nffs_test_util_create_file("/939302**", NULL, 0);
+    rc = fs_mkdir("/dir");
+    nffs_test_util_create_file("/dir/itw82", NULL, 0);
+    nffs_test_util_create_file("/dir/124", NULL, 0);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) {
+                { "zasdf" },
+                { "FfD" },
+                { "4Zvv" },
+                { "*(*2fs" },
+                { "pzzd" },
+                { "zasdf0" },
+                { "23132.bin" },
+                { "asldkfjaldskfadsfsdf.txt" },
+                { "sdgaf" },
+                { "939302**" },
+                {
+                    .filename = "dir",
+                    .is_dir = 1,
+                    .children = (struct nffs_test_file_desc[]) {
+                        { "itw82" },
+                        { "124" },
+                        { NULL },
+                    },
+                },
+                { NULL },
+            }
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/mkdir_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/mkdir_test.c b/fs/nffs/test/src/testcases/mkdir_test.c
new file mode 100644
index 0000000..87e3966
--- /dev/null
+++ b/fs/nffs/test/src/testcases/mkdir_test.c
@@ -0,0 +1,92 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_mkdir)
+{
+    struct fs_file *file;
+    int rc;
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/a/b/c/d");
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    rc = fs_mkdir("asdf");
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    rc = fs_mkdir("/a");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/a/b");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/a/b/c");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/a/b/c/d");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_open("/a/b/c/d/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "a",
+                .is_dir = 1,
+                .children = (struct nffs_test_file_desc[]) { {
+                    .filename = "b",
+                    .is_dir = 1,
+                    .children = (struct nffs_test_file_desc[]) { {
+                        .filename = "c",
+                        .is_dir = 1,
+                        .children = (struct nffs_test_file_desc[]) { {
+                            .filename = "d",
+                            .is_dir = 1,
+                            .children = (struct nffs_test_file_desc[]) { {
+                                .filename = "myfile.txt",
+                                .contents = NULL,
+                                .contents_len = 0,
+                            }, {
+                                .filename = NULL,
+                            } },
+                        }, {
+                            .filename = NULL,
+                        } },
+                    }, {
+                        .filename = NULL,
+                    } },
+                }, {
+                    .filename = NULL,
+                } },
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/open_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/open_test.c b/fs/nffs/test/src/testcases/open_test.c
new file mode 100644
index 0000000..c601526
--- /dev/null
+++ b/fs/nffs/test/src/testcases/open_test.c
@@ -0,0 +1,74 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_open)
+{
+    struct fs_file *file;
+    struct fs_dir *dir;
+    int rc;
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    /*** Fail to open an invalid path (not rooted). */
+    rc = fs_open("file", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    /*** Fail to open a directory (root directory). */
+    rc = fs_open("/", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    /*** Fail to open a nonexistent file for reading. */
+    rc = fs_open("/1234", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    /*** Fail to open a child of a nonexistent directory. */
+    rc = fs_open("/dir/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == FS_ENOENT);
+    rc = fs_opendir("/dir", &dir);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    rc = fs_mkdir("/dir");
+    TEST_ASSERT(rc == 0);
+
+    /*** Fail to open a directory. */
+    rc = fs_open("/dir", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    /*** Successfully open an existing file for reading. */
+    nffs_test_util_create_file("/dir/file.txt", "1234567890", 10);
+    rc = fs_open("/dir/file.txt", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == 0);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    /*** Successfully open an nonexistent file for writing. */
+    rc = fs_open("/dir/file2.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    /*** Ensure the file can be reopened. */
+    rc = fs_open("/dir/file.txt", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == 0);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/overwrite_many_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/overwrite_many_test.c b/fs/nffs/test/src/testcases/overwrite_many_test.c
new file mode 100644
index 0000000..7242b6f
--- /dev/null
+++ b/fs/nffs/test/src/testcases/overwrite_many_test.c
@@ -0,0 +1,105 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_overwrite_many)
+{
+    struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { {
+        .data = "abcdefgh",
+        .data_len = 8,
+    }, {
+        .data = "ijklmnop",
+        .data_len = 8,
+    }, {
+        .data = "qrstuvwx",
+        .data_len = 8,
+    } };
+
+    struct fs_file *file;
+    int rc;
+
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    /*** Overwrite middle of first block. */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 3);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 3);
+
+    rc = fs_write(file, "12", 2);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 5);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt",
+                                   "abc12fghijklmnopqrstuvwx", 24);
+    nffs_test_util_assert_block_count("/myfile.txt", 3);
+
+    /*** Overwrite end of first block, start of second. */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 6);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 6);
+
+    rc = fs_write(file, "1234", 4);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 10);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt",
+                                   "abcdef1234klmnopqrstuvwx", 24);
+    nffs_test_util_assert_block_count("/myfile.txt", 3);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = "abcdef1234klmnopqrstuvwx",
+                .contents_len = 24,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/overwrite_one_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/overwrite_one_test.c b/fs/nffs/test/src/testcases/overwrite_one_test.c
new file mode 100644
index 0000000..9f29602
--- /dev/null
+++ b/fs/nffs/test/src/testcases/overwrite_one_test.c
@@ -0,0 +1,142 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_overwrite_one)
+{
+    struct fs_file *file;
+    int rc;
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_append_file("/myfile.txt", "abcdefgh", 8);
+
+    /*** Overwrite within one block (middle). */
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 3);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 3);
+
+    rc = fs_write(file, "12", 2);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 5);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt", "abc12fgh", 8);
+    nffs_test_util_assert_block_count("/myfile.txt", 1);
+
+    /*** Overwrite within one block (start). */
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "xy", 2);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 2);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt", "xyc12fgh", 8);
+    nffs_test_util_assert_block_count("/myfile.txt", 1);
+
+    /*** Overwrite within one block (end). */
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 6);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 6);
+
+    rc = fs_write(file, "<>", 2);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 8);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt", "xyc12f<>", 8);
+    nffs_test_util_assert_block_count("/myfile.txt", 1);
+
+    /*** Overwrite one block middle, extend. */
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 4);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 4);
+
+    rc = fs_write(file, "abcdefgh", 8);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 12);
+    TEST_ASSERT(fs_getpos(file) == 12);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt", "xyc1abcdefgh", 12);
+    nffs_test_util_assert_block_count("/myfile.txt", 1);
+
+    /*** Overwrite one block start, extend. */
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 12);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "abcdefghijklmnop", 16);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 16);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt", "abcdefghijklmnop", 16);
+    nffs_test_util_assert_block_count("/myfile.txt", 1);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = "abcdefghijklmnop",
+                .contents_len = 16,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}


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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/nffs_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test.c b/fs/nffs/test/src/nffs_test.c
new file mode 100644
index 0000000..be9791c
--- /dev/null
+++ b/fs/nffs/test/src/nffs_test.c
@@ -0,0 +1,721 @@
+/**
+ * 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
+ * 
+ * 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 <stdlib.h>
+#include <errno.h>
+#include "syscfg/syscfg.h"
+#include "hal/hal_flash.h"
+#include "testutil/testutil.h"
+#include "fs/fs.h"
+#include "nffs/nffs.h"
+#include "nffs/nffs_test.h"
+#include "nffs_test_priv.h"
+#include "nffs_priv.h"
+#include "nffs_test.h"
+
+#if MYNEWT_VAL(SELFTEST)
+struct nffs_area_desc nffs_selftest_area_descs[] = {
+        { 0x00000000, 16 * 1024 },
+        { 0x00004000, 16 * 1024 },
+        { 0x00008000, 16 * 1024 },
+        { 0x0000c000, 16 * 1024 },
+        { 0x00010000, 64 * 1024 },
+        { 0x00020000, 128 * 1024 },
+        { 0x00040000, 128 * 1024 },
+        { 0x00060000, 128 * 1024 },
+        { 0x00080000, 128 * 1024 },
+        { 0x000a0000, 128 * 1024 },
+        { 0x000c0000, 128 * 1024 },
+        { 0x000e0000, 128 * 1024 },
+        { 0, 0 },
+};
+
+struct nffs_area_desc *save_area_descs;
+
+void
+nffs_testcase_pre(void* arg)
+{
+    save_area_descs = nffs_current_area_descs;
+    nffs_current_area_descs = nffs_selftest_area_descs;
+    return;
+}
+
+void
+nffs_testcase_post(void* arg)
+{
+    nffs_current_area_descs = save_area_descs;
+    return;
+}
+
+TEST_CASE_DECL(nffs_test_unlink)
+TEST_CASE_DECL(nffs_test_mkdir)
+TEST_CASE_DECL(nffs_test_rename)
+TEST_CASE_DECL(nffs_test_truncate)
+TEST_CASE_DECL(nffs_test_append)
+TEST_CASE_DECL(nffs_test_read)
+TEST_CASE_DECL(nffs_test_open)
+TEST_CASE_DECL(nffs_test_overwrite_one)
+TEST_CASE_DECL(nffs_test_overwrite_two)
+TEST_CASE_DECL(nffs_test_overwrite_three)
+TEST_CASE_DECL(nffs_test_overwrite_many)
+TEST_CASE_DECL(nffs_test_long_filename)
+TEST_CASE_DECL(nffs_test_large_write)
+TEST_CASE_DECL(nffs_test_many_children)
+TEST_CASE_DECL(nffs_test_gc)
+TEST_CASE_DECL(nffs_test_wear_level)
+TEST_CASE_DECL(nffs_test_corrupt_scratch)
+TEST_CASE_DECL(nffs_test_incomplete_block)
+TEST_CASE_DECL(nffs_test_corrupt_block)
+TEST_CASE_DECL(nffs_test_large_unlink)
+TEST_CASE_DECL(nffs_test_large_system)
+TEST_CASE_DECL(nffs_test_lost_found)
+TEST_CASE_DECL(nffs_test_readdir)
+TEST_CASE_DECL(nffs_test_split_file)
+TEST_CASE_DECL(nffs_test_gc_on_oom)
+
+void
+nffs_test_suite_gen_1_1_init(void)
+{
+    nffs_config.nc_num_cache_inodes = 1;
+    nffs_config.nc_num_cache_blocks = 1;
+
+    tu_suite_set_pre_test_cb(nffs_testcase_pre, NULL);
+    tu_suite_set_post_test_cb(nffs_testcase_post, NULL);
+    return;
+}
+    
+void
+nffs_test_suite_gen_4_32_init(void)
+{
+    nffs_config.nc_num_cache_inodes = 4;
+    nffs_config.nc_num_cache_blocks = 32;
+
+    tu_suite_set_pre_test_cb(nffs_testcase_pre, NULL);
+    tu_suite_set_post_test_cb(nffs_testcase_post, NULL);
+    return;
+}
+    
+void
+nffs_test_suite_gen_32_1024_init(void)
+{
+    nffs_config.nc_num_cache_inodes = 32;
+    nffs_config.nc_num_cache_blocks = 1024;
+
+    tu_suite_set_pre_test_cb(nffs_testcase_pre, NULL);
+    tu_suite_set_post_test_cb(nffs_testcase_post, NULL);
+    return;
+}
+
+TEST_SUITE(nffs_test_suite)
+{
+    int rc;
+
+    rc = nffs_init();
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_unlink();
+    nffs_test_mkdir();
+    nffs_test_rename();
+    nffs_test_truncate();
+    nffs_test_append();
+    nffs_test_read();
+    nffs_test_open();
+    nffs_test_overwrite_one();
+    nffs_test_overwrite_two();
+    nffs_test_overwrite_three();
+    nffs_test_overwrite_many();
+    nffs_test_long_filename();
+    nffs_test_large_write();
+    nffs_test_many_children();
+    nffs_test_gc();
+    nffs_test_wear_level();
+    nffs_test_corrupt_scratch();
+    nffs_test_incomplete_block();
+    nffs_test_corrupt_block();
+    nffs_test_large_unlink();
+    nffs_test_large_system();
+    nffs_test_lost_found();
+    nffs_test_readdir();
+    nffs_test_split_file();
+    nffs_test_gc_on_oom();
+}
+
+TEST_CASE_DECL(nffs_test_cache_large_file)
+
+TEST_SUITE(nffs_suite_cache)
+{
+    int rc;
+
+    rc = nffs_init();
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_cache_large_file();
+}
+
+void
+nffs_test_suite_cache_init(void)
+{
+    memset(&nffs_config, 0, sizeof nffs_config);
+    nffs_config.nc_num_cache_inodes = 4;
+    nffs_config.nc_num_cache_blocks = 64;
+
+    tu_suite_set_pre_test_cb(nffs_testcase_pre, NULL);
+    tu_suite_set_post_test_cb(nffs_testcase_post, NULL);
+    return;
+}
+
+int
+main(void)
+{
+    ts_config.ts_print_results = 1;
+    ts_config.ts_system_assert = 0; /* handle asserts */
+    nffs_config.nc_num_inodes = 1024 * 8;
+    nffs_config.nc_num_blocks = 1024 * 20;
+    nffs_current_area_descs = nffs_selftest_area_descs;
+
+    tu_init();
+
+    tu_suite_set_init_cb((void*)nffs_test_suite_gen_1_1_init, NULL);
+    nffs_test_suite();
+
+    tu_suite_set_init_cb((void*)nffs_test_suite_gen_4_32_init, NULL);
+    nffs_test_suite();
+
+    tu_suite_set_init_cb((void*)nffs_test_suite_gen_32_1024_init, NULL);
+    nffs_test_suite();
+
+    tu_suite_set_init_cb((void*)nffs_test_suite_cache_init, NULL);
+    nffs_suite_cache();
+
+    return tu_any_failed;
+}
+
+#if 0
+#include <unistd.h>
+
+void
+nffs_assert_handler(const char *file, int line, const char *func, const char *e)
+{
+    char msg[256];
+
+    snprintf(msg, sizeof(msg), "assert at %s:%d\n", file, line);
+    write(1, msg, strlen(msg));
+    _exit(1);
+}
+#endif
+
+#ifdef NFFS_DEBUG
+/*
+ * All debug stuff below this
+ */
+int print_verbose;
+
+void
+print_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
+{
+    struct nffs_inode inode;
+    char name[NFFS_FILENAME_MAX_LEN + 1];
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    if (inode_entry == nffs_root_dir) {
+        printf("%*s/\n", indent, "");
+        return;
+    }
+
+    rc = nffs_inode_from_entry(&inode, inode_entry);
+    /*
+     * Dummy inode
+     */
+    if (rc == FS_ENOENT) {
+        printf("    DUMMY %d\n", rc);
+        return;
+    }
+
+    nffs_flash_loc_expand(inode_entry->nie_hash_entry.nhe_flash_loc,
+                         &area_idx, &area_offset);
+
+    rc = nffs_flash_read(area_idx,
+                         area_offset + sizeof (struct nffs_disk_inode),
+                         name, inode.ni_filename_len);
+
+    name[inode.ni_filename_len] = '\0';
+
+    /*printf("%*s%s\n", indent, "", name[0] == '\0' ? "/" : name);*/
+    printf("%*s%s %d %d %x\n", indent, "", name[0] == '\0' ? "/" : name,
+           inode.ni_filename_len, inode.ni_seq,
+           inode.ni_inode_entry->nie_flags);
+}
+
+void
+process_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
+{
+    struct nffs_inode_entry *child;
+
+    print_inode_entry(inode_entry, indent);
+
+    if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
+        SLIST_FOREACH(child, &inode_entry->nie_child_list, nie_sibling_next) {
+            process_inode_entry(child, indent + 2);
+        }
+    }
+}
+
+int
+print_nffs_flash_inode(struct nffs_area *area, uint32_t off)
+{
+    struct nffs_disk_inode ndi;
+    char filename[128];
+    int len;
+    int rc;
+
+    rc = hal_flash_read(area->na_flash_id, area->na_offset + off,
+                         &ndi, sizeof(ndi));
+    assert(rc == 0);
+
+    memset(filename, 0, sizeof(filename));
+    len = min(sizeof(filename) - 1, ndi.ndi_filename_len);
+    rc = hal_flash_read(area->na_flash_id, area->na_offset + off + sizeof(ndi),
+                         filename, len);
+
+    printf("  off %x %s id %x flen %d seq %d last %x prnt %x flgs %x %s\n",
+           off,
+           (nffs_hash_id_is_file(ndi.ndi_id) ? "File" :
+            (nffs_hash_id_is_dir(ndi.ndi_id) ? "Dir" : "???")),
+           ndi.ndi_id,
+           ndi.ndi_filename_len,
+           ndi.ndi_seq,
+           ndi.ndi_lastblock_id,
+           ndi.ndi_parent_id,
+           ndi.ndi_flags,
+           filename);
+    return sizeof(ndi) + ndi.ndi_filename_len;
+}
+
+int
+print_nffs_flash_block(struct nffs_area *area, uint32_t off)
+{
+    struct nffs_disk_block ndb;
+    int rc;
+
+    rc = hal_flash_read(area->na_flash_id, area->na_offset + off,
+                        &ndb, sizeof(ndb));
+    assert(rc == 0);
+
+    printf("  off %x Block id %x len %d seq %d prev %x own ino %x\n",
+           off,
+           ndb.ndb_id,
+           ndb.ndb_data_len,
+           ndb.ndb_seq,
+           ndb.ndb_prev_id,
+           ndb.ndb_inode_id);
+    return sizeof(ndb) + ndb.ndb_data_len;
+}
+
+int
+print_nffs_flash_object(struct nffs_area *area, uint32_t off)
+{
+    struct nffs_disk_object ndo;
+
+    hal_flash_read(area->na_flash_id, area->na_offset + off,
+                        &ndo.ndo_un_obj, sizeof(ndo.ndo_un_obj));
+
+    if (nffs_hash_id_is_inode(ndo.ndo_disk_inode.ndi_id)) {
+        return print_nffs_flash_inode(area, off);
+
+    } else if (nffs_hash_id_is_block(ndo.ndo_disk_block.ndb_id)) {
+        return print_nffs_flash_block(area, off);
+
+    } else if (ndo.ndo_disk_block.ndb_id == 0xffffffff) {
+        return area->na_length;
+
+    } else {
+        return 1;
+    }
+}
+
+void
+print_nffs_flash_areas(int verbose)
+{
+    struct nffs_area area;
+    struct nffs_disk_area darea;
+    int off;
+    int i;
+
+    for (i = 0; nffs_current_area_descs[i].nad_length != 0; i++) {
+        if (i > NFFS_MAX_AREAS) {
+            return;
+        }
+        area.na_offset = nffs_current_area_descs[i].nad_offset;
+        area.na_length = nffs_current_area_descs[i].nad_length;
+        area.na_flash_id = nffs_current_area_descs[i].nad_flash_id;
+        hal_flash_read(area.na_flash_id, area.na_offset, &darea, sizeof(darea));
+        area.na_id = darea.nda_id;
+        area.na_cur = nffs_areas[i].na_cur;
+        if (!nffs_area_magic_is_set(&darea)) {
+            printf("Area header corrupt!\n");
+        }
+        printf("area %d: id %d %x-%x cur %x len %d flashid %x gc-seq %d %s%s\n",
+               i, area.na_id, area.na_offset, area.na_offset + area.na_length,
+               area.na_cur, area.na_length, area.na_flash_id, darea.nda_gc_seq,
+               nffs_scratch_area_idx == i ? "(scratch)" : "",
+               !nffs_area_magic_is_set(&darea) ? "corrupt" : "");
+        if (verbose < 2) {
+            off = sizeof (struct nffs_disk_area);
+            while (off < area.na_length) {
+                off += print_nffs_flash_object(&area, off);
+            }
+        }
+    }
+}
+
+static int
+nffs_hash_fn(uint32_t id)
+{
+    return id % NFFS_HASH_SIZE;
+}
+
+void
+print_hashlist(struct nffs_hash_entry *he)
+{
+    struct nffs_hash_list *list;
+    int idx = nffs_hash_fn(he->nhe_id);
+    list = nffs_hash + idx;
+
+    SLIST_FOREACH(he, list, nhe_next) {
+        printf("hash_entry %s 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+                   nffs_hash_id_is_inode(he->nhe_id) ? "inode" : "block",
+                   (unsigned int)he,
+                   he->nhe_id, he->nhe_flash_loc,
+                   (unsigned int)he->nhe_next.sle_next);
+   }
+}
+
+void
+print_hash(void)
+{
+    int i;
+    struct nffs_hash_entry *he;
+    struct nffs_hash_entry *next;
+    struct nffs_inode ni;
+    struct nffs_disk_inode di;
+    struct nffs_block nb;
+    struct nffs_disk_block db;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    NFFS_HASH_FOREACH(he, i, next) {
+        if (nffs_hash_id_is_inode(he->nhe_id)) {
+            printf("hash_entry inode %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+                   i, (unsigned int)he,
+                   he->nhe_id, he->nhe_flash_loc,
+                   (unsigned int)he->nhe_next.sle_next);
+            if (he->nhe_id == NFFS_ID_ROOT_DIR) {
+                continue;
+            }
+            nffs_flash_loc_expand(he->nhe_flash_loc,
+                                  &area_idx, &area_offset);
+            rc = nffs_inode_read_disk(area_idx, area_offset, &di);
+            if (rc) {
+                printf("%d: fail inode read id 0x%x rc %d\n",
+                       i, he->nhe_id, rc);
+            }
+            printf("    Disk inode: id %x seq %d parent %x last %x flgs %x\n",
+                   di.ndi_id,
+                   di.ndi_seq,
+                   di.ndi_parent_id,
+                   di.ndi_lastblock_id,
+                   di.ndi_flags);
+            ni.ni_inode_entry = (struct nffs_inode_entry *)he;
+            ni.ni_seq = di.ndi_seq; 
+            ni.ni_parent = nffs_hash_find_inode(di.ndi_parent_id);
+            printf("    RAM inode: entry 0x%x seq %d parent %x filename %s\n",
+                   (unsigned int)ni.ni_inode_entry,
+                   ni.ni_seq,
+                   (unsigned int)ni.ni_parent,
+                   ni.ni_filename);
+
+        } else if (nffs_hash_id_is_block(he->nhe_id)) {
+            printf("hash_entry block %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+                   i, (unsigned int)he,
+                   he->nhe_id, he->nhe_flash_loc,
+                   (unsigned int)he->nhe_next.sle_next);
+            rc = nffs_block_from_hash_entry(&nb, he);
+            if (rc) {
+                printf("%d: fail block read id 0x%x rc %d\n",
+                       i, he->nhe_id, rc);
+            }
+            printf("    block: id %x seq %d inode %x prev %x\n",
+                   nb.nb_hash_entry->nhe_id, nb.nb_seq, 
+                   nb.nb_inode_entry->nie_hash_entry.nhe_id, 
+                   nb.nb_prev->nhe_id);
+            nffs_flash_loc_expand(nb.nb_hash_entry->nhe_flash_loc,
+                                  &area_idx, &area_offset);
+            rc = nffs_block_read_disk(area_idx, area_offset, &db);
+            if (rc) {
+                printf("%d: fail disk block read id 0x%x rc %d\n",
+                       i, nb.nb_hash_entry->nhe_id, rc);
+            }
+            printf("    disk block: id %x seq %d inode %x prev %x len %d\n",
+                   db.ndb_id,
+                   db.ndb_seq,
+                   db.ndb_inode_id,
+                   db.ndb_prev_id,
+                   db.ndb_data_len);
+        } else {
+            printf("hash_entry UNKNONN %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+                   i, (unsigned int)he,
+                   he->nhe_id, he->nhe_flash_loc,
+                   (unsigned int)he->nhe_next.sle_next);
+        }
+    }
+
+}
+
+void
+nffs_print_object(struct nffs_disk_object *dobj)
+{
+    struct nffs_disk_inode *di = &dobj->ndo_disk_inode;
+    struct nffs_disk_block *db = &dobj->ndo_disk_block;
+
+    if (dobj->ndo_type == NFFS_OBJECT_TYPE_INODE) {
+        printf("    %s id %x seq %d prnt %x last %x\n",
+               nffs_hash_id_is_file(di->ndi_id) ? "File" :
+                nffs_hash_id_is_dir(di->ndi_id) ? "Dir" : "???",
+               di->ndi_id, di->ndi_seq, di->ndi_parent_id,
+               di->ndi_lastblock_id);
+    } else if (dobj->ndo_type != NFFS_OBJECT_TYPE_BLOCK) {
+        printf("    %s: id %x seq %d ino %x prev %x len %d\n",
+               nffs_hash_id_is_block(db->ndb_id) ? "Block" : "Block?",
+               db->ndb_id, db->ndb_seq, db->ndb_inode_id,
+               db->ndb_prev_id, db->ndb_data_len);
+    }
+}
+
+void
+print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
+{
+    struct nffs_block nb;
+    struct nffs_disk_block db;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    if (he == NULL) {
+        return;
+    }
+    if (!nffs_hash_entry_is_dummy(he)) {
+        nffs_flash_loc_expand(he->nhe_flash_loc,
+                              &area_idx, &area_offset);
+        rc = nffs_block_read_disk(area_idx, area_offset, &db);
+        if (rc) {
+            printf("%p: fail block read id 0x%x rc %d\n",
+                   he, he->nhe_id, rc);
+        }
+        nb.nb_hash_entry = he;
+        nb.nb_seq = db.ndb_seq;
+        if (db.ndb_inode_id != NFFS_ID_NONE) {
+            nb.nb_inode_entry = nffs_hash_find_inode(db.ndb_inode_id);
+        } else {
+            nb.nb_inode_entry = (void*)db.ndb_inode_id;
+        }
+        if (db.ndb_prev_id != NFFS_ID_NONE) {
+            nb.nb_prev = nffs_hash_find_block(db.ndb_prev_id);
+        } else {
+            nb.nb_prev = (void*)db.ndb_prev_id;
+        }
+        nb.nb_data_len = db.ndb_data_len;
+    } else {
+        nb.nb_inode_entry = NULL;
+        db.ndb_id = 0;
+    }
+    if (!verbose) {
+        printf("%s%s id %x idx/off %d/%x seq %d ino %x prev %x len %d\n",
+               nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
+               nffs_hash_id_is_block(he->nhe_id) ? "Block" : "Unknown",
+               he->nhe_id, area_idx, area_offset, nb.nb_seq,
+               nb.nb_inode_entry->nie_hash_entry.nhe_id,
+               (unsigned int)db.ndb_prev_id, db.ndb_data_len);
+        return;
+    }
+    printf("%s%s id %x loc %x/%x %x ent %p\n",
+           nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
+           nffs_hash_id_is_block(he->nhe_id) ? "Block:" : "Unknown:",
+           he->nhe_id, area_idx, area_offset, he->nhe_flash_loc, he);
+    if (nb.nb_inode_entry) {
+        printf("  Ram: ent %p seq %d ino %p prev %p len %d\n",
+               nb.nb_hash_entry, nb.nb_seq,
+               nb.nb_inode_entry, nb.nb_prev, nb.nb_data_len);
+    }
+    if (db.ndb_id) {
+        printf("  Disk %s id %x seq %d ino %x prev %x len %d\n",
+               nffs_hash_id_is_block(db.ndb_id) ? "Block:" : "???:",
+               db.ndb_id, db.ndb_seq, db.ndb_inode_id,
+               db.ndb_prev_id, db.ndb_data_len);
+    }
+}
+
+void
+print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
+{
+    struct nffs_inode ni;
+    struct nffs_disk_inode di;
+    struct nffs_inode_entry *nie = (struct nffs_inode_entry*)he;
+    int cached_name_len;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    if (he == NULL) {
+        return;
+    }
+    if (!nffs_hash_entry_is_dummy(he)) {
+        nffs_flash_loc_expand(he->nhe_flash_loc,
+                              &area_idx, &area_offset);
+        rc = nffs_inode_read_disk(area_idx, area_offset, &di);
+        if (rc) {
+            printf("Entry %p: fail inode read id 0x%x rc %d\n",
+                   he, he->nhe_id, rc);
+        }
+        ni.ni_inode_entry = (struct nffs_inode_entry *)he;
+        ni.ni_seq = di.ndi_seq; 
+        if (di.ndi_parent_id != NFFS_ID_NONE) {
+            ni.ni_parent = nffs_hash_find_inode(di.ndi_parent_id);
+        } else {
+            ni.ni_parent = NULL;
+        }
+        if (ni.ni_filename_len > NFFS_SHORT_FILENAME_LEN) {
+            cached_name_len = NFFS_SHORT_FILENAME_LEN;
+        } else {
+            cached_name_len = ni.ni_filename_len;
+        }
+        if (cached_name_len != 0) {
+            rc = nffs_flash_read(area_idx, area_offset + sizeof di,
+                         ni.ni_filename, cached_name_len);
+            if (rc != 0) {
+                printf("entry %p: fail filename read id 0x%x rc %d\n",
+                       he, he->nhe_id, rc);
+                return;
+            }
+        }
+    } else {
+        ni.ni_inode_entry = NULL;
+        di.ndi_id = 0;
+    }
+    if (!verbose) {
+        printf("%s%s id %x idx/off %x/%x seq %d prnt %x last %x flags %x",
+               nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
+
+               nffs_hash_id_is_file(he->nhe_id) ? "File" :
+                he->nhe_id == NFFS_ID_ROOT_DIR ? "**ROOT Dir" : 
+                nffs_hash_id_is_dir(he->nhe_id) ? "Dir" : "Inode",
+
+               he->nhe_id, area_idx, area_offset, ni.ni_seq, di.ndi_parent_id,
+               di.ndi_lastblock_id, nie->nie_flags);
+        if (ni.ni_inode_entry) {
+            printf(" ref %d\n", ni.ni_inode_entry->nie_refcnt);
+        } else {
+            printf("\n");
+        }
+        return;
+    }
+    printf("%s%s id %x loc %x/%x %x entry %p\n",
+           nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
+           nffs_hash_id_is_file(he->nhe_id) ? "File:" :
+            he->nhe_id == NFFS_ID_ROOT_DIR ? "**ROOT Dir:" : 
+            nffs_hash_id_is_dir(he->nhe_id) ? "Dir:" : "Inode:",
+           he->nhe_id, area_idx, area_offset, he->nhe_flash_loc, he);
+    if (ni.ni_inode_entry) {
+        printf("  ram: ent %p seq %d prnt %p lst %p ref %d flgs %x nm %s\n",
+               ni.ni_inode_entry, ni.ni_seq, ni.ni_parent,
+               ni.ni_inode_entry->nie_last_block_entry,
+               ni.ni_inode_entry->nie_refcnt, ni.ni_inode_entry->nie_flags,
+               ni.ni_filename);
+    }
+    if (rc == 0) {
+        printf("  Disk %s: id %x seq %d prnt %x lst %x flgs %x\n",
+               nffs_hash_id_is_file(di.ndi_id) ? "File" :
+                nffs_hash_id_is_dir(di.ndi_id) ? "Dir" : "???",
+               di.ndi_id, di.ndi_seq, di.ndi_parent_id,
+               di.ndi_lastblock_id, di.ndi_flags);
+    }
+}
+
+void
+print_hash_entries(int verbose)
+{
+    int i;
+    struct nffs_hash_entry *he;
+    struct nffs_hash_entry *next;
+
+    printf("\nnffs_hash_entries:\n");
+    for (i = 0; i < NFFS_HASH_SIZE; i++) {
+        he = SLIST_FIRST(nffs_hash + i);
+        while (he != NULL) {
+            next = SLIST_NEXT(he, nhe_next);
+            if (nffs_hash_id_is_inode(he->nhe_id)) {
+                print_nffs_hash_inode(he, verbose);
+            } else if (nffs_hash_id_is_block(he->nhe_id)) {
+                print_nffs_hash_block(he, verbose);
+            } else {
+                printf("UNKNOWN type hash entry %d: id 0x%x loc 0x%x\n",
+                       i, he->nhe_id, he->nhe_flash_loc);
+            }
+            he = next;
+        }
+    }
+}
+
+void
+print_nffs_hashlist(int verbose)
+{
+    struct nffs_hash_entry *he;
+    struct nffs_hash_entry *next;
+    int i;
+
+    NFFS_HASH_FOREACH(he, i, next) {
+        if (nffs_hash_id_is_inode(he->nhe_id)) {
+            print_nffs_hash_inode(he, verbose);
+        } else if (nffs_hash_id_is_block(he->nhe_id)) {
+            print_nffs_hash_block(he, verbose);
+        } else {
+            printf("UNKNOWN type hash entry %d: id 0x%x loc 0x%x\n",
+                   i, he->nhe_id, he->nhe_flash_loc);
+        }
+    }
+}
+
+void
+printfs()
+{
+    if (nffs_misc_ready()) {
+        printf("NFFS directory:\n");
+        process_inode_entry(nffs_root_dir, print_verbose);
+
+        printf("\nNFFS hash list:\n");
+        print_nffs_hashlist(print_verbose);
+    }
+    printf("\nNFFS flash areas:\n");
+    print_nffs_flash_areas(print_verbose);
+}
+#endif /* NFFS_DEBUG */
+#endif /* MYNEWT_VAL */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/nffs_test.h
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test.h b/fs/nffs/test/src/nffs_test.h
new file mode 100644
index 0000000..360d787
--- /dev/null
+++ b/fs/nffs/test/src/nffs_test.h
@@ -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.
+ */
+
+#ifndef H_NFFS_TEST_
+#define H_NFFS_TEST_
+
+#define LOG_BUILD_STRING "{{TARGET}} Build {{BUILD_NUMBER}}:"
+
+int nffs_test_all(void);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/nffs_test_debug.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test_debug.c b/fs/nffs/test/src/nffs_test_debug.c
new file mode 100644
index 0000000..fa9ffe8
--- /dev/null
+++ b/fs/nffs/test/src/nffs_test_debug.c
@@ -0,0 +1,522 @@
+/**
+ * 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 <stdlib.h>
+#include <errno.h>
+#include "hal/hal_flash.h"
+#include "testutil/testutil.h"
+#include "fs/fs.h"
+#include "nffs/nffs.h"
+#include "nffs_test.h"
+#include "nffs_test_priv.h"
+#include "nffs_priv.h"
+
+int print_verbose;
+
+void
+print_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
+{
+    struct nffs_inode inode;
+    char name[NFFS_FILENAME_MAX_LEN + 1];
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    if (inode_entry == nffs_root_dir) {
+        printf("%*s/\n", indent, "");
+        return;
+    }
+
+    rc = nffs_inode_from_entry(&inode, inode_entry);
+    /*
+     * Dummy inode
+     */
+    if (rc == FS_ENOENT) {
+        printf("    DUMMY %d\n", rc);
+        return;
+    }
+
+    nffs_flash_loc_expand(inode_entry->nie_hash_entry.nhe_flash_loc,
+                         &area_idx, &area_offset);
+
+
+    rc = nffs_flash_read(area_idx,
+                         area_offset + sizeof (struct nffs_disk_inode),
+                         name, inode.ni_filename_len);
+
+    name[inode.ni_filename_len] = '\0';
+
+    printf("%*s%s %d %x\n", indent, "", name[0] == '\0' ? "/" : name,
+           inode.ni_seq, inode.ni_inode_entry->nie_flags);
+}
+
+void
+process_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
+{
+    struct nffs_inode_entry *child;
+
+    print_inode_entry(inode_entry, indent);
+
+    if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
+        SLIST_FOREACH(child, &inode_entry->nie_child_list, nie_sibling_next) {
+            process_inode_entry(child, indent + 2);
+        }
+    }
+}
+
+int
+print_nffs_flash_inode(struct nffs_area *area, uint32_t off)
+{
+    struct nffs_disk_inode ndi;
+    char filename[128];
+    int len;
+    int rc;
+
+    rc = hal_flash_read(area->na_flash_id, area->na_offset + off,
+                         &ndi, sizeof(ndi));
+    assert(rc == 0);
+
+    memset(filename, 0, sizeof(filename));
+    len = min(sizeof(filename) - 1, ndi.ndi_filename_len);
+    rc = hal_flash_read(area->na_flash_id, area->na_offset + off + sizeof(ndi),
+                         filename, len);
+
+    printf("  off %x %s id %x flen %d seq %d last %x prnt %x flgs %x %s\n",
+           off,
+           (nffs_hash_id_is_file(ndi.ndi_id) ? "File" :
+            (nffs_hash_id_is_dir(ndi.ndi_id) ? "Dir" : "???")),
+           ndi.ndi_id,
+           ndi.ndi_filename_len,
+           ndi.ndi_seq,
+           ndi.ndi_lastblock_id,
+           ndi.ndi_parent_id,
+           ndi.ndi_flags,
+           filename);
+    return sizeof(ndi) + ndi.ndi_filename_len;
+}
+
+int
+print_nffs_flash_block(struct nffs_area *area, uint32_t off)
+{
+    struct nffs_disk_block ndb;
+    int rc;
+
+    rc = hal_flash_read(area->na_flash_id, area->na_offset + off,
+                        &ndb, sizeof(ndb));
+    assert(rc == 0);
+
+    printf("  off %x Block id %x len %d seq %d prev %x own ino %x\n",
+           off,
+           ndb.ndb_id,
+           ndb.ndb_data_len,
+           ndb.ndb_seq,
+           ndb.ndb_prev_id,
+           ndb.ndb_inode_id);
+    return sizeof(ndb) + ndb.ndb_data_len;
+}
+
+int
+print_nffs_flash_object(struct nffs_area *area, uint32_t off)
+{
+    struct nffs_disk_object ndo;
+
+    hal_flash_read(area->na_flash_id, area->na_offset + off,
+                        &ndo.ndo_un_obj, sizeof(ndo.ndo_un_obj));
+
+    if (nffs_hash_id_is_inode(ndo.ndo_disk_inode.ndi_id)) {
+        return print_nffs_flash_inode(area, off);
+
+    } else if (nffs_hash_id_is_block(ndo.ndo_disk_block.ndb_id)) {
+        return print_nffs_flash_block(area, off);
+
+    } else if (ndo.ndo_disk_block.ndb_id == 0xffffffff) {
+        return area->na_length;
+
+    } else {
+        return 1;
+    }
+}
+
+void
+print_nffs_flash_areas(int verbose)
+{
+    struct nffs_area area;
+    struct nffs_disk_area darea;
+    int off;
+    int i;
+
+    for (i = 0; nffs_current_area_descs[i].nad_length != 0; i++) {
+        if (i > NFFS_MAX_AREAS) {
+            return;
+        }
+        area.na_offset = nffs_current_area_descs[i].nad_offset;
+        area.na_length = nffs_current_area_descs[i].nad_length;
+        area.na_flash_id = nffs_current_area_descs[i].nad_flash_id;
+        hal_flash_read(area.na_flash_id, area.na_offset, &darea, sizeof(darea));
+        area.na_id = darea.nda_id;
+        area.na_cur = nffs_areas[i].na_cur;
+        if (!nffs_area_magic_is_set(&darea)) {
+            printf("Area header corrupt!\n");
+        }
+        printf("area %d: id %d %x-%x cur %x len %d flashid %x gc-seq %d %s%s\n",
+               i, area.na_id, area.na_offset, area.na_offset + area.na_length,
+               area.na_cur, area.na_length, area.na_flash_id, darea.nda_gc_seq,
+               nffs_scratch_area_idx == i ? "(scratch)" : "",
+               !nffs_area_magic_is_set(&darea) ? "corrupt" : "");
+        if (verbose < 2) {
+            off = sizeof (struct nffs_disk_area);
+            while (off < area.na_length) {
+                off += print_nffs_flash_object(&area, off);
+            }
+        }
+    }
+}
+
+static int
+nffs_hash_fn(uint32_t id)
+{
+    return id % NFFS_HASH_SIZE;
+}
+
+void
+print_hashlist(struct nffs_hash_entry *he)
+{
+    struct nffs_hash_list *list;
+    int idx = nffs_hash_fn(he->nhe_id);
+    list = nffs_hash + idx;
+
+    SLIST_FOREACH(he, list, nhe_next) {
+        printf("hash_entry %s 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+                   nffs_hash_id_is_inode(he->nhe_id) ? "inode" : "block",
+                   (unsigned int)he,
+                   he->nhe_id, he->nhe_flash_loc,
+                   (unsigned int)he->nhe_next.sle_next);
+   }
+}
+
+void
+print_hash(void)
+{
+    int i;
+    struct nffs_hash_entry *he;
+    struct nffs_hash_entry *next;
+    struct nffs_inode ni;
+    struct nffs_disk_inode di;
+    struct nffs_block nb;
+    struct nffs_disk_block db;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    NFFS_HASH_FOREACH(he, i, next) {
+        if (nffs_hash_id_is_inode(he->nhe_id)) {
+            printf("hash_entry inode %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+                   i, (unsigned int)he,
+                   he->nhe_id, he->nhe_flash_loc,
+                   (unsigned int)he->nhe_next.sle_next);
+            if (he->nhe_id == NFFS_ID_ROOT_DIR) {
+                continue;
+            }
+            nffs_flash_loc_expand(he->nhe_flash_loc,
+                                  &area_idx, &area_offset);
+            rc = nffs_inode_read_disk(area_idx, area_offset, &di);
+            if (rc) {
+                printf("%d: fail inode read id 0x%x rc %d\n",
+                       i, he->nhe_id, rc);
+            }
+            printf("    Disk inode: id %x seq %d parent %x last %x flgs %x\n",
+                   di.ndi_id,
+                   di.ndi_seq,
+                   di.ndi_parent_id,
+                   di.ndi_lastblock_id,
+                   di.ndi_flags);
+            ni.ni_inode_entry = (struct nffs_inode_entry *)he;
+            ni.ni_seq = di.ndi_seq; 
+            ni.ni_parent = nffs_hash_find_inode(di.ndi_parent_id);
+            printf("    RAM inode: entry 0x%x seq %d parent %x filename %s\n",
+                   (unsigned int)ni.ni_inode_entry,
+                   ni.ni_seq,
+                   (unsigned int)ni.ni_parent,
+                   ni.ni_filename);
+
+        } else if (nffs_hash_id_is_block(he->nhe_id)) {
+            printf("hash_entry block %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+                   i, (unsigned int)he,
+                   he->nhe_id, he->nhe_flash_loc,
+                   (unsigned int)he->nhe_next.sle_next);
+            rc = nffs_block_from_hash_entry(&nb, he);
+            if (rc) {
+                printf("%d: fail block read id 0x%x rc %d\n",
+                       i, he->nhe_id, rc);
+            }
+            printf("    block: id %x seq %d inode %x prev %x\n",
+                   nb.nb_hash_entry->nhe_id, nb.nb_seq, 
+                   nb.nb_inode_entry->nie_hash_entry.nhe_id, 
+                   nb.nb_prev->nhe_id);
+            nffs_flash_loc_expand(nb.nb_hash_entry->nhe_flash_loc,
+                                  &area_idx, &area_offset);
+            rc = nffs_block_read_disk(area_idx, area_offset, &db);
+            if (rc) {
+                printf("%d: fail disk block read id 0x%x rc %d\n",
+                       i, nb.nb_hash_entry->nhe_id, rc);
+            }
+            printf("    disk block: id %x seq %d inode %x prev %x len %d\n",
+                   db.ndb_id,
+                   db.ndb_seq,
+                   db.ndb_inode_id,
+                   db.ndb_prev_id,
+                   db.ndb_data_len);
+        } else {
+            printf("hash_entry UNKNONN %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+                   i, (unsigned int)he,
+                   he->nhe_id, he->nhe_flash_loc,
+                   (unsigned int)he->nhe_next.sle_next);
+        }
+    }
+
+}
+
+void
+nffs_print_object(struct nffs_disk_object *dobj)
+{
+    struct nffs_disk_inode *di = &dobj->ndo_disk_inode;
+    struct nffs_disk_block *db = &dobj->ndo_disk_block;
+
+    if (dobj->ndo_type == NFFS_OBJECT_TYPE_INODE) {
+        printf("    %s id %x seq %d prnt %x last %x\n",
+               nffs_hash_id_is_file(di->ndi_id) ? "File" :
+                nffs_hash_id_is_dir(di->ndi_id) ? "Dir" : "???",
+               di->ndi_id, di->ndi_seq, di->ndi_parent_id,
+               di->ndi_lastblock_id);
+    } else if (dobj->ndo_type != NFFS_OBJECT_TYPE_BLOCK) {
+        printf("    %s: id %x seq %d ino %x prev %x len %d\n",
+               nffs_hash_id_is_block(db->ndb_id) ? "Block" : "Block?",
+               db->ndb_id, db->ndb_seq, db->ndb_inode_id,
+               db->ndb_prev_id, db->ndb_data_len);
+    }
+}
+
+void
+print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
+{
+    struct nffs_block nb;
+    struct nffs_disk_block db;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    if (he == NULL) {
+        return;
+    }
+    if (!nffs_hash_entry_is_dummy(he)) {
+        nffs_flash_loc_expand(he->nhe_flash_loc,
+                              &area_idx, &area_offset);
+        rc = nffs_block_read_disk(area_idx, area_offset, &db);
+        if (rc) {
+            printf("%p: fail block read id 0x%x rc %d\n",
+                   he, he->nhe_id, rc);
+        }
+        nb.nb_hash_entry = he;
+        nb.nb_seq = db.ndb_seq;
+        if (db.ndb_inode_id != NFFS_ID_NONE) {
+            nb.nb_inode_entry = nffs_hash_find_inode(db.ndb_inode_id);
+        } else {
+            nb.nb_inode_entry = (void*)db.ndb_inode_id;
+        }
+        if (db.ndb_prev_id != NFFS_ID_NONE) {
+            nb.nb_prev = nffs_hash_find_block(db.ndb_prev_id);
+        } else {
+            nb.nb_prev = (void*)db.ndb_prev_id;
+        }
+        nb.nb_data_len = db.ndb_data_len;
+    } else {
+        nb.nb_inode_entry = NULL;
+        db.ndb_id = 0;
+    }
+    if (!verbose) {
+        printf("%s%s id %x idx/off %d/%x seq %d ino %x prev %x len %d\n",
+               nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
+               nffs_hash_id_is_block(he->nhe_id) ? "Block" : "Unknown",
+               he->nhe_id, area_idx, area_offset, nb.nb_seq,
+               nb.nb_inode_entry->nie_hash_entry.nhe_id,
+               (unsigned int)db.ndb_prev_id, db.ndb_data_len);
+        return;
+    }
+    printf("%s%s id %x loc %x/%x %x ent %p\n",
+           nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
+           nffs_hash_id_is_block(he->nhe_id) ? "Block:" : "Unknown:",
+           he->nhe_id, area_idx, area_offset, he->nhe_flash_loc, he);
+    if (nb.nb_inode_entry) {
+        printf("  Ram: ent %p seq %d ino %p prev %p len %d\n",
+               nb.nb_hash_entry, nb.nb_seq,
+               nb.nb_inode_entry, nb.nb_prev, nb.nb_data_len);
+    }
+    if (db.ndb_id) {
+        printf("  Disk %s id %x seq %d ino %x prev %x len %d\n",
+               nffs_hash_id_is_block(db.ndb_id) ? "Block:" : "???:",
+               db.ndb_id, db.ndb_seq, db.ndb_inode_id,
+               db.ndb_prev_id, db.ndb_data_len);
+    }
+}
+
+void
+print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
+{
+    struct nffs_inode ni;
+    struct nffs_disk_inode di;
+    struct nffs_inode_entry *nie = (struct nffs_inode_entry*)he;
+    int cached_name_len;
+    uint32_t area_offset;
+    uint8_t area_idx;
+    int rc;
+
+    if (he == NULL) {
+        return;
+    }
+    if (!nffs_hash_entry_is_dummy(he)) {
+        nffs_flash_loc_expand(he->nhe_flash_loc,
+                              &area_idx, &area_offset);
+        rc = nffs_inode_read_disk(area_idx, area_offset, &di);
+        if (rc) {
+            printf("Entry %p: fail inode read id 0x%x rc %d\n",
+                   he, he->nhe_id, rc);
+        }
+        ni.ni_inode_entry = (struct nffs_inode_entry *)he;
+        ni.ni_seq = di.ndi_seq; 
+        if (di.ndi_parent_id != NFFS_ID_NONE) {
+            ni.ni_parent = nffs_hash_find_inode(di.ndi_parent_id);
+        } else {
+            ni.ni_parent = NULL;
+        }
+        if (ni.ni_filename_len > NFFS_SHORT_FILENAME_LEN) {
+            cached_name_len = NFFS_SHORT_FILENAME_LEN;
+        } else {
+            cached_name_len = ni.ni_filename_len;
+        }
+        if (cached_name_len != 0) {
+            rc = nffs_flash_read(area_idx, area_offset + sizeof di,
+                         ni.ni_filename, cached_name_len);
+            if (rc != 0) {
+                printf("entry %p: fail filename read id 0x%x rc %d\n",
+                       he, he->nhe_id, rc);
+                return;
+            }
+        }
+    } else {
+        ni.ni_inode_entry = NULL;
+        di.ndi_id = 0;
+    }
+    if (!verbose) {
+        printf("%s%s id %x idx/off %x/%x seq %d prnt %x last %x flags %x",
+               nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
+
+               nffs_hash_id_is_file(he->nhe_id) ? "File" :
+                he->nhe_id == NFFS_ID_ROOT_DIR ? "**ROOT Dir" : 
+                nffs_hash_id_is_dir(he->nhe_id) ? "Dir" : "Inode",
+
+               he->nhe_id, area_idx, area_offset, ni.ni_seq, di.ndi_parent_id,
+               di.ndi_lastblock_id, nie->nie_flags);
+        if (ni.ni_inode_entry) {
+            printf(" ref %d\n", ni.ni_inode_entry->nie_refcnt);
+        } else {
+            printf("\n");
+        }
+        return;
+    }
+    printf("%s%s id %x loc %x/%x %x entry %p\n",
+           nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
+           nffs_hash_id_is_file(he->nhe_id) ? "File:" :
+            he->nhe_id == NFFS_ID_ROOT_DIR ? "**ROOT Dir:" : 
+            nffs_hash_id_is_dir(he->nhe_id) ? "Dir:" : "Inode:",
+           he->nhe_id, area_idx, area_offset, he->nhe_flash_loc, he);
+    if (ni.ni_inode_entry) {
+        printf("  ram: ent %p seq %d prnt %p lst %p ref %d flgs %x nm %s\n",
+               ni.ni_inode_entry, ni.ni_seq, ni.ni_parent,
+               ni.ni_inode_entry->nie_last_block_entry,
+               ni.ni_inode_entry->nie_refcnt, ni.ni_inode_entry->nie_flags,
+               ni.ni_filename);
+    }
+    if (rc == 0) {
+        printf("  Disk %s: id %x seq %d prnt %x lst %x flgs %x\n",
+               nffs_hash_id_is_file(di.ndi_id) ? "File" :
+                nffs_hash_id_is_dir(di.ndi_id) ? "Dir" : "???",
+               di.ndi_id, di.ndi_seq, di.ndi_parent_id,
+               di.ndi_lastblock_id, di.ndi_flags);
+    }
+}
+
+void
+print_hash_entries(int verbose)
+{
+    int i;
+    struct nffs_hash_entry *he;
+    struct nffs_hash_entry *next;
+
+    printf("\nnffs_hash_entries:\n");
+    for (i = 0; i < NFFS_HASH_SIZE; i++) {
+        he = SLIST_FIRST(nffs_hash + i);
+        while (he != NULL) {
+            next = SLIST_NEXT(he, nhe_next);
+            if (nffs_hash_id_is_inode(he->nhe_id)) {
+                print_nffs_hash_inode(he, verbose);
+            } else if (nffs_hash_id_is_block(he->nhe_id)) {
+                print_nffs_hash_block(he, verbose);
+            } else {
+                printf("UNKNOWN type hash entry %d: id 0x%x loc 0x%x\n",
+                       i, he->nhe_id, he->nhe_flash_loc);
+            }
+            he = next;
+        }
+    }
+}
+
+void
+print_nffs_hashlist(int verbose)
+{
+    struct nffs_hash_entry *he;
+    struct nffs_hash_entry *next;
+    int i;
+
+    NFFS_HASH_FOREACH(he, i, next) {
+        if (nffs_hash_id_is_inode(he->nhe_id)) {
+            print_nffs_hash_inode(he, verbose);
+        } else if (nffs_hash_id_is_block(he->nhe_id)) {
+            print_nffs_hash_block(he, verbose);
+        } else {
+            printf("UNKNOWN type hash entry %d: id 0x%x loc 0x%x\n",
+                   i, he->nhe_id, he->nhe_flash_loc);
+        }
+    }
+}
+
+void
+printfs()
+{
+    if (nffs_misc_ready()) {
+        printf("NFFS directory:\n");
+        process_inode_entry(nffs_root_dir, print_verbose);
+
+        printf("\nNFFS hash list:\n");
+        print_nffs_hashlist(print_verbose);
+    }
+    printf("\nNFFS flash areas:\n");
+    print_nffs_flash_areas(print_verbose);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/nffs_test_priv.h
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test_priv.h b/fs/nffs/test/src/nffs_test_priv.h
new file mode 100644
index 0000000..bad766f
--- /dev/null
+++ b/fs/nffs/test/src/nffs_test_priv.h
@@ -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.
+ */
+
+#ifndef H_NFFS_TEST_PRIV_
+#define H_NFFS_TEST_PRIV_
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+struct nffs_test_block_desc {
+    const char *data;
+    int data_len;
+};
+
+struct nffs_test_file_desc {
+    const char *filename;
+    int is_dir;
+    const char *contents;
+    int contents_len;
+    struct nffs_test_file_desc *children;
+};
+
+int nffs_test(void);
+
+extern const struct nffs_test_file_desc *nffs_test_system_01;
+extern const struct nffs_test_file_desc *nffs_test_system_01_rm_1014_mk10;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif



[15/16] incubator-mynewt-core git commit: This closes #114.

Posted by cc...@apache.org.
This closes #114.

Merge remote-tracking branch 'peterfs/ci-testing' into develop

* peterfs/ci-testing:
  Unit test infrastructure


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

Branch: refs/heads/develop
Commit: 914236c1c72d3d2df8743cb80e0aa6cc44628d05
Parents: c76c680 75101ba
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Oct 17 16:53:59 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Oct 17 16:53:59 2016 -0700

----------------------------------------------------------------------
 boot/boot_serial/test/src/boot_test.c           |  145 +-
 boot/boot_serial/test/src/boot_test.h           |   49 +
 .../src/testcases/boot_serial_empty_img_msg.c   |   35 +
 .../test/src/testcases/boot_serial_empty_msg.c  |   39 +
 .../test/src/testcases/boot_serial_img_msg.c    |   58 +
 .../test/src/testcases/boot_serial_setup.c      |   24 +
 .../testcases/boot_serial_upload_bigger_image.c |   72 +
 boot/bootutil/test/src/boot_test.c              | 1148 +--
 boot/bootutil/test/src/boot_test.h              |   85 +
 boot/bootutil/test/src/boot_test_utils.c        |  361 +
 .../test/src/testcases/boot_test_invalid_hash.c |   67 +
 .../src/testcases/boot_test_no_flag_has_hash.c  |   60 +
 .../test/src/testcases/boot_test_no_hash.c      |   59 +
 .../test/src/testcases/boot_test_nv_bs_10.c     |   47 +
 .../test/src/testcases/boot_test_nv_bs_11.c     |   69 +
 .../src/testcases/boot_test_nv_bs_11_2areas.c   |   71 +
 .../test/src/testcases/boot_test_nv_ns_01.c     |   45 +
 .../test/src/testcases/boot_test_nv_ns_10.c     |   45 +
 .../test/src/testcases/boot_test_nv_ns_11.c     |   56 +
 .../test/src/testcases/boot_test_revert.c       |   59 +
 .../src/testcases/boot_test_revert_continue.c   |   71 +
 .../test/src/testcases/boot_test_vb_ns_11.c     |   61 +
 .../test/src/testcases/boot_test_vm_ns_01.c     |   50 +
 .../test/src/testcases/boot_test_vm_ns_10.c     |   45 +
 .../src/testcases/boot_test_vm_ns_11_2areas.c   |   61 +
 .../test/src/testcases/boot_test_vm_ns_11_a.c   |   56 +
 .../test/src/testcases/boot_test_vm_ns_11_b.c   |   61 +
 crypto/mbedtls/test/src/mbedtls_test.c          |  167 +-
 crypto/mbedtls/test/src/mbedtls_test.h          |   58 +
 crypto/mbedtls/test/src/testcases/aes_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/arc4_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/bignum_test.c |   27 +
 crypto/mbedtls/test/src/testcases/ccm_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/dhm_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/ecp_test.c    |   27 +
 .../mbedtls/test/src/testcases/entropy_test.c   |   29 +
 crypto/mbedtls/test/src/testcases/gcm_test.c    |   27 +
 .../mbedtls/test/src/testcases/hmac_drbg_test.c |   27 +
 crypto/mbedtls/test/src/testcases/md5_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/pkcs5_test.c  |   27 +
 .../mbedtls/test/src/testcases/ripemd160_test.c |   27 +
 crypto/mbedtls/test/src/testcases/rsa_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/sha1_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/sha256_test.c |   27 +
 crypto/mbedtls/test/src/testcases/sha512_test.c |   27 +
 crypto/mbedtls/test/src/testcases/x509_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/xtea_test.c   |   27 +
 encoding/base64/test/src/encoding_test.c        |   11 +-
 encoding/base64/test/src/encoding_test_priv.h   |    7 +-
 encoding/base64/test/src/hex_test.c             |  125 -
 encoding/base64/test/src/testcases/hex2str.c    |   64 +
 encoding/base64/test/src/testcases/str2hex.c    |   72 +
 encoding/json/test/src/test_json.c              |    6 +-
 encoding/json/test/src/test_json.h              |   32 +-
 encoding/json/test/src/test_json_simple.c       |  360 -
 encoding/json/test/src/test_json_utils.c        |   98 +
 .../test/src/testcases/json_simple_decode.c     |  205 +
 .../test/src/testcases/json_simple_encode.c     |   85 +
 fs/fcb/test/src/fcb_test.c                      |  558 +-
 fs/fcb/test/src/fcb_test.h                      |   53 +
 fs/fcb/test/src/testcases/fcb_test_append.c     |   56 +
 .../test/src/testcases/fcb_test_append_fill.c   |   90 +
 .../src/testcases/fcb_test_append_too_big.c     |   65 +
 fs/fcb/test/src/testcases/fcb_test_empty_walk.c |   38 +
 fs/fcb/test/src/testcases/fcb_test_init.c       |   40 +
 fs/fcb/test/src/testcases/fcb_test_len.c        |   37 +
 .../src/testcases/fcb_test_multiple_scratch.c   |  110 +
 fs/fcb/test/src/testcases/fcb_test_reset.c      |  145 +
 fs/fcb/test/src/testcases/fcb_test_rotate.c     |  108 +
 fs/nffs/src/nffs_priv.h                         |    5 +
 fs/nffs/syscfg.yml                              |    1 +
 fs/nffs/test/src/arch/cortex_m4/nffs_test.c     |   27 -
 fs/nffs/test/src/arch/sim/nffs_test.c           | 3251 ---------
 fs/nffs/test/src/arch/sim/nffs_test_priv.h      |   50 -
 fs/nffs/test/src/arch/sim/nffs_test_system_01.c | 6537 ------------------
 fs/nffs/test/src/nffs_test.c                    |  721 ++
 fs/nffs/test/src/nffs_test.h                    |   27 +
 fs/nffs/test/src/nffs_test_debug.c              |  522 ++
 fs/nffs/test/src/nffs_test_priv.h               |   49 +
 fs/nffs/test/src/nffs_test_system_01.c          | 6537 ++++++++++++++++++
 fs/nffs/test/src/nffs_test_utils.c              |  744 ++
 fs/nffs/test/src/nffs_test_utils.h              |   92 +
 fs/nffs/test/src/testcases/append_test.c        |  169 +
 .../test/src/testcases/cache_large_file_test.c  |   89 +
 fs/nffs/test/src/testcases/corrupt_block_test.c |  121 +
 .../test/src/testcases/corrupt_scratch_test.c   |   83 +
 fs/nffs/test/src/testcases/gc_on_oom_test.c     |   88 +
 fs/nffs/test/src/testcases/gc_test.c            |   67 +
 .../test/src/testcases/incomplete_block_test.c  |  119 +
 fs/nffs/test/src/testcases/large_system_test.c  |   43 +
 fs/nffs/test/src/testcases/large_unlink_test.c  |   80 +
 fs/nffs/test/src/testcases/large_write_test.c   |   71 +
 fs/nffs/test/src/testcases/long_filename_test.c |   59 +
 fs/nffs/test/src/testcases/lost_found_test.c    |  107 +
 fs/nffs/test/src/testcases/many_children_test.c |   74 +
 fs/nffs/test/src/testcases/mkdir_test.c         |   92 +
 fs/nffs/test/src/testcases/open_test.c          |   74 +
 .../test/src/testcases/overwrite_many_test.c    |  105 +
 fs/nffs/test/src/testcases/overwrite_one_test.c |  142 +
 .../test/src/testcases/overwrite_three_test.c   |  167 +
 fs/nffs/test/src/testcases/overwrite_two_test.c |  159 +
 fs/nffs/test/src/testcases/read_test.c          |   53 +
 fs/nffs/test/src/testcases/readdir_test.c       |  124 +
 fs/nffs/test/src/testcases/rename_test.c        |   98 +
 fs/nffs/test/src/testcases/split_file_test.c    |   65 +
 fs/nffs/test/src/testcases/truncate_test.c      |   73 +
 fs/nffs/test/src/testcases/unlink_test.c        |  121 +
 fs/nffs/test/src/testcases/wear_level_test.c    |   58 +
 hw/bsp/native/syscfg.yml                        |    1 +
 .../test/src/arch/cortex_m4/os_test_arch_arm.c  |   27 -
 kernel/os/test/src/arch/sim/os_test_arch_sim.c  |   52 -
 kernel/os/test/src/callout_test.c               |   97 +-
 kernel/os/test/src/callout_test.h               |   96 +
 kernel/os/test/src/eventq_test.c                |  152 +-
 kernel/os/test/src/eventq_test.h                |  104 +
 kernel/os/test/src/mbuf_test.c                  |  331 +-
 kernel/os/test/src/mbuf_test.h                  |   56 +
 kernel/os/test/src/mempool_test.c               |   16 +-
 kernel/os/test/src/mempool_test.h               |   60 +
 kernel/os/test/src/mutex_test.c                 |   85 +-
 kernel/os/test/src/mutex_test.h                 |   78 +
 kernel/os/test/src/os_test.c                    |   35 +-
 kernel/os/test/src/os_test_priv.h               |   13 +
 kernel/os/test/src/sem_test.c                   |  164 +-
 kernel/os/test/src/sem_test.h                   |   79 +
 .../test/src/testcases/event_test_poll_0timo.c  |   52 +
 .../src/testcases/event_test_poll_single_sr.c   |   49 +
 .../os/test/src/testcases/event_test_poll_sr.c  |   46 +
 .../src/testcases/event_test_poll_timeout_sr.c  |   49 +
 kernel/os/test/src/testcases/event_test_src.c   |   45 +
 kernel/os/test/src/testcases/ob_mbuf_test_adj.c |   60 +
 .../os/test/src/testcases/ob_mbuf_test_pullup.c |  106 +
 kernel/os/test/src/testcases/os_callout_test.c  |   46 +
 .../test/src/testcases/os_callout_test_speak.c  |   45 +
 .../test/src/testcases/os_callout_test_stop.c   |   51 +
 .../os/test/src/testcases/os_mbuf_test_alloc.c  |   33 +
 .../os/test/src/testcases/os_mbuf_test_append.c |   43 +
 kernel/os/test/src/testcases/os_mbuf_test_dup.c |   77 +
 .../os/test/src/testcases/os_mbuf_test_extend.c |   91 +
 .../src/testcases/os_mbuf_test_get_pkghdr.c     |   34 +
 .../test/src/testcases/os_mempool_test_case.c   |   31 +
 .../os/test/src/testcases/os_mutex_test_basic.c |   32 +
 .../test/src/testcases/os_mutex_test_case_1.c   |   48 +
 .../test/src/testcases/os_mutex_test_case_2.c   |   46 +
 .../os/test/src/testcases/os_sem_test_basic.c   |   34 +
 .../os/test/src/testcases/os_sem_test_case_1.c  |   42 +
 .../os/test/src/testcases/os_sem_test_case_2.c  |   45 +
 .../os/test/src/testcases/os_sem_test_case_3.c  |   45 +
 .../os/test/src/testcases/os_sem_test_case_4.c  |   45 +
 net/ip/mn_socket/test/src/mn_sock_test.c        |  850 +--
 net/ip/mn_socket/test/src/mn_sock_test.h        |   42 +
 net/ip/mn_socket/test/src/mn_sock_util.c        |  775 +++
 .../test/src/testcases/inet_ntop_test.c         |   49 +
 .../test/src/testcases/inet_pton_test.c         |   55 +
 .../mn_socket/test/src/testcases/socket_tests.c |   31 +
 net/nimble/host/test/src/ble_hs_test.c          |    2 +-
 sys/config/include/config/config_fcb.h          |    4 +-
 sys/config/test-fcb/pkg.yml                     |   31 +
 sys/config/test-fcb/src/conf_test_fcb.c         |  363 +
 sys/config/test-fcb/src/conf_test_fcb.h         |   90 +
 .../src/testcases/config_empty_lookups.c        |   34 +
 .../test-fcb/src/testcases/config_test_commit.c |   41 +
 .../src/testcases/config_test_compress_reset.c  |   88 +
 .../src/testcases/config_test_empty_fcb.c       |   42 +
 .../src/testcases/config_test_getset_bytes.c    |   49 +
 .../src/testcases/config_test_getset_int.c      |   40 +
 .../src/testcases/config_test_getset_unknown.c  |   48 +
 .../test-fcb/src/testcases/config_test_insert.c |   27 +
 .../src/testcases/config_test_insert2.c         |   27 +
 .../src/testcases/config_test_insert3.c         |   27 +
 .../src/testcases/config_test_save_1_fcb.c      |   46 +
 .../src/testcases/config_test_save_2_fcb.c      |   76 +
 .../src/testcases/config_test_save_3_fcb.c      |   51 +
 .../src/testcases/config_test_save_one_fcb.c    |   55 +
 sys/config/test-fcb/syscfg.yml                  |    4 +
 sys/config/test-nffs/pkg.yml                    |   31 +
 sys/config/test-nffs/src/conf_test_nffs.c       |  367 +
 sys/config/test-nffs/src/conf_test_nffs.h       |   87 +
 .../src/testcases/config_empty_lookups.c        |   34 +
 .../test-nffs/src/testcases/config_setup_nffs.c |   29 +
 .../src/testcases/config_test_commit.c          |   41 +
 .../src/testcases/config_test_empty_file.c      |   56 +
 .../src/testcases/config_test_getset_bytes.c    |   49 +
 .../src/testcases/config_test_getset_int.c      |   40 +
 .../src/testcases/config_test_getset_unknown.c  |   48 +
 .../src/testcases/config_test_insert.c          |   27 +
 .../src/testcases/config_test_insert2.c         |   27 +
 .../src/testcases/config_test_insert3.c         |   27 +
 .../testcases/config_test_multiple_in_file.c    |   52 +
 .../src/testcases/config_test_save_in_file.c    |   50 +
 .../src/testcases/config_test_save_one_file.c   |   53 +
 .../src/testcases/config_test_small_file.c      |   56 +
 sys/config/test-nffs/syscfg.yml                 |    5 +
 sys/config/test/pkg.yml                         |   32 -
 sys/config/test/src/conf_test.c                 |  953 ---
 sys/config/test/src/conf_test.h                 |   33 -
 sys/config/test/src/conf_test_suite.c           |   40 -
 sys/config/test/src/config_test.h               |   32 -
 sys/config/test/syscfg.yml                      |    5 -
 sys/flash_map/test/src/flash_map_test.c         |  126 +-
 sys/flash_map/test/src/flash_map_test.h         |   44 +
 .../test/src/testcases/flash_map_test_case_1.c  |   63 +
 .../test/src/testcases/flash_map_test_case_2.c  |   96 +
 sys/log/test/src/log_test.c                     |   67 +-
 sys/log/test/src/log_test.h                     |   54 +
 sys/log/test/src/testcases/log_append_fcb.c     |   33 +
 sys/log/test/src/testcases/log_setup_fcb.c      |   39 +
 sys/log/test/src/testcases/log_walk_fcb.c       |   29 +
 test/testutil/include/testutil/testutil.h       |  253 +-
 .../src/arch/cortex_m4/testutil_arch_arm.c      |   27 -
 test/testutil/src/arch/sim/testutil_arch_sim.c  |   30 -
 test/testutil/src/arch/sim/tu_args.c            |   23 -
 test/testutil/src/case.c                        |  120 +-
 test/testutil/src/suite.c                       |   66 +-
 test/testutil/src/testutil.c                    |   45 +-
 util/cbmem/test/src/cbmem_test.c                |  120 +-
 util/cbmem/test/src/cbmem_test.h                |   48 +
 .../test/src/testcases/cbmem_test_case_1.c      |   33 +
 .../test/src/testcases/cbmem_test_case_2.c      |   49 +
 .../test/src/testcases/cbmem_test_case_3.c      |   63 +
 util/cbmem/test/src/util_test.c                 |   45 -
 util/cbmem/test/src/util_test_priv.h            |   33 -
 222 files changed, 20770 insertions(+), 15639 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/914236c1/boot/bootutil/test/src/boot_test.c
----------------------------------------------------------------------
diff --cc boot/bootutil/test/src/boot_test.c
index 205993c,269db36..68cabc0
--- a/boot/bootutil/test/src/boot_test.c
+++ b/boot/bootutil/test/src/boot_test.c
@@@ -34,1135 -35,478 +34,23 @@@
  
  #include "mbedtls/sha256.h"
  
--#define BOOT_TEST_HEADER_SIZE       0x200
--
--/** Internal flash layout. */
- static struct flash_area boot_test_area_descs[] = {
 -struct flash_area boot_test_area_descs[] = {
--    [0] = { .fa_off = 0x00020000, .fa_size = 128 * 1024 },
--    [1] = { .fa_off = 0x00040000, .fa_size = 128 * 1024 },
--    [2] = { .fa_off = 0x00060000, .fa_size = 128 * 1024 },
--    [3] = { .fa_off = 0x00080000, .fa_size = 128 * 1024 },
--    [4] = { .fa_off = 0x000a0000, .fa_size = 128 * 1024 },
--    [5] = { .fa_off = 0x000c0000, .fa_size = 128 * 1024 },
--    [6] = { .fa_off = 0x000e0000, .fa_size = 128 * 1024 },
--    [7] = { 0 },
--};
--
--/** Areas representing the beginning of image slots. */
- static uint8_t boot_test_slot_areas[] = {
 -uint8_t boot_test_slot_areas[] = {
--    0, 3,
--};
--
--/** Flash offsets of the two image slots. */
- static struct {
 -struct {
--    uint8_t flash_id;
--    uint32_t address;
--} boot_test_img_addrs[] = {
--    { 0, 0x20000 },
--    { 0, 0x80000 },
--};
 -
 -/** Three areas per image slot */
 -#define BOOT_TEST_IMAGE_NUM_AREAS  3
--
--#define BOOT_TEST_AREA_IDX_SCRATCH 6
--
- static uint8_t
 -uint8_t
--boot_test_util_byte_at(int img_msb, uint32_t image_offset)
--{
--    uint32_t u32;
--    uint8_t *u8p;
--
--    TEST_ASSERT(image_offset < 0x01000000);
--    u32 = image_offset + (img_msb << 24);
--    u8p = (void *)&u32;
--    return u8p[image_offset % 4];
--}
--
- static void
 -void
--boot_test_util_init_flash(void)
--{
--    const struct flash_area *area_desc;
--    int rc;
--
--    rc = hal_flash_init();
--    TEST_ASSERT(rc == 0);
--
--    for (area_desc = boot_test_area_descs;
--         area_desc->fa_size != 0;
--         area_desc++) {
--
--        rc = flash_area_erase(area_desc, 0, area_desc->fa_size);
--        TEST_ASSERT(rc == 0);
--    }
--}
--
- static void
 -void
--boot_test_util_copy_area(int from_area_idx, int to_area_idx)
--{
--    const struct flash_area *from_area_desc;
--    const struct flash_area *to_area_desc;
--    void *buf;
--    int rc;
--
--    from_area_desc = boot_test_area_descs + from_area_idx;
--    to_area_desc = boot_test_area_descs + to_area_idx;
--
--    TEST_ASSERT(from_area_desc->fa_size == to_area_desc->fa_size);
--
--    buf = malloc(from_area_desc->fa_size);
--    TEST_ASSERT(buf != NULL);
--
--    rc = flash_area_read(from_area_desc, 0, buf,
--                         from_area_desc->fa_size);
--    TEST_ASSERT(rc == 0);
--
--    rc = flash_area_erase(to_area_desc,
--                          0,
--                          to_area_desc->fa_size);
--    TEST_ASSERT(rc == 0);
--
--    rc = flash_area_write(to_area_desc, 0, buf,
--                          to_area_desc->fa_size);
--    TEST_ASSERT(rc == 0);
--
--    free(buf);
--}
--
--static uint32_t
--boot_test_util_area_write_size(int dst_idx, uint32_t off, uint32_t size)
--{
--    const struct flash_area *desc;
--    int64_t diff;
--    uint32_t trailer_start;
 -    int i;
--
-     if (dst_idx != BOOT_TEST_AREA_IDX_SCRATCH - 1) {
-         return size;
-     }
 -    for (i = 0;
 -         i < sizeof boot_test_slot_areas / sizeof boot_test_slot_areas[0];
 -         i++) {
--
-     /* Don't include trailer in copy to second slot. */
-     desc = boot_test_area_descs + dst_idx;
-     trailer_start = desc->fa_size - boot_status_sz(1);
-     diff = off + size - trailer_start;
-     if (diff > 0) {
-         if (diff > size) {
-             size = 0;
-         } else {
-             size -= diff;
 -        /* Don't include trailer in copy. */
 -        if (dst_idx ==
 -            boot_test_slot_areas[i] + BOOT_TEST_IMAGE_NUM_AREAS - 1) {
 -
 -            desc = boot_test_area_descs + dst_idx;
 -            trailer_start = desc->fa_size - boot_status_sz();
 -            diff = off + size - trailer_start;
 -            if (diff > 0) {
 -                if (diff > size) {
 -                    size = 0;
 -                } else {
 -                    size -= diff;
 -                }
 -            }
 -
 -            break;
--        }
--    }
--
--    return size;
--}
--
- static void
 -void
--boot_test_util_swap_areas(int area_idx1, int area_idx2)
--{
--    const struct flash_area *area_desc1;
--    const struct flash_area *area_desc2;
--    uint32_t size;
--    void *buf1;
--    void *buf2;
--    int rc;
--
--    area_desc1 = boot_test_area_descs + area_idx1;
--    area_desc2 = boot_test_area_descs + area_idx2;
--
--    TEST_ASSERT(area_desc1->fa_size == area_desc2->fa_size);
--
--    buf1 = malloc(area_desc1->fa_size);
--    TEST_ASSERT(buf1 != NULL);
--
--    buf2 = malloc(area_desc2->fa_size);
--    TEST_ASSERT(buf2 != NULL);
--
--    rc = flash_area_read(area_desc1, 0, buf1, area_desc1->fa_size);
--    TEST_ASSERT(rc == 0);
--
--    rc = flash_area_read(area_desc2, 0, buf2, area_desc2->fa_size);
--    TEST_ASSERT(rc == 0);
--
--    rc = flash_area_erase(area_desc1, 0, area_desc1->fa_size);
--    TEST_ASSERT(rc == 0);
--
--    rc = flash_area_erase(area_desc2, 0, area_desc2->fa_size);
--    TEST_ASSERT(rc == 0);
--
--    size = boot_test_util_area_write_size(area_idx1, 0, area_desc1->fa_size);
--    rc = flash_area_write(area_desc1, 0, buf2, size);
--    TEST_ASSERT(rc == 0);
--
--    size = boot_test_util_area_write_size(area_idx2, 0, area_desc2->fa_size);
--    rc = flash_area_write(area_desc2, 0, buf1, size);
--    TEST_ASSERT(rc == 0);
--
--    free(buf1);
--    free(buf2);
--}
--
- static void
 -void
--boot_test_util_write_image(const struct image_header *hdr, int slot)
--{
--    uint32_t image_off;
--    uint32_t off;
--    uint8_t flash_id;
--    uint8_t buf[256];
--    int chunk_sz;
--    int rc;
--    int i;
--
--    TEST_ASSERT(slot == 0 || slot == 1);
--
--    flash_id = boot_test_img_addrs[slot].flash_id;
--    off = boot_test_img_addrs[slot].address;
--
--    rc = hal_flash_write(flash_id, off, hdr, sizeof *hdr);
--    TEST_ASSERT(rc == 0);
--
--    off += hdr->ih_hdr_size;
--
--    image_off = 0;
--    while (image_off < hdr->ih_img_size) {
--        if (hdr->ih_img_size - image_off > sizeof buf) {
--            chunk_sz = sizeof buf;
--        } else {
--            chunk_sz = hdr->ih_img_size - image_off;
--        }
--
--        for (i = 0; i < chunk_sz; i++) {
--            buf[i] = boot_test_util_byte_at(slot, image_off + i);
--        }
--
--        rc = hal_flash_write(flash_id, off + image_off, buf, chunk_sz);
--        TEST_ASSERT(rc == 0);
--
--        image_off += chunk_sz;
--    }
--}
--
- static void
 -void
--boot_test_util_write_hash(const struct image_header *hdr, int slot)
--{
--    uint8_t tmpdata[1024];
--    uint8_t hash[32];
--    int rc;
--    uint32_t off;
--    uint32_t blk_sz;
--    uint32_t sz;
--    mbedtls_sha256_context ctx;
--    uint8_t flash_id;
--    uint32_t addr;
--    struct image_tlv tlv;
--
--    mbedtls_sha256_init(&ctx);
--    mbedtls_sha256_starts(&ctx, 0);
--
--    flash_id = boot_test_img_addrs[slot].flash_id;
--    addr = boot_test_img_addrs[slot].address;
--
--    sz = hdr->ih_hdr_size + hdr->ih_img_size;
--    for (off = 0; off < sz; off += blk_sz) {
--        blk_sz = sz - off;
--        if (blk_sz > sizeof(tmpdata)) {
--            blk_sz = sizeof(tmpdata);
--        }
--        rc = hal_flash_read(flash_id, addr + off, tmpdata, blk_sz);
--        TEST_ASSERT(rc == 0);
--        mbedtls_sha256_update(&ctx, tmpdata, blk_sz);
--    }
--    mbedtls_sha256_finish(&ctx, hash);
--
--    tlv.it_type = IMAGE_TLV_SHA256;
--    tlv._pad = 0;
--    tlv.it_len = sizeof(hash);
--
--    rc = hal_flash_write(flash_id, addr + off, &tlv, sizeof(tlv));
--    TEST_ASSERT(rc == 0);
--    off += sizeof(tlv);
--    rc = hal_flash_write(flash_id, addr + off, hash, sizeof(hash));
--    TEST_ASSERT(rc == 0);
- }
- 
- static void
- boot_test_util_write_bit(int flash_area_id, struct boot_img_trailer *bit)
- {
-     const struct flash_area *fap;
-     int rc;
- 
-     /* XXX: This function only works by chance.  It requires that the boot
-      * loader have have been run once already so that its global state has been
-      * populated.
-      */
- 
-     rc = flash_area_open(flash_area_id, &fap);
-     TEST_ASSERT_FATAL(rc == 0);
- 
-     rc = flash_area_write(fap, fap->fa_size - sizeof *bit, bit, sizeof *bit);
-     TEST_ASSERT_FATAL(rc == 0);
- }
- 
- static void
- boot_test_util_mark_revert(void)
- {
-     struct boot_img_trailer bit_slot0 = {
-         .bit_copy_start = BOOT_IMG_MAGIC,
-         .bit_copy_done = 0x01,
-         .bit_img_ok = 0xff,
-         ._pad = 0xffff,
-     };
- 
-     boot_test_util_write_bit(FLASH_AREA_IMAGE_0, &bit_slot0);
--}
--
- static void
 -void
--boot_test_util_verify_area(const struct flash_area *area_desc,
--                           const struct image_header *hdr,
--                           uint32_t image_addr, int img_msb)
--{
--    struct image_header temp_hdr;
--    uint32_t area_end;
--    uint32_t img_size;
--    uint32_t img_off;
--    uint32_t img_end;
--    uint32_t addr;
--    uint8_t buf[256];
--    int rem_area;
 -    int past_image;
--    int chunk_sz;
--    int rem_img;
--    int rc;
--    int i;
--
--    addr = area_desc->fa_off;
--
--    if (hdr != NULL) {
--        img_size = hdr->ih_img_size;
--
--        if (addr == image_addr) {
--            rc = hal_flash_read(area_desc->fa_device_id, image_addr,
--                                &temp_hdr, sizeof temp_hdr);
--            TEST_ASSERT(rc == 0);
--            TEST_ASSERT(memcmp(&temp_hdr, hdr, sizeof *hdr) == 0);
--
--            addr += hdr->ih_hdr_size;
--        }
--    } else {
--        img_size = 0;
--    }
--
--    area_end = area_desc->fa_off + area_desc->fa_size;
--    img_end = image_addr + img_size;
 -    past_image = addr >= img_end;
--
--    while (addr < area_end) {
--        rem_area = area_end - addr;
--        rem_img = img_end - addr;
--
--        if (hdr != NULL) {
--            img_off = addr - image_addr - hdr->ih_hdr_size;
--        } else {
--            img_off = 0;
--        }
--
--        if (rem_area > sizeof buf) {
--            chunk_sz = sizeof buf;
--        } else {
--            chunk_sz = rem_area;
--        }
--
--        rc = hal_flash_read(area_desc->fa_device_id, addr, buf, chunk_sz);
--        TEST_ASSERT(rc == 0);
--
--        for (i = 0; i < chunk_sz; i++) {
--            if (rem_img > 0) {
--                TEST_ASSERT(buf[i] == boot_test_util_byte_at(img_msb,
--                                                        img_off + i));
 -            } else if (past_image) {
 -#if 0
 -                TEST_ASSERT(buf[i] == 0xff);
 -#endif
--            }
--        }
--
--        addr += chunk_sz;
--    }
--}
--
- static void
 -void
--boot_test_util_verify_status_clear(void)
--{
--    struct boot_img_trailer bit;
--    const struct flash_area *fap;
--    int rc;
--
--    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
--    TEST_ASSERT(rc == 0);
--
--    rc = flash_area_read(fap, fap->fa_size - sizeof(bit), &bit, sizeof(bit));
--    TEST_ASSERT(rc == 0);
--
-     TEST_ASSERT(bit.bit_copy_start != BOOT_IMG_MAGIC ||
 -    TEST_ASSERT(bit.bit_copy_start != BOOT_MAGIC_SWAP_TEMP ||
--      bit.bit_copy_done != 0xff);
--}
--
- static void
 -void
--boot_test_util_verify_flash(const struct image_header *hdr0, int orig_slot_0,
--                            const struct image_header *hdr1, int orig_slot_1)
--{
--    const struct flash_area *area_desc;
--    int area_idx;
--
--    area_idx = 0;
--
--    while (1) {
--        area_desc = boot_test_area_descs + area_idx;
--        if (area_desc->fa_off == boot_test_img_addrs[1].address &&
--            area_desc->fa_device_id == boot_test_img_addrs[1].flash_id) {
--            break;
--        }
--
--        boot_test_util_verify_area(area_desc, hdr0,
--                                   boot_test_img_addrs[0].address, orig_slot_0);
--        area_idx++;
--    }
--
--    while (1) {
--        if (area_idx == BOOT_TEST_AREA_IDX_SCRATCH) {
--            break;
--        }
--
--        area_desc = boot_test_area_descs + area_idx;
--        boot_test_util_verify_area(area_desc, hdr1,
--                                   boot_test_img_addrs[1].address, orig_slot_1);
--        area_idx++;
--    }
--}
--
- static void
 -void
--boot_test_util_verify_all(const struct boot_req *req, int expected_swap_type,
--                          const struct image_header *hdr0,
--                          const struct image_header *hdr1)
--{
--    const struct image_header *slot0hdr;
--    const struct image_header *slot1hdr;
--    struct boot_rsp rsp;
--    int orig_slot_0;
--    int orig_slot_1;
--    int num_swaps;
--    int rc;
--    int i;
--
--    TEST_ASSERT_FATAL(req != NULL);
--    TEST_ASSERT_FATAL(hdr0 != NULL || hdr1 != NULL);
--
--    num_swaps = 0;
--    for (i = 0; i < 3; i++) {
--        rc = boot_go(req, &rsp);
--        TEST_ASSERT_FATAL(rc == 0);
--
--        if (expected_swap_type != BOOT_SWAP_TYPE_NONE) {
--            num_swaps++;
--        }
--
--        if (num_swaps % 2 == 0) {
--            if (hdr0 != NULL) {
--                slot0hdr = hdr0;
--                slot1hdr = hdr1;
--            } else {
--                slot0hdr = hdr1;
--                slot1hdr = hdr0;
--            }
--            orig_slot_0 = 0;
--            orig_slot_1 = 1;
--        } else {
--            if (hdr1 != NULL) {
--                slot0hdr = hdr1;
--                slot1hdr = hdr0;
--            } else {
--                slot0hdr = hdr0;
--                slot1hdr = hdr1;
--            }
--            orig_slot_0 = 1;
--            orig_slot_1 = 0;
--        }
--
--        TEST_ASSERT(memcmp(rsp.br_hdr, slot0hdr, sizeof *slot0hdr) == 0);
--        TEST_ASSERT(rsp.br_flash_id == boot_test_img_addrs[0].flash_id);
--        TEST_ASSERT(rsp.br_image_addr == boot_test_img_addrs[0].address);
--
--        boot_test_util_verify_flash(slot0hdr, orig_slot_0,
--                                    slot1hdr, orig_slot_1);
--        boot_test_util_verify_status_clear();
--
--        if (expected_swap_type != BOOT_SWAP_TYPE_NONE) {
--            switch (expected_swap_type) {
-             case BOOT_SWAP_TYPE_TEST:
-                 expected_swap_type = BOOT_SWAP_TYPE_REVERT;
 -            case BOOT_SWAP_TYPE_TEMP:
 -                expected_swap_type = BOOT_SWAP_TYPE_PERM;
--                break;
--
-             case BOOT_SWAP_TYPE_REVERT:
 -            case BOOT_SWAP_TYPE_PERM:
--                expected_swap_type = BOOT_SWAP_TYPE_NONE;
--                break;
--
--            default:
--                TEST_ASSERT_FATAL(0);
--                break;
--            }
--        }
--    }
- }
- 
- TEST_CASE(boot_test_nv_ns_10)
- {
-     struct image_header hdr = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 12 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 2, 3, 4 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr, 0);
-     boot_test_util_write_hash(&hdr, 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
- }
- 
- TEST_CASE(boot_test_nv_ns_01)
- {
-     struct image_header hdr = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 10 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr, 1);
-     boot_test_util_write_hash(&hdr, 1);
- 
-     boot_set_pending(1);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, NULL, &hdr);
- }
- 
- TEST_CASE(boot_test_nv_ns_11)
- {
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 5 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 5, 21, 432 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1);
- }
- 
- TEST_CASE(boot_test_vm_ns_10)
- {
-     struct image_header hdr = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 12 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 2, 3, 4 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr, 0);
-     boot_test_util_write_hash(&hdr, 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
- }
- 
- TEST_CASE(boot_test_vm_ns_01)
- {
-     int rc;
- 
-     struct image_header hdr = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 10 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr, 1);
-     boot_test_util_write_hash(&hdr, 1);
- 
-     rc = boot_set_pending(1);
-     TEST_ASSERT(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, NULL, &hdr);
- }
- 
- TEST_CASE(boot_test_vm_ns_11_a)
- {
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 5 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 5, 21, 432 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1);
- }
- 
- TEST_CASE(boot_test_vm_ns_11_b)
- {
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 5 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 5, 21, 432 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
- 
-     rc = boot_set_pending(1);
-     TEST_ASSERT(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
- }
- 
- TEST_CASE(boot_test_vm_ns_11_2areas)
- {
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 5 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 5, 21, 432 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 196 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
- 
-     rc = boot_set_pending(1);
-     TEST_ASSERT(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
- }
- 
- TEST_CASE(boot_test_nv_bs_10)
- {
-     struct image_header hdr = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 12 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 2, 3, 4 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr, 0);
-     boot_test_util_write_hash(&hdr, 0);
-     boot_test_util_swap_areas(boot_test_slot_areas[1],
-                               BOOT_TEST_AREA_IDX_SCRATCH);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
- }
- 
- TEST_CASE(boot_test_nv_bs_11)
- {
-     struct boot_status status;
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 12 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 2, 3, 4 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 17 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 1, 5, 5 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
-     rc = boot_set_pending(1);
-     boot_test_util_copy_area(5, BOOT_TEST_AREA_IDX_SCRATCH);
- 
-     boot_req_set(&req);
-     status.idx = 0;
-     status.elem_sz = 1;
-     status.state = 1;
- 
-     rc = boot_write_status(&status);
-     TEST_ASSERT(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
- }
- 
- TEST_CASE(boot_test_nv_bs_11_2areas)
- {
-     struct boot_status status;
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 150 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 5, 21, 432 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 190 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
-     rc = boot_set_pending(1);
-     TEST_ASSERT_FATAL(rc == 0);
- 
-     boot_test_util_swap_areas(2, 5);
- 
-     status.idx = 1;
-     status.elem_sz = 1;
-     status.state = 0;
- 
-     rc = boot_write_status(&status);
-     TEST_ASSERT_FATAL(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
- }
- 
- TEST_CASE(boot_test_vb_ns_11)
- {
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 5 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 5, 21, 432 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
- 
-     rc = boot_set_pending(1);
-     TEST_ASSERT(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEST, &hdr0, &hdr1);
- }
- 
- TEST_CASE(boot_test_no_hash)
- {
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 12 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 2, 3, 4 },
-     };
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 0,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = 0,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
- 
-     rc = boot_set_pending(1);
-     TEST_ASSERT(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
- }
- 
- TEST_CASE(boot_test_no_flag_has_hash)
- {
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 12 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 2, 3, 4 },
-     };
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = 0,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
- 
-     rc = boot_set_pending(1);
-     TEST_ASSERT(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
- }
- 
- TEST_CASE(boot_test_invalid_hash)
- {
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 12 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 2, 3, 4 },
-     };
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = 0,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     struct image_tlv tlv = {
-         .it_type = IMAGE_TLV_SHA256,
-         .it_len = 32
-     };
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     rc = hal_flash_write(boot_test_img_addrs[1].flash_id,
-       boot_test_img_addrs[1].address + hdr1.ih_hdr_size + hdr1.ih_img_size,
-       &tlv, sizeof(tlv));
-     TEST_ASSERT(rc == 0);
- 
-     rc = boot_set_pending(1);
-     TEST_ASSERT(rc == 0);
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
- }
- 
- TEST_CASE(boot_test_revert)
- {
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 5 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 5, 21, 432 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
- 
-     /* Indicate that the image in slot 0 is being tested. */
-     boot_test_util_mark_revert();
- 
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, &hdr0, &hdr1);
--}
- 
- TEST_CASE(boot_test_revert_continue)
- {
-     struct boot_status status;
-     int rc;
- 
-     struct image_header hdr0 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 5 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 0, 5, 21, 432 },
-     };
- 
-     struct image_header hdr1 = {
-         .ih_magic = IMAGE_MAGIC,
-         .ih_tlv_size = 4 + 32,
-         .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-         .ih_img_size = 32 * 1024,
-         .ih_flags = IMAGE_F_SHA256,
-         .ih_ver = { 1, 2, 3, 432 },
-     };
- 
-     struct boot_req req = {
-         .br_area_descs = boot_test_area_descs,
-         .br_slot_areas = boot_test_slot_areas,
-         .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-         .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-         .br_img_sz = (384 * 1024),
-     };
- 
-     boot_test_util_init_flash();
-     boot_test_util_write_image(&hdr0, 0);
-     boot_test_util_write_hash(&hdr0, 0);
-     boot_test_util_write_image(&hdr1, 1);
-     boot_test_util_write_hash(&hdr1, 1);
- 
-     /* Indicate that the image in slot 0 is being tested. */
-     boot_test_util_mark_revert();
- 
-     boot_test_util_swap_areas(2, 5);
- 
-     status.idx = 1;
-     status.elem_sz = 1;
-     status.state = 0;
- 
-     rc = boot_write_status(&status);
-     TEST_ASSERT_FATAL(rc == 0);
--
-     boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_REVERT, &hdr0, &hdr1);
- }
+ TEST_CASE_DECL(boot_test_nv_ns_10)
+ TEST_CASE_DECL(boot_test_nv_ns_01)
+ TEST_CASE_DECL(boot_test_nv_ns_11)
+ TEST_CASE_DECL(boot_test_vm_ns_10)
+ TEST_CASE_DECL(boot_test_vm_ns_01)
+ TEST_CASE_DECL(boot_test_vm_ns_11_a)
+ TEST_CASE_DECL(boot_test_vm_ns_11_b)
+ TEST_CASE_DECL(boot_test_vm_ns_11_2areas)
+ TEST_CASE_DECL(boot_test_nv_bs_10)
+ TEST_CASE_DECL(boot_test_nv_bs_11)
+ TEST_CASE_DECL(boot_test_nv_bs_11_2areas)
+ TEST_CASE_DECL(boot_test_vb_ns_11)
+ TEST_CASE_DECL(boot_test_no_hash)
+ TEST_CASE_DECL(boot_test_no_flag_has_hash)
+ TEST_CASE_DECL(boot_test_invalid_hash)
+ TEST_CASE_DECL(boot_test_revert)
+ TEST_CASE_DECL(boot_test_revert_continue)
  
  TEST_SUITE(boot_test_main)
  {


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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/overwrite_three_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/overwrite_three_test.c b/fs/nffs/test/src/testcases/overwrite_three_test.c
new file mode 100644
index 0000000..37ba872
--- /dev/null
+++ b/fs/nffs/test/src/testcases/overwrite_three_test.c
@@ -0,0 +1,167 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_overwrite_three)
+{
+    struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { {
+        .data = "abcdefgh",
+        .data_len = 8,
+    }, {
+        .data = "ijklmnop",
+        .data_len = 8,
+    }, {
+        .data = "qrstuvwx",
+        .data_len = 8,
+    } };
+
+    struct fs_file *file;
+    int rc;
+
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    /*** Overwrite three blocks (middle). */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 6);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 6);
+
+    rc = fs_write(file, "1234567890!@", 12);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 18);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt",
+                                   "abcdef1234567890!@stuvwx", 24);
+    nffs_test_util_assert_block_count("/myfile.txt", 3);
+
+    /*** Overwrite three blocks (start). */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "1234567890!@#$%^&*()", 20);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 20);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt",
+                                   "1234567890!@#$%^&*()uvwx", 24);
+    nffs_test_util_assert_block_count("/myfile.txt", 3);
+
+    /*** Overwrite three blocks (end). */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 6);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 6);
+
+    rc = fs_write(file, "1234567890!@#$%^&*", 18);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 24);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt",
+                                   "abcdef1234567890!@#$%^&*", 24);
+    nffs_test_util_assert_block_count("/myfile.txt", 3);
+
+    /*** Overwrite three blocks middle, extend. */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 6);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 6);
+
+    rc = fs_write(file, "1234567890!@#$%^&*()", 20);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 26);
+    TEST_ASSERT(fs_getpos(file) == 26);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt",
+                                   "abcdef1234567890!@#$%^&*()", 26);
+    nffs_test_util_assert_block_count("/myfile.txt", 3);
+
+    /*** Overwrite three blocks start, extend. */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 3);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 24);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "1234567890!@#$%^&*()abcdefghij", 30);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 30);
+    TEST_ASSERT(fs_getpos(file) == 30);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt",
+                                   "1234567890!@#$%^&*()abcdefghij", 30);
+    nffs_test_util_assert_block_count("/myfile.txt", 3);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = "1234567890!@#$%^&*()abcdefghij",
+                .contents_len = 30,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/overwrite_two_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/overwrite_two_test.c b/fs/nffs/test/src/testcases/overwrite_two_test.c
new file mode 100644
index 0000000..8082367
--- /dev/null
+++ b/fs/nffs/test/src/testcases/overwrite_two_test.c
@@ -0,0 +1,159 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_overwrite_two)
+{
+    struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { {
+        .data = "abcdefgh",
+        .data_len = 8,
+    }, {
+        .data = "ijklmnop",
+        .data_len = 8,
+    } };
+
+    struct fs_file *file;
+    int rc;
+
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    /*** Overwrite two blocks (middle). */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 7);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 7);
+
+    rc = fs_write(file, "123", 3);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 10);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt", "abcdefg123klmnop", 16);
+    nffs_test_util_assert_block_count("/myfile.txt", 2);
+
+    /*** Overwrite two blocks (start). */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "ABCDEFGHIJ", 10);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 10);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt", "ABCDEFGHIJklmnop", 16);
+    nffs_test_util_assert_block_count("/myfile.txt", 2);
+
+    /*** Overwrite two blocks (end). */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 6);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 6);
+
+    rc = fs_write(file, "1234567890", 10);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 16);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt", "abcdef1234567890", 16);
+    nffs_test_util_assert_block_count("/myfile.txt", 2);
+
+    /*** Overwrite two blocks middle, extend. */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_seek(file, 6);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 6);
+
+    rc = fs_write(file, "1234567890!@#$", 14);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 20);
+    TEST_ASSERT(fs_getpos(file) == 20);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt", "abcdef1234567890!@#$", 20);
+    nffs_test_util_assert_block_count("/myfile.txt", 2);
+
+    /*** Overwrite two blocks start, extend. */
+    nffs_test_util_create_file_blocks("/myfile.txt", blocks, 2);
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 16);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "1234567890!@#$%^&*()", 20);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 20);
+    TEST_ASSERT(fs_getpos(file) == 20);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents( "/myfile.txt", "1234567890!@#$%^&*()", 20);
+    nffs_test_util_assert_block_count("/myfile.txt", 2);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = "1234567890!@#$%^&*()",
+                .contents_len = 20,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/read_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/read_test.c b/fs/nffs/test/src/testcases/read_test.c
new file mode 100644
index 0000000..a21e16f
--- /dev/null
+++ b/fs/nffs/test/src/testcases/read_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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_read)
+{
+    struct fs_file *file;
+    uint8_t buf[16];
+    uint32_t bytes_read;
+    int rc;
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_create_file("/myfile.txt", "1234567890", 10);
+
+    rc = fs_open("/myfile.txt", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 10);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_read(file, 4, buf, &bytes_read);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(bytes_read == 4);
+    TEST_ASSERT(memcmp(buf, "1234", 4) == 0);
+    TEST_ASSERT(fs_getpos(file) == 4);
+
+    rc = fs_read(file, sizeof buf - 4, buf + 4, &bytes_read);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(bytes_read == 6);
+    TEST_ASSERT(memcmp(buf, "1234567890", 10) == 0);
+    TEST_ASSERT(fs_getpos(file) == 10);
+
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/readdir_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/readdir_test.c b/fs/nffs/test/src/testcases/readdir_test.c
new file mode 100644
index 0000000..aa52035
--- /dev/null
+++ b/fs/nffs/test/src/testcases/readdir_test.c
@@ -0,0 +1,124 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_readdir)
+{
+    struct fs_dirent *dirent;
+    struct fs_dir *dir;
+    int rc;
+
+    /*** Setup. */
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    rc = fs_mkdir("/mydir");
+    TEST_ASSERT_FATAL(rc == 0);
+
+    nffs_test_util_create_file("/mydir/b", "bbbb", 4);
+    nffs_test_util_create_file("/mydir/a", "aaaa", 4);
+    rc = fs_mkdir("/mydir/c");
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /* Nonexistent directory. */
+    rc = fs_opendir("/asdf", &dir);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    /* Fail to opendir a file. */
+    rc = fs_opendir("/mydir/a", &dir);
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    /* Real directory (with trailing slash). */
+    rc = fs_opendir("/mydir/", &dir);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_ent_name(dirent, "a");
+    TEST_ASSERT(fs_dirent_is_dir(dirent) == 0);
+
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_ent_name(dirent, "b");
+    TEST_ASSERT(fs_dirent_is_dir(dirent) == 0);
+
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_ent_name(dirent, "c");
+    TEST_ASSERT(fs_dirent_is_dir(dirent) == 1);
+
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    rc = fs_closedir(dir);
+    TEST_ASSERT(rc == 0);
+
+    /* Root directory. */
+    rc = fs_opendir("/", &dir);
+    TEST_ASSERT(rc == 0);
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_ent_name(dirent, "lost+found");
+    TEST_ASSERT(fs_dirent_is_dir(dirent) == 1);
+
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_ent_name(dirent, "mydir");
+    TEST_ASSERT(fs_dirent_is_dir(dirent) == 1);
+
+    rc = fs_closedir(dir);
+    TEST_ASSERT(rc == 0);
+
+    /* Delete entries while iterating. */
+    rc = fs_opendir("/mydir", &dir);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_ent_name(dirent, "a");
+    TEST_ASSERT(fs_dirent_is_dir(dirent) == 0);
+
+    rc = fs_unlink("/mydir/b");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_unlink("/mydir/c");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_unlink("/mydir");
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_ent_name(dirent, "c");
+    TEST_ASSERT(fs_dirent_is_dir(dirent) == 1);
+
+    rc = fs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    rc = fs_closedir(dir);
+    TEST_ASSERT(rc == 0);
+
+    /* Ensure directory is gone. */
+    rc = fs_opendir("/mydir", &dir);
+    TEST_ASSERT(rc == FS_ENOENT);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/rename_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/rename_test.c b/fs/nffs/test/src/testcases/rename_test.c
new file mode 100644
index 0000000..e35456d
--- /dev/null
+++ b/fs/nffs/test/src/testcases/rename_test.c
@@ -0,0 +1,98 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_rename)
+{
+    struct fs_file *file;
+    const char contents[] = "contents";
+    int rc;
+
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_rename("/nonexistent.txt", "/newname.txt");
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    /*** Rename file. */
+    nffs_test_util_create_file("/myfile.txt", contents, sizeof contents);
+
+    rc = fs_rename("/myfile.txt", "badname");
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    rc = fs_rename("/myfile.txt", "/myfile2.txt");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_open("/myfile.txt", FS_ACCESS_READ, &file);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    nffs_test_util_assert_contents("/myfile2.txt", contents, sizeof contents);
+
+    rc = fs_mkdir("/mydir");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_mkdir("/mydir/leafdir");
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_rename("/myfile2.txt", "/mydir/myfile2.txt");
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/mydir/myfile2.txt", contents,
+                                  sizeof contents);
+
+    /*** Rename directory. */
+    rc = fs_rename("/mydir", "badname");
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    /* Don't allow a directory to be moved into a descendent directory. */
+    rc = fs_rename("/mydir", "/mydir/leafdir/a");
+    TEST_ASSERT(rc == FS_EINVAL);
+
+    rc = fs_rename("/mydir", "/mydir2");
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/mydir2/myfile2.txt", contents,
+                                  sizeof contents);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "mydir2",
+                .is_dir = 1,
+                .children = (struct nffs_test_file_desc[]) { {
+                    .filename = "leafdir",
+                    .is_dir = 1,
+                }, {
+                    .filename = "myfile2.txt",
+                    .contents = "contents",
+                    .contents_len = 9,
+                }, {
+                    .filename = NULL,
+                } },
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/split_file_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/split_file_test.c b/fs/nffs/test/src/testcases/split_file_test.c
new file mode 100644
index 0000000..a152bdc
--- /dev/null
+++ b/fs/nffs/test/src/testcases/split_file_test.c
@@ -0,0 +1,65 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_split_file)
+{
+    static char data[24 * 1024];
+    int rc;
+    int i;
+
+    /*** Setup. */
+    static const struct nffs_area_desc area_descs_two[] = {
+            { 0x00000000, 16 * 1024 },
+            { 0x00004000, 16 * 1024 },
+            { 0x00008000, 16 * 1024 },
+            { 0, 0 },
+    };
+
+    rc = nffs_format(area_descs_two);
+    TEST_ASSERT(rc == 0);
+
+    for (i = 0; i < sizeof data; i++) {
+        data[i] = i;
+    }
+
+    for (i = 0; i < 256; i++) {
+        nffs_test_util_create_file("/myfile.txt", data, sizeof data);
+        rc = fs_unlink("/myfile.txt");
+        TEST_ASSERT(rc == 0);
+    }
+
+    nffs_test_util_create_file("/myfile.txt", data, sizeof data);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = data,
+                .contents_len = sizeof data,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, area_descs_two);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/truncate_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/truncate_test.c b/fs/nffs/test/src/testcases/truncate_test.c
new file mode 100644
index 0000000..cf78540
--- /dev/null
+++ b/fs/nffs/test/src/testcases/truncate_test.c
@@ -0,0 +1,73 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_truncate)
+{
+    struct fs_file *file;
+    int rc;
+
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 0);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "abcdefgh", 8);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 8);
+    TEST_ASSERT(fs_getpos(file) == 8);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt", "abcdefgh", 8);
+
+    rc = fs_open("/myfile.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 0);
+    TEST_ASSERT(fs_getpos(file) == 0);
+
+    rc = fs_write(file, "1234", 4);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_file_len(file, 4);
+    TEST_ASSERT(fs_getpos(file) == 4);
+    rc = fs_close(file);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_contents("/myfile.txt", "1234", 4);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+            .children = (struct nffs_test_file_desc[]) { {
+                .filename = "myfile.txt",
+                .contents = "1234",
+                .contents_len = 4,
+            }, {
+                .filename = NULL,
+            } },
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/unlink_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/unlink_test.c b/fs/nffs/test/src/testcases/unlink_test.c
new file mode 100644
index 0000000..e28d19c
--- /dev/null
+++ b/fs/nffs/test/src/testcases/unlink_test.c
@@ -0,0 +1,121 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_unlink)
+{
+    struct fs_file *file0;
+    struct fs_file *file2;
+    uint8_t buf[64];
+    struct nffs_file *nfs_file;
+    uint32_t bytes_read;
+    struct fs_file *file1;
+    int initial_num_blocks;
+    int initial_num_inodes;
+    int rc;
+
+    rc = nffs_format(nffs_current_area_descs);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    initial_num_blocks = nffs_block_entry_pool.mp_num_free;
+    initial_num_inodes = nffs_inode_entry_pool.mp_num_free;
+
+    nffs_test_util_create_file("/file0.txt", "0", 1);
+
+    rc = fs_open("/file0.txt", FS_ACCESS_READ | FS_ACCESS_WRITE, &file0);
+    TEST_ASSERT(rc == 0);
+    nfs_file = (struct nffs_file *)file0;
+    TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 2);
+
+    rc = fs_unlink("/file0.txt");
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 1);
+
+    rc = fs_open("/file0.txt", FS_ACCESS_READ, &file2);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    rc = fs_write(file0, "00", 2);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_seek(file0, 0);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_read(file0, sizeof buf, buf, &bytes_read);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(bytes_read == 2);
+    TEST_ASSERT(memcmp(buf, "00", 2) == 0);
+
+    rc = fs_close(file0);
+    TEST_ASSERT(rc == 0);
+
+
+    rc = fs_open("/file0.txt", FS_ACCESS_READ, &file0);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    /* Ensure the file was fully removed from RAM. */
+    TEST_ASSERT(nffs_inode_entry_pool.mp_num_free == initial_num_inodes);
+    TEST_ASSERT(nffs_block_entry_pool.mp_num_free == initial_num_blocks);
+
+    /*** Nested unlink. */
+    rc = fs_mkdir("/mydir");
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_create_file("/mydir/file1.txt", "1", 2);
+
+    rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ | FS_ACCESS_WRITE, &file1);
+    TEST_ASSERT(rc == 0);
+    nfs_file = (struct nffs_file *)file1;
+    TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 2);
+
+    rc = fs_unlink("/mydir");
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(nfs_file->nf_inode_entry->nie_refcnt == 1);
+
+    rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ, &file2);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    rc = fs_write(file1, "11", 2);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_seek(file1, 0);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_read(file1, sizeof buf, buf, &bytes_read);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(bytes_read == 2);
+    TEST_ASSERT(memcmp(buf, "11", 2) == 0);
+
+    rc = fs_close(file1);
+    TEST_ASSERT(rc == 0);
+
+    rc = fs_open("/mydir/file1.txt", FS_ACCESS_READ, &file1);
+    TEST_ASSERT(rc == FS_ENOENT);
+
+    struct nffs_test_file_desc *expected_system =
+        (struct nffs_test_file_desc[]) { {
+            .filename = "",
+            .is_dir = 1,
+    } };
+
+    nffs_test_assert_system(expected_system, nffs_current_area_descs);
+
+    /* Ensure the files and directories were fully removed from RAM. */
+    TEST_ASSERT(nffs_inode_entry_pool.mp_num_free == initial_num_inodes);
+    TEST_ASSERT(nffs_block_entry_pool.mp_num_free == initial_num_blocks);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/testcases/wear_level_test.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/testcases/wear_level_test.c b/fs/nffs/test/src/testcases/wear_level_test.c
new file mode 100644
index 0000000..2afcc7b
--- /dev/null
+++ b/fs/nffs/test/src/testcases/wear_level_test.c
@@ -0,0 +1,58 @@
+/**
+ * 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 "nffs_test_utils.h"
+
+TEST_CASE(nffs_test_wear_level)
+{
+    int rc;
+    int i;
+    int j;
+
+    static const struct nffs_area_desc area_descs_uniform[] = {
+        { 0x00000000, 2 * 1024 },
+        { 0x00020000, 2 * 1024 },
+        { 0x00040000, 2 * 1024 },
+        { 0x00060000, 2 * 1024 },
+        { 0x00080000, 2 * 1024 },
+        { 0, 0 },
+    };
+
+    /*** Setup. */
+    rc = nffs_format(area_descs_uniform);
+    TEST_ASSERT(rc == 0);
+
+    /* Ensure areas rotate properly. */
+    for (i = 0; i < 255; i++) {
+        for (j = 0; j < nffs_num_areas; j++) {
+            nffs_test_assert_area_seqs(i, nffs_num_areas - j, i + 1, j);
+            nffs_gc(NULL);
+        }
+    }
+
+    /* Ensure proper rollover of sequence numbers. */
+    for (j = 0; j < nffs_num_areas; j++) {
+        nffs_test_assert_area_seqs(255, nffs_num_areas - j, 0, j);
+        nffs_gc(NULL);
+    }
+    for (j = 0; j < nffs_num_areas; j++) {
+        nffs_test_assert_area_seqs(0, nffs_num_areas - j, 1, j);
+        nffs_gc(NULL);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/hw/bsp/native/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/native/syscfg.yml b/hw/bsp/native/syscfg.yml
index d648bb0..fb238e0 100644
--- a/hw/bsp/native/syscfg.yml
+++ b/hw/bsp/native/syscfg.yml
@@ -1,2 +1,3 @@
 syscfg.vals:
     NFFS_FLASH_AREA: FLASH_AREA_NFFS
+    CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
deleted file mode 100644
index 35134f7..0000000
--- a/kernel/os/test/src/arch/cortex_m4/os_test_arch_arm.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * 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/75101ba4/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
deleted file mode 100644
index 3b6cfbf..0000000
--- a/kernel/os/test/src/arch/sim/os_test_arch_sim.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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/75101ba4/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
index 8353217..72e44a5 100644
--- a/kernel/os/test/src/callout_test.c
+++ b/kernel/os/test/src/callout_test.c
@@ -16,19 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.
  */
- 
 #include "sysinit/sysinit.h"
 #include "testutil/testutil.h"
 #include "os/os.h"
 #include "os_test_priv.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];
 
@@ -40,16 +36,13 @@ 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*/
@@ -57,12 +50,10 @@ 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];
 
@@ -72,6 +63,7 @@ struct os_callout_func callout_func_speak;
 int p;
 int q;
 int t;
+
 /* This is the function for callout_init*/
 void
 my_callout_func(void *arg)
@@ -235,90 +227,9 @@ callout_task_stop_listen( void *arg )
 
 }
 
-/* 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();
-}
-
-/* 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();
-
-}
-
-/* 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();
-
-}
+TEST_CASE_DECL(callout_test_speak)
+TEST_CASE_DECL(callout_test_stop)
+TEST_CASE_DECL(callout_test)
 
 TEST_SUITE(os_callout_test_suite)
 {   

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/callout_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/callout_test.h b/kernel/os/test/src/callout_test.h
new file mode 100644
index 0000000..3e0d94d
--- /dev/null
+++ b/kernel/os/test/src/callout_test.h
@@ -0,0 +1,96 @@
+/**
+ * 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 _CALLOUT_TEST_H
+#define _CALLOUT_TEST_H
+
+#include "sysinit/sysinit.h"
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Task 1 for sending */
+#define CALLOUT_STACK_SIZE        (5120)
+#define SEND_CALLOUT_TASK_PRIO        (1)
+extern struct os_task callout_task_struct_send;
+extern os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE];
+
+#define RECEIVE_CALLOUT_TASK_PRIO        (2)
+extern struct os_task callout_task_struct_receive;
+extern os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE];
+
+/* Delearing variables for callout_func */
+extern struct os_callout_func callout_func_test;
+
+/* The event to be sent*/
+extern struct os_eventq callout_evq;
+extern struct os_event callout_ev;
+
+/* The callout_stop task */
+#define SEND_STOP_CALLOUT_TASK_PRIO        (3)
+extern struct os_task callout_task_struct_stop_send;
+extern os_stack_t callout_task_stack_stop_send[CALLOUT_STACK_SIZE];
+
+#define RECEIVE_STOP_CALLOUT_TASK_PRIO        (4)
+extern struct os_task callout_task_struct_stop_receive;
+extern os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE];
+
+/* Delearing variables for callout_stop_func */
+#define MULTI_SIZE    (2)
+extern struct os_callout_func callout_func_stop_test[MULTI_SIZE];
+
+/* The event to be sent*/
+extern struct os_eventq callout_stop_evq[MULTI_SIZE];
+extern struct os_event callout_stop_ev;
+
+/* Declearing varables for callout_speak */
+#define SPEAK_CALLOUT_TASK_PRIO        (5)
+extern struct os_task callout_task_struct_speak;
+extern os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE];
+
+/* Declearing varaibles for listen */
+#define LISTEN_CALLOUT_TASK_PRIO        (6)
+extern struct os_task callout_task_struct_listen;
+extern os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE];
+
+extern struct os_callout_func callout_func_speak;
+
+/* Global variables to be used by the callout functions */
+extern int p;
+extern int q;
+extern int t;
+
+void my_callout_func(void *arg);
+void my_callout_stop_func(void *arg);
+void my_callout_speak_func(void *arg);
+void callout_task_send(void *arg);
+void callout_task_receive(void *arg);
+void callout_task_stop_send(void *arg);
+void callout_task_stop_receive(void *arg);
+void callout_task_stop_speak(void *arg);
+void callout_task_stop_listen(void *arg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CALLOUT_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/eventq_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/eventq_test.c b/kernel/os/test/src/eventq_test.c
index a891f0c..77c24a6 100644
--- a/kernel/os/test/src/eventq_test.c
+++ b/kernel/os/test/src/eventq_test.c
@@ -82,6 +82,12 @@ os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE];
 struct os_task eventq_task_poll_single_r;
 os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE];
 
+TEST_CASE_DECL(event_test_sr)
+TEST_CASE_DECL(event_test_poll_sr)
+TEST_CASE_DECL(event_test_poll_timeout_sr)
+TEST_CASE_DECL(event_test_poll_single_sr)
+TEST_CASE_DECL(event_test_poll_0timo)
+
 /* This is the task function  to send data */
 void
 eventq_task_send(void *arg)
@@ -261,152 +267,6 @@ eventq_task_poll_single_receive(void *arg)
     os_test_restart();
 }
 
-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();
-
-}
-
-/* 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();
-
-}
-
-/* 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();
-
-}
-
-/* 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();
-
-}
-
-/**
- * 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();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/eventq_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/eventq_test.h b/kernel/os/test/src/eventq_test.h
new file mode 100644
index 0000000..a061b86
--- /dev/null
+++ b/kernel/os/test/src/eventq_test.h
@@ -0,0 +1,104 @@
+/**
+ * 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 _EVENTQ_TEST_H
+#define _EVENTQ_TEST_H
+ 
+#include <string.h>
+#include "sysinit/sysinit.h"
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+#include "os/os_eventq.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+#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)
+extern struct os_task eventq_task_s;
+extern os_stack_t eventq_task_stack_s[MY_STACK_SIZE];
+
+/* Task 2 receiving task */
+#define RECEIVE_TASK_PRIO     (2)
+extern struct os_task eventq_task_r;
+extern os_stack_t eventq_task_stack_r[MY_STACK_SIZE];
+
+extern struct os_eventq my_eventq;
+
+#define SIZE_MULTI_EVENT        (4)
+extern struct os_eventq multi_eventq[SIZE_MULTI_EVENT];
+
+/* This is to set the events we will use below */
+extern struct os_event g_event;
+extern struct os_event m_event[SIZE_MULTI_EVENT];
+
+/* Setting the event to send and receive multiple data */
+extern uint8_t my_event_type;
+
+/* Setting up data for the poll */
+/* Define the task stack for the eventq_task_poll_send */
+#define SEND_TASK_POLL_PRIO        (3)
+extern struct os_task eventq_task_poll_s;
+extern 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)
+extern struct os_task eventq_task_poll_r;
+extern 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)
+extern struct os_task eventq_task_poll_timeout_s;
+extern 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)
+extern struct os_task eventq_task_poll_timeout_r;
+extern 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)
+extern struct os_task eventq_task_poll_single_s;
+extern 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];
+
+void eventq_task_send(void *arg);
+void eventq_task_receive(void *arg);
+void eventq_task_poll_send(void *arg);
+void eventq_task_poll_receive(void *arg);
+void eventq_task_poll_timeout_send(void *arg);
+void eventq_task_poll_timeout_receive(void *arg);
+void eventq_task_poll_single_send(void *arg);
+void eventq_task_poll_single_receive(void *arg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _EVENTQ_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/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
index dd4121d..73b6660 100644
--- a/kernel/os/test/src/mbuf_test.c
+++ b/kernel/os/test/src/mbuf_test.c
@@ -32,14 +32,14 @@
 
 #define MBUF_TEST_DATA_LEN          (1024)
 
-static os_membuf_t os_mbuf_membuf[OS_MEMPOOL_SIZE(MBUF_TEST_POOL_BUF_SIZE,
+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];
+struct os_mbuf_pool os_mbuf_pool;
+struct os_mempool os_mbuf_mempool;
+uint8_t os_mbuf_test_data[MBUF_TEST_DATA_LEN];
 
-static void
+void
 os_mbuf_test_setup(void)
 {
     int rc;
@@ -58,7 +58,7 @@ os_mbuf_test_setup(void)
     }
 }
 
-static void
+void
 os_mbuf_test_misc_assert_sane(struct os_mbuf *om, void *data,
                               int buflen, int pktlen, int pkthdr_len)
 {
@@ -95,318 +95,13 @@ os_mbuf_test_misc_assert_sane(struct os_mbuf *om, void *data,
     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_CASE_DECL(os_mbuf_test_alloc)
+TEST_CASE_DECL(os_mbuf_test_dup)
+TEST_CASE_DECL(os_mbuf_test_append)
+TEST_CASE_DECL(os_mbuf_test_pullup)
+TEST_CASE_DECL(os_mbuf_test_extend)
+TEST_CASE_DECL(os_mbuf_test_adj)
+TEST_CASE_DECL(os_mbuf_test_get_pkthdr)
 
 TEST_SUITE(os_mbuf_test_suite)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mbuf_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mbuf_test.h b/kernel/os/test/src/mbuf_test.h
new file mode 100644
index 0000000..7585263
--- /dev/null
+++ b/kernel/os/test/src/mbuf_test.h
@@ -0,0 +1,56 @@
+/**
+ * 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 _MBUF_TEST_H
+#define _MBUF_TEST_H
+
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+
+#include <string.h>
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+/* 
+ * 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)
+
+extern os_membuf_t os_mbuf_membuf[OS_MEMPOOL_SIZE(MBUF_TEST_POOL_BUF_SIZE,
+        MBUF_TEST_POOL_BUF_COUNT)];
+
+extern struct os_mbuf_pool os_mbuf_pool;
+extern struct os_mempool os_mbuf_mempool;
+extern uint8_t os_mbuf_test_data[MBUF_TEST_DATA_LEN];
+
+void os_mbuf_test_setup(void);
+void os_mbuf_test_misc_assert_sane(struct os_mbuf *om, void *data, int buflen,
+                                   int pktlen, int pkthdr_len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MBUF_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mempool_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mempool_test.c b/kernel/os/test/src/mempool_test.c
index cd17c90..15a48bc 100644
--- a/kernel/os/test/src/mempool_test.c
+++ b/kernel/os/test/src/mempool_test.c
@@ -46,7 +46,7 @@ void *block_array[MEMPOOL_TEST_MAX_BLOCKS];
 
 int verbose = 0;
 
-static int
+int
 mempool_test_get_pool_size(int num_blocks, int block_size)
 {
     int mem_pool_size;
@@ -60,7 +60,7 @@ mempool_test_get_pool_size(int num_blocks, int block_size)
     return mem_pool_size;
 }
 
-static void
+void
 mempool_test(int num_blocks, int block_size)
 {
     int cnt;
@@ -209,17 +209,7 @@ mempool_test(int num_blocks, int block_size)
     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_CASE_DECL(os_mempool_test_case)
 
 TEST_SUITE(os_mempool_test_suite)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mempool_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mempool_test.h b/kernel/os/test/src/mempool_test.h
new file mode 100644
index 0000000..78258ca
--- /dev/null
+++ b/kernel/os/test/src/mempool_test.h
@@ -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.
+ */
+#ifndef _MEMPOOL_TEST_H
+#define _MEMPOOL_TEST_H
+
+#include <stdio.h>
+#include <string.h>
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+/* 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)
+
+extern int alignment;
+
+/* Test memory pool structure */
+extern struct os_mempool g_TstMempool;
+
+/* Test memory pool buffer */
+extern os_membuf_t TstMembuf[OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE)];
+
+/* Array of block pointers. */
+extern void *block_array[MEMPOOL_TEST_MAX_BLOCKS];
+
+extern int verbose;
+
+int mempool_test_get_pool_size(int num_blocks, int block_size);
+
+void mempool_test(int num_blocks, int block_size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MEMPOOL_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mutex_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mutex_test.c b/kernel/os/test/src/mutex_test.c
index fbcfe17..54a1f2d 100644
--- a/kernel/os/test/src/mutex_test.c
+++ b/kernel/os/test/src/mutex_test.c
@@ -56,7 +56,7 @@ volatile int g_task17_val;
 struct os_mutex g_mutex1;
 struct os_mutex g_mutex2;
 
-static volatile int g_mutex_test;
+volatile int g_mutex_test;
 
 /**
  * mutex test basic 
@@ -65,7 +65,7 @@ static volatile int g_mutex_test;
  * 
  * @return int 
  */
-static void
+void
 mutex_test_basic_handler(void *arg)
 {
     struct os_mutex *mu;
@@ -137,7 +137,7 @@ mutex_test_basic_handler(void *arg)
     os_test_restart();
 }
 
-static void 
+void 
 mutex_test1_task14_handler(void *arg)
 {
     os_error_t err;
@@ -162,7 +162,7 @@ mutex_test1_task14_handler(void *arg)
     os_test_restart();
 }
 
-static void 
+void 
 mutex_test2_task14_handler(void *arg)
 {
     os_error_t err;
@@ -198,7 +198,7 @@ mutex_test2_task14_handler(void *arg)
     os_test_restart();
 }
 
-static void 
+void 
 task15_handler(void *arg) 
 {
     os_error_t err;
@@ -241,7 +241,7 @@ task15_handler(void *arg)
     }
 }
 
-static void 
+void 
 task16_handler(void *arg) 
 {
     os_error_t err;
@@ -297,7 +297,7 @@ task16_handler(void *arg)
     }
 }
 
-static void 
+void 
 task17_handler(void *arg)
 {
     os_error_t err;
@@ -329,74 +329,9 @@ task17_handler(void *arg)
     }
 }
 
-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();
-}
-
-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();
-}
-
-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();
-}
+TEST_CASE_DECL(os_mutex_test_basic)
+TEST_CASE_DECL(os_mutex_test_case_1)
+TEST_CASE_DECL(os_mutex_test_case_2)
 
 TEST_SUITE(os_mutex_test_suite)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/mutex_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/mutex_test.h b/kernel/os/test/src/mutex_test.h
new file mode 100644
index 0000000..221d0ad
--- /dev/null
+++ b/kernel/os/test/src/mutex_test.h
@@ -0,0 +1,78 @@
+/**
+ * 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 _MUTEX_TEST_H
+#define _MUTEX_TEST_H
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/time.h>
+#include "sysinit/sysinit.h"
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os/os_test.h"
+#include "os_test_priv.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+#ifdef ARCH_sim
+#define MUTEX_TEST_STACK_SIZE   1024
+#else
+#define MUTEX_TEST_STACK_SIZE   256
+#endif
+
+extern struct os_task task14;
+extern os_stack_t stack14[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
+
+extern struct os_task task15;
+extern os_stack_t stack15[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
+
+extern struct os_task task16;
+extern os_stack_t stack16[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
+
+extern struct os_task task17;
+extern os_stack_t stack17[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
+
+#define TASK14_PRIO (4)
+#define TASK15_PRIO (5)
+#define TASK16_PRIO (6)
+#define TASK17_PRIO (7)
+
+extern volatile int g_task14_val;
+extern volatile int g_task15_val;
+extern volatile int g_task16_val;
+extern volatile int g_task17_val;
+extern struct os_mutex g_mutex1;
+extern struct os_mutex g_mutex2;
+extern volatile int g_mutex_test;
+
+void mutex_test_basic_handler(void *arg);
+void mutex_test1_task14_handler(void *arg);
+void mutex_test2_task14_handler(void *arg);
+void task15_handler(void *arg);
+void task16_handler(void *arg);
+void task17_handler(void *arg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MUTEX_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/os_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/os_test.c b/kernel/os/test/src/os_test.c
index e9d041b..71188d2 100644
--- a/kernel/os/test/src/os_test.c
+++ b/kernel/os/test/src/os_test.c
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #include <assert.h>
 #include <stddef.h>
 #include "syscfg/syscfg.h"
@@ -24,6 +23,38 @@
 #include "os/os_test.h"
 #include "os_test_priv.h"
 
+#include <stdio.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/time.h>
+#include "os/os.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();
+}
+
 int
 os_test_all(void)
 {
@@ -42,7 +73,7 @@ os_test_all(void)
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     os_test_all();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/os_test_priv.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/os_test_priv.h b/kernel/os/test/src/os_test_priv.h
index 945efc0..eaa33d1 100644
--- a/kernel/os/test/src/os_test_priv.h
+++ b/kernel/os/test/src/os_test_priv.h
@@ -20,6 +20,19 @@
 #ifndef H_OS_TEST_PRIV_
 #define H_OS_TEST_PRIV_
 
+#include "sysinit/sysinit.h"
+#include "testutil/testutil.h"
+#include "os/os.h"
+#include "os_test_priv.h"
+
+#include "callout_test.h"
+
+#include "eventq_test.h"
+#include "mbuf_test.h"
+#include "mempool_test.h"
+#include "mutex_test.h"
+#include "sem_test.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/kernel/os/test/src/sem_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/sem_test.c b/kernel/os/test/src/sem_test.c
index 9fe7824..1319bc7 100644
--- a/kernel/os/test/src/sem_test.c
+++ b/kernel/os/test/src/sem_test.c
@@ -58,6 +58,8 @@ struct os_sem g_sem1;
  * 
  */
 
+char sem_test_buf[128];
+
 /**
  * sem test disp sem
  *  
@@ -65,18 +67,25 @@ struct os_sem g_sem1;
  * 
  * @param sem 
  */
-static const char *
+const char *
 sem_test_sem_to_s(const struct os_sem *sem)
 {
-    static char buf[128];
+#if 0
+    char buf[128];
 
     snprintf(buf, sizeof buf, "\tSemaphore: tokens=%u head=%p",
              sem->sem_tokens, SLIST_FIRST(&sem->sem_head));
 
     return buf;
+#else
+    snprintf(sem_test_buf, sizeof sem_test_buf, "\tSemaphore: tokens=%u head=%p",
+             sem->sem_tokens, SLIST_FIRST(&sem->sem_head));
+
+    return sem_test_buf;
+#endif
 }
 
-static void 
+void 
 sem_test_sleep_task_handler(void *arg)
 {
     struct os_task *t;
@@ -88,7 +97,7 @@ sem_test_sleep_task_handler(void *arg)
     os_test_restart();
 }
 
-static void
+void
 sem_test_pend_release_loop(int delay, int timeout, int itvl)
 {
     os_error_t err;
@@ -113,7 +122,7 @@ sem_test_pend_release_loop(int delay, int timeout, int itvl)
  * 
  * @return int 
  */
-static void 
+void 
 sem_test_basic_handler(void *arg)
 {
     struct os_task *t;
@@ -178,7 +187,7 @@ sem_test_basic_handler(void *arg)
     os_test_restart();
 }
 
-static void 
+void 
 sem_test_1_task1_handler(void *arg)
 {
     os_error_t err;
@@ -207,188 +216,77 @@ sem_test_1_task1_handler(void *arg)
     os_test_restart();
 }
 
-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();
-}
-
-static void 
+void 
 sem_test_1_task2_handler(void *arg) 
 {
     sem_test_pend_release_loop(0, OS_TICKS_PER_SEC / 10, OS_TICKS_PER_SEC / 10);
 }
 
-static void 
+void 
 sem_test_1_task3_handler(void *arg) 
 {
     sem_test_pend_release_loop(0, OS_TIMEOUT_NEVER, OS_TICKS_PER_SEC * 2);
 }
 
-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();
-}
-
-static void 
+void 
 sem_test_2_task2_handler(void *arg) 
 {
     sem_test_pend_release_loop(0, 2000, 2000);
 }
 
-static void 
+void 
 sem_test_2_task3_handler(void *arg) 
 {
     sem_test_pend_release_loop(0, OS_TIMEOUT_NEVER, 2000);
 }
 
-static void 
+void 
 sem_test_2_task4_handler(void *arg) 
 {
     sem_test_pend_release_loop(0, 2000, 2000);
 }
 
-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();
-}
-
-static void 
+void 
 sem_test_3_task2_handler(void *arg) 
 {
     sem_test_pend_release_loop(100, 2000, 2000);
 }
 
-static void 
+void 
 sem_test_3_task3_handler(void *arg) 
 {
     sem_test_pend_release_loop(150, 2000, 2000);
 }
 
-static void 
+void 
 sem_test_3_task4_handler(void *arg) 
 {
     sem_test_pend_release_loop(0, 2000, 2000);
 }
 
-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();
-}
-
-static void 
+void 
 sem_test_4_task2_handler(void *arg) 
 {
     sem_test_pend_release_loop(60, 2000, 2000);
 }
 
-static void 
+void 
 sem_test_4_task3_handler(void *arg) 
 {
     sem_test_pend_release_loop(60, 2000, 2000);
 }
 
-static void 
+void 
 sem_test_4_task4_handler(void *arg) 
 {
     sem_test_pend_release_loop(0, 2000, 2000);
 }
 
-
-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();
-}
+TEST_CASE_DECL(os_sem_test_basic)
+TEST_CASE_DECL(os_sem_test_case_1)
+TEST_CASE_DECL(os_sem_test_case_2)
+TEST_CASE_DECL(os_sem_test_case_3)
+TEST_CASE_DECL(os_sem_test_case_4)
 
 TEST_SUITE(os_sem_test_suite)
 {



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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/arch/sim/nffs_test_system_01.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/arch/sim/nffs_test_system_01.c b/fs/nffs/test/src/arch/sim/nffs_test_system_01.c
deleted file mode 100644
index cd30544..0000000
--- a/fs/nffs/test/src/arch/sim/nffs_test_system_01.c
+++ /dev/null
@@ -1,6537 +0,0 @@
-/**
- * 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.
- */
-
-
-/** Generated by makefs.rb */
-
-#include <stddef.h>
-#include "nffs_test_priv.h"
-
-const struct nffs_test_file_desc *nffs_test_system_01 =
-    (struct nffs_test_file_desc[]) {
-{
-.filename = "",
-.is_dir = 1,
-.children = (struct nffs_test_file_desc[]) {
- {
- .filename = "lvl1dir-0000",
- .is_dir = 1,
- .children = (struct nffs_test_file_desc[]) {
-  {
-  .filename = "lvl2dir-0000",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0001",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0002",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0003",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0004",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
- { .filename = NULL, } }
- },
- {
- .filename = "lvl1dir-0001",
- .is_dir = 1,
- .children = (struct nffs_test_file_desc[]) {
-  {
-  .filename = "lvl2dir-0000",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0001",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0002",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0003",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0004",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
- { .filename = NULL, } }
- },
- {
- .filename = "lvl1dir-0002",
- .is_dir = 1,
- .children = (struct nffs_test_file_desc[]) {
-  {
-  .filename = "lvl2dir-0000",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0001",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0002",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0003",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0004",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
- { .filename = NULL, } }
- },
- {
- .filename = "lvl1dir-0003",
- .is_dir = 1,
- .children = (struct nffs_test_file_desc[]) {
-  {
-  .filename = "lvl2dir-0000",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0001",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0002",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0003",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0004",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
- { .filename = NULL, } }
- },
- {
- .filename = "lvl1dir-0004",
- .is_dir = 1,
- .children = (struct nffs_test_file_desc[]) {
-  {
-  .filename = "lvl2dir-0000",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0001",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0002",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0003",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0004",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
- { .filename = NULL, } }
- },
-{ .filename = NULL, } }
-},
-};
-
-const struct nffs_test_file_desc *nffs_test_system_01_rm_1014_mk10 =
-    (struct nffs_test_file_desc[]) {
-{
-.filename = "",
-.is_dir = 1,
-.children = (struct nffs_test_file_desc[]) {
- {
- .filename = "lvl1dir-0000",
- .is_dir = 1,
- },
- {
- .filename = "lvl1dir-0001",
- .is_dir = 1,
- .children = (struct nffs_test_file_desc[]) {
-  {
-  .filename = "lvl2dir-0000",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0001",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0001",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0002",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0003",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-   {
-   .filename = "lvl3dir-0004",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0003",
-    .contents = "3",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0004",
-    .contents = "4",
-    .contents_len = 1,
-    },
-   { .filename = NULL, } }
-   },
-  { .filename = NULL, } }
-  },
-  {
-  .filename = "lvl2dir-0002",
-  .is_dir = 1,
-  .children = (struct nffs_test_file_desc[]) {
-   {
-   .filename = "lvl3dir-0000",
-   .is_dir = 1,
-   .children = (struct nffs_test_file_desc[]) {
-    {
-    .filename = "lvl4file-0000",
-    .contents = "0",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0001",
-    .contents = "1",
-    .contents_len = 1,
-    },
-    {
-    .filename = "lvl4file-0002",
-    .contents = "2",
-    .conte

<TRUNCATED>


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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_ns_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_ns_11.c b/boot/bootutil/test/src/testcases/boot_test_nv_ns_11.c
new file mode 100644
index 0000000..4a43ef2
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_11.c
@@ -0,0 +1,56 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_ns_11)
+{
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_revert.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_revert.c b/boot/bootutil/test/src/testcases/boot_test_revert.c
new file mode 100644
index 0000000..d49d42d
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_revert.c
@@ -0,0 +1,59 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_revert)
+{
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    /* Indicate that the image in slot 0 is being tested. */
+    boot_set_copy_done();
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_revert_continue.c b/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
new file mode 100644
index 0000000..ec4f56c
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_revert_continue.c
@@ -0,0 +1,71 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_revert_continue)
+{
+    struct boot_status status;
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    boot_test_util_swap_areas(2, 5);
+
+    /* Indicate that the image in slot 0 is being tested. */
+    boot_set_copy_done();
+
+    status.idx = 1;
+    status.elem_sz = 1;
+    status.state = 0;
+
+    rc = boot_write_status(&status);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
new file mode 100644
index 0000000..38fa8f9
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_vb_ns_11.c
@@ -0,0 +1,61 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_vb_ns_11)
+{
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
new file mode 100644
index 0000000..ac31824
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_01.c
@@ -0,0 +1,50 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_vm_ns_01)
+{
+    int rc;
+
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 10 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 1);
+    boot_test_util_write_hash(&hdr, 1);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_10.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_10.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_10.c
new file mode 100644
index 0000000..24c7361
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_10.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 "boot_test.h"
+
+TEST_CASE(boot_test_vm_ns_10)
+{
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+    boot_test_util_write_hash(&hdr, 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
new file mode 100644
index 0000000..84e6a91
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_2areas.c
@@ -0,0 +1,61 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_vm_ns_11_2areas)
+{
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 196 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_a.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_a.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_a.c
new file mode 100644
index 0000000..7ef5196
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_a.c
@@ -0,0 +1,56 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_vm_ns_11_a)
+{
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
new file mode 100644
index 0000000..f4df74a
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_vm_ns_11_b.c
@@ -0,0 +1,61 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_vm_ns_11_b)
+{
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 5 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/mbedtls_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/mbedtls_test.c b/crypto/mbedtls/test/src/mbedtls_test.c
index 85038f8..877452a 100644
--- a/crypto/mbedtls/test/src/mbedtls_test.c
+++ b/crypto/mbedtls/test/src/mbedtls_test.c
@@ -43,152 +43,24 @@
 #include "mbedtls/x509.h"
 #include "mbedtls/xtea.h"
 
-TEST_CASE(sha1_test)
-{
-    int rc;
-
-    rc = mbedtls_sha1_self_test(0);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(sha256_test)
-{
-    int rc;
-
-    rc = mbedtls_sha256_self_test(0);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(sha512_test)
-{
-    int rc;
-
-    rc = mbedtls_sha512_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(aes_test)
-{
-    int rc;
-
-    rc = mbedtls_aes_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(arc4_test)
-{
-    int rc;
-
-    rc = mbedtls_arc4_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(bignum_test)
-{
-    int rc;
-
-    rc = mbedtls_mpi_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ccm_test)
-{
-    int rc;
-
-    rc = mbedtls_ccm_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(dhm_test)
-{
-    int rc;
-
-    rc = mbedtls_dhm_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ecp_test)
-{
-    int rc;
-
-    rc = mbedtls_ecp_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(entropy_test)
-{
-#if 0 /* XXX fix this later, no strong entropy source atm */
-    int rc;
-
-    rc = mbedtls_entropy_self_test(1);
-    TEST_ASSERT(rc == 0);
-#endif
-}
-
-TEST_CASE(gcm_test)
-{
-    int rc;
-
-    rc = mbedtls_gcm_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(hmac_drbg_test)
-{
-    int rc;
-
-    rc = mbedtls_hmac_drbg_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(md5_test)
-{
-    int rc;
-
-    rc = mbedtls_md5_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(pkcs5_test)
-{
-    int rc;
-
-    rc = mbedtls_pkcs5_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ripemd160_test)
-{
-    int rc;
-
-    rc = mbedtls_ripemd160_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(rsa_test)
-{
-    int rc;
-
-    rc = mbedtls_rsa_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(x509_test)
-{
-    int rc;
-
-    rc = mbedtls_x509_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(xtea_test)
-{
-    int rc;
-
-    rc = mbedtls_xtea_self_test(1);
-    TEST_ASSERT(rc == 0);
-}
-
+TEST_CASE_DECL(sha1_test)
+TEST_CASE_DECL(sha256_test)
+TEST_CASE_DECL(sha512_test)
+TEST_CASE_DECL(aes_test)
+TEST_CASE_DECL(arc4_test)
+TEST_CASE_DECL(bignum_test)
+TEST_CASE_DECL(ccm_test)
+TEST_CASE_DECL(dhm_test)
+TEST_CASE_DECL(ecp_test)
+TEST_CASE_DECL(entropy_test)
+TEST_CASE_DECL(gcm_test)
+TEST_CASE_DECL(hmac_drbg_test)
+TEST_CASE_DECL(md5_test)
+TEST_CASE_DECL(pkcs5_test)
+TEST_CASE_DECL(ripemd160_test)
+TEST_CASE_DECL(rsa_test)
+TEST_CASE_DECL(x509_test)
+TEST_CASE_DECL(xtea_test)
 
 TEST_SUITE(mbedtls_test_all)
 {
@@ -216,7 +88,7 @@ TEST_SUITE(mbedtls_test_all)
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     mbedtls_test_all();
@@ -225,4 +97,3 @@ main(int argc, char **argv)
 }
 
 #endif
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/mbedtls_test.h
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/mbedtls_test.h b/crypto/mbedtls/test/src/mbedtls_test.h
new file mode 100644
index 0000000..fd82fde
--- /dev/null
+++ b/crypto/mbedtls/test/src/mbedtls_test.h
@@ -0,0 +1,58 @@
+/**
+ * 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 _MBEDTLS_TEST_H
+#define _MBEDTLS_TEST_H
+#include <stdio.h>
+#include <string.h>
+
+#include "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+
+#include "mbedtls/mbedtls_test.h"
+#include "mbedtls/sha1.h"
+#include "mbedtls/sha256.h"
+#include "mbedtls/sha512.h"
+#include "mbedtls/aes.h"
+#include "mbedtls/arc4.h"
+#include "mbedtls/bignum.h"
+#include "mbedtls/ccm.h"
+#include "mbedtls/dhm.h"
+#include "mbedtls/ecjpake.h"
+#include "mbedtls/ecp.h"
+#include "mbedtls/entropy.h"
+#include "mbedtls/gcm.h"
+#include "mbedtls/hmac_drbg.h"
+#include "mbedtls/md5.h"
+#include "mbedtls/pkcs5.h"
+#include "mbedtls/ripemd160.h"
+#include "mbedtls/rsa.h"
+#include "mbedtls/x509.h"
+#include "mbedtls/xtea.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+/* This space intentionally left blank */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MBEDTLS_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/aes_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/aes_test.c b/crypto/mbedtls/test/src/testcases/aes_test.c
new file mode 100644
index 0000000..828c1cc
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/aes_test.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 "mbedtls_test.h"
+
+TEST_CASE(aes_test)
+{
+    int rc;
+
+    rc = mbedtls_aes_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/arc4_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/arc4_test.c b/crypto/mbedtls/test/src/testcases/arc4_test.c
new file mode 100644
index 0000000..91655e3
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/arc4_test.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 "mbedtls_test.h"
+
+TEST_CASE(arc4_test)
+{
+    int rc;
+
+    rc = mbedtls_arc4_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/bignum_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/bignum_test.c b/crypto/mbedtls/test/src/testcases/bignum_test.c
new file mode 100644
index 0000000..af5b704
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/bignum_test.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 "mbedtls_test.h"
+
+TEST_CASE(bignum_test)
+{
+    int rc;
+
+    rc = mbedtls_mpi_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/ccm_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/ccm_test.c b/crypto/mbedtls/test/src/testcases/ccm_test.c
new file mode 100644
index 0000000..efb77a6
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/ccm_test.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 "mbedtls_test.h"
+
+TEST_CASE(ccm_test)
+{
+    int rc;
+
+    rc = mbedtls_ccm_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/dhm_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/dhm_test.c b/crypto/mbedtls/test/src/testcases/dhm_test.c
new file mode 100644
index 0000000..6123298
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/dhm_test.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 "mbedtls_test.h"
+
+TEST_CASE(dhm_test)
+{
+    int rc;
+
+    rc = mbedtls_dhm_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/ecp_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/ecp_test.c b/crypto/mbedtls/test/src/testcases/ecp_test.c
new file mode 100644
index 0000000..b4a218e
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/ecp_test.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 "mbedtls_test.h"
+
+TEST_CASE(ecp_test)
+{
+    int rc;
+
+    rc = mbedtls_ecp_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/entropy_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/entropy_test.c b/crypto/mbedtls/test/src/testcases/entropy_test.c
new file mode 100644
index 0000000..7088313
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/entropy_test.c
@@ -0,0 +1,29 @@
+/**
+ * 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 "mbedtls_test.h"
+
+TEST_CASE(entropy_test)
+{
+#if 0 /* XXX fix this later, no strong entropy source atm */
+    int rc;
+
+    rc = mbedtls_entropy_self_test(1);
+    TEST_ASSERT(rc == 0);
+#endif
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/gcm_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/gcm_test.c b/crypto/mbedtls/test/src/testcases/gcm_test.c
new file mode 100644
index 0000000..27e0aea
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/gcm_test.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 "mbedtls_test.h"
+
+TEST_CASE(gcm_test)
+{
+    int rc;
+
+    rc = mbedtls_gcm_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/hmac_drbg_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/hmac_drbg_test.c b/crypto/mbedtls/test/src/testcases/hmac_drbg_test.c
new file mode 100644
index 0000000..cd1f38c
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/hmac_drbg_test.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 "mbedtls_test.h"
+
+TEST_CASE(hmac_drbg_test)
+{
+    int rc;
+
+    rc = mbedtls_hmac_drbg_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/md5_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/md5_test.c b/crypto/mbedtls/test/src/testcases/md5_test.c
new file mode 100644
index 0000000..a8bb014
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/md5_test.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 "mbedtls_test.h"
+
+TEST_CASE(md5_test)
+{
+    int rc;
+
+    rc = mbedtls_md5_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/pkcs5_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/pkcs5_test.c b/crypto/mbedtls/test/src/testcases/pkcs5_test.c
new file mode 100644
index 0000000..b9565d8
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/pkcs5_test.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 "mbedtls_test.h"
+
+TEST_CASE(pkcs5_test)
+{
+    int rc;
+
+    rc = mbedtls_pkcs5_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/ripemd160_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/ripemd160_test.c b/crypto/mbedtls/test/src/testcases/ripemd160_test.c
new file mode 100644
index 0000000..c7c5922
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/ripemd160_test.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 "mbedtls_test.h"
+
+TEST_CASE(ripemd160_test)
+{
+    int rc;
+
+    rc = mbedtls_ripemd160_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/rsa_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/rsa_test.c b/crypto/mbedtls/test/src/testcases/rsa_test.c
new file mode 100644
index 0000000..a9442f0
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/rsa_test.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 "mbedtls_test.h"
+
+TEST_CASE(rsa_test)
+{
+    int rc;
+
+    rc = mbedtls_rsa_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/sha1_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/sha1_test.c b/crypto/mbedtls/test/src/testcases/sha1_test.c
new file mode 100644
index 0000000..33427a7
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/sha1_test.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 "mbedtls_test.h"
+
+TEST_CASE(sha1_test)
+{
+    int rc;
+
+    rc = mbedtls_sha1_self_test(0);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/sha256_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/sha256_test.c b/crypto/mbedtls/test/src/testcases/sha256_test.c
new file mode 100644
index 0000000..8fd4860
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/sha256_test.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 "mbedtls_test.h"
+
+TEST_CASE(sha256_test)
+{
+    int rc;
+
+    rc = mbedtls_sha256_self_test(0);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/sha512_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/sha512_test.c b/crypto/mbedtls/test/src/testcases/sha512_test.c
new file mode 100644
index 0000000..6575d60
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/sha512_test.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 "mbedtls_test.h"
+
+TEST_CASE(sha512_test)
+{
+    int rc;
+
+    rc = mbedtls_sha512_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/x509_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/x509_test.c b/crypto/mbedtls/test/src/testcases/x509_test.c
new file mode 100644
index 0000000..53ac342
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/x509_test.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 "mbedtls_test.h"
+
+TEST_CASE(x509_test)
+{
+    int rc;
+
+    rc = mbedtls_x509_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/crypto/mbedtls/test/src/testcases/xtea_test.c
----------------------------------------------------------------------
diff --git a/crypto/mbedtls/test/src/testcases/xtea_test.c b/crypto/mbedtls/test/src/testcases/xtea_test.c
new file mode 100644
index 0000000..72296b5
--- /dev/null
+++ b/crypto/mbedtls/test/src/testcases/xtea_test.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 "mbedtls_test.h"
+
+TEST_CASE(xtea_test)
+{
+    int rc;
+
+    rc = mbedtls_xtea_self_test(1);
+    TEST_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/encoding_test.c
----------------------------------------------------------------------
diff --git a/encoding/base64/test/src/encoding_test.c b/encoding/base64/test/src/encoding_test.c
index b21fee8..c3656b0 100644
--- a/encoding/base64/test/src/encoding_test.c
+++ b/encoding/base64/test/src/encoding_test.c
@@ -16,13 +16,14 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #include <assert.h>
 #include <stddef.h>
 #include "syscfg/syscfg.h"
 #include "testutil/testutil.h"
 #include "encoding_test_priv.h"
 
+TEST_CASE_DECL(hex2str)
+TEST_CASE_DECL(str2hex)
 
 int
 hex_fmt_test_all(void)
@@ -31,12 +32,18 @@ hex_fmt_test_all(void)
     return tu_case_failed;
 }
 
+TEST_SUITE(hex_fmt_test_suite)
+{
+    hex2str();
+    str2hex();
+}
+
 #if MYNEWT_VAL(SELFTEST)
 
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     hex_fmt_test_all();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/encoding_test_priv.h
----------------------------------------------------------------------
diff --git a/encoding/base64/test/src/encoding_test_priv.h b/encoding/base64/test/src/encoding_test_priv.h
index 424bb28..8bab6fe 100644
--- a/encoding/base64/test/src/encoding_test_priv.h
+++ b/encoding/base64/test/src/encoding_test_priv.h
@@ -16,10 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #ifndef __ENCODING_TEST_PRIV_
 #define __ENCODING_TEST_PRIV_
 
+#include <assert.h>
+#include <stddef.h>
+#include "syscfg/syscfg.h"
+#include "base64/hex.h"
+#include "testutil/testutil.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/hex_test.c
----------------------------------------------------------------------
diff --git a/encoding/base64/test/src/hex_test.c b/encoding/base64/test/src/hex_test.c
deleted file mode 100644
index 471a14e..0000000
--- a/encoding/base64/test/src/hex_test.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/**
- * 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 "base64/hex.h"
-
-TEST_CASE(hex2str)
-{
-    int i;
-    char *ret;
-    char cmp_data[8];
-
-    struct {
-        char *in;
-        int inlen;
-        char *out;
-        int outlen;
-    } test_data[] = {
-        [0] = {
-            .in = "\x01",
-            .inlen = 1,
-            .out = "01",
-            .outlen = 2,
-        },
-        [1] = {
-            .in = "\xaf\xf2",
-            .inlen = 2,
-            .out = "aff2",
-            .outlen = 4,
-        }
-    };
-
-    for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) {
-        ret = hex_format(test_data[i].in, test_data[i].inlen,
-          cmp_data, sizeof(cmp_data));
-        TEST_ASSERT(ret == cmp_data);
-        TEST_ASSERT(strlen(cmp_data) == test_data[i].outlen);
-        TEST_ASSERT(!strcmp(test_data[i].out, cmp_data));
-    }
-
-    /*
-     * Test not enough space. Must have space for '\0' at the end.
-     */
-    ret = hex_format("\x01\x02", 2, cmp_data, 1);
-    TEST_ASSERT(ret == NULL);
-
-    ret = hex_format("\x01\x02", 2, cmp_data, 2);
-    TEST_ASSERT(ret == NULL);
-}
-
-TEST_CASE(str2hex)
-{
-    int i;
-    char cmp_data[8];
-    int rc;
-
-    struct {
-        char *in;
-        int inlen;
-        char *out;
-        int outlen;
-    } test_data[] = {
-        [0] = {
-            .in = "01",
-            .inlen = 2,
-            .out = "\x01",
-            .outlen = 1,
-        },
-        [1] = {
-            .in = "AfF2",
-            .inlen = 4,
-            .out = "\xaf\xf2",
-            .outlen = 2,
-        }
-    };
-
-    for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) {
-        rc = hex_parse(test_data[i].in, test_data[i].inlen,
-          cmp_data, sizeof(cmp_data));
-        TEST_ASSERT(rc == test_data[i].outlen);
-        TEST_ASSERT(!memcmp(test_data[i].out, cmp_data, rc));
-    }
-
-    /*
-     * Test invalid input
-     */
-    rc = hex_parse("HJ", 2, cmp_data, sizeof(cmp_data));
-    TEST_ASSERT(rc < 0);
-
-    rc = hex_parse("a", 1, cmp_data, sizeof(cmp_data));
-    TEST_ASSERT(rc < 0);
-
-    rc = hex_parse("0102", 4, cmp_data, 1);
-    TEST_ASSERT(rc < 0);
-
-    /*
-     * This should be valid.
-     */
-    rc = hex_parse("0102", 4, cmp_data, 2);
-    TEST_ASSERT(rc == 2);
-}
-
-TEST_SUITE(hex_fmt_test_suite)
-{
-    hex2str();
-    str2hex();
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/testcases/hex2str.c
----------------------------------------------------------------------
diff --git a/encoding/base64/test/src/testcases/hex2str.c b/encoding/base64/test/src/testcases/hex2str.c
new file mode 100644
index 0000000..7d79c4f
--- /dev/null
+++ b/encoding/base64/test/src/testcases/hex2str.c
@@ -0,0 +1,64 @@
+/**
+ * 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 "encoding_test_priv.h"
+
+TEST_CASE(hex2str)
+{
+    int i;
+    char *ret;
+    char cmp_data[8];
+
+    struct {
+        char *in;
+        int inlen;
+        char *out;
+        int outlen;
+    } test_data[] = {
+        [0] = {
+            .in = "\x01",
+            .inlen = 1,
+            .out = "01",
+            .outlen = 2,
+        },
+        [1] = {
+            .in = "\xaf\xf2",
+            .inlen = 2,
+            .out = "aff2",
+            .outlen = 4,
+        }
+    };
+
+    for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) {
+        ret = hex_format(test_data[i].in, test_data[i].inlen,
+          cmp_data, sizeof(cmp_data));
+        TEST_ASSERT(ret == cmp_data);
+        TEST_ASSERT(strlen(cmp_data) == test_data[i].outlen);
+        TEST_ASSERT(!strcmp(test_data[i].out, cmp_data));
+    }
+
+    /*
+     * Test not enough space. Must have space for '\0' at the end.
+     */
+    ret = hex_format("\x01\x02", 2, cmp_data, 1);
+    TEST_ASSERT(ret == NULL);
+
+    ret = hex_format("\x01\x02", 2, cmp_data, 2);
+    TEST_ASSERT(ret == NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/base64/test/src/testcases/str2hex.c
----------------------------------------------------------------------
diff --git a/encoding/base64/test/src/testcases/str2hex.c b/encoding/base64/test/src/testcases/str2hex.c
new file mode 100644
index 0000000..83a6b0d
--- /dev/null
+++ b/encoding/base64/test/src/testcases/str2hex.c
@@ -0,0 +1,72 @@
+/**
+ * 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 "encoding_test_priv.h"
+
+TEST_CASE(str2hex)
+{
+    int i;
+    char cmp_data[8];
+    int rc;
+
+    struct {
+        char *in;
+        int inlen;
+        char *out;
+        int outlen;
+    } test_data[] = {
+        [0] = {
+            .in = "01",
+            .inlen = 2,
+            .out = "\x01",
+            .outlen = 1,
+        },
+        [1] = {
+            .in = "AfF2",
+            .inlen = 4,
+            .out = "\xaf\xf2",
+            .outlen = 2,
+        }
+    };
+
+    for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) {
+        rc = hex_parse(test_data[i].in, test_data[i].inlen,
+          cmp_data, sizeof(cmp_data));
+        TEST_ASSERT(rc == test_data[i].outlen);
+        TEST_ASSERT(!memcmp(test_data[i].out, cmp_data, rc));
+    }
+
+    /*
+     * Test invalid input
+     */
+    rc = hex_parse("HJ", 2, cmp_data, sizeof(cmp_data));
+    TEST_ASSERT(rc < 0);
+
+    rc = hex_parse("a", 1, cmp_data, sizeof(cmp_data));
+    TEST_ASSERT(rc < 0);
+
+    rc = hex_parse("0102", 4, cmp_data, 1);
+    TEST_ASSERT(rc < 0);
+
+    /*
+     * This should be valid.
+     */
+    rc = hex_parse("0102", 4, cmp_data, 2);
+    TEST_ASSERT(rc == 2);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/test_json.c
----------------------------------------------------------------------
diff --git a/encoding/json/test/src/test_json.c b/encoding/json/test/src/test_json.c
index dab3f06..ca64f9e 100644
--- a/encoding/json/test/src/test_json.c
+++ b/encoding/json/test/src/test_json.c
@@ -21,6 +21,8 @@
 #include "testutil/testutil.h"
 #include "test_json.h"
 
+TEST_CASE_DECL(test_json_simple_encode);
+TEST_CASE_DECL(test_json_simple_decode);
 
 TEST_SUITE(test_json_suite) {
     test_json_simple_encode();
@@ -28,16 +30,14 @@ TEST_SUITE(test_json_suite) {
 }
 
 #if MYNEWT_VAL(SELFTEST)
-
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     test_json_suite();
 
     return tu_any_failed;
 }
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/test_json.h
----------------------------------------------------------------------
diff --git a/encoding/json/test/src/test_json.h b/encoding/json/test/src/test_json.h
index b7b9742..0cfa159 100644
--- a/encoding/json/test/src/test_json.h
+++ b/encoding/json/test/src/test_json.h
@@ -16,16 +16,42 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #ifndef TEST_JSON_H
 #define TEST_JSON_H
 
+#include <assert.h>
+#include <string.h>
+#include "testutil/testutil.h"
+#include "test_json.h"
+#include "json/json.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-TEST_CASE_DECL(test_json_simple_encode);
-TEST_CASE_DECL(test_json_simple_decode);
+char *output;
+char *output1;
+char *outputboolspace;
+char *outputboolempty;
+
+char bigbuf[512];
+int buf_index;
+
+/* a test structure to hold the json flat buffer and pass bytes
+ * to the decoder */
+struct test_jbuf {
+    /* json_buffer must be first element in the structure */
+    struct json_buffer json_buf;
+    char * start_buf;
+    char * end_buf;
+    int current_position;
+};
+
+char test_jbuf_read_next(struct json_buffer *jb);
+char test_jbuf_read_prev(struct json_buffer *jb);
+int test_jbuf_readn(struct json_buffer *jb, char *buf, int size);
+int test_write(void *buf, char* data, int len);
+void test_buf_init(struct test_jbuf *ptjb, char *string);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/test_json_simple.c
----------------------------------------------------------------------
diff --git a/encoding/json/test/src/test_json_simple.c b/encoding/json/test/src/test_json_simple.c
deleted file mode 100644
index 0f9e10e..0000000
--- a/encoding/json/test/src/test_json_simple.c
+++ /dev/null
@@ -1,360 +0,0 @@
-/**
- * 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 <string.h>
-#include "testutil/testutil.h"
-#include "test_json.h"
-#include "json/json.h"
-
-static char *output = "{\"KeyBool\": true,\"KeyInt\": -1234,\"KeyUint\": 1353214,\"KeyString\": \"foobar\",\"KeyStringN\": \"foobarlong\",\"KeyIntArr\": [153,2532,-322]}";
-
-static char *output1 ="{\"KeyBoolArr\": [true, false], \"KeyUintArr\": [0, 65535, 4294967295, 8589934590, 3451257]}";
-static char *outputboolspace = "{\"KeyBoolArr\": [    true    ,    false,true         ]}";
-static char *outputboolempty = "{\"KeyBoolArr\": , \"KeyBoolArr\": [  ]}";
-
-static char bigbuf[512];
-static int buf_index;
-
-static int test_write(void *buf, char* data, int len) {
-    int i;
-    for(i = 0; i < len; i++) {
-        bigbuf[buf_index++] = data[i];
-    }
-    return len;
-}
-
-TEST_CASE(test_json_simple_encode){
-    struct json_encoder encoder;
-    struct json_value value;
-    int rc;
-
-    /* reset the state of the internal test */
-    buf_index = 0;
-    memset(&encoder, 0, sizeof(encoder));
-
-    encoder.je_write = test_write;
-    encoder.je_arg= NULL;
-
-    rc = json_encode_object_start(&encoder);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_BOOL(&value, 1);
-    rc = json_encode_object_entry(&encoder, "KeyBool", &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_INT(&value, -1234);
-    rc = json_encode_object_entry(&encoder, "KeyInt", &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_UINT(&value, 1353214);
-    rc = json_encode_object_entry(&encoder, "KeyUint", &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_STRING(&value, "foobar");
-    rc = json_encode_object_entry(&encoder, "KeyString", &value);
-    TEST_ASSERT(rc == 0);
-
-    /* we'll decode later differently */
-    JSON_VALUE_STRINGN(&value, "foobarlongstring", 10);
-    rc = json_encode_object_entry(&encoder, "KeyStringN", &value);
-    TEST_ASSERT(rc == 0);
-
-    rc = json_encode_array_name(&encoder, "KeyIntArr");
-    TEST_ASSERT(rc == 0);
-
-    rc = json_encode_array_start(&encoder);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_INT(&value, 153);
-    rc = json_encode_array_value(&encoder, &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_INT(&value, 2532);
-    rc = json_encode_array_value(&encoder, &value);
-    TEST_ASSERT(rc == 0);
-
-    JSON_VALUE_INT(&value, -322);
-    rc = json_encode_array_value(&encoder, &value);
-    TEST_ASSERT(rc == 0);
-
-    rc = json_encode_array_finish(&encoder);
-    TEST_ASSERT(rc == 0);
-
-    rc = json_encode_object_finish(&encoder);
-    TEST_ASSERT(rc == 0);
-
-    /* does it match what we expect it to */
-    rc = strcmp(bigbuf, output);
-    TEST_ASSERT(rc == 0);
-}
-
-
-/* a test structure to hold the json flat buffer and pass bytes
- * to the decoder */
-struct test_jbuf {
-    /* json_buffer must be first element in the structure */
-    struct json_buffer json_buf;
-    char * start_buf;
-    char * end_buf;
-    int current_position;
-};
-
-
-static char
-test_jbuf_read_next(struct json_buffer *jb) {
-    char c;
-    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
-
-    if((ptjb->start_buf + ptjb->current_position) <= ptjb->end_buf) {
-        c = *(ptjb->start_buf + ptjb->current_position);
-        ptjb->current_position++;
-        return c;
-    }
-    return '\0';
-}
-
-/* this goes backward in the buffer one character */
-static char
-test_jbuf_read_prev(struct json_buffer *jb) {
-    char c;
-    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
-    if(ptjb->current_position) {
-       ptjb->current_position--;
-       c = *(ptjb->start_buf + ptjb->current_position);
-       return c;
-    }
-
-    /* can't rewind */
-    return '\0';
-
-}
-
-static int
-test_jbuf_readn(struct json_buffer *jb, char *buf, int size) {
-    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
-
-    int remlen;
-
-    remlen = ptjb->end_buf - (ptjb->start_buf + ptjb->current_position);
-    if (size > remlen) {
-        size = remlen;
-    }
-
-    memcpy(buf, ptjb->start_buf + ptjb->current_position, size);
-    ptjb->current_position += size;
-    return size;
-}
-
-static void
-test_buf_init(struct test_jbuf *ptjb, char *string) {
-    /* initialize the decode */
-    ptjb->json_buf.jb_read_next = test_jbuf_read_next;
-    ptjb->json_buf.jb_read_prev = test_jbuf_read_prev;
-    ptjb->json_buf.jb_readn = test_jbuf_readn;
-    ptjb->start_buf = string;
-    ptjb->end_buf = string + strlen(string);
-    /* end buf points to the NULL */
-    ptjb->current_position = 0;
-}
-
-/* now test the decode on a string */
-TEST_CASE(test_json_simple_decode){
-    struct test_jbuf tjb;
-    struct test_jbuf tjb1;
-    struct test_jbuf tjbboolspacearr;
-    struct test_jbuf tjbboolemptyarr;
-    long long unsigned int uint_val;
-    long long int int_val;
-    bool bool_val;
-    char string1[16];
-    char string2[16];
-    long long int intarr[8];
-    int rc;
-    int rc1;
-    int rcbsa;
-    int array_count;
-    int array_countemp;
-    bool boolarr[2];
-    unsigned long long uintarr[5];
-    int array_count1;
-    int array_count1u;
-    bool boolspacearr[3];
-    bool boolemptyarr[2];
-    
-    struct json_attr_t test_attr[7] = {
-        [0] = {
-            .attribute = "KeyBool",
-            .type = t_boolean,
-            .addr.boolean = &bool_val,
-            .nodefault = true
-        },
-        [1] = {
-            .attribute = "KeyInt",
-            .type = t_integer,
-            .addr.integer = &int_val,
-            .nodefault = true
-            },
-        [2] = {
-            .attribute = "KeyUint",
-            .type = t_uinteger,
-            .addr.uinteger = &uint_val,
-            .nodefault = true
-            },
-        [3] = {
-            .attribute = "KeyString",
-            .type = t_string,
-            .addr.string = string1,
-            .nodefault = true,
-            .len = sizeof(string1)
-            },
-        [4] = {
-            .attribute = "KeyStringN",
-            .type = t_string,
-            .addr.string = string2,
-            .nodefault = true,
-            .len = sizeof(string2)
-        },
-        [5] = {
-            .attribute = "KeyIntArr",
-            .type = t_array,
-            .addr.array = {
-                .element_type = t_integer,
-                .arr.integers.store = intarr,
-                .maxlen = sizeof intarr / sizeof intarr[0],
-                .count = &array_count,
-            },
-            .nodefault = true,
-            .len = sizeof(intarr)
-        },
-        [6] = {
-            .attribute = NULL
-        }
-    };
-    
-    test_buf_init(&tjb, output);
-
-    rc = json_read_object(&tjb.json_buf, test_attr);
-    TEST_ASSERT(rc==0);
-    TEST_ASSERT(bool_val == 1);
-    TEST_ASSERT(int_val ==  -1234);
-    TEST_ASSERT(uint_val == 1353214);
-
-    rc = memcmp(string1, "foobar", strlen("foobar"));
-    TEST_ASSERT(rc==0);
-
-    rc = memcmp(string2, "foobarlongstring", 10);
-    TEST_ASSERT(rc==0);
-
-    TEST_ASSERT(array_count == 3);
-    TEST_ASSERT(intarr[0] == 153);
-    TEST_ASSERT(intarr[1] == 2532);
-    TEST_ASSERT(intarr[2] == -322);
-
-   /*testing for the boolean*/
-   struct json_attr_t test_attr1[2] = {
-       [0] = {
-           .attribute = "KeyBoolArr",
-           .type = t_array,
-           .addr.array = {
-               .element_type = t_boolean,
-               .arr.booleans.store = boolarr,
-               .maxlen = sizeof boolarr / sizeof boolarr[0],
-               .count =&array_count1,
-           },
-           .nodefault = true,
-           .len = sizeof( boolarr),
-       },
-
-       [1] = {
-           .attribute = "KeyUintArr",
-           .type = t_array,
-           .addr.array = {
-               .element_type = t_uinteger,
-               .arr.uintegers.store = uintarr,
-               .maxlen = sizeof uintarr / sizeof uintarr[0],
-               .count =&array_count1u,
-           },
-           .nodefault = true,
-           .len = sizeof( uintarr),
-       }
-   };
-   
-   test_buf_init(&tjb1, output1);
-
-   rc1 = json_read_object(&tjb1.json_buf, test_attr1);
-   TEST_ASSERT(rc1==0);
-
-   TEST_ASSERT(boolarr[0] == true);
-   TEST_ASSERT(boolarr[1] == false);
-
-   TEST_ASSERT(uintarr[0] == 0);
-   TEST_ASSERT(uintarr[1] == 65535);
-   TEST_ASSERT(uintarr[2] == 4294967295ULL);
-   TEST_ASSERT(uintarr[3] == 8589934590ULL);
-   TEST_ASSERT(uintarr[4] == 3451257ULL);
-
-    /*testing arrays with empty spaces within the elements*/
-    struct json_attr_t test_boolspacearr[2] = {
-       [0] = {    
-           .attribute = "KeyBoolArr",
-           .type = t_array,
-           .addr.array = {
-               .element_type = t_boolean,
-               .arr.booleans.store = boolspacearr,
-               .maxlen = sizeof boolspacearr / sizeof boolspacearr[0],
-               .count =&array_count1,
-           },
-           .nodefault = true,
-           .len = sizeof( boolspacearr),
-       }
-           
-    };
-    
-    test_buf_init(&tjbboolspacearr, outputboolspace);
-
-    rcbsa = json_read_object(&tjbboolspacearr.json_buf, test_boolspacearr);
-    TEST_ASSERT(rcbsa == 0);
-
-    TEST_ASSERT(boolspacearr[0] == true);
-    TEST_ASSERT(boolspacearr[1] == false);
-    TEST_ASSERT(boolspacearr[2] == true);
-
-    /*testing array with empty value*/
-    struct json_attr_t test_boolemptyarr[2] = {
-        [0] = {
-            .attribute = "KeyBoolArr",
-           .type = t_array,
-           .addr.array = {
-               .element_type = t_boolean,
-               .arr.booleans.store = boolemptyarr,
-               .maxlen = sizeof boolemptyarr / sizeof boolemptyarr[0],
-               .count =&array_countemp,
-           },
-           .nodefault = true,
-           .len = sizeof( boolemptyarr),
-        }
-    };
-   
-   test_buf_init(&tjbboolemptyarr, outputboolempty);
-
-    rcbsa = json_read_object(&tjbboolemptyarr.json_buf, test_boolemptyarr);
-    TEST_ASSERT(rcbsa == 6); 
-    
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/test_json_utils.c
----------------------------------------------------------------------
diff --git a/encoding/json/test/src/test_json_utils.c b/encoding/json/test/src/test_json_utils.c
new file mode 100644
index 0000000..95d1111
--- /dev/null
+++ b/encoding/json/test/src/test_json_utils.c
@@ -0,0 +1,98 @@
+/**
+ * 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 <string.h>
+#include "testutil/testutil.h"
+#include "test_json.h"
+#include "json/json.h"
+
+char *output = "{\"KeyBool\": true,\"KeyInt\": -1234,\"KeyUint\": 1353214,\"KeyString\": \"foobar\",\"KeyStringN\": \"foobarlong\",\"KeyIntArr\": [153,2532,-322]}";
+
+char *output1 ="{\"KeyBoolArr\": [true, false], \"KeyUintArr\": [0, 65535, 4294967295, 8589934590, 3451257]}";
+char *outputboolspace = "{\"KeyBoolArr\": [    true    ,    false,true         ]}";
+char *outputboolempty = "{\"KeyBoolArr\": , \"KeyBoolArr\": [  ]}";
+
+char bigbuf[512];
+int buf_index;
+
+int
+test_write(void *buf, char* data, int len) {
+    int i;
+    for(i = 0; i < len; i++) {
+        bigbuf[buf_index++] = data[i];
+    }
+    return len;
+}
+
+char
+test_jbuf_read_next(struct json_buffer *jb) {
+    char c;
+    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
+
+    if((ptjb->start_buf + ptjb->current_position) <= ptjb->end_buf) {
+        c = *(ptjb->start_buf + ptjb->current_position);
+        ptjb->current_position++;
+        return c;
+    }
+    return '\0';
+}
+
+/* this goes backward in the buffer one character */
+char
+test_jbuf_read_prev(struct json_buffer *jb) {
+    char c;
+    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
+    if(ptjb->current_position) {
+       ptjb->current_position--;
+       c = *(ptjb->start_buf + ptjb->current_position);
+       return c;
+    }
+
+    /* can't rewind */
+    return '\0';
+
+}
+
+int
+test_jbuf_readn(struct json_buffer *jb, char *buf, int size) {
+    struct test_jbuf  *ptjb = (struct test_jbuf*) jb;
+
+    int remlen;
+
+    remlen = ptjb->end_buf - (ptjb->start_buf + ptjb->current_position);
+    if (size > remlen) {
+        size = remlen;
+    }
+
+    memcpy(buf, ptjb->start_buf + ptjb->current_position, size);
+    ptjb->current_position += size;
+    return size;
+}
+
+void
+test_buf_init(struct test_jbuf *ptjb, char *string) {
+    /* initialize the decode */
+    ptjb->json_buf.jb_read_next = test_jbuf_read_next;
+    ptjb->json_buf.jb_read_prev = test_jbuf_read_prev;
+    ptjb->json_buf.jb_readn = test_jbuf_readn;
+    ptjb->start_buf = string;
+    ptjb->end_buf = string + strlen(string);
+    /* end buf points to the NULL */
+    ptjb->current_position = 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/encoding/json/test/src/testcases/json_simple_decode.c
----------------------------------------------------------------------
diff --git a/encoding/json/test/src/testcases/json_simple_decode.c b/encoding/json/test/src/testcases/json_simple_decode.c
new file mode 100644
index 0000000..31766db
--- /dev/null
+++ b/encoding/json/test/src/testcases/json_simple_decode.c
@@ -0,0 +1,205 @@
+/**
+ * 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 "test_json.h"
+
+/* now test the decode on a string */
+TEST_CASE(test_json_simple_decode)
+{
+    struct test_jbuf tjb;
+    struct test_jbuf tjb1;
+    struct test_jbuf tjbboolspacearr;
+    struct test_jbuf tjbboolemptyarr;
+    long long unsigned int uint_val;
+    long long int int_val;
+    bool bool_val;
+    char string1[16];
+    char string2[16];
+    long long int intarr[8];
+    int rc;
+    int rc1;
+    int rcbsa;
+    int array_count;
+    int array_countemp;
+    bool boolarr[2];
+    unsigned long long uintarr[5];
+    int array_count1;
+    int array_count1u;
+    bool boolspacearr[3];
+    bool boolemptyarr[2];
+    
+    struct json_attr_t test_attr[7] = {
+        [0] = {
+            .attribute = "KeyBool",
+            .type = t_boolean,
+            .addr.boolean = &bool_val,
+            .nodefault = true
+        },
+        [1] = {
+            .attribute = "KeyInt",
+            .type = t_integer,
+            .addr.integer = &int_val,
+            .nodefault = true
+            },
+        [2] = {
+            .attribute = "KeyUint",
+            .type = t_uinteger,
+            .addr.uinteger = &uint_val,
+            .nodefault = true
+            },
+        [3] = {
+            .attribute = "KeyString",
+            .type = t_string,
+            .addr.string = string1,
+            .nodefault = true,
+            .len = sizeof(string1)
+            },
+        [4] = {
+            .attribute = "KeyStringN",
+            .type = t_string,
+            .addr.string = string2,
+            .nodefault = true,
+            .len = sizeof(string2)
+        },
+        [5] = {
+            .attribute = "KeyIntArr",
+            .type = t_array,
+            .addr.array = {
+                .element_type = t_integer,
+                .arr.integers.store = intarr,
+                .maxlen = sizeof intarr / sizeof intarr[0],
+                .count = &array_count,
+            },
+            .nodefault = true,
+            .len = sizeof(intarr)
+        },
+        [6] = {
+            .attribute = NULL
+        }
+    };
+    
+    test_buf_init(&tjb, output);
+
+    rc = json_read_object(&tjb.json_buf, test_attr);
+    TEST_ASSERT(rc==0);
+    TEST_ASSERT(bool_val == 1);
+    TEST_ASSERT(int_val ==  -1234);
+    TEST_ASSERT(uint_val == 1353214);
+
+    rc = memcmp(string1, "foobar", strlen("foobar"));
+    TEST_ASSERT(rc==0);
+
+    rc = memcmp(string2, "foobarlongstring", 10);
+    TEST_ASSERT(rc==0);
+
+    TEST_ASSERT(array_count == 3);
+    TEST_ASSERT(intarr[0] == 153);
+    TEST_ASSERT(intarr[1] == 2532);
+    TEST_ASSERT(intarr[2] == -322);
+
+   /*testing for the boolean*/
+   struct json_attr_t test_attr1[2] = {
+       [0] = {
+           .attribute = "KeyBoolArr",
+           .type = t_array,
+           .addr.array = {
+               .element_type = t_boolean,
+               .arr.booleans.store = boolarr,
+               .maxlen = sizeof boolarr / sizeof boolarr[0],
+               .count =&array_count1,
+           },
+           .nodefault = true,
+           .len = sizeof( boolarr),
+       },
+
+       [1] = {
+           .attribute = "KeyUintArr",
+           .type = t_array,
+           .addr.array = {
+               .element_type = t_uinteger,
+               .arr.uintegers.store = uintarr,
+               .maxlen = sizeof uintarr / sizeof uintarr[0],
+               .count =&array_count1u,
+           },
+           .nodefault = true,
+           .len = sizeof( uintarr),
+       }
+   };
+   
+   test_buf_init(&tjb1, output1);
+
+   rc1 = json_read_object(&tjb1.json_buf, test_attr1);
+   TEST_ASSERT(rc1==0);
+
+   TEST_ASSERT(boolarr[0] == true);
+   TEST_ASSERT(boolarr[1] == false);
+
+   TEST_ASSERT(uintarr[0] == 0);
+   TEST_ASSERT(uintarr[1] == 65535);
+   TEST_ASSERT(uintarr[2] == 4294967295ULL);
+   TEST_ASSERT(uintarr[3] == 8589934590ULL);
+   TEST_ASSERT(uintarr[4] == 3451257ULL);
+
+    /*testing arrays with empty spaces within the elements*/
+    struct json_attr_t test_boolspacearr[2] = {
+       [0] = {    
+           .attribute = "KeyBoolArr",
+           .type = t_array,
+           .addr.array = {
+               .element_type = t_boolean,
+               .arr.booleans.store = boolspacearr,
+               .maxlen = sizeof boolspacearr / sizeof boolspacearr[0],
+               .count =&array_count1,
+           },
+           .nodefault = true,
+           .len = sizeof( boolspacearr),
+       }
+           
+    };
+    
+    test_buf_init(&tjbboolspacearr, outputboolspace);
+
+    rcbsa = json_read_object(&tjbboolspacearr.json_buf, test_boolspacearr);
+    TEST_ASSERT(rcbsa == 0);
+
+    TEST_ASSERT(boolspacearr[0] == true);
+    TEST_ASSERT(boolspacearr[1] == false);
+    TEST_ASSERT(boolspacearr[2] == true);
+
+    /*testing array with empty value*/
+    struct json_attr_t test_boolemptyarr[2] = {
+        [0] = {
+            .attribute = "KeyBoolArr",
+           .type = t_array,
+           .addr.array = {
+               .element_type = t_boolean,
+               .arr.booleans.store = boolemptyarr,
+               .maxlen = sizeof boolemptyarr / sizeof boolemptyarr[0],
+               .count =&array_countemp,
+           },
+           .nodefault = true,
+           .len = sizeof( boolemptyarr),
+        }
+    };
+   
+   test_buf_init(&tjbboolemptyarr, outputboolempty);
+
+    rcbsa = json_read_object(&tjbboolemptyarr.json_buf, test_boolemptyarr);
+    TEST_ASSERT(rcbsa == 6); 
+    
+}


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

Posted by cc...@apache.org.
Unit test infrastructure

Rework unit test infrastructure to enable target applications to run unit tests.
Unit tests were split up into individual files enabling applications to select individual tests across subsystems. Unit test case macros updated to allow
initialization and pre/post callbackas on a per-testcase basis. Test suite macros
updated to allow pre/post, pass/fail callbacks on individual testcases in
the suite as well as initialization and completion callbacks for the suite.
The intention is that enable customization of test suites for target devices.

Partial checkin for MYNEWT-139 and MYNEWT-41.


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

Branch: refs/heads/develop
Commit: 75101ba4f3e9416602ca1ea2344d92c6a0ce3fea
Parents: 2316913
Author: Peter Snyder <gi...@peterfs.com>
Authored: Sun Oct 16 20:32:04 2016 -0700
Committer: Peter Snyder <gi...@peterfs.com>
Committed: Sun Oct 16 20:32:04 2016 -0700

----------------------------------------------------------------------
 boot/boot_serial/test/src/boot_test.c           |  145 +-
 boot/boot_serial/test/src/boot_test.h           |   49 +
 .../src/testcases/boot_serial_empty_img_msg.c   |   35 +
 .../test/src/testcases/boot_serial_empty_msg.c  |   39 +
 .../test/src/testcases/boot_serial_img_msg.c    |   58 +
 .../test/src/testcases/boot_serial_setup.c      |   24 +
 .../testcases/boot_serial_upload_bigger_image.c |   72 +
 boot/bootutil/test/src/boot_test.c              |  704 +-
 boot/bootutil/test/src/boot_test.h              |   85 +
 boot/bootutil/test/src/boot_test_utils.c        |  361 +
 .../test/src/testcases/boot_test_invalid_hash.c |   67 +
 .../src/testcases/boot_test_no_flag_has_hash.c  |   60 +
 .../test/src/testcases/boot_test_no_hash.c      |   59 +
 .../test/src/testcases/boot_test_nv_bs_10.c     |   47 +
 .../test/src/testcases/boot_test_nv_bs_11.c     |   69 +
 .../src/testcases/boot_test_nv_bs_11_2areas.c   |   71 +
 .../test/src/testcases/boot_test_nv_ns_01.c     |   45 +
 .../test/src/testcases/boot_test_nv_ns_10.c     |   45 +
 .../test/src/testcases/boot_test_nv_ns_11.c     |   56 +
 .../test/src/testcases/boot_test_revert.c       |   59 +
 .../src/testcases/boot_test_revert_continue.c   |   71 +
 .../test/src/testcases/boot_test_vb_ns_11.c     |   61 +
 .../test/src/testcases/boot_test_vm_ns_01.c     |   50 +
 .../test/src/testcases/boot_test_vm_ns_10.c     |   45 +
 .../src/testcases/boot_test_vm_ns_11_2areas.c   |   61 +
 .../test/src/testcases/boot_test_vm_ns_11_a.c   |   56 +
 .../test/src/testcases/boot_test_vm_ns_11_b.c   |   61 +
 crypto/mbedtls/test/src/mbedtls_test.c          |  167 +-
 crypto/mbedtls/test/src/mbedtls_test.h          |   58 +
 crypto/mbedtls/test/src/testcases/aes_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/arc4_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/bignum_test.c |   27 +
 crypto/mbedtls/test/src/testcases/ccm_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/dhm_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/ecp_test.c    |   27 +
 .../mbedtls/test/src/testcases/entropy_test.c   |   29 +
 crypto/mbedtls/test/src/testcases/gcm_test.c    |   27 +
 .../mbedtls/test/src/testcases/hmac_drbg_test.c |   27 +
 crypto/mbedtls/test/src/testcases/md5_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/pkcs5_test.c  |   27 +
 .../mbedtls/test/src/testcases/ripemd160_test.c |   27 +
 crypto/mbedtls/test/src/testcases/rsa_test.c    |   27 +
 crypto/mbedtls/test/src/testcases/sha1_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/sha256_test.c |   27 +
 crypto/mbedtls/test/src/testcases/sha512_test.c |   27 +
 crypto/mbedtls/test/src/testcases/x509_test.c   |   27 +
 crypto/mbedtls/test/src/testcases/xtea_test.c   |   27 +
 encoding/base64/test/src/encoding_test.c        |   11 +-
 encoding/base64/test/src/encoding_test_priv.h   |    7 +-
 encoding/base64/test/src/hex_test.c             |  125 -
 encoding/base64/test/src/testcases/hex2str.c    |   64 +
 encoding/base64/test/src/testcases/str2hex.c    |   72 +
 encoding/json/test/src/test_json.c              |    6 +-
 encoding/json/test/src/test_json.h              |   32 +-
 encoding/json/test/src/test_json_simple.c       |  360 -
 encoding/json/test/src/test_json_utils.c        |   98 +
 .../test/src/testcases/json_simple_decode.c     |  205 +
 .../test/src/testcases/json_simple_encode.c     |   85 +
 fs/fcb/test/src/fcb_test.c                      |  558 +-
 fs/fcb/test/src/fcb_test.h                      |   53 +
 fs/fcb/test/src/testcases/fcb_test_append.c     |   56 +
 .../test/src/testcases/fcb_test_append_fill.c   |   90 +
 .../src/testcases/fcb_test_append_too_big.c     |   65 +
 fs/fcb/test/src/testcases/fcb_test_empty_walk.c |   38 +
 fs/fcb/test/src/testcases/fcb_test_init.c       |   40 +
 fs/fcb/test/src/testcases/fcb_test_len.c        |   37 +
 .../src/testcases/fcb_test_multiple_scratch.c   |  110 +
 fs/fcb/test/src/testcases/fcb_test_reset.c      |  145 +
 fs/fcb/test/src/testcases/fcb_test_rotate.c     |  108 +
 fs/nffs/src/nffs_priv.h                         |    5 +
 fs/nffs/syscfg.yml                              |    1 +
 fs/nffs/test/src/arch/cortex_m4/nffs_test.c     |   27 -
 fs/nffs/test/src/arch/sim/nffs_test.c           | 3251 ---------
 fs/nffs/test/src/arch/sim/nffs_test_priv.h      |   50 -
 fs/nffs/test/src/arch/sim/nffs_test_system_01.c | 6537 ------------------
 fs/nffs/test/src/nffs_test.c                    |  721 ++
 fs/nffs/test/src/nffs_test.h                    |   27 +
 fs/nffs/test/src/nffs_test_debug.c              |  522 ++
 fs/nffs/test/src/nffs_test_priv.h               |   49 +
 fs/nffs/test/src/nffs_test_system_01.c          | 6537 ++++++++++++++++++
 fs/nffs/test/src/nffs_test_utils.c              |  744 ++
 fs/nffs/test/src/nffs_test_utils.h              |   92 +
 fs/nffs/test/src/testcases/append_test.c        |  169 +
 .../test/src/testcases/cache_large_file_test.c  |   89 +
 fs/nffs/test/src/testcases/corrupt_block_test.c |  121 +
 .../test/src/testcases/corrupt_scratch_test.c   |   83 +
 fs/nffs/test/src/testcases/gc_on_oom_test.c     |   88 +
 fs/nffs/test/src/testcases/gc_test.c            |   67 +
 .../test/src/testcases/incomplete_block_test.c  |  119 +
 fs/nffs/test/src/testcases/large_system_test.c  |   43 +
 fs/nffs/test/src/testcases/large_unlink_test.c  |   80 +
 fs/nffs/test/src/testcases/large_write_test.c   |   71 +
 fs/nffs/test/src/testcases/long_filename_test.c |   59 +
 fs/nffs/test/src/testcases/lost_found_test.c    |  107 +
 fs/nffs/test/src/testcases/many_children_test.c |   74 +
 fs/nffs/test/src/testcases/mkdir_test.c         |   92 +
 fs/nffs/test/src/testcases/open_test.c          |   74 +
 .../test/src/testcases/overwrite_many_test.c    |  105 +
 fs/nffs/test/src/testcases/overwrite_one_test.c |  142 +
 .../test/src/testcases/overwrite_three_test.c   |  167 +
 fs/nffs/test/src/testcases/overwrite_two_test.c |  159 +
 fs/nffs/test/src/testcases/read_test.c          |   53 +
 fs/nffs/test/src/testcases/readdir_test.c       |  124 +
 fs/nffs/test/src/testcases/rename_test.c        |   98 +
 fs/nffs/test/src/testcases/split_file_test.c    |   65 +
 fs/nffs/test/src/testcases/truncate_test.c      |   73 +
 fs/nffs/test/src/testcases/unlink_test.c        |  121 +
 fs/nffs/test/src/testcases/wear_level_test.c    |   58 +
 hw/bsp/native/syscfg.yml                        |    1 +
 .../test/src/arch/cortex_m4/os_test_arch_arm.c  |   27 -
 kernel/os/test/src/arch/sim/os_test_arch_sim.c  |   52 -
 kernel/os/test/src/callout_test.c               |   97 +-
 kernel/os/test/src/callout_test.h               |   96 +
 kernel/os/test/src/eventq_test.c                |  152 +-
 kernel/os/test/src/eventq_test.h                |  104 +
 kernel/os/test/src/mbuf_test.c                  |  331 +-
 kernel/os/test/src/mbuf_test.h                  |   56 +
 kernel/os/test/src/mempool_test.c               |   16 +-
 kernel/os/test/src/mempool_test.h               |   60 +
 kernel/os/test/src/mutex_test.c                 |   85 +-
 kernel/os/test/src/mutex_test.h                 |   78 +
 kernel/os/test/src/os_test.c                    |   35 +-
 kernel/os/test/src/os_test_priv.h               |   13 +
 kernel/os/test/src/sem_test.c                   |  164 +-
 kernel/os/test/src/sem_test.h                   |   79 +
 .../test/src/testcases/event_test_poll_0timo.c  |   52 +
 .../src/testcases/event_test_poll_single_sr.c   |   49 +
 .../os/test/src/testcases/event_test_poll_sr.c  |   46 +
 .../src/testcases/event_test_poll_timeout_sr.c  |   49 +
 kernel/os/test/src/testcases/event_test_src.c   |   45 +
 kernel/os/test/src/testcases/ob_mbuf_test_adj.c |   60 +
 .../os/test/src/testcases/ob_mbuf_test_pullup.c |  106 +
 kernel/os/test/src/testcases/os_callout_test.c  |   46 +
 .../test/src/testcases/os_callout_test_speak.c  |   45 +
 .../test/src/testcases/os_callout_test_stop.c   |   51 +
 .../os/test/src/testcases/os_mbuf_test_alloc.c  |   33 +
 .../os/test/src/testcases/os_mbuf_test_append.c |   43 +
 kernel/os/test/src/testcases/os_mbuf_test_dup.c |   77 +
 .../os/test/src/testcases/os_mbuf_test_extend.c |   91 +
 .../src/testcases/os_mbuf_test_get_pkghdr.c     |   34 +
 .../test/src/testcases/os_mempool_test_case.c   |   31 +
 .../os/test/src/testcases/os_mutex_test_basic.c |   32 +
 .../test/src/testcases/os_mutex_test_case_1.c   |   48 +
 .../test/src/testcases/os_mutex_test_case_2.c   |   46 +
 .../os/test/src/testcases/os_sem_test_basic.c   |   34 +
 .../os/test/src/testcases/os_sem_test_case_1.c  |   42 +
 .../os/test/src/testcases/os_sem_test_case_2.c  |   45 +
 .../os/test/src/testcases/os_sem_test_case_3.c  |   45 +
 .../os/test/src/testcases/os_sem_test_case_4.c  |   45 +
 net/ip/mn_socket/test/src/mn_sock_test.c        |  850 +--
 net/ip/mn_socket/test/src/mn_sock_test.h        |   42 +
 net/ip/mn_socket/test/src/mn_sock_util.c        |  775 +++
 .../test/src/testcases/inet_ntop_test.c         |   49 +
 .../test/src/testcases/inet_pton_test.c         |   55 +
 .../mn_socket/test/src/testcases/socket_tests.c |   31 +
 net/nimble/host/test/src/ble_hs_test.c          |    2 +-
 sys/config/include/config/config_fcb.h          |    4 +-
 sys/config/test-fcb/pkg.yml                     |   31 +
 sys/config/test-fcb/src/conf_test_fcb.c         |  363 +
 sys/config/test-fcb/src/conf_test_fcb.h         |   90 +
 .../src/testcases/config_empty_lookups.c        |   34 +
 .../test-fcb/src/testcases/config_test_commit.c |   41 +
 .../src/testcases/config_test_compress_reset.c  |   88 +
 .../src/testcases/config_test_empty_fcb.c       |   42 +
 .../src/testcases/config_test_getset_bytes.c    |   49 +
 .../src/testcases/config_test_getset_int.c      |   40 +
 .../src/testcases/config_test_getset_unknown.c  |   48 +
 .../test-fcb/src/testcases/config_test_insert.c |   27 +
 .../src/testcases/config_test_insert2.c         |   27 +
 .../src/testcases/config_test_insert3.c         |   27 +
 .../src/testcases/config_test_save_1_fcb.c      |   46 +
 .../src/testcases/config_test_save_2_fcb.c      |   76 +
 .../src/testcases/config_test_save_3_fcb.c      |   51 +
 .../src/testcases/config_test_save_one_fcb.c    |   55 +
 sys/config/test-fcb/syscfg.yml                  |    4 +
 sys/config/test-nffs/pkg.yml                    |   31 +
 sys/config/test-nffs/src/conf_test_nffs.c       |  367 +
 sys/config/test-nffs/src/conf_test_nffs.h       |   87 +
 .../src/testcases/config_empty_lookups.c        |   34 +
 .../test-nffs/src/testcases/config_setup_nffs.c |   29 +
 .../src/testcases/config_test_commit.c          |   41 +
 .../src/testcases/config_test_empty_file.c      |   56 +
 .../src/testcases/config_test_getset_bytes.c    |   49 +
 .../src/testcases/config_test_getset_int.c      |   40 +
 .../src/testcases/config_test_getset_unknown.c  |   48 +
 .../src/testcases/config_test_insert.c          |   27 +
 .../src/testcases/config_test_insert2.c         |   27 +
 .../src/testcases/config_test_insert3.c         |   27 +
 .../testcases/config_test_multiple_in_file.c    |   52 +
 .../src/testcases/config_test_save_in_file.c    |   50 +
 .../src/testcases/config_test_save_one_file.c   |   53 +
 .../src/testcases/config_test_small_file.c      |   56 +
 sys/config/test-nffs/syscfg.yml                 |    5 +
 sys/config/test/pkg.yml                         |   32 -
 sys/config/test/src/conf_test.c                 |  953 ---
 sys/config/test/src/conf_test.h                 |   33 -
 sys/config/test/src/conf_test_suite.c           |   40 -
 sys/config/test/src/config_test.h               |   32 -
 sys/config/test/syscfg.yml                      |    5 -
 sys/flash_map/test/src/flash_map_test.c         |  126 +-
 sys/flash_map/test/src/flash_map_test.h         |   44 +
 .../test/src/testcases/flash_map_test_case_1.c  |   63 +
 .../test/src/testcases/flash_map_test_case_2.c  |   96 +
 sys/log/test/src/log_test.c                     |   67 +-
 sys/log/test/src/log_test.h                     |   54 +
 sys/log/test/src/testcases/log_append_fcb.c     |   33 +
 sys/log/test/src/testcases/log_setup_fcb.c      |   39 +
 sys/log/test/src/testcases/log_walk_fcb.c       |   29 +
 test/testutil/include/testutil/testutil.h       |  253 +-
 .../src/arch/cortex_m4/testutil_arch_arm.c      |   27 -
 test/testutil/src/arch/sim/testutil_arch_sim.c  |   30 -
 test/testutil/src/arch/sim/tu_args.c            |   23 -
 test/testutil/src/case.c                        |  120 +-
 test/testutil/src/suite.c                       |   66 +-
 test/testutil/src/testutil.c                    |   45 +-
 util/cbmem/test/src/cbmem_test.c                |  120 +-
 util/cbmem/test/src/cbmem_test.h                |   48 +
 .../test/src/testcases/cbmem_test_case_1.c      |   33 +
 .../test/src/testcases/cbmem_test_case_2.c      |   49 +
 .../test/src/testcases/cbmem_test_case_3.c      |   63 +
 util/cbmem/test/src/util_test.c                 |   45 -
 util/cbmem/test/src/util_test_priv.h            |   33 -
 222 files changed, 20783 insertions(+), 15182 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/boot_test.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/boot_test.c b/boot/boot_serial/test/src/boot_test.c
index 384606b..94efbd6 100644
--- a/boot/boot_serial/test/src/boot_test.c
+++ b/boot/boot_serial/test/src/boot_test.c
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #include <assert.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -34,147 +33,18 @@
 
 #include "boot_serial_priv.h"
 
+TEST_CASE_DECL(boot_serial_setup)
+TEST_CASE_DECL(boot_serial_empty_msg)
+TEST_CASE_DECL(boot_serial_empty_img_msg)
+TEST_CASE_DECL(boot_serial_img_msg)
+TEST_CASE_DECL(boot_serial_upload_bigger_image)
+
 void
 tx_msg(void *src, int len)
 {
     boot_serial_input(src, len);
 }
 
-TEST_CASE(boot_serial_setup)
-{
-
-}
-
-TEST_CASE(boot_serial_empty_msg)
-{
-    char buf[4];
-    struct nmgr_hdr hdr;
-
-    boot_serial_input(buf, 0);
-
-    tx_msg(buf, 0);
-
-    strcpy(buf, "--");
-    tx_msg(buf, 2);
-
-    memset(&hdr, 0, sizeof(hdr));
-    tx_msg(&hdr, sizeof(hdr));
-
-    hdr.nh_op = NMGR_OP_WRITE;
-
-    tx_msg(&hdr, sizeof(hdr));
-}
-
-TEST_CASE(boot_serial_empty_img_msg)
-{
-    char buf[sizeof(struct nmgr_hdr) + 32];
-    struct nmgr_hdr *hdr;
-
-    hdr = (struct nmgr_hdr *)buf;
-    memset(hdr, 0, sizeof(*hdr));
-    hdr->nh_op = NMGR_OP_WRITE;
-    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-    hdr->nh_len = htons(2);
-    strcpy((char *)(hdr + 1), "{}");
-
-    tx_msg(buf, sizeof(*hdr) + 2);
-}
-
-TEST_CASE(boot_serial_img_msg)
-{
-    char img[16];
-    char enc_img[BASE64_ENCODE_SIZE(sizeof(img)) + 1];
-    char buf[sizeof(struct nmgr_hdr) + sizeof(enc_img) + 32];
-    int len;
-    int rc;
-    struct nmgr_hdr *hdr;
-    const struct flash_area *fap;
-
-    memset(img, 0xa5, sizeof(img));
-    len = base64_encode(img, sizeof(img), enc_img, 1);
-    assert(len > 0);
-    enc_img[len] = '\0';
-
-    hdr = (struct nmgr_hdr *)buf;
-    memset(hdr, 0, sizeof(*hdr));
-    hdr->nh_op = NMGR_OP_WRITE;
-    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-
-    len = sprintf((char *)(hdr + 1), "{\"off\":0,\"len\":16,\"data\":\"%s\"}",
-      enc_img);
-    hdr->nh_len = htons(len);
-
-    len = sizeof(*hdr) + len;
-
-    tx_msg(buf, len);
-
-    /*
-     * Validate contents inside image 0 slot
-     */
-    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
-    assert(rc == 0);
-
-    rc = flash_area_read(fap, 0, enc_img, sizeof(img));
-    assert(rc == 0);
-    assert(!memcmp(enc_img, img, sizeof(img)));
-}
-
-TEST_CASE(boot_serial_upload_bigger_image)
-{
-    char img[256];
-    char enc_img[64];
-    char buf[sizeof(struct nmgr_hdr) + 128];
-    int len;
-    int off;
-    int rc;
-    struct nmgr_hdr *hdr;
-    const struct flash_area *fap;
-    int i;
-
-    for (i = 0; i < sizeof(img); i++) {
-        img[i] = i;
-    }
-
-    for (off = 0; off < sizeof(img); off += 32) {
-        len = base64_encode(&img[off], 32, enc_img, 1);
-        assert(len > 0);
-        enc_img[len] = '\0';
-
-        hdr = (struct nmgr_hdr *)buf;
-        memset(hdr, 0, sizeof(*hdr));
-        hdr->nh_op = NMGR_OP_WRITE;
-        hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
-        hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
-
-        if (off) {
-            len = sprintf((char *)(hdr + 1), "{\"off\":%d,\"data\":\"%s\"}",
-              off, enc_img);
-        } else {
-            len = sprintf((char *)(hdr + 1), "{\"off\": 0 ,\"len\":%ld, "
-              "\"data\":\"%s\"}", (long)sizeof(img), enc_img);
-        }
-        hdr->nh_len = htons(len);
-
-        len = sizeof(*hdr) + len;
-
-        tx_msg(buf, len);
-    }
-
-    /*
-     * Validate contents inside image 0 slot
-     */
-    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
-    assert(rc == 0);
-
-    for (off = 0; off < sizeof(img); off += sizeof(enc_img)) {
-        rc = flash_area_read(fap, off, enc_img, sizeof(enc_img));
-        assert(rc == 0);
-        assert(!memcmp(enc_img, &img[off], sizeof(enc_img)));
-    }
-}
-
 TEST_SUITE(boot_serial_suite)
 {
     boot_serial_setup();
@@ -195,12 +65,11 @@ boot_serial_test(void)
 int
 main(void)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_init();
 
     boot_serial_test();
 
     return tu_any_failed;
 }
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/boot_test.h
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/boot_test.h b/boot/boot_serial/test/src/boot_test.h
new file mode 100644
index 0000000..b517a04
--- /dev/null
+++ b/boot/boot_serial/test/src/boot_test.h
@@ -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.
+ */
+#ifndef _BOOT_TEST_H
+#define _BOOT_TEST_H
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "syscfg/syscfg.h"
+#include "sysflash/sysflash.h"
+#include "os/endian.h"
+#include "base64/base64.h"
+#include "crc/crc16.h"
+#include "testutil/testutil.h"
+#include "hal/hal_flash.h"
+#include "flash_map/flash_map.h"
+
+#include "boot_serial_priv.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+void tx_msg(void *src, int len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BOOT_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_empty_img_msg.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_empty_img_msg.c b/boot/boot_serial/test/src/testcases/boot_serial_empty_img_msg.c
new file mode 100644
index 0000000..88a4ee8
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_empty_img_msg.c
@@ -0,0 +1,35 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_empty_img_msg)
+{
+    char buf[sizeof(struct nmgr_hdr) + 32];
+    struct nmgr_hdr *hdr;
+
+    hdr = (struct nmgr_hdr *)buf;
+    memset(hdr, 0, sizeof(*hdr));
+    hdr->nh_op = NMGR_OP_WRITE;
+    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+    hdr->nh_len = htons(2);
+    strcpy((char *)(hdr + 1), "{}");
+
+    tx_msg(buf, sizeof(*hdr) + 2);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_empty_msg.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_empty_msg.c b/boot/boot_serial/test/src/testcases/boot_serial_empty_msg.c
new file mode 100644
index 0000000..a4bd470
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_empty_msg.c
@@ -0,0 +1,39 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_empty_msg)
+{
+    char buf[4];
+    struct nmgr_hdr hdr;
+
+    boot_serial_input(buf, 0);
+
+    tx_msg(buf, 0);
+
+    strcpy(buf, "--");
+    tx_msg(buf, 2);
+
+    memset(&hdr, 0, sizeof(hdr));
+    tx_msg(&hdr, sizeof(hdr));
+
+    hdr.nh_op = NMGR_OP_WRITE;
+
+    tx_msg(&hdr, sizeof(hdr));
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c b/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
new file mode 100644
index 0000000..7c5428f
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_img_msg.c
@@ -0,0 +1,58 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_img_msg)
+{
+    char img[16];
+    char enc_img[BASE64_ENCODE_SIZE(sizeof(img)) + 1];
+    char buf[sizeof(struct nmgr_hdr) + sizeof(enc_img) + 32];
+    int len;
+    int rc;
+    struct nmgr_hdr *hdr;
+    const struct flash_area *fap;
+
+    memset(img, 0xa5, sizeof(img));
+    len = base64_encode(img, sizeof(img), enc_img, 1);
+    assert(len > 0);
+
+    hdr = (struct nmgr_hdr *)buf;
+    memset(hdr, 0, sizeof(*hdr));
+    hdr->nh_op = NMGR_OP_WRITE;
+    hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+    hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+
+    len = sprintf((char *)(hdr + 1),
+                  "{\"off\":0,\"len\":16,\"data\":\"%s\"}", enc_img);
+    hdr->nh_len = htons(len);
+
+    len = sizeof(*hdr) + len;
+
+    tx_msg(buf, len);
+
+    /*
+     * Validate contents inside image 0 slot
+     */
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    assert(rc == 0);
+
+    rc = flash_area_read(fap, 0, enc_img, sizeof(img));
+    assert(rc == 0);
+    assert(!memcmp(enc_img, img, sizeof(img)));
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_setup.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_setup.c b/boot/boot_serial/test/src/testcases/boot_serial_setup.c
new file mode 100644
index 0000000..791e845
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_setup.c
@@ -0,0 +1,24 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_setup)
+{
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/boot_serial/test/src/testcases/boot_serial_upload_bigger_image.c
----------------------------------------------------------------------
diff --git a/boot/boot_serial/test/src/testcases/boot_serial_upload_bigger_image.c b/boot/boot_serial/test/src/testcases/boot_serial_upload_bigger_image.c
new file mode 100644
index 0000000..b551bb2
--- /dev/null
+++ b/boot/boot_serial/test/src/testcases/boot_serial_upload_bigger_image.c
@@ -0,0 +1,72 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_serial_upload_bigger_image)
+{
+    char img[256];
+    char enc_img[64];
+    char buf[sizeof(struct nmgr_hdr) + 128];
+    int len;
+    int off;
+    int rc;
+    struct nmgr_hdr *hdr;
+    const struct flash_area *fap;
+    int i;
+
+    for (i = 0; i < sizeof(img); i++) {
+        img[i] = i;
+    }
+
+    for (off = 0; off < sizeof(img); off += 32) {
+        len = base64_encode(&img[off], 32, enc_img, 1);
+        assert(len > 0);
+
+        hdr = (struct nmgr_hdr *)buf;
+        memset(hdr, 0, sizeof(*hdr));
+        hdr->nh_op = NMGR_OP_WRITE;
+        hdr->nh_group = htons(NMGR_GROUP_ID_IMAGE);
+        hdr->nh_id = IMGMGR_NMGR_OP_UPLOAD;
+
+        if (off) {
+            len = sprintf((char *)(hdr + 1), "{\"off\":%d,\"data\":\"%s\"}",
+              off, enc_img);
+        } else {
+            len = sprintf((char *)(hdr + 1), "{\"off\": 0 ,\"len\":%ld, "
+              "\"data\":\"%s\"}", (long)sizeof(img), enc_img);
+        }
+        hdr->nh_len = htons(len);
+
+        len = sizeof(*hdr) + len;
+
+        tx_msg(buf, len);
+    }
+
+    /*
+     * Validate contents inside image 0 slot
+     */
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    assert(rc == 0);
+
+    for (off = 0; off < sizeof(img); off += sizeof(enc_img)) {
+        rc = flash_area_read(fap, off, enc_img, sizeof(enc_img));
+        assert(rc == 0);
+        assert(!memcmp(enc_img, &img[off], sizeof(enc_img)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/boot_test.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test.c b/boot/bootutil/test/src/boot_test.c
index 65715d6..269db36 100644
--- a/boot/bootutil/test/src/boot_test.c
+++ b/boot/bootutil/test/src/boot_test.c
@@ -38,7 +38,7 @@
 #define BOOT_TEST_HEADER_SIZE       0x200
 
 /** Internal flash layout. */
-static struct flash_area boot_test_area_descs[] = {
+struct flash_area boot_test_area_descs[] = {
     [0] = { .fa_off = 0x00020000, .fa_size = 128 * 1024 },
     [1] = { .fa_off = 0x00040000, .fa_size = 128 * 1024 },
     [2] = { .fa_off = 0x00060000, .fa_size = 128 * 1024 },
@@ -50,12 +50,12 @@ static struct flash_area boot_test_area_descs[] = {
 };
 
 /** Areas representing the beginning of image slots. */
-static uint8_t boot_test_slot_areas[] = {
+uint8_t boot_test_slot_areas[] = {
     0, 3,
 };
 
 /** Flash offsets of the two image slots. */
-static struct {
+struct {
     uint8_t flash_id;
     uint32_t address;
 } boot_test_img_addrs[] = {
@@ -68,7 +68,7 @@ static struct {
 
 #define BOOT_TEST_AREA_IDX_SCRATCH 6
 
-static uint8_t
+uint8_t
 boot_test_util_byte_at(int img_msb, uint32_t image_offset)
 {
     uint32_t u32;
@@ -80,7 +80,7 @@ boot_test_util_byte_at(int img_msb, uint32_t image_offset)
     return u8p[image_offset % 4];
 }
 
-static void
+void
 boot_test_util_init_flash(void)
 {
     const struct flash_area *area_desc;
@@ -98,7 +98,7 @@ boot_test_util_init_flash(void)
     }
 }
 
-static void
+void
 boot_test_util_copy_area(int from_area_idx, int to_area_idx)
 {
     const struct flash_area *from_area_desc;
@@ -164,7 +164,7 @@ boot_test_util_area_write_size(int dst_idx, uint32_t off, uint32_t size)
     return size;
 }
 
-static void
+void
 boot_test_util_swap_areas(int area_idx1, int area_idx2)
 {
     const struct flash_area *area_desc1;
@@ -209,7 +209,7 @@ boot_test_util_swap_areas(int area_idx1, int area_idx2)
     free(buf2);
 }
 
-static void
+void
 boot_test_util_write_image(const struct image_header *hdr, int slot)
 {
     uint32_t image_off;
@@ -249,7 +249,7 @@ boot_test_util_write_image(const struct image_header *hdr, int slot)
     }
 }
 
-static void
+void
 boot_test_util_write_hash(const struct image_header *hdr, int slot)
 {
     uint8_t tmpdata[1024];
@@ -292,7 +292,7 @@ boot_test_util_write_hash(const struct image_header *hdr, int slot)
     TEST_ASSERT(rc == 0);
 }
 
-static void
+void
 boot_test_util_verify_area(const struct flash_area *area_desc,
                            const struct image_header *hdr,
                            uint32_t image_addr, int img_msb)
@@ -366,7 +366,7 @@ boot_test_util_verify_area(const struct flash_area *area_desc,
     }
 }
 
-static void
+void
 boot_test_util_verify_status_clear(void)
 {
     struct boot_img_trailer bit;
@@ -383,7 +383,7 @@ boot_test_util_verify_status_clear(void)
       bit.bit_copy_done != 0xff);
 }
 
-static void
+void
 boot_test_util_verify_flash(const struct image_header *hdr0, int orig_slot_0,
                             const struct image_header *hdr1, int orig_slot_1)
 {
@@ -416,7 +416,7 @@ boot_test_util_verify_flash(const struct image_header *hdr0, int orig_slot_0,
     }
 }
 
-static void
+void
 boot_test_util_verify_all(const struct boot_req *req, int expected_swap_type,
                           const struct image_header *hdr0,
                           const struct image_header *hdr1)
@@ -490,665 +490,23 @@ boot_test_util_verify_all(const struct boot_req *req, int expected_swap_type,
     }
 }
 
-TEST_CASE(boot_test_nv_ns_10)
-{
-    struct image_header hdr = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 12 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 2, 3, 4 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr, 0);
-    boot_test_util_write_hash(&hdr, 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
-}
-
-TEST_CASE(boot_test_nv_ns_01)
-{
-    struct image_header hdr = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 10 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr, 1);
-    boot_test_util_write_hash(&hdr, 1);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
-}
-
-TEST_CASE(boot_test_nv_ns_11)
-{
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 5 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 5, 21, 432 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_vm_ns_10)
-{
-    struct image_header hdr = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 12 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 2, 3, 4 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr, 0);
-    boot_test_util_write_hash(&hdr, 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
-}
-
-TEST_CASE(boot_test_vm_ns_01)
-{
-    int rc;
-
-    struct image_header hdr = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 10 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr, 1);
-    boot_test_util_write_hash(&hdr, 1);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
-}
-
-TEST_CASE(boot_test_vm_ns_11_a)
-{
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 5 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 5, 21, 432 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_vm_ns_11_b)
-{
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 5 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 5, 21, 432 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_vm_ns_11_2areas)
-{
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 5 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 5, 21, 432 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 196 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_nv_bs_10)
-{
-    struct image_header hdr = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 12 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 2, 3, 4 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr, 0);
-    boot_test_util_write_hash(&hdr, 0);
-    boot_test_util_swap_areas(boot_test_slot_areas[1],
-      BOOT_TEST_AREA_IDX_SCRATCH);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
-}
-
-TEST_CASE(boot_test_nv_bs_11)
-{
-    struct boot_status status;
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 12 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 2, 3, 4 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 17 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 1, 5, 5 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-    rc = boot_set_pending(1);
-    boot_test_util_copy_area(5, BOOT_TEST_AREA_IDX_SCRATCH);
-
-    boot_req_set(&req);
-    status.idx = 0;
-    status.elem_sz = 1;
-    status.state = 1;
-
-    rc = boot_write_status(&status);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_nv_bs_11_2areas)
-{
-    struct boot_status status;
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 150 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 5, 21, 432 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 190 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    boot_test_util_swap_areas(2, 5);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    status.idx = 1;
-    status.elem_sz = 1;
-    status.state = 0;
-
-    rc = boot_write_status(&status);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_vb_ns_11)
-{
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 5 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 5, 21, 432 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_no_hash)
-{
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 12 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 2, 3, 4 },
-    };
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 0,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = 0,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
-}
-
-TEST_CASE(boot_test_no_flag_has_hash)
-{
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 12 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 2, 3, 4 },
-    };
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = 0,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
-}
-
-TEST_CASE(boot_test_invalid_hash)
-{
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 12 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 2, 3, 4 },
-    };
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = 0,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    struct image_tlv tlv = {
-        .it_type = IMAGE_TLV_SHA256,
-        .it_len = 32
-    };
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    rc = hal_flash_write(boot_test_img_addrs[1].flash_id,
-      boot_test_img_addrs[1].address + hdr1.ih_hdr_size + hdr1.ih_img_size,
-      &tlv, sizeof(tlv));
-    TEST_ASSERT(rc == 0);
-
-    rc = boot_set_pending(1);
-    TEST_ASSERT(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
-}
-
-TEST_CASE(boot_test_revert)
-{
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 5 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 5, 21, 432 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    /* Indicate that the image in slot 0 is being tested. */
-    boot_set_copy_done();
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
-}
-
-TEST_CASE(boot_test_revert_continue)
-{
-    struct boot_status status;
-    int rc;
-
-    struct image_header hdr0 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 5 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 0, 5, 21, 432 },
-    };
-
-    struct image_header hdr1 = {
-        .ih_magic = IMAGE_MAGIC,
-        .ih_tlv_size = 4 + 32,
-        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
-        .ih_img_size = 32 * 1024,
-        .ih_flags = IMAGE_F_SHA256,
-        .ih_ver = { 1, 2, 3, 432 },
-    };
-
-    struct boot_req req = {
-        .br_area_descs = boot_test_area_descs,
-        .br_slot_areas = boot_test_slot_areas,
-        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
-        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
-        .br_img_sz = (384 * 1024),
-    };
-
-    boot_test_util_init_flash();
-    boot_test_util_write_image(&hdr0, 0);
-    boot_test_util_write_hash(&hdr0, 0);
-    boot_test_util_write_image(&hdr1, 1);
-    boot_test_util_write_hash(&hdr1, 1);
-
-    boot_test_util_swap_areas(2, 5);
-
-    /* Indicate that the image in slot 0 is being tested. */
-    boot_set_copy_done();
-
-    status.idx = 1;
-    status.elem_sz = 1;
-    status.state = 0;
-
-    rc = boot_write_status(&status);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, &hdr0, &hdr1);
-}
+TEST_CASE_DECL(boot_test_nv_ns_10)
+TEST_CASE_DECL(boot_test_nv_ns_01)
+TEST_CASE_DECL(boot_test_nv_ns_11)
+TEST_CASE_DECL(boot_test_vm_ns_10)
+TEST_CASE_DECL(boot_test_vm_ns_01)
+TEST_CASE_DECL(boot_test_vm_ns_11_a)
+TEST_CASE_DECL(boot_test_vm_ns_11_b)
+TEST_CASE_DECL(boot_test_vm_ns_11_2areas)
+TEST_CASE_DECL(boot_test_nv_bs_10)
+TEST_CASE_DECL(boot_test_nv_bs_11)
+TEST_CASE_DECL(boot_test_nv_bs_11_2areas)
+TEST_CASE_DECL(boot_test_vb_ns_11)
+TEST_CASE_DECL(boot_test_no_hash)
+TEST_CASE_DECL(boot_test_no_flag_has_hash)
+TEST_CASE_DECL(boot_test_invalid_hash)
+TEST_CASE_DECL(boot_test_revert)
+TEST_CASE_DECL(boot_test_revert_continue)
 
 TEST_SUITE(boot_test_main)
 {
@@ -1183,7 +541,7 @@ boot_test_all(void)
 int
 main(int argc, char **argv)
 {
-    tu_config.tc_print_results = 1;
+    ts_config.ts_print_results = 1;
     tu_parse_args(argc, argv);
 
     tu_init();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/boot_test.h
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test.h b/boot/bootutil/test/src/boot_test.h
new file mode 100644
index 0000000..25e2da2
--- /dev/null
+++ b/boot/bootutil/test/src/boot_test.h
@@ -0,0 +1,85 @@
+/**
+ * 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 _BOOT_TEST_H
+#define _BOOT_TEST_H
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "syscfg/syscfg.h"
+#include "sysflash/sysflash.h"
+#include "testutil/testutil.h"
+#include "hal/hal_flash.h"
+#include "flash_map/flash_map.h"
+#include "bootutil/image.h"
+#include "bootutil/loader.h"
+#include "bootutil/bootutil_misc.h"
+#include "../../src/bootutil_priv.h"
+#include "testutil/testutil.h"
+
+#include "mbedtls/sha256.h"
+
+#ifdef __cplusplus
+#extern "C" {
+#endif
+
+#define BOOT_TEST_HEADER_SIZE       0x200
+
+/** Internal flash layout. */
+extern struct flash_area boot_test_area_descs[];
+
+/** Areas representing the beginning of image slots. */
+extern uint8_t boot_test_slot_areas[];
+
+/** Flash offsets of the two image slots. */
+struct boot_test_img_addrs {
+    uint8_t flash_id;
+    uint32_t address;
+};
+extern struct boot_test_img_addrs boot_test_img_addrs[];
+
+#define BOOT_TEST_AREA_IDX_SCRATCH 6
+
+uint8_t boot_test_util_byte_at(int img_msb, uint32_t image_offset);
+void boot_test_util_init_flash(void);
+void boot_test_util_copy_area(int from_area_idx, int to_area_idx);
+void boot_test_util_swap_areas(int area_idx1, int area_idx2);
+void boot_test_util_write_image(const struct image_header *hdr,
+                                       int slot);
+void boot_test_util_write_hash(const struct image_header *hdr, int slot);
+void boot_test_util_verify_area(const struct flash_area *area_desc,
+                                       const struct image_header *hdr,
+                                       uint32_t image_addr, int img_msb);
+void boot_test_util_verify_status_clear(void);
+void boot_test_util_verify_flash(const struct image_header *hdr0,
+                                        int orig_slot_0,
+                                        const struct image_header *hdr1,
+                                        int orig_slot_1);
+void boot_test_util_verify_all(const struct boot_req *req,
+                               int expected_swap_type,
+                               const struct image_header *hdr0,
+                               const struct image_header *hdr1);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_BOOT_TEST_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/boot_test_utils.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/boot_test_utils.c b/boot/bootutil/test/src/boot_test_utils.c
new file mode 100644
index 0000000..160e81d
--- /dev/null
+++ b/boot/bootutil/test/src/boot_test_utils.c
@@ -0,0 +1,361 @@
+/**
+ * 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 "boot_test.h"
+
+/** Internal flash layout. */
+struct flash_area boot_test_area_descs[] = {
+    [0] = { .fa_off = 0x00020000, .fa_size = 128 * 1024 },
+    [1] = { .fa_off = 0x00040000, .fa_size = 128 * 1024 },
+    [2] = { .fa_off = 0x00060000, .fa_size = 128 * 1024 },
+    [3] = { .fa_off = 0x00080000, .fa_size = 128 * 1024 },
+    [4] = { .fa_off = 0x000a0000, .fa_size = 128 * 1024 },
+    [5] = { .fa_off = 0x000c0000, .fa_size = 128 * 1024 },
+    [6] = { .fa_off = 0x000e0000, .fa_size = 128 * 1024 },
+    [7] = { 0 },
+};
+
+/** Areas representing the beginning of image slots. */
+uint8_t boot_test_slot_areas[] = {
+    0, 3,
+};
+
+/** Flash offsets of the two image slots. */
+struct boot_test_img_addrs boot_test_img_addrs[] = {
+    { 0, 0x20000 },
+    { 0, 0x80000 },
+};
+
+uint8_t
+boot_test_util_byte_at(int img_msb, uint32_t image_offset)
+{
+    uint32_t u32;
+    uint8_t *u8p;
+
+    TEST_ASSERT(image_offset < 0x01000000);
+    u32 = image_offset + (img_msb << 24);
+    u8p = (void *)&u32;
+    return u8p[image_offset % 4];
+}
+
+
+void
+boot_test_util_init_flash(void)
+{
+    const struct flash_area *area_desc;
+    int rc;
+
+    rc = hal_flash_init();
+    TEST_ASSERT(rc == 0);
+
+    for (area_desc = boot_test_area_descs;
+         area_desc->fa_size != 0;
+         area_desc++) {
+
+        rc = flash_area_erase(area_desc, 0, area_desc->fa_size);
+        TEST_ASSERT(rc == 0);
+    }
+}
+
+
+void
+boot_test_util_copy_area(int from_area_idx, int to_area_idx)
+{
+    const struct flash_area *from_area_desc;
+    const struct flash_area *to_area_desc;
+    void *buf;
+    int rc;
+
+    from_area_desc = boot_test_area_descs + from_area_idx;
+    to_area_desc = boot_test_area_descs + to_area_idx;
+
+    TEST_ASSERT(from_area_desc->fa_size == to_area_desc->fa_size);
+
+    buf = malloc(from_area_desc->fa_size);
+    TEST_ASSERT(buf != NULL);
+
+    rc = flash_area_read(from_area_desc, 0, buf,
+                         from_area_desc->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_erase(to_area_desc,
+                          0,
+                          to_area_desc->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_write(to_area_desc, 0, buf,
+                          to_area_desc->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    free(buf);
+}
+
+
+void
+boot_test_util_swap_areas(int area_idx1, int area_idx2)
+{
+    const struct flash_area *area_desc1;
+    const struct flash_area *area_desc2;
+    void *buf1;
+    void *buf2;
+    int rc;
+
+    area_desc1 = boot_test_area_descs + area_idx1;
+    area_desc2 = boot_test_area_descs + area_idx2;
+
+    TEST_ASSERT(area_desc1->fa_size == area_desc2->fa_size);
+
+    buf1 = malloc(area_desc1->fa_size);
+    TEST_ASSERT(buf1 != NULL);
+
+    buf2 = malloc(area_desc2->fa_size);
+    TEST_ASSERT(buf2 != NULL);
+
+    rc = flash_area_read(area_desc1, 0, buf1, area_desc1->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_read(area_desc2, 0, buf2, area_desc2->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_erase(area_desc1, 0, area_desc1->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_erase(area_desc2, 0, area_desc2->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_write(area_desc1, 0, buf2, area_desc1->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_write(area_desc2, 0, buf1, area_desc2->fa_size);
+    TEST_ASSERT(rc == 0);
+
+    free(buf1);
+    free(buf2);
+}
+
+
+void
+boot_test_util_write_image(const struct image_header *hdr, int slot)
+{
+    uint32_t image_off;
+    uint32_t off;
+    uint8_t flash_id;
+    uint8_t buf[256];
+    int chunk_sz;
+    int rc;
+    int i;
+
+    TEST_ASSERT(slot == 0 || slot == 1);
+
+    flash_id = boot_test_img_addrs[slot].flash_id;
+    off = boot_test_img_addrs[slot].address;
+
+    rc = hal_flash_write(flash_id, off, hdr, sizeof *hdr);
+    TEST_ASSERT(rc == 0);
+
+    off += hdr->ih_hdr_size;
+
+    image_off = 0;
+    while (image_off < hdr->ih_img_size) {
+        if (hdr->ih_img_size - image_off > sizeof buf) {
+            chunk_sz = sizeof buf;
+        } else {
+            chunk_sz = hdr->ih_img_size - image_off;
+        }
+
+        for (i = 0; i < chunk_sz; i++) {
+            buf[i] = boot_test_util_byte_at(slot, image_off + i);
+        }
+
+        rc = hal_flash_write(flash_id, off + image_off, buf, chunk_sz);
+        TEST_ASSERT(rc == 0);
+
+        image_off += chunk_sz;
+    }
+}
+
+
+void
+boot_test_util_write_hash(const struct image_header *hdr, int slot)
+{
+    uint8_t tmpdata[1024];
+    uint8_t hash[32];
+    int rc;
+    uint32_t off;
+    uint32_t blk_sz;
+    uint32_t sz;
+    mbedtls_sha256_context ctx;
+    uint8_t flash_id;
+    uint32_t addr;
+    struct image_tlv tlv;
+
+    mbedtls_sha256_init(&ctx);
+    mbedtls_sha256_starts(&ctx, 0);
+
+    flash_id = boot_test_img_addrs[slot].flash_id;
+    addr = boot_test_img_addrs[slot].address;
+
+    sz = hdr->ih_hdr_size + hdr->ih_img_size;
+    for (off = 0; off < sz; off += blk_sz) {
+        blk_sz = sz - off;
+        if (blk_sz > sizeof(tmpdata)) {
+            blk_sz = sizeof(tmpdata);
+        }
+        rc = hal_flash_read(flash_id, addr + off, tmpdata, blk_sz);
+        TEST_ASSERT(rc == 0);
+        mbedtls_sha256_update(&ctx, tmpdata, blk_sz);
+    }
+    mbedtls_sha256_finish(&ctx, hash);
+
+    tlv.it_type = IMAGE_TLV_SHA256;
+    tlv._pad = 0;
+    tlv.it_len = sizeof(hash);
+
+    rc = hal_flash_write(flash_id, addr + off, &tlv, sizeof(tlv));
+    TEST_ASSERT(rc == 0);
+    off += sizeof(tlv);
+    rc = hal_flash_write(flash_id, addr + off, hash, sizeof(hash));
+    TEST_ASSERT(rc == 0);
+}
+
+void
+boot_test_util_verify_area(const struct flash_area *area_desc,
+                           const struct image_header *hdr,
+                           uint32_t image_addr, int img_msb)
+{
+    struct image_header temp_hdr;
+    uint32_t area_end;
+    uint32_t img_size;
+    uint32_t img_off;
+    uint32_t img_end;
+    uint32_t addr;
+    uint8_t buf[256];
+    int rem_area;
+    int past_image;
+    int chunk_sz;
+    int rem_img;
+    int rc;
+    int i;
+
+    addr = area_desc->fa_off;
+
+    if (hdr != NULL) {
+        img_size = hdr->ih_img_size;
+
+        if (addr == image_addr) {
+            rc = hal_flash_read(area_desc->fa_device_id, image_addr,
+                                &temp_hdr, sizeof temp_hdr);
+            TEST_ASSERT(rc == 0);
+            TEST_ASSERT(memcmp(&temp_hdr, hdr, sizeof *hdr) == 0);
+
+            addr += hdr->ih_hdr_size;
+        }
+    } else {
+        img_size = 0;
+    }
+
+    area_end = area_desc->fa_off + area_desc->fa_size;
+    img_end = image_addr + img_size;
+    past_image = addr >= img_end;
+
+    while (addr < area_end) {
+        rem_area = area_end - addr;
+        rem_img = img_end - addr;
+
+        if (hdr != NULL) {
+            img_off = addr - image_addr - hdr->ih_hdr_size;
+        } else {
+            img_off = 0;
+        }
+
+        if (rem_area > sizeof buf) {
+            chunk_sz = sizeof buf;
+        } else {
+            chunk_sz = rem_area;
+        }
+
+        rc = hal_flash_read(area_desc->fa_device_id, addr, buf, chunk_sz);
+        TEST_ASSERT(rc == 0);
+
+        for (i = 0; i < chunk_sz; i++) {
+            if (rem_img > 0) {
+                TEST_ASSERT(buf[i] == boot_test_util_byte_at(img_msb,
+                                                        img_off + i));
+            } else if (past_image) {
+#if 0
+                TEST_ASSERT(buf[i] == 0xff);
+#endif
+            }
+        }
+
+        addr += chunk_sz;
+    }
+}
+
+
+void
+boot_test_util_verify_status_clear(void)
+{
+    struct boot_img_trailer bit;
+    const struct flash_area *fap;
+    int rc;
+
+    rc = flash_area_open(FLASH_AREA_IMAGE_0, &fap);
+    TEST_ASSERT(rc == 0);
+
+    rc = flash_area_read(fap, fap->fa_size - sizeof(bit), &bit, sizeof(bit));
+    TEST_ASSERT(rc == 0);
+
+    TEST_ASSERT(bit.bit_copy_start != BOOT_MAGIC_SWAP_TEMP ||
+      bit.bit_copy_done != 0xff);
+}
+
+
+void
+boot_test_util_verify_flash(const struct image_header *hdr0, int orig_slot_0,
+                            const struct image_header *hdr1, int orig_slot_1)
+{
+    const struct flash_area *area_desc;
+    int area_idx;
+
+    area_idx = 0;
+
+    while (1) {
+        area_desc = boot_test_area_descs + area_idx;
+        if (area_desc->fa_off == boot_test_img_addrs[1].address &&
+            area_desc->fa_device_id == boot_test_img_addrs[1].flash_id) {
+            break;
+        }
+
+        boot_test_util_verify_area(area_desc, hdr0,
+                                   boot_test_img_addrs[0].address, orig_slot_0);
+        area_idx++;
+    }
+
+    while (1) {
+        if (area_idx == BOOT_TEST_AREA_IDX_SCRATCH) {
+            break;
+        }
+
+        area_desc = boot_test_area_descs + area_idx;
+        boot_test_util_verify_area(area_desc, hdr1,
+                                   boot_test_img_addrs[1].address, orig_slot_1);
+        area_idx++;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c b/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
new file mode 100644
index 0000000..af3e558
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_invalid_hash.c
@@ -0,0 +1,67 @@
+/*
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_invalid_hash)
+{
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = 0,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    struct image_tlv tlv = {
+        .it_type = IMAGE_TLV_SHA256,
+        .it_len = 32
+    };
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    rc = hal_flash_write(boot_test_img_addrs[1].flash_id,
+      boot_test_img_addrs[1].address + hdr1.ih_hdr_size + hdr1.ih_img_size,
+      &tlv, sizeof(tlv));
+    TEST_ASSERT(rc == 0);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c b/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.c
new file mode 100644
index 0000000..c3d1636
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_no_flag_has_hash.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 "boot_test.h"
+
+TEST_CASE(boot_test_no_flag_has_hash)
+{
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = 0,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_no_hash.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_no_hash.c b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
new file mode 100644
index 0000000..339753e
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_no_hash.c
@@ -0,0 +1,59 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_no_hash)
+{
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 0,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 32 * 1024,
+        .ih_flags = 0,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr0, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c b/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
new file mode 100644
index 0000000..cced9fb
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_10.c
@@ -0,0 +1,47 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_bs_10)
+{
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+    boot_test_util_write_hash(&hdr, 0);
+    boot_test_util_swap_areas(boot_test_slot_areas[1],
+      BOOT_TEST_AREA_IDX_SCRATCH);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
new file mode 100644
index 0000000..3312ec4
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11.c
@@ -0,0 +1,69 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_bs_11)
+{
+    struct boot_status status;
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 17 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 1, 5, 5 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+    rc = boot_set_pending(1);
+    boot_test_util_copy_area(5, BOOT_TEST_AREA_IDX_SCRATCH);
+
+    boot_req_set(&req);
+    status.idx = 0;
+    status.elem_sz = 1;
+    status.state = 1;
+
+    rc = boot_write_status(&status);
+    TEST_ASSERT(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
new file mode 100644
index 0000000..11a8a6f
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_bs_11_2areas.c
@@ -0,0 +1,71 @@
+/**
+ * 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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_bs_11_2areas)
+{
+    struct boot_status status;
+    int rc;
+
+    struct image_header hdr0 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 150 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 5, 21, 432 },
+    };
+
+    struct image_header hdr1 = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 190 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr0, 0);
+    boot_test_util_write_hash(&hdr0, 0);
+    boot_test_util_write_image(&hdr1, 1);
+    boot_test_util_write_hash(&hdr1, 1);
+
+    boot_test_util_swap_areas(2, 5);
+
+    rc = boot_set_pending(1);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    status.idx = 1;
+    status.elem_sz = 1;
+    status.state = 0;
+
+    rc = boot_write_status(&status);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_TEMP, &hdr0, &hdr1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.c
new file mode 100644
index 0000000..c887eca
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_01.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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_ns_01)
+{
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 10 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 1, 2, 3, 432 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 1);
+    boot_test_util_write_hash(&hdr, 1);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_PERM, NULL, &hdr);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/boot/bootutil/test/src/testcases/boot_test_nv_ns_10.c
----------------------------------------------------------------------
diff --git a/boot/bootutil/test/src/testcases/boot_test_nv_ns_10.c b/boot/bootutil/test/src/testcases/boot_test_nv_ns_10.c
new file mode 100644
index 0000000..a6bbff2
--- /dev/null
+++ b/boot/bootutil/test/src/testcases/boot_test_nv_ns_10.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 "boot_test.h"
+
+TEST_CASE(boot_test_nv_ns_10)
+{
+    struct image_header hdr = {
+        .ih_magic = IMAGE_MAGIC,
+        .ih_tlv_size = 4 + 32,
+        .ih_hdr_size = BOOT_TEST_HEADER_SIZE,
+        .ih_img_size = 12 * 1024,
+        .ih_flags = IMAGE_F_SHA256,
+        .ih_ver = { 0, 2, 3, 4 },
+    };
+
+    struct boot_req req = {
+        .br_area_descs = boot_test_area_descs,
+        .br_slot_areas = boot_test_slot_areas,
+        .br_num_image_areas = BOOT_TEST_AREA_IDX_SCRATCH + 1,
+        .br_scratch_area_idx = BOOT_TEST_AREA_IDX_SCRATCH,
+        .br_img_sz = (384 * 1024),
+    };
+
+    boot_test_util_init_flash();
+    boot_test_util_write_image(&hdr, 0);
+    boot_test_util_write_hash(&hdr, 0);
+
+    boot_test_util_verify_all(&req, BOOT_SWAP_TYPE_NONE, &hdr, NULL);
+}



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

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/75101ba4/fs/nffs/test/src/nffs_test_system_01.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test_system_01.c b/fs/nffs/test/src/nffs_test_system_01.c
new file mode 100644
index 0000000..cd30544
--- /dev/null
+++ b/fs/nffs/test/src/nffs_test_system_01.c
@@ -0,0 +1,6537 @@
+/**
+ * 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.
+ */
+
+
+/** Generated by makefs.rb */
+
+#include <stddef.h>
+#include "nffs_test_priv.h"
+
+const struct nffs_test_file_desc *nffs_test_system_01 =
+    (struct nffs_test_file_desc[]) {
+{
+.filename = "",
+.is_dir = 1,
+.children = (struct nffs_test_file_desc[]) {
+ {
+ .filename = "lvl1dir-0000",
+ .is_dir = 1,
+ .children = (struct nffs_test_file_desc[]) {
+  {
+  .filename = "lvl2dir-0000",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0001",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0002",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0003",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0004",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+ { .filename = NULL, } }
+ },
+ {
+ .filename = "lvl1dir-0001",
+ .is_dir = 1,
+ .children = (struct nffs_test_file_desc[]) {
+  {
+  .filename = "lvl2dir-0000",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0001",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0002",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0003",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0004",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+ { .filename = NULL, } }
+ },
+ {
+ .filename = "lvl1dir-0002",
+ .is_dir = 1,
+ .children = (struct nffs_test_file_desc[]) {
+  {
+  .filename = "lvl2dir-0000",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0001",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0002",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0003",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0004",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+ { .filename = NULL, } }
+ },
+ {
+ .filename = "lvl1dir-0003",
+ .is_dir = 1,
+ .children = (struct nffs_test_file_desc[]) {
+  {
+  .filename = "lvl2dir-0000",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0001",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0002",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0003",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0004",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+ { .filename = NULL, } }
+ },
+ {
+ .filename = "lvl1dir-0004",
+ .is_dir = 1,
+ .children = (struct nffs_test_file_desc[]) {
+  {
+  .filename = "lvl2dir-0000",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0001",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0002",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0003",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0004",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+ { .filename = NULL, } }
+ },
+{ .filename = NULL, } }
+},
+};
+
+const struct nffs_test_file_desc *nffs_test_system_01_rm_1014_mk10 =
+    (struct nffs_test_file_desc[]) {
+{
+.filename = "",
+.is_dir = 1,
+.children = (struct nffs_test_file_desc[]) {
+ {
+ .filename = "lvl1dir-0000",
+ .is_dir = 1,
+ },
+ {
+ .filename = "lvl1dir-0001",
+ .is_dir = 1,
+ .children = (struct nffs_test_file_desc[]) {
+  {
+  .filename = "lvl2dir-0000",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0001",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0001",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0002",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0003",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+   {
+   .filename = "lvl3dir-0004",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0003",
+    .contents = "3",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0004",
+    .contents = "4",
+    .contents_len = 1,
+    },
+   { .filename = NULL, } }
+   },
+  { .filename = NULL, } }
+  },
+  {
+  .filename = "lvl2dir-0002",
+  .is_dir = 1,
+  .children = (struct nffs_test_file_desc[]) {
+   {
+   .filename = "lvl3dir-0000",
+   .is_dir = 1,
+   .children = (struct nffs_test_file_desc[]) {
+    {
+    .filename = "lvl4file-0000",
+    .contents = "0",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0001",
+    .contents = "1",
+    .contents_len = 1,
+    },
+    {
+    .filename = "lvl4file-0002",
+    .contents = "2",
+    .contents_len = 1,
+    },
+    {
+    .filena

<TRUNCATED>