1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
10 #include <ecoli_log.h>
15 #define EC_TEST_REGISTER(t) \
16 static void ec_test_init_##t(void); \
17 static void __attribute__((constructor, used)) \
18 ec_test_init_##t(void) \
20 if (ec_test_register(&t) < 0) \
21 fprintf(stderr, "cannot register test %s\n", \
26 * Type of test function. Return 0 on success, -1 on error.
28 typedef int (ec_test_t)(void);
30 TAILQ_HEAD(ec_test_list, ec_test);
33 * A structure describing a test case.
36 TAILQ_ENTRY(ec_test) next; /**< Next in list. */
37 const char *name; /**< Test name. */
38 ec_test_t *test; /**< Test function. */
42 * Register a test case.
45 * A pointer to a ec_test structure describing the test
48 * 0 on success, -1 on error (errno is set).
50 int ec_test_register(struct ec_test *test);
52 int ec_test_all(void);
53 int ec_test_one(const char *name);
55 /* expected == -1 means no match */
56 int ec_test_check_parse(struct ec_node *node, int expected, ...);
58 #define EC_TEST_ERR(fmt, ...) \
59 EC_LOG(EC_LOG_ERR, "%s:%d: error: " fmt "\n", \
60 __FILE__, __LINE__, ##__VA_ARGS__); \
62 #define EC_TEST_CHECK(cond, fmt, ...) ({ \
65 EC_TEST_ERR("(" #cond ") is wrong. " fmt \
72 /* node, input, [expected1, expected2, ...] */
73 #define EC_TEST_CHECK_PARSE(node, args...) ({ \
74 int ret_ = ec_test_check_parse(node, args, EC_NODE_ENDLIST); \
76 EC_TEST_ERR("parse test failed"); \
80 int ec_test_check_complete(struct ec_node *node,
81 enum ec_comp_type type, ...);
83 #define EC_TEST_CHECK_COMPLETE(node, args...) ({ \
84 int ret_ = ec_test_check_complete(node, EC_COMP_FULL, args); \
86 EC_TEST_ERR("complete test failed"); \
90 #define EC_TEST_CHECK_COMPLETE_PARTIAL(node, args...) ({ \
91 int ret_ = ec_test_check_complete(node, EC_COMP_PARTIAL, args); \
93 EC_TEST_ERR("complete test failed"); \