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

Reply via email to