summaryrefslogtreecommitdiff
path: root/unittests/unittest.c
blob: c37e1971a0518544c2cdc136b5e276f387b16d4e (plain)
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
/*
 * 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);
	}

	fio_unittest_register(fio_unittest_lib_memalign);
	fio_unittest_register(fio_unittest_lib_strntol);
	fio_unittest_register(fio_unittest_oslib_strlcat);
	fio_unittest_register(fio_unittest_oslib_strndup);
	fio_unittest_register(fio_unittest_oslib_strcasestr);
	fio_unittest_register(fio_unittest_oslib_strsep);

	CU_basic_set_mode(CU_BRM_VERBOSE);
	CU_basic_run_tests();
	CU_cleanup_registry();

	return CU_get_error();
}