tests: misc: iterable_sections: test alternate foreach
Add tests for `STRUCT_SECTION_FOREACH_ALTERNATE()`. Signed-off-by: Chris Friedt <cfriedt@meta.com>
This commit is contained in:
parent
e684ed9f24
commit
6841d96a59
3 changed files with 22 additions and 0 deletions
|
@ -1 +1,2 @@
|
|||
ITERABLE_SECTION_RAM(test_ram, 4)
|
||||
ITERABLE_SECTION_RAM(test_ram2, 4)
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
ITERABLE_SECTION_ROM(test_rom, 4)
|
||||
ITERABLE_SECTION_ROM(test_rom2, 4)
|
||||
|
|
|
@ -20,6 +20,9 @@ STRUCT_SECTION_ITERABLE(test_ram, ram1) = {0x01};
|
|||
|
||||
#define RAM_EXPECT 0x01020304
|
||||
|
||||
/* iterable section items can also be static */
|
||||
static const STRUCT_SECTION_ITERABLE_ALTERNATE(test_ram2, test_ram, ram5) = {RAM_EXPECT};
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Test iterable in read write section.
|
||||
|
@ -44,6 +47,13 @@ ZTEST(iterable_sections, test_ram)
|
|||
"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);
|
||||
|
||||
out = 0;
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(test_ram2, test_ram, t) {
|
||||
out = (out << 8) | t->i;
|
||||
}
|
||||
|
||||
zassert_equal(out, RAM_EXPECT, "Check value incorrect (got: 0x%08x)", out);
|
||||
}
|
||||
|
||||
struct test_rom {
|
||||
|
@ -58,6 +68,9 @@ const STRUCT_SECTION_ITERABLE(test_rom, rom2) = {0x20};
|
|||
|
||||
#define ROM_EXPECT 0x10203040
|
||||
|
||||
/* iterable section items can also be static */
|
||||
static const STRUCT_SECTION_ITERABLE_ALTERNATE(test_rom2, test_rom, rom5) = {ROM_EXPECT};
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief Test iterable in read only section.
|
||||
|
@ -72,6 +85,13 @@ ZTEST(iterable_sections, test_rom)
|
|||
}
|
||||
|
||||
zassert_equal(out, ROM_EXPECT, "Check value incorrect (got: 0x%x)", out);
|
||||
|
||||
out = 0;
|
||||
STRUCT_SECTION_FOREACH_ALTERNATE(test_rom2, test_rom, t) {
|
||||
out = (out << 8) | t->i;
|
||||
}
|
||||
|
||||
zassert_equal(out, ROM_EXPECT, "Check value incorrect (got: 0x%x)", out);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(iterable_sections, NULL, NULL, NULL, NULL, NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue