summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/test.c121
-rw-r--r--common/test.h20
2 files changed, 126 insertions, 15 deletions
diff --git a/common/test.c b/common/test.c
index e917701..18cb501 100644
--- a/common/test.c
+++ b/common/test.c
@@ -89,6 +89,34 @@ struct {
jmp_buf jump;
} gl = { NULL, NULL, 0, };
+static void
+print_diagnostics (const char *filename,
+ int line,
+ const char *function,
+ char *output)
+{
+ const char *pos;
+ char *from;
+ char *next;
+
+ for (from = output; from != NULL; ) {
+ next = strchr (from, '\n');
+ if (next) {
+ next[0] = '\0';
+ next += 1;
+ }
+
+ printf ("# %s\n", from);
+ from = next;
+ }
+
+ pos = strrchr (filename, '/');
+ if (pos != NULL && pos[1] != '\0')
+ filename = pos + 1;
+
+ printf ("# in %s() at %s:%d\n", function, filename, line);
+}
+
void
p11_test_fail (const char *filename,
int line,
@@ -96,10 +124,7 @@ p11_test_fail (const char *filename,
const char *message,
...)
{
- const char *pos;
char *output;
- char *from;
- char *next;
va_list va;
assert (gl.last != NULL);
@@ -113,23 +138,89 @@ p11_test_fail (const char *filename,
assert (0 && "vasprintf() failed");
va_end (va);
- for (from = output; from != NULL; ) {
- next = strchr (from, '\n');
- if (next) {
- next[0] = '\0';
- next += 1;
- }
+ print_diagnostics (filename, line, function, output);
+ free (output);
- printf ("# %s\n", from);
- from = next;
+ /* Let coverity know we're not supposed to return from here */
+#ifdef __COVERITY__
+ abort();
+#endif
+
+ longjmp (gl.jump, 1);
+}
+
+void
+p11_test_skip (const char *filename,
+ int line,
+ const char *function,
+ const char *message,
+ ...)
+{
+ char *output;
+ char *pos;
+ va_list va;
+
+ assert (gl.last != NULL);
+ assert (gl.last->type == TEST);
+ gl.last->x.test.failed = 1;
+
+ printf ("ok %d %s", gl.number, gl.last->x.test.name);
+
+ va_start (va, message);
+ if (vasprintf (&output, message, va) < 0)
+ assert (0 && "vasprintf() failed");
+ va_end (va);
+
+ pos = strchr (output, '\n');
+ if (pos) {
+ *pos = '\0';
+ pos++;
}
+ printf (" # SKIP %s\n", output);
- pos = strrchr (filename, '/');
- if (pos != NULL && pos[1] != '\0')
- filename = pos + 1;
+ if (pos)
+ print_diagnostics (filename, line, function, pos);
+ free (output);
- printf ("# in %s() at %s:%d\n", function, filename, line);
+ /* Let coverity know we're not supposed to return from here */
+#ifdef __COVERITY__
+ abort();
+#endif
+
+ longjmp (gl.jump, 1);
+}
+
+void
+p11_test_todo (const char *filename,
+ int line,
+ const char *function,
+ const char *message,
+ ...)
+{
+ char *output;
+ char *pos;
+ va_list va;
+
+ assert (gl.last != NULL);
+ assert (gl.last->type == TEST);
+ gl.last->x.test.failed = 1;
+
+ printf ("not ok %d %s", gl.number, gl.last->x.test.name);
+
+ va_start (va, message);
+ if (vasprintf (&output, message, va) < 0)
+ assert (0 && "vasprintf() failed");
+ va_end (va);
+
+ pos = strchr (output, '\n');
+ if (pos) {
+ *pos = '\0';
+ pos++;
+ }
+ printf (" # TODO %s\n", output);
+ if (pos)
+ print_diagnostics (filename, line, function, pos);
free (output);
/* Let coverity know we're not supposed to return from here */
diff --git a/common/test.h b/common/test.h
index e28bb55..1c952b0 100644
--- a/common/test.h
+++ b/common/test.h
@@ -63,6 +63,14 @@
do { const char *__s = (detail); \
p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "%s%s%s", (msg), __s ? ": ": "", __s ? __s : ""); \
} while (0)
+#define assert_skip(msg, detail) \
+ do { const char *__s = (detail); \
+ p11_test_skip (__FILE__, __LINE__, __FUNCTION__, "%s%s%s", (msg), __s ? ": ": "", __s ? __s : ""); \
+ } while (0)
+#define assert_todo(msg, detail) \
+ do { const char *__s = (detail); \
+ p11_test_todo (__FILE__, __LINE__, __FUNCTION__, "%s%s%s", (msg), __s ? ": ": "", __s ? __s : ""); \
+ } while (0)
#define assert_not_reached(msg) \
do { \
p11_test_fail (__FILE__, __LINE__, __FUNCTION__, "code should not be reached"); \
@@ -113,6 +121,18 @@ void p11_test_fail (const char *filename,
const char *message,
...) GNUC_PRINTF(4, 5) CLANG_ANALYZER_NORETURN;
+void p11_test_skip (const char *filename,
+ int line,
+ const char *function,
+ const char *message,
+ ...) GNUC_PRINTF(4, 5) CLANG_ANALYZER_NORETURN;
+
+void p11_test_todo (const char *filename,
+ int line,
+ const char *function,
+ const char *message,
+ ...) GNUC_PRINTF(4, 5) CLANG_ANALYZER_NORETURN;
+
void p11_test (void (* function) (void),
const char *name,
...) GNUC_PRINTF(2, 3);