Bluetooth: Host: Remove printk dependency from settings
Some modules use snprintk to format the settings keys. Unfortunately snprintk is tied with printk which is very large for some embedded systems. To be able to have settings enabled without also enabling printk support, change creation of settings key strings to use bin2hex, strlen and strcpy instead. A utility function to make decimal presentation of a byte value is added as u8_to_dec in lib/os/dec.c Add new Kconfig setting BT_SETTINGS_USE_PRINTK Signed-off-by: Kim Sekkelund <ksek@oticon.com>
This commit is contained in:
parent
9828b0fae8
commit
0450263393
11 changed files with 215 additions and 29 deletions
8
tests/lib/sys/util/CMakeLists.txt
Normal file
8
tests/lib/sys/util/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(lib_sys_util_tests)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
1
tests/lib/sys/util/prj.conf
Normal file
1
tests/lib/sys/util/prj.conf
Normal file
|
@ -0,0 +1 @@
|
|||
CONFIG_ZTEST=y
|
81
tests/lib/sys/util/src/main.c
Normal file
81
tests/lib/sys/util/src/main.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Oticon A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <sys/util.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* @brief Test of u8_to_dec
|
||||
*
|
||||
* This test verifies conversion of various input values.
|
||||
*
|
||||
*/
|
||||
static void test_u8_to_dec(void)
|
||||
{
|
||||
char text[4];
|
||||
u8_t len;
|
||||
|
||||
len = u8_to_dec(text, sizeof(text), 0);
|
||||
zassert_equal(len, 1, "Length of 0 is not 1");
|
||||
zassert_equal(strcmp(text, "0"), 0,
|
||||
"Value=0 is not converted to \"0\"");
|
||||
|
||||
len = u8_to_dec(text, sizeof(text), 1);
|
||||
zassert_equal(len, 1, "Length of 1 is not 1");
|
||||
zassert_equal(strcmp(text, "1"), 0,
|
||||
"Value=1 is not converted to \"1\"");
|
||||
|
||||
len = u8_to_dec(text, sizeof(text), 11);
|
||||
zassert_equal(len, 2, "Length of 11 is not 2");
|
||||
zassert_equal(strcmp(text, "11"), 0,
|
||||
"Value=10 is not converted to \"11\"");
|
||||
|
||||
len = u8_to_dec(text, sizeof(text), 100);
|
||||
zassert_equal(len, 3, "Length of 100 is not 3");
|
||||
zassert_equal(strcmp(text, "100"), 0,
|
||||
"Value=100 is not converted to \"100\"");
|
||||
|
||||
len = u8_to_dec(text, sizeof(text), 101);
|
||||
zassert_equal(len, 3, "Length of 101 is not 3");
|
||||
zassert_equal(strcmp(text, "101"), 0,
|
||||
"Value=101 is not converted to \"101\"");
|
||||
|
||||
len = u8_to_dec(text, sizeof(text), 255);
|
||||
zassert_equal(len, 3, "Length of 255 is not 3");
|
||||
zassert_equal(strcmp(text, "255"), 0,
|
||||
"Value=255 is not converted to \"255\"");
|
||||
|
||||
memset(text, 0, sizeof(text));
|
||||
len = u8_to_dec(text, 2, 123);
|
||||
zassert_equal(len, 2,
|
||||
"Length of converted value using 2 byte buffer isn't 2");
|
||||
zassert_equal(
|
||||
strcmp(text, "12"), 0,
|
||||
"Value=123 is not converted to \"12\" using 2-byte buffer");
|
||||
|
||||
memset(text, 0, sizeof(text));
|
||||
len = u8_to_dec(text, 1, 123);
|
||||
zassert_equal(len, 1,
|
||||
"Length of converted value using 1 byte buffer isn't 1");
|
||||
zassert_equal(
|
||||
strcmp(text, "1"), 0,
|
||||
"Value=123 is not converted to \"1\" using 1-byte buffer");
|
||||
|
||||
memset(text, 0, sizeof(text));
|
||||
len = u8_to_dec(text, 0, 123);
|
||||
zassert_equal(len, 0,
|
||||
"Length of converted value using 0 byte buffer isn't 0");
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(test_lib_sys_util_tests,
|
||||
ztest_unit_test(test_u8_to_dec)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(test_lib_sys_util_tests);
|
||||
}
|
3
tests/lib/sys/util/testcase.yaml
Normal file
3
tests/lib/sys/util/testcase.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
tests:
|
||||
libraries.sys.util.dec:
|
||||
tags: lib_sys_util_tests
|
Loading…
Add table
Add a link
Reference in a new issue