Skip to content

Commit 209a631

Browse files
committed
tests: kernel: cache: Add test for __dcacheline_aligned/unique
Add test which checks that variable tagged with __dcacheline_aligned is correctly aligned, and that the variables tagged with __dcacheline_unique are in the proper section that gives a unique data cache line for each. Co-authored-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no> Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no> Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
1 parent 9275437 commit 209a631

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/kernel/cache/src/test_cache_api.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,53 @@ ZTEST_USER(cache_api, test_data_cache_api_user)
7979
zassert_true((ret == 0) || (ret == -ENOTSUP));
8080
}
8181

82+
#ifdef CONFIG_DCACHE_LINE_SIZE
83+
ZTEST(cache_api, test_dcacheline_aligned_unique)
84+
{
85+
static uint8_t var1 __dcacheline_unique;
86+
static uint8_t var2[5] __dcacheline_unique;
87+
88+
static uint8_t var3 __dcacheline_unique;
89+
90+
static uint8_t var4 __dcacheline_aligned;
91+
static uint8_t var5[5] __dcacheline_aligned;
92+
93+
static uint8_t var6 __dcacheline_aligned;
94+
extern uintptr_t __data_cache_start;
95+
extern uintptr_t __data_cache_end;
96+
97+
zassert_true(IS_ALIGNED(&var1, CONFIG_DCACHE_LINE_SIZE));
98+
zassert_true(IS_ALIGNED(var2, CONFIG_DCACHE_LINE_SIZE));
99+
zassert_true(IS_ALIGNED(&var3, CONFIG_DCACHE_LINE_SIZE));
100+
zassert_true(IS_ALIGNED(&var4, CONFIG_DCACHE_LINE_SIZE));
101+
zassert_true(IS_ALIGNED(var5, CONFIG_DCACHE_LINE_SIZE));
102+
zassert_true(IS_ALIGNED(&var6, CONFIG_DCACHE_LINE_SIZE));
103+
104+
/* Validate that variables are placed in the dedicated section
105+
* that gives a unique data cache line for each.
106+
*/
107+
zassert_between_inclusive((uintptr_t)&var1, (uintptr_t)&__data_cache_start,
108+
(uintptr_t)&__data_cache_end);
109+
zassert_between_inclusive((uintptr_t)var2, (uintptr_t)&__data_cache_start,
110+
(uintptr_t)&__data_cache_end);
111+
zassert_between_inclusive((uintptr_t)&var3, (uintptr_t)&__data_cache_start,
112+
(uintptr_t)&__data_cache_end);
113+
114+
var1 = 1;
115+
var2[0] = 2;
116+
var3 = 3;
117+
var4 = 4;
118+
var5[0] = 5;
119+
var6 = 6;
120+
zassert_equal(var1, 1);
121+
zassert_equal(var2[0], 2);
122+
zassert_equal(var3, 3);
123+
zassert_equal(var4, 4);
124+
zassert_equal(var5[0], 5);
125+
zassert_equal(var6, 6);
126+
}
127+
#endif
128+
82129
static void *cache_api_setup(void)
83130
{
84131
sys_cache_data_enable();

0 commit comments

Comments
 (0)