tests: iterable_sections: add a tests for iterable_sections
Add a test for iterable sections macro, covering read write and read only sections. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
parent
171739d06e
commit
29585ee864
6 changed files with 106 additions and 0 deletions
11
tests/misc/iterable_sections/CMakeLists.txt
Normal file
11
tests/misc/iterable_sections/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(iterable_sections)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
|
||||
zephyr_linker_sources(DATA_SECTIONS sections-ram.ld)
|
||||
zephyr_linker_sources(SECTIONS sections-rom.ld)
|
||||
1
tests/misc/iterable_sections/prj.conf
Normal file
1
tests/misc/iterable_sections/prj.conf
Normal file
|
|
@ -0,0 +1 @@
|
|||
CONFIG_ZTEST=y
|
||||
1
tests/misc/iterable_sections/sections-ram.ld
Normal file
1
tests/misc/iterable_sections/sections-ram.ld
Normal file
|
|
@ -0,0 +1 @@
|
|||
ITERABLE_SECTION_RAM(test_ram, 4)
|
||||
1
tests/misc/iterable_sections/sections-rom.ld
Normal file
1
tests/misc/iterable_sections/sections-rom.ld
Normal file
|
|
@ -0,0 +1 @@
|
|||
ITERABLE_SECTION_ROM(test_rom, 4)
|
||||
88
tests/misc/iterable_sections/src/main.c
Normal file
88
tests/misc/iterable_sections/src/main.c
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2021 Google LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
|
||||
struct test_ram {
|
||||
int i;
|
||||
};
|
||||
|
||||
#define CHECK_BIT 0x80
|
||||
|
||||
/* declare in random order to check that the linker is sorting by name */
|
||||
STRUCT_SECTION_ITERABLE(test_ram, ram3) = {0x03};
|
||||
STRUCT_SECTION_ITERABLE(test_ram, ram2) = {0x02};
|
||||
STRUCT_SECTION_ITERABLE(test_ram, ram4) = {0x04};
|
||||
STRUCT_SECTION_ITERABLE(test_ram, ram1) = {0x01};
|
||||
|
||||
#define RAM_EXPECT 0x01020304
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Test iterable in read write section.
|
||||
*
|
||||
*/
|
||||
void test_ram(void)
|
||||
{
|
||||
int out = 0;
|
||||
|
||||
STRUCT_SECTION_FOREACH(test_ram, t) {
|
||||
out = (out << 8) | t->i;
|
||||
t->i |= CHECK_BIT;
|
||||
}
|
||||
|
||||
zassert_equal(out, RAM_EXPECT, "Check value incorrect (got: 0x%08x)", out);
|
||||
|
||||
zassert_equal(ram1.i & CHECK_BIT, CHECK_BIT,
|
||||
"ram1.i check bit incorrect (got: 0x%x)", ram1.i);
|
||||
zassert_equal(ram2.i & CHECK_BIT, CHECK_BIT,
|
||||
"ram2.i check bit incorrect (got: 0x%x)", ram2.i);
|
||||
zassert_equal(ram3.i & CHECK_BIT, CHECK_BIT,
|
||||
"ram3.i check bit incorrect (got: 0x%x)", ram3.i);
|
||||
zassert_equal(ram4.i & CHECK_BIT, CHECK_BIT,
|
||||
"ram4.i check bit incorrect (got: 0x%x)", ram4.i);
|
||||
}
|
||||
|
||||
struct test_rom {
|
||||
int i;
|
||||
};
|
||||
|
||||
/* declare in random order to check that the linker is sorting by name */
|
||||
STRUCT_SECTION_ITERABLE(test_rom, rom1) = {0x10};
|
||||
STRUCT_SECTION_ITERABLE(test_rom, rom3) = {0x30};
|
||||
STRUCT_SECTION_ITERABLE(test_rom, rom4) = {0x40};
|
||||
STRUCT_SECTION_ITERABLE(test_rom, rom2) = {0x20};
|
||||
|
||||
#define ROM_EXPECT 0x10203040
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Test iterable in read only section.
|
||||
*
|
||||
*/
|
||||
void test_rom(void)
|
||||
{
|
||||
int out = 0;
|
||||
|
||||
STRUCT_SECTION_FOREACH(test_rom, t) {
|
||||
out = (out << 8) | t->i;
|
||||
}
|
||||
|
||||
zassert_equal(out, ROM_EXPECT, "Check value incorrect (got: 0x%x)", out);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Test entry point
|
||||
*
|
||||
*/
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(iterable_sections,
|
||||
ztest_unit_test(test_ram),
|
||||
ztest_unit_test(test_rom));
|
||||
ztest_run_test_suite(iterable_sections);
|
||||
}
|
||||
4
tests/misc/iterable_sections/testcase.yaml
Normal file
4
tests/misc/iterable_sections/testcase.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
tests:
|
||||
misc.iterable_sections:
|
||||
tags: iterable_sections
|
||||
arch_exclude: posix xtensa
|
||||
Loading…
Reference in a new issue