Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <yonatan.schachter@gmail.com>
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2023 Yonatan Schachter | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(bindesc) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2023 Yonatan Schachter | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
CONFIG_ZTEST=y | ||
CONFIG_ZTEST_NEW_API=y | ||
|
||
CONFIG_BINDESC=y | ||
CONFIG_BINDESC_DEFINE=y | ||
|
||
CONFIG_BINDESC_DEFINE_VERSION=y | ||
CONFIG_BINDESC_KERNEL_VERSION_NUMBER=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2023 Yonatan Schachter | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/ztest.h> | ||
#include <zephyr/bindesc.h> | ||
#include <version.h> | ||
|
||
#define STR_ID 1 | ||
#define UINT_ID 2 | ||
#define BYTES_ID 3 | ||
|
||
#define STR_DATA "Hello world!" | ||
#define UINT_DATA 5 | ||
#define BYTES_DATA {1, 2, 3, 4} | ||
|
||
BINDESC_STR_DEFINE(bindesc_string, STR_ID, STR_DATA); | ||
BINDESC_UINT_DEFINE(bindesc_uint, UINT_ID, UINT_DATA); | ||
BINDESC_BYTES_DEFINE(bindesc_bytes, BYTES_ID, (BYTES_DATA)); | ||
|
||
ZTEST(bindesc_define, test_version_number) | ||
{ | ||
zassert_equal(BINDESC_GET_UINT(kernel_version_number), KERNEL_VERSION_NUMBER, | ||
"bindesc kernel version number is incorrect"); | ||
} | ||
|
||
ZTEST(bindesc_define, test_custom_bindesc_str) | ||
{ | ||
zassert_equal(BINDESC_GET_SIZE(bindesc_string), sizeof(STR_DATA)); | ||
zassert_mem_equal(BINDESC_GET_STR(bindesc_string), STR_DATA, sizeof(STR_DATA)); | ||
} | ||
|
||
ZTEST(bindesc_define, test_custom_bindesc_uint) | ||
{ | ||
zassert_equal(BINDESC_GET_SIZE(bindesc_uint), 4); | ||
zassert_equal(BINDESC_GET_UINT(bindesc_uint), UINT_DATA); | ||
} | ||
|
||
ZTEST(bindesc_define, test_custom_bindesc_bytes) | ||
{ | ||
uint8_t expected_data[] = BYTES_DATA; | ||
|
||
zassert_equal(BINDESC_GET_SIZE(bindesc_bytes), 4); | ||
zassert_mem_equal(BINDESC_GET_STR(bindesc_bytes), expected_data, 4); | ||
} | ||
|
||
ZTEST_SUITE(bindesc_define, NULL, NULL, NULL, NULL, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
tests: | ||
bindesc.define: | ||
tags: bindesc | ||
platform_allow: > | ||
native_posix qemu_x86 qemu_cortex_m0 qemu_cortex_m3 | ||
qemu_cortex_r5 qemu_arc_em qemu_arc_hs qemu_arc_hs5x | ||
qemu_arc_hs6x qemu_riscv32 qemu_riscv32e qemu_riscv64 | ||
bindesc.define.c99: | ||
platform_allow: native_posix | ||
tags: bindesc | ||
extra_args: CSTD="c99" | ||
bindesc.define.c11: | ||
platform_allow: native_posix | ||
tags: bindesc | ||
extra_args: CSTD="c11" | ||
bindesc.define.c17: | ||
platform_allow: native_posix | ||
tags: bindesc | ||
extra_args: CSTD="c17" | ||
bindesc.define.gnu99: | ||
platform_allow: native_posix | ||
tags: bindesc | ||
extra_args: CSTD="gnu99" | ||
bindesc.define.gnu11: | ||
platform_allow: native_posix | ||
tags: bindesc | ||
extra_args: CSTD="gnu11" | ||
bindesc.define.gnu17: | ||
platform_allow: native_posix | ||
tags: bindesc | ||
extra_args: CSTD="gnu17" |