Skip to content

Commit a92214b

Browse files
nordic-krchcarlescufi
authored andcommitted
tests: lib: cbprintf_package: Extend to test static packaging
Extend test to validate cbprintf static packaging on various platforms. Added more test configurations: complete, nano, long double. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent f946892 commit a92214b

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
CONFIG_ZTEST=y
2-
CONFIG_CBPRINTF_COMPLETE=y

tests/lib/cbprintf_package/src/main.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ static int out(int c, void *dest)
2727
return rv;
2828
}
2929

30-
static char runtime_buf[128];
30+
static char static_buf[512];
31+
static char runtime_buf[512];
3132
static char compare_buf[128];
3233

3334
void dump(const char *desc, uint8_t *package, size_t len)
@@ -58,13 +59,23 @@ void unpack(const char *desc, struct out_buffer *buf,
5859
}; \
5960
int rc = cbprintf_package(NULL, 0, fmt, __VA_ARGS__); \
6061
zassert_true(rc > 0, "cbprintf_package() returned %d", rc); \
61-
size_t len = rc; \
62-
uint8_t __aligned(8) rt_package[len]; \
62+
int len = rc; \
63+
/* Aligned so the package is similar to the static one. */ \
64+
uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) rt_package[len]; \
6365
memset(rt_package, 0, len); \
6466
rc = cbprintf_package(rt_package, len, fmt, __VA_ARGS__); \
6567
zassert_equal(rc, len, "cbprintf_package() returned %d, expected %d", rc, len); \
6668
dump("runtime", rt_package, len); \
6769
unpack("runtime", &rt_buf, rt_package, len); \
70+
\
71+
struct out_buffer st_buf = { \
72+
.buf = static_buf, .idx = 0, .size = sizeof(static_buf) \
73+
}; \
74+
CBPRINTF_STATIC_PACKAGE(NULL, 0, len, fmt, __VA_ARGS__); \
75+
uint8_t __aligned(CBPRINTF_PACKAGE_ALIGNMENT) package[len]; \
76+
CBPRINTF_STATIC_PACKAGE(package, len, len, fmt, __VA_ARGS__); \
77+
dump("static", package, len); \
78+
unpack("static", &st_buf, package, len); \
6879
} while (0)
6980

7081
void test_cbprintf_package(void)
@@ -97,6 +108,11 @@ void test_cbprintf_package(void)
97108
TEST_PACKAGING("test %c %p", c, &c);
98109
if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) {
99110
TEST_PACKAGING("test %f %a", f, d);
111+
#if CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE
112+
long double ld = 1.2333;
113+
114+
TEST_PACKAGING("test %Lf", ld);
115+
#endif
100116
}
101117
}
102118

tests/lib/cbprintf_package/testcase.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ tests:
77
qemu_arc_em qemu_arc_hs qemu_cortex_a53 qemu_cortex_m0 qemu_cortex_m3
88
qemu_cortex_r5 qemu_leon3 qemu_nios2 qemu_riscv32 qemu_riscv64 qemu_x86
99
qemu_x86_64 qemu_xtensa
10+
extra_configs:
11+
- CONFIG_CBPRINTF_COMPLETE=y
12+
1013
libraries.cbprintf_package_fp:
1114
tags: cbprintf
1215
integration_platforms:
@@ -17,3 +20,29 @@ tests:
1720
qemu_x86_64 qemu_xtensa
1821
extra_configs:
1922
- CONFIG_CBPRINTF_FP_SUPPORT=y
23+
- CONFIG_CBPRINTF_COMPLETE=y
24+
25+
libraries.cbprintf_package_long_double:
26+
tags: cbprintf
27+
integration_platforms:
28+
- native_posix
29+
platform_allow: >
30+
qemu_arc_em qemu_arc_hs qemu_cortex_a53 qemu_cortex_m0 qemu_cortex_m3
31+
qemu_cortex_r5 qemu_leon3 qemu_nios2 qemu_riscv64
32+
qemu_x86_64 qemu_xtensa
33+
platform_exclude: qemu_riscv32
34+
extra_configs:
35+
- CONFIG_CBPRINTF_FP_SUPPORT=y
36+
- CONFIG_CBPRINTF_COMPLETE=y
37+
- CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE=y
38+
39+
libraries.cbprintf_package_nano:
40+
tags: cbprintf
41+
integration_platforms:
42+
- native_posix
43+
platform_allow: >
44+
qemu_arc_em qemu_arc_hs qemu_cortex_a53 qemu_cortex_m0 qemu_cortex_m3
45+
qemu_cortex_r5 qemu_leon3 qemu_nios2 qemu_riscv32 qemu_riscv64 qemu_x86
46+
qemu_x86_64 qemu_xtensa
47+
extra_configs:
48+
- CONFIG_CBPRINTF_NANO=y

0 commit comments

Comments
 (0)