tests: lib: cbprintf: Update test after adding alignment parameter
Add validation of the case when package buffer is not aligned to CBPRINTF_PACKAGE_ALIGNMENT. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
4cbded9cc2
commit
0e39b7d707
2 changed files with 52 additions and 12 deletions
|
@ -9,6 +9,12 @@
|
|||
|
||||
#define CBPRINTF_DEBUG 1
|
||||
|
||||
#ifndef CBPRINTF_PACKAGE_ALIGN_OFFSET
|
||||
#define CBPRINTF_PACKAGE_ALIGN_OFFSET 0
|
||||
#endif
|
||||
|
||||
#define ALIGN_OFFSET (sizeof(void *) * CBPRINTF_PACKAGE_ALIGN_OFFSET)
|
||||
|
||||
struct out_buffer {
|
||||
char *buf;
|
||||
size_t idx;
|
||||
|
@ -54,31 +60,37 @@ void unpack(const char *desc, struct out_buffer *buf,
|
|||
snprintf(compare_buf, sizeof(compare_buf), fmt, __VA_ARGS__); \
|
||||
printk("-----------------------------------------\n"); \
|
||||
printk("%s\n", compare_buf); \
|
||||
uint8_t *pkg; \
|
||||
struct out_buffer rt_buf = { \
|
||||
.buf = runtime_buf, .idx = 0, .size = sizeof(runtime_buf) \
|
||||
}; \
|
||||
int rc = cbprintf_package(NULL, 0, fmt, __VA_ARGS__); \
|
||||
int rc = cbprintf_package(NULL, ALIGN_OFFSET, fmt, __VA_ARGS__); \
|
||||
zassert_true(rc > 0, "cbprintf_package() returned %d", rc); \
|
||||
int len = rc; \
|
||||
/* Aligned so the package is similar to the static one. */ \
|
||||
uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) rt_package[len]; \
|
||||
memset(rt_package, 0, len); \
|
||||
rc = cbprintf_package(rt_package, len, fmt, __VA_ARGS__); \
|
||||
zassert_equal(rc, len, "cbprintf_package() returned %d, expected %d", rc, len); \
|
||||
dump("runtime", rt_package, len); \
|
||||
unpack("runtime", &rt_buf, rt_package, len); \
|
||||
uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) \
|
||||
rt_package[len + ALIGN_OFFSET]; \
|
||||
memset(rt_package, 0, len + ALIGN_OFFSET); \
|
||||
pkg = &rt_package[ALIGN_OFFSET]; \
|
||||
rc = cbprintf_package(pkg, len, fmt, __VA_ARGS__); \
|
||||
zassert_equal(rc, len, "cbprintf_package() returned %d, expected %d", \
|
||||
rc, len); \
|
||||
dump("runtime", pkg, len); \
|
||||
unpack("runtime", &rt_buf, pkg, len); \
|
||||
\
|
||||
struct out_buffer st_buf = { \
|
||||
.buf = static_buf, .idx = 0, .size = sizeof(static_buf) \
|
||||
}; \
|
||||
CBPRINTF_STATIC_PACKAGE(NULL, 0, len, fmt, __VA_ARGS__); \
|
||||
CBPRINTF_STATIC_PACKAGE(NULL, 0, len, ALIGN_OFFSET, fmt, __VA_ARGS__); \
|
||||
zassert_true(len > 0, "CBPRINTF_STATIC_PACKAGE() returned %d", len); \
|
||||
uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package[len]; \
|
||||
uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) \
|
||||
package[len + ALIGN_OFFSET];\
|
||||
int outlen; \
|
||||
CBPRINTF_STATIC_PACKAGE(package, len, outlen, fmt, __VA_ARGS__); \
|
||||
pkg = &package[ALIGN_OFFSET]; \
|
||||
CBPRINTF_STATIC_PACKAGE(pkg, len, outlen, ALIGN_OFFSET, fmt, __VA_ARGS__);\
|
||||
zassert_equal(len, outlen, NULL); \
|
||||
dump("static", package, len); \
|
||||
unpack("static", &st_buf, package, len); \
|
||||
dump("static", pkg, len); \
|
||||
unpack("static", &st_buf, pkg, len); \
|
||||
} while (0)
|
||||
|
||||
void test_cbprintf_package(void)
|
||||
|
|
|
@ -34,6 +34,19 @@ tests:
|
|||
- CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||
- CONFIG_CBPRINTF_COMPLETE=y
|
||||
|
||||
libraries.cbprintf_package_fp_align_offset:
|
||||
tags: cbprintf
|
||||
integration_platforms:
|
||||
- native_posix
|
||||
platform_allow: >
|
||||
qemu_arc_em qemu_arc_hs qemu_cortex_a53 qemu_cortex_m0 qemu_cortex_m3
|
||||
qemu_cortex_r5 qemu_leon3 qemu_nios2 qemu_riscv32 qemu_riscv64
|
||||
qemu_x86_64
|
||||
extra_configs:
|
||||
- CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||
- CONFIG_CBPRINTF_COMPLETE=y
|
||||
- CONFIG_COMPILER_OPT="-DCBPRINTF_PACKAGE_ALIGN_OFFSET=1"
|
||||
|
||||
libraries.cbprintf_package_long_double:
|
||||
tags: cbprintf
|
||||
integration_platforms:
|
||||
|
@ -48,6 +61,21 @@ tests:
|
|||
- CONFIG_CBPRINTF_COMPLETE=y
|
||||
- CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE=y
|
||||
|
||||
libraries.cbprintf_package_long_double_align_offset:
|
||||
tags: cbprintf
|
||||
integration_platforms:
|
||||
- native_posix
|
||||
platform_allow: >
|
||||
qemu_arc_em qemu_arc_hs qemu_cortex_a53 qemu_cortex_m0 qemu_cortex_m3
|
||||
qemu_cortex_r5 qemu_leon3 qemu_nios2 qemu_riscv64
|
||||
qemu_x86_64
|
||||
platform_exclude: qemu_riscv32
|
||||
extra_configs:
|
||||
- CONFIG_CBPRINTF_FP_SUPPORT=y
|
||||
- CONFIG_CBPRINTF_COMPLETE=y
|
||||
- CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE=y
|
||||
- CONFIG_COMPILER_OPT="-DCBPRINTF_PACKAGE_ALIGN_OFFSET=1"
|
||||
|
||||
libraries.cbprintf_package_nano:
|
||||
tags: cbprintf
|
||||
integration_platforms:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue