Skip to content

Commit 31fe964

Browse files
yonschnashif
authored andcommitted
tests: Add tests for bindesc reading
Added tests for bindesc reading, to test reading on multiple C/C++ standards. Only RAM and flash backends are tested, as the flash simulator can't simulate a memory mapped flash. Signed-off-by: Yonatan Schachter <[email protected]>
1 parent 41e1c43 commit 31fe964

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-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)

tests/subsys/bindesc/reading/prj.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2023 Yonatan Schachter
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
CONFIG_ZTEST=y
6+
CONFIG_FLASH=y
7+
8+
CONFIG_BINDESC=y
9+
CONFIG_BINDESC_READ=y
10+
CONFIG_BINDESC_READ_FLASH=y
11+
CONFIG_BINDESC_READ_RAM=y
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 <zephyr/drivers/flash.h>
10+
11+
#ifdef CONFIG_ARCH_POSIX
12+
#define SOC_NV_FLASH_NODE DT_CHILD(DT_INST(0, zephyr_sim_flash), flash_0)
13+
#else
14+
#define SOC_NV_FLASH_NODE DT_CHILD(DT_INST(0, zephyr_sim_flash), flash_sim_0)
15+
#endif /* CONFIG_ARCH_POSIX */
16+
17+
#if (defined(CONFIG_ARCH_POSIX) || defined(CONFIG_BOARD_QEMU_X86))
18+
static const struct device *const flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
19+
#else
20+
static const struct device *const flash_dev = DEVICE_DT_GET(DT_NODELABEL(sim_flash_controller));
21+
#endif
22+
23+
#define FLASH_SIMULATOR_ERASE_UNIT DT_PROP(SOC_NV_FLASH_NODE, erase_block_size)
24+
25+
static __aligned(BINDESC_ALIGNMENT) const uint8_t descriptors[] = {
26+
0x46, 0x60, 0xa4, 0x7e, 0x5a, 0x3e, 0x86, 0xb9, /* magic */
27+
0x00, 0x18, 0x06, 0x00, /* tag: 0x1800 (app version string), length: 0x0006 */
28+
0x31, 0x2e, 0x30, 0x2e, 0x30, 0x00, /* "1.0.0" */
29+
0x00, 0x00, /* padding */
30+
0x01, 0x1b, 0x04, 0x00, /* tag: 0x1b01 (compiler name), length: 0x0004 */
31+
0x47, 0x4e, 0x55, 0x00, /* "GNU" */
32+
0x02, 0x1b, 0x07, 0x00, /* tag: 0x1b02 (compiler version), length: 0x0007 */
33+
0x31, 0x32, 0x2e, 0x32, 0x2e, 0x30, 0x00, /* "12.2.0" */
34+
0x00, /* padding */
35+
0x00, 0x19, 0x07, 0x00, /* tag: 0x1900 (kernel version string), length: 0x0007 */
36+
0x33, 0x2e, 0x35, 0x2e, 0x39, 0x39, 0x00, /* "3.5.99" */
37+
0x00, /* padding */
38+
0xff, 0xff, 0x00, 0x00, /* tag: 0xffff (descriptors end), length: 0x0000 */
39+
};
40+
41+
static void *test_setup(void)
42+
{
43+
flash_erase(flash_dev, 0, FLASH_SIMULATOR_ERASE_UNIT);
44+
flash_write(flash_dev, 0, descriptors, sizeof(descriptors));
45+
46+
return NULL;
47+
}
48+
49+
static void test_bindesc_read(struct bindesc_handle *handle)
50+
{
51+
const char *result;
52+
53+
bindesc_find_str(handle, BINDESC_ID_KERNEL_VERSION_STRING, &result);
54+
zassert_mem_equal("3.5.99", result, sizeof("3.5.99"));
55+
56+
bindesc_find_str(handle, BINDESC_ID_APP_VERSION_STRING, &result);
57+
zassert_mem_equal("1.0.0", result, sizeof("1.0.0"));
58+
59+
bindesc_find_str(handle, BINDESC_ID_C_COMPILER_NAME, &result);
60+
zassert_mem_equal("GNU", result, sizeof("GNU"));
61+
62+
bindesc_find_str(handle, BINDESC_ID_C_COMPILER_VERSION, &result);
63+
zassert_mem_equal("12.2.0", result, sizeof("12.2.0"));
64+
}
65+
66+
ZTEST(bindesc_read, test_bindesc_read_from_flash)
67+
{
68+
struct bindesc_handle handle;
69+
70+
bindesc_open_flash(&handle, 0, flash_dev);
71+
72+
test_bindesc_read(&handle);
73+
}
74+
75+
ZTEST(bindesc_read, test_bindesc_read_from_ram)
76+
{
77+
struct bindesc_handle handle;
78+
79+
bindesc_open_ram(&handle, descriptors, sizeof(descriptors));
80+
81+
test_bindesc_read(&handle);
82+
}
83+
84+
ZTEST_SUITE(bindesc_read, NULL, test_setup, NULL, NULL, NULL);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
common:
2+
platform_allow:
3+
- native_sim
4+
integration_platforms:
5+
- native_sim
6+
tags: bindesc
7+
tests:
8+
bindesc.read:
9+
platform_allow:
10+
- native_posix
11+
- native_sim
12+
bindesc.read.c99:
13+
extra_args: CSTD="c99"
14+
bindesc.read.c11:
15+
extra_args: CSTD="c11"
16+
bindesc.read.c17:
17+
extra_args: CSTD="c17"
18+
bindesc.read.gnu99:
19+
extra_args: CSTD="gnu99"
20+
bindesc.read.gnu11:
21+
extra_args: CSTD="gnu11"
22+
bindesc.read.gnu17:
23+
extra_args: CSTD="gnu17"

0 commit comments

Comments
 (0)