1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/* Copyright (c) 2015, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdarg.h>
#include <odp.h>
#include <CUnit/Basic.h>
int replacement_logging_used;
ODP_PRINTF_FORMAT(2, 3)
static int odp_init_log(odp_log_level_e level, const char *fmt, ...);
static void test_odp_init_global_replace_log(void)
{
int status;
struct odp_init_t init_data;
memset(&init_data, 0, sizeof(init_data));
init_data.log_fn = &odp_init_log;
replacement_logging_used = 0;
status = odp_init_global(&init_data, NULL);
CU_ASSERT_FATAL(status == 0);
CU_ASSERT_TRUE(replacement_logging_used);
status = odp_term_global();
CU_ASSERT(status == 0);
}
CU_TestInfo test_odp_init[] = {
{"replace log", test_odp_init_global_replace_log},
CU_TEST_INFO_NULL,
};
CU_SuiteInfo odp_testsuites[] = {
{"Init", NULL, NULL, NULL, NULL, test_odp_init},
CU_SUITE_INFO_NULL,
};
int main(void)
{
int ret;
printf("\tODP API version: %s\n", odp_version_api_str());
printf("\tODP implementation version: %s\n", odp_version_impl_str());
CU_set_error_action(CUEA_ABORT);
CU_initialize_registry();
CU_register_suites(odp_testsuites);
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
ret = CU_get_number_of_failure_records();
CU_cleanup_registry();
return ret;
}
int odp_init_log(odp_log_level_e level __attribute__((unused)),
const char *fmt, ...)
{
va_list args;
int r;
/* just set a flag to be sure the replacement fn was used */
replacement_logging_used = 1;
va_start(args, fmt);
r = vfprintf(stderr, fmt, args);
va_end(args);
return r;
}
|