Skip to content

Commit 859be8c

Browse files
yonschnashif
authored andcommitted
tests: bindesc: Added definition tests
Added tests for the bindesc subsystem, testing definition of binary descriptors on several qemu architectures, and using several C standards (c99, c11, etc.). Signed-off-by: Yonatan Schachter <[email protected]>
1 parent 726e14e commit 859be8c

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2023 Yonatan Schachter
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
cmake_minimum_required(VERSION 3.20.0)
6+
7+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
8+
project(bindesc)
9+
10+
target_sources(app PRIVATE src/main.c)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2023 Yonatan Schachter
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
CONFIG_ZTEST=y
6+
CONFIG_ZTEST_NEW_API=y
7+
8+
CONFIG_BINDESC=y
9+
CONFIG_BINDESC_DEFINE=y
10+
11+
CONFIG_BINDESC_DEFINE_VERSION=y
12+
CONFIG_BINDESC_KERNEL_VERSION_NUMBER=y
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2023 Yonatan Schachter
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
#include <zephyr/bindesc.h>
9+
#include <version.h>
10+
11+
#define STR_ID 1
12+
#define UINT_ID 2
13+
#define BYTES_ID 3
14+
15+
#define STR_DATA "Hello world!"
16+
#define UINT_DATA 5
17+
#define BYTES_DATA {1, 2, 3, 4}
18+
19+
BINDESC_STR_DEFINE(bindesc_string, STR_ID, STR_DATA);
20+
BINDESC_UINT_DEFINE(bindesc_uint, UINT_ID, UINT_DATA);
21+
BINDESC_BYTES_DEFINE(bindesc_bytes, BYTES_ID, (BYTES_DATA));
22+
23+
ZTEST(bindesc_define, test_version_number)
24+
{
25+
zassert_equal(BINDESC_GET_UINT(kernel_version_number), KERNEL_VERSION_NUMBER,
26+
"bindesc kernel version number is incorrect");
27+
}
28+
29+
ZTEST(bindesc_define, test_custom_bindesc_str)
30+
{
31+
zassert_equal(BINDESC_GET_SIZE(bindesc_string), sizeof(STR_DATA));
32+
zassert_mem_equal(BINDESC_GET_STR(bindesc_string), STR_DATA, sizeof(STR_DATA));
33+
}
34+
35+
ZTEST(bindesc_define, test_custom_bindesc_uint)
36+
{
37+
zassert_equal(BINDESC_GET_SIZE(bindesc_uint), 4);
38+
zassert_equal(BINDESC_GET_UINT(bindesc_uint), UINT_DATA);
39+
}
40+
41+
ZTEST(bindesc_define, test_custom_bindesc_bytes)
42+
{
43+
uint8_t expected_data[] = BYTES_DATA;
44+
45+
zassert_equal(BINDESC_GET_SIZE(bindesc_bytes), 4);
46+
zassert_mem_equal(BINDESC_GET_STR(bindesc_bytes), expected_data, 4);
47+
}
48+
49+
ZTEST_SUITE(bindesc_define, NULL, NULL, NULL, NULL, NULL);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tests:
2+
bindesc.define:
3+
tags: bindesc
4+
platform_allow: >
5+
native_posix qemu_x86 qemu_cortex_m0 qemu_cortex_m3
6+
qemu_cortex_r5 qemu_arc_em qemu_arc_hs qemu_arc_hs5x
7+
qemu_arc_hs6x qemu_riscv32 qemu_riscv32e qemu_riscv64
8+
bindesc.define.c99:
9+
platform_allow: native_posix
10+
tags: bindesc
11+
extra_args: CSTD="c99"
12+
bindesc.define.c11:
13+
platform_allow: native_posix
14+
tags: bindesc
15+
extra_args: CSTD="c11"
16+
bindesc.define.c17:
17+
platform_allow: native_posix
18+
tags: bindesc
19+
extra_args: CSTD="c17"
20+
bindesc.define.gnu99:
21+
platform_allow: native_posix
22+
tags: bindesc
23+
extra_args: CSTD="gnu99"
24+
bindesc.define.gnu11:
25+
platform_allow: native_posix
26+
tags: bindesc
27+
extra_args: CSTD="gnu11"
28+
bindesc.define.gnu17:
29+
platform_allow: native_posix
30+
tags: bindesc
31+
extra_args: CSTD="gnu17"

0 commit comments

Comments
 (0)