1 /* 2 * Copyright (c) 2023 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _IUT_H_ 8 #define _IUT_H_ 9 10 #include <stdint.h> 11 12 typedef int (*iut_test_func)(int argc, char **argv); 13 14 struct iut_case { 15 16 const char *const name; 17 18 const char *const group; 19 20 /* test function to run */ 21 const iut_test_func func; 22 23 uint32_t attri; 24 }; 25 26 #define IUT_ATTRI_NONE ((uint32_t)0x0) 27 #define IUT_ATTRI_AUTORUN ((uint32_t)(0x1 << 0)) 28 29 #define DEFINE_IUT_CASE(_name, _group, _attri) \ 30 struct iut_case iut_##_name\ 31 __attribute__((__used__)) \ 32 __attribute__((__section__(".iut_cases."#_group"."#_name))) = { \ 33 .name = #_name, \ 34 .group = #_group, \ 35 .func = &test_##_name, \ 36 .attri = _attri, \ 37 } 38 39 extern const char __iut_cases_start[]; 40 extern const char __iut_cases_end[]; 41 42 #include <zephyr/sys/printk.h> 43 #define iut_print(fmt, arg...) printk(fmt, ## arg) 44 45 extern const struct iut_case *iut_running; 46 47 #define iut_case_print(fmt, arg...) \ 48 iut_print("IUT: (%s, %s): "fmt, iut_running->group, iut_running->name, ## arg) 49 50 /* for strtoul */ 51 #include <stdlib.h> 52 53 #ifndef ARG_UNUSED 54 #define ARG_UNUSED(arg) ((void)arg) 55 #endif 56 57 #define IUT_ERR_OK (0) 58 #define IUT_ERR_ASSERT (-1) 59 60 #define TEST_ASSERT_TRUE(_expr) \ 61 do { \ 62 if (_expr) \ 63 break; \ 64 printk("%s:%d: ASSERT failed\n", __FILE__, __LINE__); \ 65 return IUT_ERR_ASSERT; \ 66 } while (0) 67 68 #define TEST_ASSERT_EQUAL(_expr1, _expr2) \ 69 TEST_ASSERT_TRUE((_expr1) == (_expr2)) 70 71 #endif 72