1 /*
2 * Copyright (c) 2021 Nordic Semiconductor
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifndef SRC_MOCK_BACKEND_H__
8 #define SRC_MOCK_BACKEND_H__
9
10 #include <zephyr/logging/log_backend.h>
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 extern const struct log_backend_api mock_log_backend_api;
17
18 struct mock_log_backend_msg {
19 log_timestamp_t timestamp;
20 uint16_t source_id;
21 uint16_t domain_id;
22 uint8_t level;
23 bool check;
24 char str[128];
25 uint8_t data[32];
26 uint32_t data_len;
27 };
28
29 struct mock_log_backend {
30 bool do_check;
31 bool panic;
32 struct mock_log_backend_msg exp_msgs[64];
33 int msg_rec_idx;
34 int msg_proc_idx;
35 int exp_drop_cnt;
36 int drop_cnt;
37
38 #if defined(CONFIG_LOG_MODE_DEFERRED) && \
39 defined(CONFIG_LOG_PROCESS_THREAD)
40 bool evt_notified;
41 #endif
42 };
43
44 void mock_log_backend_reset(const struct log_backend *backend);
45 void mock_log_backend_check_enable(const struct log_backend *backend);
46 void mock_log_backend_check_disable(const struct log_backend *backend);
47
48 void mock_log_backend_dummy_record(const struct log_backend *backend, int cnt);
49
50 void mock_log_backend_drop_record(const struct log_backend *backend, int cnt);
51
52 void mock_log_backend_generic_record(const struct log_backend *backend,
53 uint16_t source_id,
54 uint16_t domain_id,
55 uint8_t level,
56 log_timestamp_t timestamp,
57 const char *str,
58 uint8_t *data,
59 uint32_t data_len);
60
mock_log_backend_record(const struct log_backend * backend,uint16_t source_id,uint16_t domain_id,uint8_t level,log_timestamp_t timestamp,const char * str)61 static inline void mock_log_backend_record(const struct log_backend *backend,
62 uint16_t source_id,
63 uint16_t domain_id,
64 uint8_t level,
65 log_timestamp_t timestamp,
66 const char *str)
67 {
68 mock_log_backend_generic_record(backend, source_id, domain_id, level,
69 timestamp, str, NULL, 0);
70 }
71
72 void mock_log_backend_validate(const struct log_backend *backend, bool panic);
73
74
75 #define MOCK_LOG_BACKEND_DEFINE(name, autostart) \
76 static struct mock_log_backend name##_mock; \
77 LOG_BACKEND_DEFINE(name, mock_log_backend_api, autostart, &name##_mock)
78
79 #ifdef __cplusplus
80 }
81 #endif
82
83 #endif /* SRC_MOCK_BACKEND_H__ */
84