You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by pe...@apache.org on 2016/12/15 21:33:06 UTC

incubator-mynewt-core git commit: MYNEWT-139: newtmgr cli to execute device tests

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 0ad791a08 -> 58fe11a90


MYNEWT-139: newtmgr cli to execute device tests

Handle "run test" "run list" commands from newtmgr.
"run list" lists all the registered test suites on device
"run test" takes a specific test or defaults to running all tests.
Optional "token" argument allows log messages to have the specified token
added. Use "run test all token" to run all tests by default.


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/58fe11a9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/58fe11a9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/58fe11a9

Branch: refs/heads/develop
Commit: 58fe11a9071adf639e47b52bee26415c4d61fad7
Parents: 0ad791a
Author: Peter Snyder <pe...@apache.org>
Authored: Thu Dec 15 13:28:26 2016 -0800
Committer: Peter Snyder <pe...@apache.org>
Committed: Thu Dec 15 13:28:26 2016 -0800

----------------------------------------------------------------------
 fs/fcb/test/src/fcb_test.c                      |   2 +-
 mgmt/mgmt/include/mgmt/mgmt.h                   |   2 +-
 test/runtest/include/runtest/runtest.h          |  19 +-
 test/runtest/src/ctags.list                     |   1 +
 test/runtest/src/runtest.c                      |  18 +-
 test/runtest/src/runtest_cli.c                  |   4 +-
 test/runtest/src/runtest_nmgr.c                 | 152 +++++++++++----
 test/testreport/include/testreport/testreport.h |  42 ----
 test/testreport/pkg.yml                         |  30 ---
 test/testreport/src/arch/cortex_m4/io.c         |  91 ---------
 test/testreport/src/arch/sim/io.c               | 140 --------------
 test/testreport/src/results.c                   | 190 -------------------
 test/testreport/src/testreport.c                | 131 -------------
 test/testreport/src/testreport_priv.h           |  56 ------
 test/testutil/include/testutil/testutil.h       |  13 +-
 test/testutil/src/suite.c                       |  12 +-
 16 files changed, 167 insertions(+), 736 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/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 2cd6a0e..77d2d3e 100644
--- a/fs/fcb/test/src/fcb_test.c
+++ b/fs/fcb/test/src/fcb_test.c
@@ -58,7 +58,6 @@ struct flash_area test_fcb_area[] = {
         .fa_size = 0x4000
     }
 };
-#endif
 
 void
 fcb_test_wipe(void)
@@ -73,6 +72,7 @@ fcb_test_wipe(void)
         TEST_ASSERT(rc == 0);
     }
 }
+#endif
 
 int
 fcb_test_empty_walk_cb(struct fcb_entry *loc, void *arg)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/mgmt/mgmt/include/mgmt/mgmt.h
