| 1 | /* |
| 2 | * fio unittest |
| 3 | * Copyright (C) 2018 Tomohiro Kusumi <kusumi.tomohiro@osnexus.com> |
| 4 | */ |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | |
| 9 | #include "./unittest.h" |
| 10 | |
| 11 | /* XXX workaround lib/memalign.c's dependency on smalloc.c */ |
| 12 | void *smalloc(size_t size) |
| 13 | { |
| 14 | return malloc(size); |
| 15 | } |
| 16 | |
| 17 | void sfree(void *ptr) |
| 18 | { |
| 19 | free(ptr); |
| 20 | } |
| 21 | |
| 22 | CU_ErrorCode fio_unittest_add_suite(const char *name, CU_InitializeFunc initfn, |
| 23 | CU_CleanupFunc cleanfn, struct fio_unittest_entry *tvec) |
| 24 | { |
| 25 | CU_pSuite pSuite; |
| 26 | struct fio_unittest_entry *t; |
| 27 | |
| 28 | pSuite = CU_add_suite(name, initfn, cleanfn); |
| 29 | if (!pSuite) { |
| 30 | CU_cleanup_registry(); |
| 31 | return CU_get_error(); |
| 32 | } |
| 33 | |
| 34 | t = tvec; |
| 35 | while (t && t->name) { |
| 36 | if (!CU_add_test(pSuite, t->name, t->fn)) { |
| 37 | CU_cleanup_registry(); |
| 38 | return CU_get_error(); |
| 39 | } |
| 40 | t++; |
| 41 | } |
| 42 | |
| 43 | return CUE_SUCCESS; |
| 44 | } |
| 45 | |
| 46 | static void fio_unittest_register(CU_ErrorCode (*fn)(void)) |
| 47 | { |
| 48 | if (fn && fn() != CUE_SUCCESS) { |
| 49 | fprintf(stderr, "%s\n", CU_get_error_msg()); |
| 50 | exit(1); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | int main(void) |
| 55 | { |
| 56 | if (CU_initialize_registry() != CUE_SUCCESS) { |
| 57 | fprintf(stderr, "%s\n", CU_get_error_msg()); |
| 58 | exit(1); |
| 59 | } |
| 60 | |
| 61 | fio_unittest_register(fio_unittest_lib_memalign); |
| 62 | fio_unittest_register(fio_unittest_lib_strntol); |
| 63 | fio_unittest_register(fio_unittest_oslib_strlcat); |
| 64 | fio_unittest_register(fio_unittest_oslib_strndup); |
| 65 | |
| 66 | CU_basic_set_mode(CU_BRM_VERBOSE); |
| 67 | CU_basic_run_tests(); |
| 68 | CU_cleanup_registry(); |
| 69 | |
| 70 | return CU_get_error(); |
| 71 | } |