1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2018 Intel Corporation. All rights reserved. 4 * 5 * Author: Michal Jerzy Wierzbicki <michalx.wierzbicki@linux.intel.com> 6 */ 7 8 #include <test_simple_macro.h> 9 #include <sof/trace/preproc.h> 10 #include <rtos/sof.h> 11 #include <rtos/alloc.h> 12 13 /* CMOCKA SETUP */ 14 #define setup_alloc(ptr, type, size, offset) do {\ 15 if (ptr)\ 16 free(ptr);\ 17 ptr = malloc(sizeof(type) * (size) + offset);\ 18 if (ptr == NULL)\ 19 return -1;\ 20 } while (0) 21 22 #define setup_part(result, setup_func) do {\ 23 result |= setup_func;\ 24 if (result)\ 25 return result;\ 26 } while (0) 27 28 /* TEST GROUPS GENERATORS */ 29 30 #define gen_test_concat(prefix, name) META_CONCAT_SEQ_DELIM_(prefix, name) 31 #define gen_test_concat_base(prefix) META_CONCAT_SEQ_DELIM_(prefix, base) 32 #define gen_test_concat_func(prefix, name, ...) \ 33 META_CONCAT_SEQ_DELIM_(prefix, name, for, __VA_ARGS__) 34 #define gen_test_concat_flag(prefix, ...) \ 35 META_CONCAT_SEQ_DELIM_(prefix, isetup, for, __VA_ARGS__) 36 37 // make function body for "${prefix}_${name}_for_${dlen}_${cbeg}_${cend}" 38 #define gen_test_with_prefix(prefix_check, prefix_setup, name, ...) \ 39 static void gen_test_concat_func(prefix_setup, name, __VA_ARGS__) \ 40 (void **state) {\ 41 if (!gen_test_concat_flag(prefix_setup, __VA_ARGS__)) {\ 42 if (_setup(state, __VA_ARGS__))\ 43 exit(1);\ 44 gen_test_concat_base(prefix_setup)(state);\ 45 ++gen_test_concat_flag(prefix_setup, __VA_ARGS__);\ 46 } \ 47 gen_test_concat(prefix_check, name)(state);\ 48 } 49 50 #define c_u_t_concat(prefix_check, prefix_setup, name, ...)\ 51 c_u_t(gen_test_concat_func(prefix_setup, name, __VA_ARGS__)), 52 53 /* make function bodies for 54 * function group "${prefix}_for_${dlen}_${cbeg}_${cend}" 55 */ 56 #define gen_test_group(bind_macro, ...)\ 57 bind_macro(gen_test_with_prefix, __VA_ARGS__) 58 59 /* create 1 flag for 60 * function group "${prefix}_for_${dlen}_${cbeg}_${cend}" 61 */ 62 #define flg_test_group(prefix, ...)\ 63 static int gen_test_concat_flag(prefix, __VA_ARGS__); 64 65 /* paste instances to 66 * function grup "${prefix}_for_${dlen}_${cbeg}_${cend}" 67 */ 68 #define use_test_group(bind_macro, ...)\ 69 bind_macro(c_u_t_concat, __VA_ARGS__) 70 71 /* for example usage, see /test/cmocka/src/lib/lib/strcheck.c 72 * section TEST GROUPS GENERATORS 73 */ 74