----------------------------------------------------------------------
diff --git a/mgmt/mgmt/include/mgmt/mgmt.h b/mgmt/mgmt/include/mgmt/mgmt.h
index 9856405..a6a1c99 100644
--- a/mgmt/mgmt/include/mgmt/mgmt.h
+++ b/mgmt/mgmt/include/mgmt/mgmt.h
@@ -47,7 +47,7 @@ extern "C" {
 #define MGMT_GROUP_ID_LOGS      (4)
 #define MGMT_GROUP_ID_CRASH     (5)
 #define MGMT_GROUP_ID_SPLIT     (6)
-#define MGMT_GROUP_ID_RUNTEST   (7)
+#define MGMT_GROUP_ID_RUN   (7)
 #define MGMT_GROUP_ID_PERUSER   (64)
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/runtest/include/runtest/runtest.h
----------------------------------------------------------------------
diff --git a/test/runtest/include/runtest/runtest.h b/test/runtest/include/runtest/runtest.h
index 59c7ef0..12f3e52 100644
--- a/test/runtest/include/runtest/runtest.h
+++ b/test/runtest/include/runtest/runtest.h
@@ -29,9 +29,24 @@ extern "C" {
 void runtest_init(void);
 
 /*
- * XXX global used to gate starting test - hack
+ * Callback for runtest events - newtmgr uses this to add
+ * run test requests to default queue for test application (e.g., mynewtsanity)
  */
-extern volatile int runtest_start;
+void run_evcb_set(os_event_fn *cb);
+
+/*
+ * Token is append to log messages - for use by ci gateway
+ */
+#define RUNTEST_REQ_SIZE  32
+extern char runtest_test_token[RUNTEST_REQ_SIZE];
+
+/*
+ * Argument struct passed in from "run" requests via newtmgr
+ */
+struct runtest_evq_arg {
+    char* run_testname;
+    char* run_token;
+};
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/runtest/src/ctags.list
----------------------------------------------------------------------
diff --git a/test/runtest/src/ctags.list b/test/runtest/src/ctags.list
new file mode 120000
index 0000000..ff9c2c0
--- /dev/null
+++ b/test/runtest/src/ctags.list
@@ -0,0 +1 @@
+/Users/peterfs/dev/newt/newt_ci/ctags.list
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/runtest/src/runtest.c
----------------------------------------------------------------------
diff --git a/test/runtest/src/runtest.c b/test/runtest/src/runtest.c
index 28657d0..3a68185 100644
--- a/test/runtest/src/runtest.c
+++ b/test/runtest/src/runtest.c
@@ -39,27 +39,25 @@ struct shell_cmd runtest_cmd_struct;
 struct mgmt_group runtest_nmgr_group;
 #endif
 
-int
-runtest()
-{
-    /* XXX */
-
-    return 0;
-}
+extern int run_nmgr_register_group();
 
+/*
+ * Package init routine to register newtmgr "run" commands
+ */
 void
 runtest_init(void)
 {
+    int rc;
+
     /* Ensure this function only gets called by sysinit. */
     SYSINIT_ASSERT_ACTIVE();
 
-    runtest_start = 1;
-
 #if MYNEWT_VAL(RUNTEST_CLI)
     shell_cmd_register(&runtest_cmd_struct);
 #endif
 
 #if MYNEWT_VAL(RUNTEST_NEWTMGR)
-    mgmt_group_register(&runtest_nmgr_group);
+    rc = run_nmgr_register_group();
+    SYSINIT_PANIC_ASSERT(rc == 0);
 #endif
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/runtest/src/runtest_cli.c
----------------------------------------------------------------------
diff --git a/test/runtest/src/runtest_cli.c b/test/runtest/src/runtest_cli.c
index 282663c..739dc2f 100644
--- a/test/runtest/src/runtest_cli.c
+++ b/test/runtest/src/runtest_cli.c
@@ -32,14 +32,14 @@
 
 static int runtest_cli_cmd(int argc, char **argv);
 struct shell_cmd runtest_cmd_struct = {
-    .sc_cmd = "runtest",
+    .sc_cmd = "run",
     .sc_cmd_func = runtest_cli_cmd
 };
 
 static int
 runtest_cli_cmd(int argc, char **argv)
 {
-    console_printf("Usage runtest \n");
+    console_printf("Usage run [list | test testname token] \n");
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/runtest/src/runtest_nmgr.c
----------------------------------------------------------------------
diff --git a/test/runtest/src/runtest_nmgr.c b/test/runtest/src/runtest_nmgr.c
index 625af75..7281e99 100644
--- a/test/runtest/src/runtest_nmgr.c
+++ b/test/runtest/src/runtest_nmgr.c
@@ -25,63 +25,151 @@
 #include "mgmt/mgmt.h"
 #include "cborattr/cborattr.h"
 #include "console/console.h"
+#include "os/os_eventq.h"
+
+#include "testutil/testutil.h"
 
 #include "runtest/runtest.h"
 #include "runtest_priv.h"
 
-static int runtest_nmgr_write(struct mgmt_cbuf *);
+static int run_nmgr_test(struct mgmt_cbuf *);
+static int run_nmgr_list(struct mgmt_cbuf *);
 
-static const struct mgmt_handler runtest_nmgr_handler[] = {
-    [0] = { runtest_nmgr_write, runtest_nmgr_write }
-};
+struct mgmt_group run_nmgr_group;
+
+#define RUN_NMGR_OP_TEST    0
+#define RUN_NMGR_OP_LIST    1
 
-struct mgmt_group runtest_nmgr_group = {
-    .mg_handlers = (struct mgmt_handler *)runtest_nmgr_handler,
-    .mg_handlers_count = 1,
-    .mg_group_id = MGMT_GROUP_ID_RUNTEST
+const struct mgmt_handler run_nmgr_handlers[] = {
+    [RUN_NMGR_OP_TEST] = {NULL, run_nmgr_test},
+    [RUN_NMGR_OP_LIST] = {run_nmgr_list, NULL}
 };
 
+extern void sanity_start_test();
+struct os_event run_test_event;
+
+char run_testname[RUNTEST_REQ_SIZE];
+char run_token[RUNTEST_REQ_SIZE];
+
+static struct os_eventq *run_evq;
+struct runtest_evq_arg runtest_arg;
+os_event_fn *run_callback;
+
+void
+run_evcb_set(os_event_fn *cb)
+{
+    run_callback = cb;
+}
+
+static struct os_eventq *
+run_evq_get(void)
+{
+    os_eventq_ensure(&run_evq, NULL);
+    return run_evq;
+}
+
 /*
- * XXX global used to gate starting test - hack
+ * package "run test" request from newtmgr and enqueue on default queue
+ * of the application which is actually running the tests (e.g., mynewtsanity).
+ * Application callback was initialized by call to run_evb_set() above.
  */
-volatile int runtest_start;
-
 static int
-runtest_nmgr_write(struct mgmt_cbuf *cb)
+run_nmgr_test(struct mgmt_cbuf *cb)
 {
-    char tmp_str[64];
-    const struct cbor_attr_t attr[2] = {
+    int rc;
+
+    const struct cbor_attr_t attr[3] = {
         [0] = {
-            .attribute = "u",
+            .attribute = "testname",
             .type = CborAttrTextStringType,
-            .addr.string = tmp_str,
-            .len = sizeof(tmp_str)
+            .addr.string = run_testname,
+            .len = sizeof(run_testname)
         },
         [1] = {
+            .attribute = "token",
+            .type = CborAttrTextStringType,
+            .addr.string = run_token,
+            .len = sizeof(run_token)
+        },
+        [2] = {
             .attribute = NULL
         }
     };
-    int rc;
 
     rc = cbor_read_object(&cb->it, attr);
     if (rc) {
+        return rc;
+    }
+
+    /*
+     * testname is either a specific test or newtmgr passed "all".
+     * token is appened to log messages.
+     */
+    runtest_arg.run_testname = run_testname;
+    runtest_arg.run_token = run_token;
+
+    run_test_event.ev_arg = &runtest_arg;
+    run_test_event.ev_cb = run_callback;
+
+    os_eventq_put(run_evq_get(), &run_test_event);
+            
+    if (rc) {
         rc = MGMT_ERR_EINVAL;
-    } else {
-        /* XXX ugh - drop out of a loop allowing a test to run in an app */
-        runtest_start = 0;
-        /*
-         * we should be doing something more like this where we call
-         * a named test suite directly
-         */
-#ifdef NOTYET
-        rc = start_test(tmp_str);
-#endif
-        if (rc) {
-            rc = MGMT_ERR_EINVAL;
-        }
     }
+
     mgmt_cbuf_setoerr(cb, rc);
     return 0;
 }
 
-#endif /* MYNEWT_VAL(RUNTEST_NEWTMGR) */
+/*
+ * List all register tests
+ */
+static int
+run_nmgr_list(struct mgmt_cbuf *cb)
+{
+    CborError g_err = CborNoError;
+    CborEncoder *penc = &cb->encoder;
+    CborEncoder rsp, run_list;
+    struct ts_suite *ts;
+
+    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&rsp, "rc");
+    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+
+    g_err |= cbor_encode_text_stringz(&rsp, "run_list");
+    g_err |= cbor_encoder_create_array(&rsp, &run_list, CborIndefiniteLength);
+
+    SLIST_FOREACH(ts, &g_ts_suites, ts_next) {
+        g_err |= cbor_encode_text_stringz(&run_list, ts->ts_name);
+    }
+
+    g_err |= cbor_encoder_close_container(&rsp, &run_list);
+    g_err |= cbor_encoder_close_container(penc, &rsp);
+
+    if (g_err) {
+        return MGMT_ERR_ENOMEM;
+    }
+    return (0);
+}
+
+/*
+ * Register nmgr group handlers
+ */
+int
+run_nmgr_register_group(void)
+{
+    int rc;
+
+    MGMT_GROUP_SET_HANDLERS(&run_nmgr_group, run_nmgr_handlers);
+    run_nmgr_group.mg_group_id = MGMT_GROUP_ID_RUN;
+
+    rc = mgmt_group_register(&run_nmgr_group);
+    if (rc != 0) {
+        goto err;
+    }
+    return (0);
+
+err:
+    return (rc);
+}
+#endif /* MYNEWT_VAL(RUN_NEWTMGR) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testreport/include/testreport/testreport.h
----------------------------------------------------------------------
diff --git a/test/testreport/include/testreport/testreport.h b/test/testreport/include/testreport/testreport.h
deleted file mode 100644
index 3b14da8..0000000
--- a/test/testreport/include/testreport/testreport.h
+++ /dev/null
@@ -1,42 +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_TESTREPORT_
-#define H_TESTREPORT_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct nffs_area_desc;
-
-struct tr_config {
-    const char *tc_base_path;
-    const struct nffs_area_desc *tc_area_descs;
-};
-
-extern struct tr_config tr_config;
-
-int tr_init(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testreport/pkg.yml
----------------------------------------------------------------------
diff --git a/test/testreport/pkg.yml b/test/testreport/pkg.yml
deleted file mode 100644
index 42e8482..0000000
--- a/test/testreport/pkg.yml
+++ /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.
-#
-
-pkg.name: test/testreport
-pkg.description: Library for recording unit test results to flash.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-    - unit
-    - test
-
-pkg.deps:
-    - fs/nffs
-    - test/testutil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testreport/src/arch/cortex_m4/io.c
----------------------------------------------------------------------
diff --git a/test/testreport/src/arch/cortex_m4/io.c b/test/testreport/src/arch/cortex_m4/io.c
deleted file mode 100644
index 0ae2aa0..0000000
--- a/test/testreport/src/arch/cortex_m4/io.c
+++ /dev/null
@@ -1,91 +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 <stddef.h>
-#include "nffs/nffs.h"
-#include "nffs/nffsutil.h"
-#include "testreport_priv.h"
-
-int
-tr_io_write(const char *path, const void *contents, size_t len)
-{
-    int rc;
-
-    rc = nffsutil_write_file(path, contents, len);
-    if (rc != 0) {
-        return -1;
-    }
-
-    return 0;
-}
-
-int
-tr_io_mkdir(const char *path)
-{
-    int rc;
-
-    rc = nffs_mkdir(path);
-    if (rc != 0 && rc != NFFS_EEXIST) {
-        return -1;
-    }
-
-    return 0;
-}
-
-int
-tr_io_rmdir(const char *path)
-{
-    int rc;
-
-    rc = nffs_unlink(path);
-    if (rc != 0 && rc != NFFS_ENOENT) {
-        return -1;
-    }
-
-    return 0;
-}
-
-int
-tr_io_read(const char *path, void *out_data, size_t len, size_t *out_len)
-{
-    uint32_t u32;
-    int rc;
-
-    rc = nffsutil_read_file(path, 0, len, out_data, &u32);
-    if (rc != 0) {
-        return -1;
-    }
-
-    *out_len = u32;
-
-    return 0;
-}
-
-int
-tr_io_delete(const char *path)
-{
-    int rc;
-
-    rc = nffs_unlink(path);
-    if (rc != 0 && rc != NFFS_ENOENT) {
-        return -1;
-    }
-
-    return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testreport/src/arch/sim/io.c
----------------------------------------------------------------------
diff --git a/test/testreport/src/arch/sim/io.c b/test/testreport/src/arch/sim/io.c
deleted file mode 100644
index f28a4dd..0000000
--- a/test/testreport/src/arch/sim/io.c
+++ /dev/null
@@ -1,140 +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 <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include "testreport_priv.h"
-
-static char tr_io_buf[1024];
-
-int
-tr_io_write(const char *path, const void *contents, size_t len)
-{
-    FILE *fp;
-    int rc;
-
-    fp = NULL;
-
-    fp = fopen(path, "w+");
-    if (fp == NULL) {
-        rc = -1;
-        goto done;
-    }
-
-    if (contents != NULL && len > 0) {
-        rc = fwrite(contents, len, 1, fp);
-        if (rc != 1) {
-            rc = -1;
-            goto done;
-        }
-    }
-
-    rc = 0;
-
-done:
-    if (fp != NULL) {
-        fclose(fp);
-    }
-
-    return rc;
-}
-
-int
-tr_io_mkdir(const char *path)
-{
-    int rc;
-
-    rc = mkdir(path, 0755);
-    if (rc == -1 && errno != EEXIST) {
-        return -1;
-    }
-
-    return 0;
-}
-
-/* XXX security risk, not portable, blah blah blah */
-int
-tr_io_rmdir(const char *path)
-{
-    int rc; 
-
-    rc = snprintf(tr_io_buf, sizeof tr_io_buf,
-                  "rm -rf '%s'", path);
-    if (rc >= sizeof tr_io_buf) {
-        return -1;
-    }
-
-    rc = system(tr_io_buf);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-int
-tr_io_read(const char *path, void *out_data, size_t len, size_t *out_len)
-{
-    FILE *fp;
-    uint8_t *dst;
-    int rc;
-    int i;
-
-    fp = NULL;
-
-    fp = fopen(path, "rb");
-    if (fp == NULL) {
-        rc = -1;
-        goto done;
-    }
-
-    dst = out_data;
-    for (i = 0; i < len; i++) {
-        rc = getc(fp);
-        if (rc == EOF) {
-            rc = -1;
-            goto done;
-        }
-
-        dst[i] = rc;
-    }
-
-    *out_len = i;
-    rc = 0;
-
-done:
-    if (fp != NULL) {
-        fclose(fp);
-    }
-
-    return rc;
-}
-
-int
-tr_io_delete(const char *path)
-{
-    int rc;
-
-    rc = remove(path);
-
-    return rc;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testreport/src/results.c
----------------------------------------------------------------------
diff --git a/test/testreport/src/results.c b/test/testreport/src/results.c
deleted file mode 100644
index bc54bb3..0000000
--- a/test/testreport/src/results.c
+++ /dev/null
@@ -1,190 +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 "testutil/testutil.h"
-#include "testreport/testreport.h"
-#include "testreport_priv.h"
-
-#define TU_REPORT_META_DIR          ".meta"
-#define TU_REPORT_STATUS_FILENAME   "status"
-
-static char tr_report_buf[1024];
-
-int
-tr_report_rmdir_results(void)
-{
-    if (tr_config.tc_base_path == NULL) {
-        return 0;
-    }
-
-    return tr_io_rmdir(tr_config.tc_base_path);
-}
-
-int
-tr_report_mkdir_results(void)
-{
-    int rc;
-
-    if (tr_config.tc_base_path == NULL) {
-        return 0;
-    }
-
-    rc = snprintf(tr_report_buf, sizeof tr_report_buf,
-                  "%s", tr_config.tc_base_path);
-    if (rc >= sizeof tr_report_buf) {
-        return -1;
-    }
-    return tr_io_mkdir(tr_report_buf);
-}
-
-int
-tr_report_mkdir_meta(void)
-{
-    int rc;
-
-    if (tr_config.tc_base_path == NULL) {
-        return 0;
-    }
-
-    rc = snprintf(tr_report_buf, sizeof tr_report_buf,
-                  "%s/" TU_REPORT_META_DIR, tr_config.tc_base_path);
-    if (rc >= sizeof tr_report_buf) {
-        return -1;
-    }
-    return tr_io_mkdir(tr_report_buf);
-}
-
-int
-tr_report_mkdir_suite(void)
-{
-    int rc;
-
-    if (tr_config.tc_base_path == NULL) {
-        return 0;
-    }
-
-    rc = snprintf(tr_report_buf, sizeof tr_report_buf,
-                  "%s/%s", tr_config.tc_base_path,
-                  ts_current_config->ts_suite_name);
-    if (rc >= sizeof tr_report_buf) {
-        return -1;
-    }
-
-    rc = tr_io_mkdir(tr_report_buf);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-int
-tr_report_mkdir_case(void)
-{
-    int rc;
-
-    if (tr_config.tc_base_path == NULL) {
-        return 0;
-    }
-
-    rc = snprintf(tr_report_buf, sizeof tr_report_buf,
-                  "%s/%s/%s", tr_config.tc_base_path,
-                  ts_current_config->ts_suite_name, tu_case_name);
-    if (rc >= sizeof tr_report_buf) {
-        return -1;
-    }
-
-    rc = tr_io_mkdir(tr_report_buf);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-int
-tr_report_write_file(const char *filename, const uint8_t *data,
-                     size_t data_len)
-{
-    int rc;
-
-    if (tr_config.tc_base_path == NULL) {
-        return 0;
-    }
-
-    rc = snprintf(tr_report_buf, sizeof tr_report_buf,
-                  "%s/%s/%s/%s", tr_config.tc_base_path,
-                  ts_current_config->ts_suite_name, tu_case_name, filename);
-    if (rc >= sizeof tr_report_buf) {
-        return -1;
-    }
-
-    rc = tr_io_write(tr_report_buf, data, data_len);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-int
-tr_report_read_status(void)
-{
-    size_t bytes_read;
-    int rc;
-
-    rc = snprintf(tr_report_buf, sizeof tr_report_buf,
-                  "%s/%s/%s", tr_config.tc_base_path,
-                  TU_REPORT_META_DIR, TU_REPORT_STATUS_FILENAME);
-    if (rc >= sizeof tr_report_buf) {
-        return -1;
-    }
-
-    rc = tr_io_read(tr_report_buf, &tu_first_idx, sizeof tu_first_idx,
-                    &bytes_read);
-    if (rc != 0 || bytes_read != sizeof tu_first_idx) {
-        return -1;
-    }
-
-    tr_io_delete(tr_report_buf);
-
-    return 0;
-}
-
-int
-tr_report_write_status(void)
-{
-    int rc;
-
-    rc = snprintf(tr_report_buf, sizeof tr_report_buf,
-                  "%s/%s/%s", tr_config.tc_base_path,
-                  TU_REPORT_META_DIR, TU_REPORT_STATUS_FILENAME);
-    if (rc >= sizeof tr_report_buf) {
-        return -1;
-    }
-
-    rc = tr_io_write(tr_report_buf, &tu_first_idx, sizeof tu_first_idx);
-    if (rc != 0) {
-        return -1;
-    }
-
-    return 0;
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testreport/src/testreport.c
----------------------------------------------------------------------
diff --git a/test/testreport/src/testreport.c b/test/testreport/src/testreport.c
deleted file mode 100644
index 85c1258..0000000
--- a/test/testreport/src/testreport.c
+++ /dev/null
@@ -1,131 +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 <stdio.h>
-#include "hal/hal_flash.h"
-#include "fs/fs.h"
-#include "nffs/nffs.h"
-#include "testutil/testutil.h"
-#include "testreport/testreport.h"
-#include "testreport_priv.h"
-
-struct tr_config tr_config;
-
-static int tr_case_fail_idx;
-
-static void
-tr_case_init(void *unused)
-{
-    int rc;
-
-    rc = tr_results_mkdir_case();
-    assert(rc == 0);
-}
-
-static void
-tr_case_fail(char *msg, int msg_len, void *unused)
-{
-    char filename[14];
-    int rc;
-
-    rc = snprintf(filename, sizeof filename, "fail-%04d.txt",
-                  tr_case_fail_idx);
-    assert(rc < sizeof filename);
-
-    rc = tr_results_write_file(filename, (uint8_t *)msg, msg_len);
-    assert(rc == 0);
-
-    tr_case_fail_idx++;
-}
-
-static void
-tr_case_pass(char *msg, int msg_len, void *unused)
-{
-    int rc;
-
-    rc = tr_results_write_file("pass.txt", (uint8_t *)msg, msg_len);
-    assert(rc == 0);
-}
-
-static void
-tr_suite_init(void *unused)
-{
-    int rc;
-
-    rc = tr_results_mkdir_suite();
-    assert(rc == 0);
-}
-
-static void
-tr_restart(void *unused)
-{
-    tr_results_write_status();
-}
-
-int
-tr_init(void)
-{
-    int rc;
-
-    if (tr_config.tc_base_path != NULL) {
-        if (tr_config.tc_area_descs != NULL) {
-            rc = hal_flash_init();
-            if (rc != 0) {
-                return -1;
-            }
-
-            rc = nffs_init();
-            if (rc != 0) {
-                return -1;
-            }
-
-            rc = nffs_detect(tr_config.tc_area_descs);
-            if (rc == FS_ECORRUPT) {
-                rc = nffs_format(tr_config.tc_area_descs);
-            }
-            if (rc != 0) {
-                return -1;
-            }
-        }
-
-        rc = tr_results_read_status();
-        if (rc != 0) {
-            tr_results_rmdir_results();
-        }
-
-        rc = tr_results_mkdir_results();
-        if (rc != 0) {
-            return -1;
-        }
-
-        rc = tr_results_mkdir_meta();
-        if (rc != 0) {
-            return -1;
-        }
-    }
-
-    tu_config.tc_case_init_cb = tr_case_init;
-    tu_config.tc_case_fail_cb = tr_case_fail;
-    tu_config.tc_case_pass_cb = tr_case_pass;
-    tu_config.tc_suite_init_cb = tr_suite_init;
-    tu_config.tc_restart_cb = tr_restart;
-
-    return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testreport/src/testreport_priv.h
----------------------------------------------------------------------
diff --git a/test/testreport/src/testreport_priv.h b/test/testreport/src/testreport_priv.h
deleted file mode 100644
index 64f95a1..0000000
--- a/test/testreport/src/testreport_priv.h
+++ /dev/null
@@ -1,56 +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_TESTREPORT_PRIV_
-#define H_TESTREPORT_PRIV_
-
-#include <stddef.h>
-#include <inttypes.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int tr_results_mkdir_results(void);
-int tr_results_rmdir_results(void);
-
-int tr_results_mkdir_meta(void);
-
-int tr_results_mkdir_suite(void);
-int tr_results_mkdir_case(void);
-
-int tr_results_write_file(const char *filename, const uint8_t *data,
-                          size_t data_len);
-
-int tr_results_read_status(void);
-int tr_results_write_status(void);
-
-int tr_io_read(const char *path, void *out_data, size_t len, size_t *out_len);
-int tr_io_write(const char *path, const void *contents, size_t len);
-
-int tr_io_delete(const char *path);
-
-int tr_io_mkdir(const char *path);
-int tr_io_rmdir(const char *path);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testutil/include/testutil/testutil.h
----------------------------------------------------------------------
diff --git a/test/testutil/include/testutil/testutil.h b/test/testutil/include/testutil/testutil.h
index 66701f2..4749186 100644
--- a/test/testutil/include/testutil/testutil.h
+++ b/test/testutil/include/testutil/testutil.h
@@ -74,6 +74,8 @@ void tu_suite_pre_test(void);
 void tu_suite_post_test(void);
 void tu_suite_complete(void);
 
+int tu_suite_register(tu_testsuite_fn_t* ts, const char *name);
+
 struct ts_suite {
     SLIST_ENTRY(ts_suite) ts_next;
     const char *ts_name;
@@ -81,8 +83,7 @@ struct ts_suite {
 };
 
 SLIST_HEAD(ts_testsuite_list, ts_suite);
-
-extern struct ts_testsuite_list *ts_suites;
+extern struct ts_testsuite_list g_ts_suites;
 
 struct ts_config {
     int ts_print_results;
@@ -193,10 +194,10 @@ extern int tu_case_failed;
 extern int tu_case_idx;
 extern jmp_buf tu_case_jb;
 
-#define TEST_SUITE_NAME(suite_name) TEST_SUITE##suite_name
+#define TEST_SUITE_DECL(suite_name) extern void suite_name()
 
-#define TEST_SUITE_DECL(suite_name)                         \
-  extern tu_testsuite_fn_t *TEST_SUITE##suite_name()
+#define TEST_SUITE_REGISTER(suite_name)                      \
+  tu_suite_register((tu_testsuite_fn_t*)suite_name, ((const char *)#suite_name));
 
 #define TEST_SUITE(suite_name)                               \
 void                                                         \
@@ -266,7 +267,9 @@ TEST_SUITE_##suite_name(void);                               \
 #define REST_OR_0_AUX_N(first, ...) __VA_ARGS__
 
 #define XSTR(s) STR(s)
+#ifndef STR
 #define STR(s) #s
+#endif
 
 #if MYNEWT_VAL(TESTUTIL_SYSTEM_ASSERT)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58fe11a9/test/testutil/src/suite.c
----------------------------------------------------------------------
diff --git a/test/testutil/src/suite.c b/test/testutil/src/suite.c
index 6cca44a..4ccff7c 100644
--- a/test/testutil/src/suite.c
+++ b/test/testutil/src/suite.c
@@ -25,11 +25,17 @@
 const char *tu_suite_name = 0;
 int tu_suite_failed = 0;
 
+struct ts_testsuite_list g_ts_suites;
+
+/*
+ * tu_suite_register must be called for each test_suite that's to
+ * be run from a list rather than explicitly called.
+ * See mynewtsanity.
+ */
 int
-tu_suite_register(const char *name, tu_testsuite_fn_t* ts)
+tu_suite_register(tu_testsuite_fn_t* ts, const char *name)
 {
     struct ts_suite *tsp;
-    TEST_SUITE_DECL(name);
 
     tsp = (struct ts_suite *)os_malloc(sizeof(*tsp));
     if (!tsp) {
@@ -37,7 +43,7 @@ tu_suite_register(const char *name, tu_testsuite_fn_t* ts)
     }
     tsp->ts_name = name;
     tsp->ts_test = ts;
-    SLIST_INSERT_HEAD(ts_suites, tsp, ts_next);
+    SLIST_INSERT_HEAD(&g_ts_suites, tsp, ts_next);
     return 0;
 }