Skip to content

Commit

Permalink
tests: bindesc: Added definition tests
Browse files Browse the repository at this point in the history
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
yonsch committed Sep 26, 2023
1 parent a7e6371 commit ef3b1a3
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/subsys/bindesc/definition/CMakeLists.txt
@@ -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)
12 changes: 12 additions & 0 deletions tests/subsys/bindesc/definition/prj.conf
@@ -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
49 changes: 49 additions & 0 deletions tests/subsys/bindesc/definition/src/main.c
@@ -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);
31 changes: 31 additions & 0 deletions tests/subsys/bindesc/definition/testcase.yaml
@@ -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"

0 comments on commit ef3b1a3

Please sign in to comment.