1 /*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/cache.h>
9
10 #define SIZE (4096)
11
12 static ZTEST_BMEM uint8_t user_buffer[SIZE];
13
ZTEST(cache_api,test_instr_cache_api)14 ZTEST(cache_api, test_instr_cache_api)
15 {
16 int ret;
17
18 ret = sys_cache_instr_flush_all();
19 zassert_true((ret == 0) || (ret == -ENOTSUP));
20
21 ret = sys_cache_instr_invd_all();
22 zassert_true((ret == 0) || (ret == -ENOTSUP));
23
24 ret = sys_cache_instr_flush_and_invd_all();
25 zassert_true((ret == 0) || (ret == -ENOTSUP));
26
27 ret = sys_cache_instr_flush_range(user_buffer, SIZE);
28 zassert_true((ret == 0) || (ret == -ENOTSUP));
29
30 ret = sys_cache_instr_invd_range(user_buffer, SIZE);
31 zassert_true((ret == 0) || (ret == -ENOTSUP));
32
33 ret = sys_cache_instr_flush_and_invd_range(user_buffer, SIZE);
34 zassert_true((ret == 0) || (ret == -ENOTSUP));
35 }
36
ZTEST(cache_api,test_data_cache_api)37 ZTEST(cache_api, test_data_cache_api)
38 {
39 int ret;
40
41 ret = sys_cache_data_flush_all();
42 zassert_true((ret == 0) || (ret == -ENOTSUP));
43
44 ret = sys_cache_data_invd_all();
45 zassert_true((ret == 0) || (ret == -ENOTSUP));
46
47 ret = sys_cache_data_flush_and_invd_all();
48 zassert_true((ret == 0) || (ret == -ENOTSUP));
49
50 ret = sys_cache_data_flush_range(user_buffer, SIZE);
51 zassert_true((ret == 0) || (ret == -ENOTSUP));
52
53 ret = sys_cache_data_invd_range(user_buffer, SIZE);
54 zassert_true((ret == 0) || (ret == -ENOTSUP));
55
56 ret = sys_cache_data_flush_and_invd_range(user_buffer, SIZE);
57 zassert_true((ret == 0) || (ret == -ENOTSUP));
58
59 }
60
ZTEST_USER(cache_api,test_data_cache_api_user)61 ZTEST_USER(cache_api, test_data_cache_api_user)
62 {
63 int ret;
64
65 ret = sys_cache_data_flush_range(user_buffer, SIZE);
66 zassert_true((ret == 0) || (ret == -ENOTSUP));
67
68 ret = sys_cache_data_invd_range(user_buffer, SIZE);
69 zassert_true((ret == 0) || (ret == -ENOTSUP));
70
71 ret = sys_cache_data_flush_and_invd_range(user_buffer, SIZE);
72 zassert_true((ret == 0) || (ret == -ENOTSUP));
73 }
74
cache_api_setup(void)75 static void *cache_api_setup(void)
76 {
77 sys_cache_data_enable();
78 sys_cache_instr_enable();
79
80 return NULL;
81 }
82
cache_api_teardown(void * unused)83 static void cache_api_teardown(void *unused)
84 {
85 sys_cache_data_disable();
86 sys_cache_instr_disable();
87 }
88
89 ZTEST_SUITE(cache_api, NULL, cache_api_setup, NULL, NULL, cache_api_teardown);
90