Update to clar 2b73f5e
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
diff --git a/tests/clar.c b/tests/clar.c
index 17f767a..1182ed1 100644
--- a/tests/clar.c
+++ b/tests/clar.c
@@ -132,6 +132,10 @@ static struct {
jmp_buf trampoline;
int trampoline_enabled;
+
+ cl_trace_cb *pfn_trace_cb;
+ void *trace_payload;
+
} _clar;
struct clar_func {
@@ -163,6 +167,23 @@ static int clar_sandbox(void);
/* Load the declarations for the test suite */
#include "clar.suite"
+
+#define CL_TRACE(ev) \
+ do { \
+ if (_clar.pfn_trace_cb) \
+ _clar.pfn_trace_cb(ev, \
+ _clar.active_suite, \
+ _clar.active_test, \
+ _clar.trace_payload); \
+ } while (0)
+
+void cl_trace_register(cl_trace_cb *cb, void *payload)
+{
+ _clar.pfn_trace_cb = cb;
+ _clar.trace_payload = payload;
+}
+
+
/* Core test functions */
static void
clar_report_errors(void)
@@ -191,11 +212,15 @@ clar_run_test(
_clar.test_status = CL_TEST_OK;
_clar.trampoline_enabled = 1;
+ CL_TRACE(CL_TRACE__TEST__BEGIN);
+
if (setjmp(_clar.trampoline) == 0) {
if (initialize->ptr != NULL)
initialize->ptr();
+ CL_TRACE(CL_TRACE__TEST__RUN_BEGIN);
test->ptr();
+ CL_TRACE(CL_TRACE__TEST__RUN_END);
}
_clar.trampoline_enabled = 0;
@@ -206,6 +231,8 @@ clar_run_test(
if (cleanup->ptr != NULL)
cleanup->ptr();
+ CL_TRACE(CL_TRACE__TEST__END);
+
_clar.tests_ran++;
/* remove any local-set cleanup methods */
@@ -235,6 +262,8 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
clar_print_onsuite(suite->name, ++_clar.suites_ran);
_clar.active_suite = suite->name;
+ _clar.active_test = NULL;
+ CL_TRACE(CL_TRACE__SUITE_BEGIN);
if (filter) {
size_t suitelen = strlen(suite->name);
@@ -259,6 +288,9 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
if (_clar.exit_on_error && _clar.total_errors)
return;
}
+
+ _clar.active_test = NULL;
+ CL_TRACE(CL_TRACE__SUITE_END);
}
static void
@@ -424,6 +456,7 @@ static void abort_test(void)
exit(-1);
}
+ CL_TRACE(CL_TRACE__TEST__LONGJMP);
longjmp(_clar.trampoline, -1);
}
diff --git a/tests/clar.h b/tests/clar.h
index 514203f..5c674d7 100644
--- a/tests/clar.h
+++ b/tests/clar.h
@@ -26,6 +26,48 @@ const char *clar_sandbox_path(void);
void cl_set_cleanup(void (*cleanup)(void *), void *opaque);
void cl_fs_cleanup(void);
+/**
+ * cl_trace_* is a hook to provide a simple global tracing
+ * mechanism.
+ *
+ * The goal here is to let main() provide clar-proper
+ * with a callback to optionally write log info for
+ * test operations into the same stream used by their
+ * actual tests. This would let them print test names
+ * and maybe performance data as they choose.
+ *
+ * The goal is NOT to alter the flow of control or to
+ * override test selection/skipping. (So the callback
+ * does not return a value.)
+ *
+ * The goal is NOT to duplicate the existing
+ * pass/fail/skip reporting. (So the callback
+ * does not accept a status/errorcode argument.)
+ *
+ */
+typedef enum cl_trace_event {
+ CL_TRACE__SUITE_BEGIN,
+ CL_TRACE__SUITE_END,
+ CL_TRACE__TEST__BEGIN,
+ CL_TRACE__TEST__END,
+ CL_TRACE__TEST__RUN_BEGIN,
+ CL_TRACE__TEST__RUN_END,
+ CL_TRACE__TEST__LONGJMP,
+} cl_trace_event;
+
+typedef void (cl_trace_cb)(
+ cl_trace_event ev,
+ const char *suite_name,
+ const char *test_name,
+ void *payload);
+
+/**
+ * Register a callback into CLAR to send global trace events.
+ * Pass NULL to disable.
+ */
+void cl_trace_register(cl_trace_cb *cb, void *payload);
+
+
#ifdef CLAR_FIXTURE_PATH
const char *cl_fixture(const char *fixture_name);
void cl_fixture_sandbox(const char *fixture_name);