summaryrefslogtreecommitdiff
path: root/unittests/unittest.c
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/unittest.c')
-rw-r--r--unittests/unittest.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/unittests/unittest.c b/unittests/unittest.c
new file mode 100644
index 00000000..bc75bb6e
--- /dev/null
+++ b/unittests/unittest.c
@@ -0,0 +1,58 @@
+/*
+ * fio unittest
+ * Copyright (C) 2018 Tomohiro Kusumi <kusumi.tomohiro@osnexus.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "./unittest.h"
+
+CU_ErrorCode fio_unittest_add_suite(const char *name, CU_InitializeFunc initfn,
+ CU_CleanupFunc cleanfn, struct fio_unittest_entry *tvec)
+{
+ CU_pSuite pSuite;
+ struct fio_unittest_entry *t;
+
+ pSuite = CU_add_suite(name, initfn, cleanfn);
+ if (!pSuite) {
+ CU_cleanup_registry();
+ return CU_get_error();
+ }
+
+ t = tvec;
+ while (t && t->name) {
+ if (!CU_add_test(pSuite, t->name, t->fn)) {
+ CU_cleanup_registry();
+ return CU_get_error();
+ }
+ t++;
+ }
+
+ return CUE_SUCCESS;
+}
+
+static void fio_unittest_register(CU_ErrorCode (*fn)(void))
+{
+ if (fn && fn() != CUE_SUCCESS) {
+ fprintf(stderr, "%s\n", CU_get_error_msg());
+ exit(1);
+ }
+}
+
+int main(void)
+{
+ if (CU_initialize_registry() != CUE_SUCCESS) {
+ fprintf(stderr, "%s\n", CU_get_error_msg());
+ exit(1);
+ }
+
+ /* Register unittest suites. */
+ fio_unittest_register(NULL); /* prevent unused warning */
+
+ CU_basic_set_mode(CU_BRM_VERBOSE);
+ CU_basic_run_tests();
+ CU_cleanup_registry();
+
+ return CU_get_error();
+}