Commit 6841d96a authored by Christopher Friedt's avatar Christopher Friedt Committed by Carles Cufi
Browse files

tests: misc: iterable_sections: test alternate foreach

Add tests for `STRUCT_SECTION_FOREACH_ALTERNATE()`.

Signed-off-by: default avatarChris Friedt <cfriedt@meta.com>
parent e684ed9f
Loading
Loading
Loading
Loading
+1 −0
Changes for tests/misc/iterable_sections/sections-ram.ld: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
ITERABLE_SECTION_RAM(test_ram, 4)
ITERABLE_SECTION_RAM(test_ram2, 4)
+1 −0
Changes for tests/misc/iterable_sections/sections-rom.ld: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
ITERABLE_SECTION_ROM(test_rom, 4)
ITERABLE_SECTION_ROM(test_rom2, 4)
+20 −0
Changes for tests/misc/iterable_sections/src/main.c: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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);