1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2016 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef SPDK_CUNIT_H 7 #define SPDK_CUNIT_H 8 9 #include "spdk/stdinc.h" 10 11 #include <CUnit/Basic.h> 12 13 /* 14 * CU_ASSERT_FATAL calls a function that does a longjmp() internally, but only for fatal asserts, 15 * so the function itself is not marked as noreturn. Add an abort() after the assert to help 16 * static analyzers figure out that it really doesn't return. 17 * The abort() will never actually execute. 18 */ 19 #define SPDK_CU_ASSERT_FATAL(cond) \ 20 do { \ 21 int result_ = !!(cond); \ 22 CU_ASSERT_FATAL(result_); \ 23 if (!result_) { \ 24 abort(); \ 25 } \ 26 } while (0) 27 28 /** Extra option callback */ 29 typedef int (*spdk_ut_option_cb)(int opt, const char *optarg, void *cb_arg); 30 31 /** Extra usage callback, called when user asks for --help */ 32 typedef void (*spdk_ut_usage_cb)(void *cb_arg); 33 34 /** Init callback, called before tests are executed after parsing arguments */ 35 typedef int (*spdk_ut_init_cb)(void *cb_arg); 36 37 struct spdk_ut_opts { 38 /** Extra optstring */ 39 const char *optstring; 40 /** Extra options */ 41 const struct option *opts; 42 /** Number of extra options */ 43 size_t optlen; 44 /** Callback argument */ 45 void *cb_arg; 46 /** Extra option callback */ 47 spdk_ut_option_cb option_cb_fn; 48 /** Init callack */ 49 spdk_ut_init_cb init_cb_fn; 50 /** Usage callback */ 51 spdk_ut_usage_cb usage_cb_fn; 52 }; 53 54 /** 55 * Execute unit tests registered using CUnit. 56 * 57 * \param argc Size of the `argv` array. 58 * \param argv Arguments to the test app. 59 * \param opts Options. 60 * 61 * \return Number of test failures. 62 */ 63 int spdk_ut_run_tests(int argc, char **argv, const struct spdk_ut_opts *opts); 64 65 #endif /* SPDK_CUNIT_H */ 66