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/07/23 02:47:32 UTC

[05/11] incubator-mynewt-core git commit: testutil - Allow post-test callback per suite.

testutil - Allow post-test callback per suite.

/**
 * 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 callback.
 */
void
tu_suite_set_post_test_cb(tu_post_test_fn_t *cb, void *cb_arg)


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

Branch: refs/heads/develop
Commit: 6c457ca51e3fe156fe585dd96ba0d8180715dc79
Parents: 491ef44
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jul 21 12:32:59 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Jul 22 18:34:01 2016 -0700

----------------------------------------------------------------------
 libs/testutil/include/testutil/testutil.h |  8 +++++++-
 libs/testutil/src/case.c                  | 10 ++++++++++
 libs/testutil/src/suite.c                 | 24 ++++++++++++++++++++++++
 libs/testutil/src/testutil_priv.h         |  5 +++++
 4 files changed, 46 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c457ca5/libs/testutil/include/testutil/testutil.h
----------------------------------------------------------------------
diff --git a/libs/testutil/include/testutil/testutil.h b/libs/testutil/include/testutil/testutil.h
index da3f618..9c6192a 100644
--- a/libs/testutil/include/testutil/testutil.h
+++ b/libs/testutil/include/testutil/testutil.h
@@ -57,6 +57,9 @@ 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);
@@ -65,6 +68,7 @@ void tu_restart(void);
  * Private declarations                                                      *
  *****************************************************************************/
 
+void tu_suite_complete(void);
 void tu_suite_init(const char *name);
 
 void tu_case_init(const char *name);
@@ -74,7 +78,7 @@ void tu_case_fail_assert(int fatal, const char *file, int line,
 void tu_case_write_pass_auto(void);
 void tu_case_pass_manual(const char *file, int line,
                          const char *format, ...);
-
+void tu_case_post_test(void);
 
 extern int tu_any_failed;
 extern int tu_suite_failed;
@@ -91,6 +95,7 @@ extern jmp_buf tu_case_jb;
     {                                                                         \
         tu_suite_init(#suite_name);                                           \
         TEST_SUITE_##suite_name();                                            \
+        tu_suite_complete();                                                  \
                                                                               \
         return tu_suite_failed;                                               \
     }                                                                         \
@@ -113,6 +118,7 @@ extern jmp_buf tu_case_jb;
                                                                               \
             if (setjmp(tu_case_jb) == 0) {                                    \
                 TEST_CASE_##case_name();                                      \
+                tu_case_post_test();                                          \
                 tu_case_write_pass_auto();                                    \
             }                                                                 \
         }                                                                     \

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c457ca5/libs/testutil/src/case.c
----------------------------------------------------------------------
diff --git a/libs/testutil/src/case.c b/libs/testutil/src/case.c
index bea6efa..614b142 100644
--- a/libs/testutil/src/case.c
+++ b/libs/testutil/src/case.c
@@ -30,6 +30,8 @@ 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
 
@@ -101,6 +103,14 @@ tu_case_complete(void)
     tu_case_idx++;
 }
 
+void
+tu_case_post_test(void)
+{
+    if (tu_case_post_test_cb != NULL) {
+        tu_case_post_test_cb(tu_case_post_test_cb_arg);
+    }
+}
+
 static void
 tu_case_write_fail_buf(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c457ca5/libs/testutil/src/suite.c
----------------------------------------------------------------------
diff --git a/libs/testutil/src/suite.c b/libs/testutil/src/suite.c
index 5c2e5cb..93ca639 100644
--- a/libs/testutil/src/suite.c
+++ b/libs/testutil/src/suite.c
@@ -30,6 +30,30 @@ tu_suite_set_name(const char *name)
     tu_suite_name = name;
 }
 
+/**
+ * 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
+ *                                  callback.
+ */
+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;
+}
+
+void
+tu_suite_complete(void)
+{
+    tu_suite_set_post_test_cb(NULL, NULL);
+}
+
 void
 tu_suite_init(const char *name)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6c457ca5/libs/testutil/src/testutil_priv.h
----------------------------------------------------------------------
diff --git a/libs/testutil/src/testutil_priv.h b/libs/testutil/src/testutil_priv.h
index 0047874..3f8cb2d 100644
--- a/libs/testutil/src/testutil_priv.h
+++ b/libs/testutil/src/testutil_priv.h
@@ -23,7 +23,12 @@
 #include <stddef.h>
 #include <inttypes.h>
 
+#include "testutil/testutil.h"
+
 void tu_arch_restart(void);
 void tu_case_abort(void);
 
+extern tu_post_test_fn_t *tu_case_post_test_cb;
+extern void *tu_case_post_test_cb_arg;
+
 #endif