tests: logging: log_api: Validate CONFIG_LOG_MSG_APPEND_RO_STRING_LOC
Extended test to validate that RO string locations are appended to the cbprintf package for a log message if Kconfig option is enabled. Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
44e0a64a90
commit
4d6bce34f7
|
@ -5,4 +5,8 @@ module = SAMPLE_MODULE
|
|||
module-str = Test logging API
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
config TEST_LOG_MSG_APPEND_RO_STRING_LOC
|
||||
bool "Append read-only string locations to the package"
|
||||
select LOG_MSG_APPEND_RO_STRING_LOC
|
||||
|
||||
source "Kconfig.zephyr"
|
||||
|
|
|
@ -27,11 +27,14 @@ LOG_MODULE_REGISTER(test, CONFIG_SAMPLE_MODULE_LOG_LEVEL);
|
|||
#define LOG_SIMPLE_MSG_LEN \
|
||||
ROUND_UP(sizeof(struct log_msg) + \
|
||||
sizeof(struct cbprintf_package_hdr_ext) + \
|
||||
sizeof(int), CBPRINTF_PACKAGE_ALIGNMENT)
|
||||
sizeof(int) + (IS_ENABLED(CONFIG_LOG_MSG_APPEND_RO_STRING_LOC) ? 1 : 0), \
|
||||
CBPRINTF_PACKAGE_ALIGNMENT)
|
||||
#else
|
||||
#define LOG_SIMPLE_MSG_LEN \
|
||||
ROUND_UP(sizeof(struct log_msg) + \
|
||||
sizeof(struct cbprintf_package_hdr_ext), CBPRINTF_PACKAGE_ALIGNMENT)
|
||||
sizeof(struct cbprintf_package_hdr_ext) + \
|
||||
(IS_ENABLED(CONFIG_LOG_MSG_APPEND_RO_STRING_LOC) ? 1 : 0), \
|
||||
CBPRINTF_PACKAGE_ALIGNMENT)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LOG_TIMESTAMP_64BIT
|
||||
|
@ -366,6 +369,9 @@ static size_t get_long_hexdump(void)
|
|||
*/
|
||||
extra_hexdump_sz = sizeof(int);
|
||||
}
|
||||
if (IS_ENABLED(CONFIG_TEST_LOG_MSG_APPEND_RO_STRING_LOC)) {
|
||||
extra_msg_sz += sizeof(uint8_t); /* Location of format string. */
|
||||
}
|
||||
|
||||
return CONFIG_LOG_BUFFER_SIZE -
|
||||
/* First message */
|
||||
|
|
|
@ -167,8 +167,10 @@ static void process(const struct log_backend *const backend,
|
|||
|
||||
size_t len;
|
||||
uint8_t *data;
|
||||
struct cbprintf_package_desc *package_desc;
|
||||
|
||||
data = log_msg_get_data(&msg->log, &len);
|
||||
|
||||
zassert_equal(exp->data_len, len);
|
||||
if (exp->data_len <= sizeof(exp->data)) {
|
||||
zassert_equal(memcmp(data, exp->data, len), 0);
|
||||
|
@ -178,6 +180,15 @@ static void process(const struct log_backend *const backend,
|
|||
struct test_str s = { .str = str };
|
||||
|
||||
data = log_msg_get_package(&msg->log, &len);
|
||||
package_desc = (struct cbprintf_package_desc *)data;
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_MSG_APPEND_RO_STRING_LOC)) {
|
||||
/* If RO string locations are appended there is always at least 1: format string. */
|
||||
zassert_true(package_desc->ro_str_cnt > 0);
|
||||
} else {
|
||||
zassert_equal(package_desc->ro_str_cnt, 0);
|
||||
}
|
||||
|
||||
len = cbpprintf(out, &s, data);
|
||||
if (len > 0) {
|
||||
str[len] = '\0';
|
||||
|
|
|
@ -88,6 +88,7 @@ void log_frontend_msg(const void *source,
|
|||
uint8_t *package, const void *data)
|
||||
{
|
||||
struct mock_log_backend_msg *exp_msg = &mock.exp_msgs[mock.msg_proc_idx];
|
||||
struct cbprintf_package_desc *package_desc = (struct cbprintf_package_desc *)package;
|
||||
|
||||
if (mock.do_check == false) {
|
||||
return;
|
||||
|
@ -99,6 +100,13 @@ void log_frontend_msg(const void *source,
|
|||
return;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_MSG_APPEND_RO_STRING_LOC)) {
|
||||
/* If RO string locations are appended there is always at least 1: format string. */
|
||||
zassert_true(package_desc->ro_str_cnt > 0);
|
||||
} else {
|
||||
zassert_equal(package_desc->ro_str_cnt, 0);
|
||||
}
|
||||
|
||||
zassert_equal(desc.level, exp_msg->level);
|
||||
zassert_equal(desc.domain, exp_msg->domain_id);
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ tests:
|
|||
extra_configs:
|
||||
- CONFIG_LOG_MODE_DEFERRED=y
|
||||
- CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG=y
|
||||
- CONFIG_TEST_LOG_MSG_APPEND_RO_STRING_LOC=y
|
||||
|
||||
logging.deferred.api.printk:
|
||||
extra_configs:
|
||||
|
@ -105,6 +106,7 @@ tests:
|
|||
extra_configs:
|
||||
- CONFIG_LOG_FRONTEND=y
|
||||
- CONFIG_LOG_MODE_DEFERRED=y
|
||||
- CONFIG_TEST_LOG_MSG_APPEND_RO_STRING_LOC=y
|
||||
|
||||
logging.frontend.rt_filtering:
|
||||
extra_configs:
|
||||
|
|
Loading…
Reference in a new issue