blob: 9ab2b1427c94c764af7503d98e606d23b567d46e [file] [log] [blame]
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6#include <CppUTest/CommandLineTestRunner.h>
7#include <CppUTest/TestHarness.h>
8
9extern "C" {
10#include <cpuid.h>
11#include <granule_types.h>
12#include <host_harness.h>
13#include <host_utils.h>
14#include <status.h>
15#include <stdlib.h>
16#include <string.h>
17#include <s2tt_pvt_defs.h>
18#include <s2tt_test_helpers.h>
19#include <ripas.h>
20#include <s2tt.h> /* Interface to exercise */
21#include <test_helpers.h>
22#include <unistd.h>
23#include <utils_def.h>
24}
25
26void s2tte_create_unassigned_empty_tc1(void)
27{
28 /***************************************************************
29 * TEST CASE 1:
30 *
31 * Create an unassigned empty S2TTE and verify that the
32 * S2TTE is valid.
33 ***************************************************************/
34
35 unsigned long expected_tte = S2TTE_INVALID_RIPAS_EMPTY |
36 S2TTE_INVALID_HIPAS_UNASSIGNED;
37
38 /* s2tt_context argument is ignored */
39 unsigned long tte = s2tte_create_unassigned_empty(NULL);
40
41 UNSIGNED_LONGS_EQUAL(expected_tte, tte);
42}
43
44void s2tte_create_unassigned_ram_tc1(void)
45{
46 /***************************************************************
47 * TEST CASE 1:
48 *
49 * Create an unassigned ram S2TTE and verify that the
50 * S2TTE is valid.
51 ***************************************************************/
52
53 unsigned long expected_tte = S2TTE_INVALID_RIPAS_RAM |
54 S2TTE_INVALID_HIPAS_UNASSIGNED;
55
56 /* s2tt_context argument is ignored */
57 unsigned long tte = s2tte_create_unassigned_ram(NULL);
58
59 UNSIGNED_LONGS_EQUAL(expected_tte, tte);
60}
61
62void s2tte_create_unassigned_destroyed_tc1(void)
63{
64 /***************************************************************
65 * TEST CASE 1:
66 *
67 * Create an unassigned destroyed S2TTE and verify that the
68 * S2TTE is valid.
69 ***************************************************************/
70
71 unsigned long expected_tte = S2TTE_INVALID_RIPAS_DESTROYED |
72 S2TTE_INVALID_HIPAS_UNASSIGNED;
73
74 /* s2tt_context argument is ignored */
75 unsigned long tte = s2tte_create_unassigned_destroyed(NULL);
76
77 UNSIGNED_LONGS_EQUAL(expected_tte, tte);
78}
79
80void s2tte_create_unassigned_ns_tc1(void)
81{
82 /***************************************************************
83 * TEST CASE 1:
84 *
85 * Create an unassigned ns S2TTE and verify that the
86 * S2TTE is valid.
87 ***************************************************************/
88
89 unsigned long expected_tte = S2TTE_NS | S2TTE_INVALID_HIPAS_UNASSIGNED;
90
91 /* s2tt_context argument is ignored */
92 unsigned long tte = s2tte_create_unassigned_ns(NULL);
93
94 UNSIGNED_LONGS_EQUAL(expected_tte, tte);
95}
96
97void s2tte_create_assigned_destroyed_tc1(void)
98{
99 /***************************************************************
100 * TEST CASE 1:
101 *
102 * Create an assigned destroyed S2TTE with valid parameters and
103 * verify that the S2TTE is valid.
104 ***************************************************************/
105
106 /* Test for each possible level */
107 for (long i = s2tt_test_helpers_min_block_lvl();
108 i <= S2TT_TEST_HELPERS_MAX_LVL; i++) {
109
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100110 unsigned long pa = s2tt_test_helpers_gen_addr(i, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100111 unsigned long tte;
Soby Mathewb1228bb2024-12-31 17:42:46 +0000112 s2tt_context s2tt_ctx;
113
114 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100115
116 /*
117 * Generate an s2tt context to be used for the test.
118 * only s2tt_ctx.enable_lpa2 is of use on this API, so
119 * the rest of them can be uninitialized.
120 */
121 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
122
123 tte = s2tte_create_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
124 pa, i);
125
126 /* Validate the address */
127 UNSIGNED_LONGS_EQUAL(
128 s2tt_test_helpers_s2tte_to_pa(tte, i), pa);
129
130 /* Validate the RIPAS */
131 UNSIGNED_LONGS_EQUAL((tte & S2TTE_INVALID_RIPAS_MASK),
132 S2TTE_INVALID_RIPAS_DESTROYED);
133
134 /* Validate the HIPAS */
135 UNSIGNED_LONGS_EQUAL((tte & S2TTE_INVALID_HIPAS_MASK),
136 S2TTE_INVALID_HIPAS_ASSIGNED);
137
138 /* The rest of the fields must be all 0 */
139 UNSIGNED_LONGS_EQUAL(
140 (tte & ~(s2tt_test_helpers_s2tte_oa_mask() |
141 S2TTE_INVALID_RIPAS_MASK |
142 S2TTE_INVALID_HIPAS_MASK)), 0UL);
143 }
144}
145
146void s2tte_create_assigned_destroyed_tc2(void)
147{
148 /***************************************************************
149 * TEST CASE 2:
150 *
151 * For a valid level, try to create an assigned-destroyed S2TTE
152 * with an unaligned address.
153 ***************************************************************/
154
155 long level = (long)test_helpers_get_rand_in_range(
156 (unsigned long)s2tt_test_helpers_min_block_lvl(),
157 (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100158 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Soby Mathewb1228bb2024-12-31 17:42:46 +0000159 struct s2tt_context s2tt_ctx;
160
161 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100162
163 pa += test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
164
165 /*
166 * Generate an s2tt context to be used for the test.
167 * only s2tt_ctx.enable_lpa2 is of use on this API, so
168 * the rest of them can be uninitialized.
169 */
170 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
171
172 test_helpers_expect_assert_fail(true);
173 (void)s2tte_create_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
174 pa, level);
175 test_helpers_fail_if_no_assert_failed();
176}
177
178void s2tte_create_assigned_destroyed_tc3(void)
179{
180 /***************************************************************
181 * TEST CASE 3:
182 *
183 * For a valid address, try to create an assigned-destroyed
184 * S2TTE with a level below the minimum.
185 ***************************************************************/
186
187 long level = s2tt_test_helpers_min_block_lvl() - 1;
188 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000189 struct s2tt_context s2tt_ctx;
190
191 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100192
193 /*
194 * Generate an s2tt context to be used for the test.
195 * only s2tt_ctx.enable_lpa2 is of use on this API, so
196 * the rest of them can be uninitialized.
197 */
198 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
199
200 test_helpers_expect_assert_fail(true);
201 (void)s2tte_create_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
202 pa, level);
203 test_helpers_fail_if_no_assert_failed();
204}
205
206void s2tte_create_assigned_destroyed_tc4(void)
207{
208 /***************************************************************
209 * TEST CASE 4:
210 *
211 * For a valid address, try to create an assigned-destroyed
212 * S2TTE with a level above the maximum.
213 ***************************************************************/
214
215 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
216 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000217 struct s2tt_context s2tt_ctx;
218
219 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100220
221 /*
222 * Generate an s2tt context to be used for the test.
223 * only s2tt_ctx.enable_lpa2 is of use on this API, so
224 * the rest of them can be uninitialized.
225 */
226 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
227
228 test_helpers_expect_assert_fail(true);
229 (void)s2tte_create_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
230 pa, level);
231 test_helpers_fail_if_no_assert_failed();
232}
233
234void s2tte_create_assigned_destroyed_tc5(void)
235{
236 /***************************************************************
237 * TEST CASE 5:
238 *
239 * For a valid address, try to create an assigned-destroyed
240 * S2TTE with a null s2tt_context structure.
241 ***************************************************************/
242
243 long level = S2TT_TEST_HELPERS_MAX_LVL;
244 unsigned long pa = 0UL; /* Valid for any level */
245
246 test_helpers_expect_assert_fail(true);
247 (void)s2tte_create_assigned_destroyed((const struct s2tt_context *)NULL,
248 pa, level);
249 test_helpers_fail_if_no_assert_failed();
250}
251
252void s2tte_create_assigned_empty_tc1(void)
253{
254 /***************************************************************
255 * TEST CASE 1:
256 *
257 * Create an assigned empty S2TTE with valid parameters and
258 * verify that the S2TTE is valid.
259 ***************************************************************/
260
261 /* Test for each possible level */
262 for (long i = s2tt_test_helpers_min_block_lvl();
263 i <= S2TT_TEST_HELPERS_MAX_LVL; i++) {
264
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100265 unsigned long pa = s2tt_test_helpers_gen_addr(i, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100266 unsigned long tte;
Soby Mathewb1228bb2024-12-31 17:42:46 +0000267 s2tt_context s2tt_ctx;
268
269 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100270
271 /*
272 * Generate an s2tt context to be used for the test.
273 * only s2tt_ctx.enable_lpa2 is of use on this API, so
274 * the rest of them can be uninitialized.
275 */
276 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
277
278 tte = s2tte_create_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
279 pa, i);
280
281 /* Validate the address */
282 UNSIGNED_LONGS_EQUAL(
283 s2tt_test_helpers_s2tte_to_pa(tte, i), pa);
284
285 /* Validate the RIPAS */
286 UNSIGNED_LONGS_EQUAL((tte & S2TTE_INVALID_RIPAS_MASK),
287 S2TTE_INVALID_RIPAS_EMPTY);
288
289 /* Validate the HIPAS */
290 UNSIGNED_LONGS_EQUAL((tte & S2TTE_INVALID_HIPAS_MASK),
291 S2TTE_INVALID_HIPAS_ASSIGNED);
292
293 /* The rest of the fields must be all 0 */
294 UNSIGNED_LONGS_EQUAL(
295 (tte & ~(s2tt_test_helpers_s2tte_oa_mask() |
296 S2TTE_INVALID_RIPAS_MASK |
297 S2TTE_INVALID_HIPAS_MASK)), 0UL);
298 }
299}
300
301void s2tte_create_assigned_empty_tc2(void)
302{
303 /***************************************************************
304 * TEST CASE 2:
305 *
306 * For a valid level, try to create an assigned-empty S2TTE
307 * with an unaligned address.
308 ***************************************************************/
309
310 long level = (long)test_helpers_get_rand_in_range(
311 (unsigned long)s2tt_test_helpers_min_block_lvl(),
312 (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100313 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Soby Mathewb1228bb2024-12-31 17:42:46 +0000314 struct s2tt_context s2tt_ctx;
315
316 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100317
318 pa += test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
319
320 /*
321 * Generate an s2tt context to be used for the test.
322 * only s2tt_ctx.enable_lpa2 is of use on this API, so
323 * the rest of them can be uninitialized.
324 */
325 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
326
327 test_helpers_expect_assert_fail(true);
328 (void)s2tte_create_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
329 pa, level);
330 test_helpers_fail_if_no_assert_failed();
331}
332
333void s2tte_create_assigned_empty_tc3(void)
334{
335 /***************************************************************
336 * TEST CASE 3:
337 *
338 * For a valid address, try to create an assigned-empty
339 * S2TTE with a level below the minimum.
340 ***************************************************************/
341
342 long level = s2tt_test_helpers_min_block_lvl() - 1;
343 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000344 struct s2tt_context s2tt_ctx;
345
346 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100347
348 /*
349 * Generate an s2tt context to be used for the test.
350 * only s2tt_ctx.enable_lpa2 is of use on this API, so
351 * the rest of them can be uninitialized.
352 */
353 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
354
355 test_helpers_expect_assert_fail(true);
356 (void)s2tte_create_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
357 pa, level);
358 test_helpers_fail_if_no_assert_failed();
359}
360
361void s2tte_create_assigned_empty_tc4(void)
362{
363 /***************************************************************
364 * TEST CASE 4:
365 *
366 * For a valid address, try to create an assigned-empty
367 * S2TTE with a level above the maximum.
368 ***************************************************************/
369
370 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
371 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000372 struct s2tt_context s2tt_ctx;
373
374 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100375
376 /*
377 * Generate an s2tt context to be used for the test.
378 * only s2tt_ctx.enable_lpa2 is of use on this API, so
379 * the rest of them can be uninitialized.
380 */
381 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
382
383 test_helpers_expect_assert_fail(true);
384 (void)s2tte_create_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
385 pa, level);
386 test_helpers_fail_if_no_assert_failed();
387}
388
389void s2tte_create_assigned_empty_tc5(void)
390{
391 /***************************************************************
392 * TEST CASE 5:
393 *
394 * For a valid address, try to create an assigned-empty
395 * S2TTE with a null s2tt_context structure.
396 ***************************************************************/
397
398 long level = S2TT_TEST_HELPERS_MAX_LVL;
399 unsigned long pa = 0UL; /* Valid for any level */
400
401 test_helpers_expect_assert_fail(true);
402 (void)s2tte_create_assigned_empty((const struct s2tt_context *)NULL,
403 pa, level);
404 test_helpers_fail_if_no_assert_failed();
405}
406
407void s2tte_create_assigned_ram_tc1(void)
408{
409 /***************************************************************
410 * TEST CASE 1:
411 *
412 * Create an assigned-ram S2TTE with valid parameters and
413 * verify that it is valid.
414 ***************************************************************/
415
Soby Mathewb1228bb2024-12-31 17:42:46 +0000416 struct s2tt_context s2tt_ctx;
417
418 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100419
420 /*
421 * Generate an s2tt context to be used for the test.
422 * only s2tt_ctx.enable_lpa2 is of use on this API, so
423 * the rest of them can be uninitialized.
424 */
425 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
426
427 /* Test for each possible level */
428 for (long i = s2tt_test_helpers_min_block_lvl();
429 i <= S2TT_TEST_HELPERS_MAX_LVL; i++) {
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100430 unsigned long pa = s2tt_test_helpers_gen_addr(i, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100431 unsigned long tte =
432 s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
433 pa, i);
434 unsigned long attrs = (is_feat_lpa2_4k_2_present() == true) ?
435 S2TTE_ATTRS_LPA2 : S2TTE_ATTRS;
436
437 attrs |= (i == S2TT_TEST_HELPERS_MAX_LVL) ?
438 S2TT_TEST_PAGE_DESC : S2TT_TEST_BLOCK_DESC;
439
440 /* Validate the address */
441 UNSIGNED_LONGS_EQUAL(s2tt_test_helpers_s2tte_to_pa(tte, i), pa);
442
443 /* Validate the attributes */
444 UNSIGNED_LONGS_EQUAL(s2tt_test_helpers_s2tte_to_attrs(tte, false),
445 attrs);
446
447 /* The rest of the fields must be all 0 */
448 UNSIGNED_LONGS_EQUAL((tte & ~(s2tt_test_helpers_s2tte_oa_mask() |
449 attrs)), 0UL);
450 }
451}
452
453void s2tte_create_assigned_ram_tc2(void)
454{
455 /***************************************************************
456 * TEST CASE 2:
457 *
458 * For a valid level, try to create an assigned-ram S2TTE with
459 * an unaligned address.
460 ***************************************************************/
461
462 long level = (long)test_helpers_get_rand_in_range(
463 (unsigned long)s2tt_test_helpers_min_block_lvl(),
464 (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100465 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100466
Soby Mathewb1228bb2024-12-31 17:42:46 +0000467 struct s2tt_context s2tt_ctx;
468
469 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100470
471 /*
472 * Generate an s2tt context to be used for the test.
473 * only s2tt_ctx.enable_lpa2 is of use on this API, so
474 * the rest of them can be uninitialized.
475 */
476 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
477
478 pa += test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
479
480 test_helpers_expect_assert_fail(true);
481 (void)s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
482 pa, level);
483 test_helpers_fail_if_no_assert_failed();
484}
485
486void s2tte_create_assigned_ram_tc3(void)
487{
488 /***************************************************************
489 * TEST CASE 3:
490 *
491 * For a valid address, try to create an assigned-ram S2TTE
492 * with a level below the minimum.
493 ***************************************************************/
494
495 long level = s2tt_test_helpers_min_block_lvl() - 1;
496 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000497 struct s2tt_context s2tt_ctx;
498
499 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100500
501 /*
502 * Generate an s2tt context to be used for the test.
503 * only s2tt_ctx.enable_lpa2 is of use on this API, so
504 * the rest of them can be uninitialized.
505 */
506 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
507
508 test_helpers_expect_assert_fail(true);
509 (void)s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
510 pa, level);
511 test_helpers_fail_if_no_assert_failed();
512}
513
514void s2tte_create_assigned_ram_tc4(void)
515{
516 /***************************************************************
517 * TEST CASE 4:
518 *
519 * For a valid address, try to create an assigned-ram S2TTE
520 * with a level above the maximum.
521 ***************************************************************/
522
523 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
524 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000525 struct s2tt_context s2tt_ctx;
526
527 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100528
529 /*
530 * Generate an s2tt context to be used for the test.
531 * only s2tt_ctx.enable_lpa2 is of use on this API, so
532 * the rest of them can be uninitialized.
533 */
534 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
535
536 test_helpers_expect_assert_fail(true);
537 (void)s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
538 pa, level);
539 test_helpers_fail_if_no_assert_failed();
540}
541
542void s2tte_create_assigned_ram_tc5(void)
543{
544 /***************************************************************
545 * TEST CASE 5:
546 *
547 * For a valid address, try to create an assigned-ram S2TTE
548 * with a null s2tt_context structure.
549 ***************************************************************/
550
551 long level = S2TT_TEST_HELPERS_MAX_LVL;
552 unsigned long pa = 0UL; /* Valid for any level */
553
554 test_helpers_expect_assert_fail(true);
555 (void)s2tte_create_assigned_ram((const struct s2tt_context *)NULL,
556 pa, level);
557 test_helpers_fail_if_no_assert_failed();
558}
559
560void s2tte_create_assigned_ns_tc1(void)
561{
562 /***************************************************************
563 * TEST CASE 1:
564 *
565 * Create an assigned-NS S2TTE with valid parameters and
566 * verify that it is valid.
567 ***************************************************************/
568
569 /* Test for each possible level */
570 for (long i = s2tt_test_helpers_min_block_lvl();
571 i <= S2TT_TEST_HELPERS_MAX_LVL; i++) {
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100572 unsigned long pa = s2tt_test_helpers_gen_addr(i, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100573 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true,
574 false);
575 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(false,
576 false);
Soby Mathewb1228bb2024-12-31 17:42:46 +0000577 struct s2tt_context s2tt_ctx;
578
579 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Soby Mathew217748d2024-10-02 11:02:19 +0100580
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100581 /*
Soby Mathew217748d2024-10-02 11:02:19 +0100582 * Initialize an s2tt_context structure for the test.
583 * Only 'enable_lpa2' is used by the API, so the rest of fields
584 * can be left untouched.
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100585 */
Soby Mathew217748d2024-10-02 11:02:19 +0100586 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100587 unsigned long tte = s2tte_create_assigned_ns(
Soby Mathew217748d2024-10-02 11:02:19 +0100588 (const struct s2tt_context *)&s2tt_ctx,
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100589 s2tt_test_helpers_pa_to_s2tte(pa, i) |
590 host_attrs, i);
591
592 attrs |= (i == S2TT_TEST_HELPERS_MAX_LVL) ?
593 S2TT_TEST_PAGE_DESC : S2TT_TEST_BLOCK_DESC;
594
Soby Mathew217748d2024-10-02 11:02:19 +0100595 if (!s2tt_test_helpers_lpa2_enabled()) {
596 attrs |= S2TTE_SH_IS;
597 }
598
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100599 /* Validate the address */
600 UNSIGNED_LONGS_EQUAL(s2tt_test_helpers_s2tte_to_pa(tte, i), pa);
601
602 /* Validate the attributes */
603 UNSIGNED_LONGS_EQUAL(s2tt_test_helpers_s2tte_to_attrs(tte, true),
604 (attrs | host_attrs));
605
Soby Mathew217748d2024-10-02 11:02:19 +0100606
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100607 /* The rest of the fields must be all 0 */
608 UNSIGNED_LONGS_EQUAL((tte & ~(s2tt_test_helpers_s2tte_oa_mask() |
Soby Mathew217748d2024-10-02 11:02:19 +0100609 S2TTE_NS_ATTR_RMM | S2TT_DESC_TYPE_MASK | S2TTE_NS_ATTR_MASK |
610 (is_feat_lpa2_4k_2_present() ? 0UL : S2TTE_SH_MASK))), 0UL);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100611 }
612}
613
614void s2tte_create_assigned_ns_tc2(void)
615{
616 /***************************************************************
617 * TEST CASE 2:
618 *
619 * For a valid address, try to create an assigned-ns S2TTE
620 * with a level below the minimum.
621 ***************************************************************/
622
623 long level = s2tt_test_helpers_min_table_lvl() - 1L;
624 unsigned long pa = 0UL; /* Valid for any level */
625
626 test_helpers_expect_assert_fail(true);
627 /*
628 * s2tte_create_assigned_ns() does not make use of the
629 * s2tt_context structure even though it receives it, so
630 * it is safe to just pass a NULL pointer.
631 */
632 (void)s2tte_create_assigned_ns((const struct s2tt_context *)NULL,
633 pa, level);
634 test_helpers_fail_if_no_assert_failed();
635}
636
637void s2tte_create_assigned_ns_tc3(void)
638{
639 /***************************************************************
640 * TEST CASE 3:
641 *
642 * For a valid address, try to create an assigned-ns S2TTE
643 * with a level above the maximum.
644 ***************************************************************/
645
646 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
647 unsigned long pa = 0UL; /* Valid for any level */
648
649 test_helpers_expect_assert_fail(true);
650 /*
651 * s2tte_create_assigned_ns() does not make use of the
652 * s2tt_context structure even though it receives it, so
653 * it is safe to just pass a NULL pointer.
654 */
655 (void)s2tte_create_assigned_ns((const struct s2tt_context *)NULL,
656 s2tt_test_helpers_pa_to_s2tte(pa, level), level);
657 test_helpers_fail_if_no_assert_failed();
658}
659
660void s2tte_create_assigned_unchanged_tc1(void)
661{
662 /***************************************************************
663 * TEST CASE 1:
664 *
665 * For each possible level and each possible RIPAS, invoke
666 * create_assigned_unchanged() and verify that the TTE is
667 * correct.
668 ***************************************************************/
669
Soby Mathewb1228bb2024-12-31 17:42:46 +0000670 struct s2tt_context s2tt_ctx;
671
672 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100673
674 /*
675 * Generate an s2tt context to be used for the test.
676 * Only the 'enable_lpa2' field is needed for this API
677 * so we can safely ignore the rest.
678 */
679 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
680
681 for (long level = s2tt_test_helpers_min_block_lvl();
682 level <= S2TT_TEST_HELPERS_MAX_LVL;
683 level++) {
684 for (unsigned long ripas = RIPAS_EMPTY;
685 ripas < S2TT_TEST_RIPAS_INVALID;
686 ripas++) {
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100687 unsigned long pa = s2tt_test_helpers_gen_addr(level,
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100688 true);
689 unsigned long tte = s2tte_create_assigned_unchanged(
690 (const struct s2tt_context *)&s2tt_ctx,
691 INPLACE(S2TTE_INVALID_RIPAS, ripas),
692 pa, level);
693
694 /* Validate the address */
695 UNSIGNED_LONGS_EQUAL(
696 s2tt_test_helpers_s2tte_to_pa(tte, level), pa);
697
698 if (ripas == RIPAS_RAM) {
699 /*
700 * Manually generate an assigned-ram entry and
701 * compare it with the generated TTE. The PA,
702 * which has already been validated, is the
703 * same so this check will fail if any
704 * attribute is invalid.
705 */
706 unsigned long expected_tte =
707 s2tt_test_helpers_pa_to_s2tte(pa, level) |
708 s2tt_test_helpers_gen_attrs(false, level);
709
710 UNSIGNED_LONGS_EQUAL(expected_tte, tte);
711 } else {
712 /* Verify the RIPAS */
713 UNSIGNED_LONGS_EQUAL(
714 (tte & S2TTE_INVALID_RIPAS_MASK),
715 INPLACE(S2TTE_INVALID_RIPAS,
716 ripas));
717
718 /* Verify the HIPAS */
719 UNSIGNED_LONGS_EQUAL(
720 (tte & S2TTE_INVALID_HIPAS_MASK),
721 S2TTE_INVALID_HIPAS_ASSIGNED);
722
723 /* The Descriptor type must be invalid */
724 UNSIGNED_LONGS_EQUAL(
725 (tte & S2TT_TEST_DESC_TYPE_MASK),
726 S2TT_TEST_INVALID_DESC);
727 }
728 }
729 }
730}
731
732void s2tte_create_assigned_unchanged_tc2(void)
733{
734 /***************************************************************
735 * TEST CASE 2:
736 *
737 * For a valid level and ripas try to create an
738 * assigned-unchanged S2TTE with an unaligned address.
739 ***************************************************************/
740
741 long level = (long)test_helpers_get_rand_in_range(
742 (unsigned long)s2tt_test_helpers_min_block_lvl(),
743 (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
744 unsigned long ripas = test_helpers_get_rand_in_range(
745 RIPAS_EMPTY,
746 RIPAS_DESTROYED);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100747 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Soby Mathewb1228bb2024-12-31 17:42:46 +0000748 struct s2tt_context s2tt_ctx;
749
750 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100751
752 /*
753 * Generate an s2tt context to be used for the test.
754 * Only the 'enable_lpa2' field is needed for this API
755 * so we can safely ignore the rest.
756 */
757 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
758
759 pa += test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
760
761 test_helpers_expect_assert_fail(true);
762 (void)s2tte_create_assigned_unchanged((const struct s2tt_context *)&s2tt_ctx,
763 ripas, pa, level);
764 test_helpers_fail_if_no_assert_failed();
765}
766
767void s2tte_create_assigned_unchanged_tc3(void)
768{
769 /***************************************************************
770 * TEST CASE 3:
771 *
772 * For a valid address and ripas try to create an
773 * assigned-unchanged S2TTE with a level below the minimum.
774 ***************************************************************/
775
776 long level = s2tt_test_helpers_min_block_lvl() - 1;
777 unsigned long ripas = test_helpers_get_rand_in_range(
778 RIPAS_EMPTY,
779 RIPAS_DESTROYED);
780 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000781 struct s2tt_context s2tt_ctx;
782
783 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100784
785 /*
786 * Generate an s2tt context to be used for the test.
787 * Only the 'enable_lpa2' field is needed for this API
788 * so we can safely ignore the rest.
789 */
790 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
791
792 test_helpers_expect_assert_fail(true);
793 (void)s2tte_create_assigned_unchanged((const struct s2tt_context *)&s2tt_ctx,
794 ripas, pa, level);
795 test_helpers_fail_if_no_assert_failed();
796}
797
798void s2tte_create_assigned_unchanged_tc4(void)
799{
800 /***************************************************************
801 * TEST CASE 4:
802 *
803 * For a valid address and ripas, try to create an
804 * assigned-unchanged S2TTE with a level above the maximum.
805 ***************************************************************/
806
807 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
808 unsigned long ripas = test_helpers_get_rand_in_range(
809 RIPAS_EMPTY,
810 RIPAS_DESTROYED);
811 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000812 struct s2tt_context s2tt_ctx;
813
814 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100815
816 /*
817 * Generate an s2tt context to be used for the test.
818 * Only the 'enable_lpa2' field is needed for this API
819 * so we can safely ignore the rest.
820 */
821 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
822
823 test_helpers_expect_assert_fail(true);
824 (void)s2tte_create_assigned_unchanged((const struct s2tt_context *)&s2tt_ctx,
825 ripas, pa, level);
826 test_helpers_fail_if_no_assert_failed();
827}
828
829void s2tte_create_assigned_unchanged_tc5(void)
830{
831 /***************************************************************
832 * TEST CASE 5:
833 *
834 * For a valid level and pa try to create an
835 * assigned-unchanged S2TTE with an invalid RIPAS.
836 ***************************************************************/
837
838 long level = (long)test_helpers_get_rand_in_range(
839 (unsigned long)s2tt_test_helpers_min_block_lvl(),
840 (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
841 unsigned long ripas = INPLACE(S2TTE_INVALID_RIPAS,
842 S2TT_TEST_RIPAS_INVALID);
843 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000844 struct s2tt_context s2tt_ctx;
845
846 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100847
848 /*
849 * Generate an s2tt context to be used for the test.
850 * Only the 'enable_lpa2' field is needed for this API
851 * so we can safely ignore the rest.
852 */
853 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
854
855 test_helpers_expect_assert_fail(true);
856 (void)s2tte_create_assigned_unchanged((const struct s2tt_context *)&s2tt_ctx,
857 ripas, pa, level);
858 test_helpers_fail_if_no_assert_failed();
859}
860
861void s2tte_create_assigned_unchanged_tc6(void)
862{
863 /***************************************************************
864 * TEST CASE 6:
865 *
866 * For a valid level, pa and RIPAS, try to create an
867 * assigned-unchanged S2TTE with a null s2tt_context structure.
868 ***************************************************************/
869
870 long level = (long)test_helpers_get_rand_in_range(
871 (unsigned long)s2tt_test_helpers_min_block_lvl(),
872 (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
873 unsigned long ripas = test_helpers_get_rand_in_range(
874 RIPAS_EMPTY,
875 RIPAS_DESTROYED);
876 unsigned long pa = 0UL; /* Valid for any level */
877
878 test_helpers_expect_assert_fail(true);
879 (void)s2tte_create_assigned_unchanged((const struct s2tt_context *)NULL,
880 ripas, pa, level);
881 test_helpers_fail_if_no_assert_failed();
882}
883
884void s2tte_create_table_tc1(void)
885{
886 /***************************************************************
887 * TEST CASE 1:
888 *
889 * For all possible valid levels, try to create and validate
890 * a table tte.
891 ***************************************************************/
892
Soby Mathewb1228bb2024-12-31 17:42:46 +0000893 struct s2tt_context s2tt_ctx;
894
895 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100896
897 /*
898 * Generate an s2tt context to be used for the test.
899 * only s2tt_ctx.enable_lpa2 is of use on this API, so
900 * the rest of them can be uninitialized.
901 */
902 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
903
904 for (long level = s2tt_test_helpers_min_table_lvl();
905 level < S2TT_TEST_HELPERS_MAX_LVL; level++) {
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100906 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100907 unsigned long tte = s2tte_create_table(
908 (const struct s2tt_context *)&s2tt_ctx,
909 pa, level);
910
911 /* Validate the address */
912 UNSIGNED_LONGS_EQUAL(s2tt_test_helpers_s2tte_to_pa(tte, level),
913 pa);
914
915 /* Validate the descriptor type */
916 UNSIGNED_LONGS_EQUAL(EXTRACT(S2TT_TEST_DESC_TYPE, tte),
917 S2TT_TEST_TABLE_DESC);
918
919 /* Validate that the rest of the descriptor is all zero */
920 UNSIGNED_LONGS_EQUAL((tte & ~(S2TT_TEST_DESC_TYPE_MASK |
921 s2tt_test_helpers_s2tte_oa_mask())), 0UL);
922
923 }
924}
925
926void s2tte_create_table_tc2(void)
927{
928 /***************************************************************
929 * TEST CASE 2:
930 *
931 * For a valid level try to create a table tte with an
932 * unaligned address.
933 ***************************************************************/
934
935 long level = (long)test_helpers_get_rand_in_range(
936 (unsigned long)s2tt_test_helpers_min_block_lvl(),
937 (unsigned long)S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +0100938 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Soby Mathewb1228bb2024-12-31 17:42:46 +0000939 struct s2tt_context s2tt_ctx;
940
941 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100942
943 /*
944 * Generate an s2tt context to be used for the test.
945 * only s2tt_ctx.enable_lpa2 is of use on this API, so
946 * the rest of them can be uninitialized.
947 */
948 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
949
950 pa += test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
951
952 test_helpers_expect_assert_fail(true);
953 (void)s2tte_create_table((const struct s2tt_context *)&s2tt_ctx, pa, level);
954 test_helpers_fail_if_no_assert_failed();
955}
956
957void s2tte_create_table_tc3(void)
958{
959 /***************************************************************
960 * TEST CASE 3:
961 *
962 * For a valid address to create a table tte with a level below
963 * the minimum.
964 ***************************************************************/
965
966 long level = s2tt_test_helpers_min_table_lvl() - 1;
967 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000968 struct s2tt_context s2tt_ctx;
969
970 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100971
972 /*
973 * Generate an s2tt context to be used for the test.
974 * only s2tt_ctx.enable_lpa2 is of use on this API, so
975 * the rest of them can be uninitialized.
976 */
977 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
978
979 test_helpers_expect_assert_fail(true);
980 (void)s2tte_create_table((const struct s2tt_context *)&s2tt_ctx, pa, level);
981 test_helpers_fail_if_no_assert_failed();
982}
983
984void s2tte_create_table_tc4(void)
985{
986 /***************************************************************
987 * TEST CASE 4:
988 *
989 * For a valid address to create a table tte with a level above
990 * the maximum.
991 ***************************************************************/
992
993 long level = S2TT_TEST_HELPERS_MAX_LVL;
994 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +0000995 struct s2tt_context s2tt_ctx;
996
997 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +0100998
999 /*
1000 * Generate an s2tt context to be used for the test.
1001 * only s2tt_ctx.enable_lpa2 is of use on this API, so
1002 * the rest of them can be uninitialized.
1003 */
1004 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1005
1006 test_helpers_expect_assert_fail(true);
1007 (void)s2tte_create_table((const struct s2tt_context *)&s2tt_ctx, pa, level);
1008 test_helpers_fail_if_no_assert_failed();
1009}
1010
1011void s2tte_create_table_tc5(void)
1012{
1013 /***************************************************************
1014 * TEST CASE 5:
1015 *
1016 * Test s2tte_create_table() with a set of valid arguments and
1017 * a NULL struct s2tt_context pointer.
1018 ***************************************************************/
1019
1020 long level = s2tt_test_helpers_min_table_lvl();
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001021 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001022
1023 test_helpers_expect_assert_fail(true);
1024 (void)s2tte_create_table((const struct s2tt_context *)NULL,
1025 pa, level);
1026 test_helpers_fail_if_no_assert_failed();
1027}
1028
1029void host_ns_s2tte_is_valid_tc1(void)
1030{
1031 /***************************************************************
1032 * TEST CASE 1:
1033 *
1034 * For all valid levels, generate a random ns_s2tte and pass it
1035 * to host_ns_s2tte_is_valid() to validate its behaviour.
1036 ***************************************************************/
Soby Mathewb1228bb2024-12-31 17:42:46 +00001037 struct s2tt_context s2tt_ctx;
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001038
Soby Mathewb1228bb2024-12-31 17:42:46 +00001039 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001040
1041 /*
1042 * Initialize an s2tt_context structure for the test.
1043 * Only 'enable_lpa2' is used by the API, so the rest of fields
1044 * can be left untouched.
1045 */
1046 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1047
1048 for (long level = s2tt_test_helpers_min_block_lvl();
1049 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1050
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001051 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001052 unsigned long host_attrs =
1053 s2tt_test_helpers_gen_ns_attrs(true, false);
1054 unsigned long tte = s2tt_test_helpers_pa_to_s2tte(pa, level) |
1055 host_attrs;
1056
1057 CHECK_TRUE(host_ns_s2tte_is_valid(
1058 (const struct s2tt_context *)&s2tt_ctx,
1059 tte, level));
1060 }
1061}
1062
1063void host_ns_s2tte_is_valid_tc2(void)
1064{
1065 /***************************************************************
1066 * TEST CASE 2:
1067 *
1068 * For all valid levels, generate different invalid NS-S2TTEs
1069 * and pass them to host_ns_s2tte_is_valid() to validate its
1070 * behaviour.
1071 ***************************************************************/
Soby Mathewb1228bb2024-12-31 17:42:46 +00001072 struct s2tt_context s2tt_ctx;
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001073
Soby Mathewb1228bb2024-12-31 17:42:46 +00001074 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001075
1076 /*
1077 * Initialize an s2tt_context structure for the test.
1078 * Only 'enable_lpa2' is used by the API, so the rest of fields
1079 * can be left untouched.
1080 */
1081 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1082
1083 for (long level = s2tt_test_helpers_min_block_lvl();
1084 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1085
1086 /* Generate a NS S2TTE with a set of invalid host attrs */
1087 unsigned long host_attrs =
1088 s2tt_test_helpers_gen_ns_attrs(true, true);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001089 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001090 unsigned long tte = s2tt_test_helpers_pa_to_s2tte(pa, level) |
1091 host_attrs;
1092
1093 CHECK_FALSE(host_ns_s2tte_is_valid(
1094 (const struct s2tt_context *)&s2tt_ctx,
1095 tte, level));
1096
1097 /*
1098 * Generate a NS S2TTE with invalid bits set to '1'.
1099 *
1100 * This case would also cover unaligned PAs on the S2TTE
1101 * as that would be equivalent to have some invalid bits
1102 * set to '1' as well.
1103 */
Javier Almansa Sobrinod38d1722025-05-15 17:56:20 +01001104 do {
1105 host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false) |
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001106 test_helpers_get_rand_in_range(1UL, ULONG_MAX);
Javier Almansa Sobrinod38d1722025-05-15 17:56:20 +01001107 } while ((host_attrs & ~(S2TTE_NS_ATTR_MASK |
1108 s2tt_test_helpers_s2tte_oa_mask())) == 0UL);
1109
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001110 tte = s2tt_test_helpers_pa_to_s2tte(pa, level) | host_attrs;
1111
1112 CHECK_FALSE(host_ns_s2tte_is_valid(
1113 (const struct s2tt_context *)&s2tt_ctx,
1114 tte, level));
1115 }
1116}
1117
1118void host_ns_s2tte_is_valid_tc3(void)
1119{
1120 /***************************************************************
1121 * TEST CASE 3:
1122 *
1123 * Test host_ns_s2tte_is_valid() with a valid NS S2TTE but a
1124 * level below the minimum supported. This should cause an
1125 * assert fail even if the PA is not aligned to the invalid
1126 * level.
1127 ***************************************************************/
1128
Soby Mathewb1228bb2024-12-31 17:42:46 +00001129 struct s2tt_context s2tt_ctx;
1130
1131 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001132
1133 /*
1134 * Initialize an s2tt_context structure for the test.
1135 * Only 'enable_lpa2' is used by the API, so the rest of fields
1136 * can be left untouched.
1137 */
1138 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1139
1140 /*
1141 * Generate the tte with an assumed PA == 0, which is aligned to
1142 * any level.
1143 */
1144 unsigned long tte = s2tt_test_helpers_gen_ns_attrs(true, false);
1145 long level = s2tt_test_helpers_min_block_lvl() - 1L;
1146
1147 test_helpers_expect_assert_fail(true);
1148 (void)host_ns_s2tte_is_valid((const struct s2tt_context *)&s2tt_ctx,
1149 tte, level);
1150 test_helpers_fail_if_no_assert_failed();
1151}
1152
1153void host_ns_s2tte_is_valid_tc4(void)
1154{
1155 /***************************************************************
1156 * TEST CASE 4:
1157 *
1158 * Test host_ns_s2tte_is_valid() with a valid NS S2TTE but a
1159 * level above the maximum supported. This should cause an
1160 * assert fail even if the PA is not aligned to the invalid
1161 * level.
1162 ***************************************************************/
1163
Soby Mathewb1228bb2024-12-31 17:42:46 +00001164 struct s2tt_context s2tt_ctx;
1165
1166 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001167
1168 /*
1169 * Initialize an s2tt_context structure for the test.
1170 * Only 'enable_lpa2' is used by the API, so the rest of fields
1171 * can be left untouched.
1172 */
1173 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1174
1175 /*
1176 * Generate the tte with an assumed PA == 0, which is aligned to
1177 * any level.
1178 */
1179 unsigned long tte = s2tt_test_helpers_gen_ns_attrs(true, false);
1180 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
1181
1182 test_helpers_expect_assert_fail(true);
1183 (void)host_ns_s2tte_is_valid((const struct s2tt_context *)&s2tt_ctx,
1184 tte, level);
1185 test_helpers_fail_if_no_assert_failed();
1186}
1187
1188void host_ns_s2tte_is_valid_tc5(void)
1189{
1190 /***************************************************************
1191 * TEST CASE 5:
1192 *
1193 * Test host_ns_s2tte_is_valid() with valid parameters but a
1194 * NULL s2tt_context struct pointer.
1195 ***************************************************************/
1196
1197 long level = s2tt_test_helpers_min_block_lvl();
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001198 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001199 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
1200 unsigned long tte = s2tt_test_helpers_pa_to_s2tte(pa, level) | host_attrs;
1201
1202 test_helpers_expect_assert_fail(true);
1203 (void)host_ns_s2tte_is_valid((const struct s2tt_context *)NULL,
1204 tte, level);
1205 test_helpers_fail_if_no_assert_failed();
1206}
1207
Shruti Guptac5a3c202024-09-23 13:43:22 +01001208void host_ns_s2tte_is_valid_tc6(void)
1209{
1210 /***************************************************************
1211 * TEST CASE 6:
1212 *
1213 * Test host_ns_s2tte_is_valid() with invalid PA >= 48 bits
1214 * when LPA2 is disabled
1215 **************************************************************/
1216
Soby Mathewb1228bb2024-12-31 17:42:46 +00001217 struct s2tt_context s2tt_ctx;
1218
1219 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
1220
Shruti Guptac5a3c202024-09-23 13:43:22 +01001221 unsigned long host_attrs;
1222 unsigned long tte;
1223 long level = s2tt_test_helpers_min_block_lvl();
1224 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
1225
1226 if (is_feat_lpa2_4k_2_present() == false) {
1227 CHECK_TRUE(true);
1228 return;
1229 }
1230
1231 pa = pa | (1UL << S2TT_MAX_PA_BITS);
1232 host_attrs =
1233 s2tt_test_helpers_gen_ns_attrs(true, false);
1234 tte = s2tt_test_helpers_pa_to_s2tte(pa, level) |
1235 host_attrs;
1236
1237 CHECK_TRUE(s2tt_test_helpers_s2tte_to_pa(tte, level) >= (1UL << S2TT_MAX_PA_BITS));
1238 CHECK_FALSE(host_ns_s2tte_is_valid((const struct s2tt_context *)&s2tt_ctx,
1239 tte, level));
1240}
1241
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001242void host_ns_s2tte_tc1(void)
1243{
1244 /***************************************************************
1245 * TEST CASE 1:
1246 *
1247 * Create an assigned-NS S2TTE with valid parameters and
1248 * verify that host_ns_s2tte() returns the portion of the S2TTE
1249 * has been set by the host.
1250 ***************************************************************/
1251
Soby Mathewb1228bb2024-12-31 17:42:46 +00001252 struct s2tt_context s2tt_ctx;
1253
1254 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001255
1256 /*
1257 * Initialize an s2tt_context structure for the test.
1258 * Only 'enable_lpa2' is used by the API, so the rest of fields
1259 * can be left untouched.
1260 */
1261 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1262
1263 /* Test for each possible level */
1264 for (long level = s2tt_test_helpers_min_block_lvl();
1265 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001266 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001267 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true,
1268 false);
1269 unsigned long val_tte = s2tte_create_assigned_ns(
1270 (const struct s2tt_context *)&s2tt_ctx,
1271 s2tt_test_helpers_pa_to_s2tte(pa, level) |
1272 host_attrs, level);
1273 unsigned long tte = host_ns_s2tte((const struct s2tt_context *)&s2tt_ctx,
1274 val_tte, level);
1275
1276 /* Validate the address */
1277 UNSIGNED_LONGS_EQUAL(s2tt_test_helpers_s2tte_to_pa(val_tte, level),
1278 s2tt_test_helpers_s2tte_to_pa(tte, level));
1279
1280 /*
1281 * Validate that the rest of the S2TTE (excluding the PA)
1282 * matches the host_attrs (and therefore any other bit is '0')
1283 */
1284 UNSIGNED_LONGS_EQUAL(host_attrs,
1285 (tte & ~s2tt_test_helpers_s2tte_oa_mask()));
1286 }
1287}
1288
1289void host_ns_s2tte_tc2(void)
1290{
1291 /***************************************************************
1292 * TEST CASE 2:
1293 *
1294 * Test host_ns_s2tte() with a valid NS S2TTE but a level
1295 * below the minimum supported.
1296 ***************************************************************/
1297
Soby Mathewb1228bb2024-12-31 17:42:46 +00001298 struct s2tt_context s2tt_ctx;
1299
1300 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001301
1302 /*
1303 * Initialize an s2tt_context structure for the test.
1304 * Only 'enable_lpa2' is used by the API, so the rest of fields
1305 * can be left untouched.
1306 */
1307 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1308
1309 /*
1310 * Generate the tte with an assumed PA == 0, which is aligned to
1311 * any level.
1312 */
1313 long level = s2tt_test_helpers_min_block_lvl();
1314 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
1315
1316 /* s2tte_create_assigned_ns() can receive a NULL s2tt_context pointer */
1317 unsigned long tte = s2tte_create_assigned_ns(
1318 (const struct s2tt_context *)&s2tt_ctx,
1319 0UL | host_attrs, level);
1320
1321 test_helpers_expect_assert_fail(true);
1322
1323 /*
1324 * Initialize an s2tt_context structure for the test.
1325 * Only 'enable_lpa2' is used by the API, so the rest of fields
1326 * can be left untouched.
1327 */
1328 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1329 (void)host_ns_s2tte((const struct s2tt_context *)&s2tt_ctx, tte, level - 1L);
1330 test_helpers_fail_if_no_assert_failed();
1331}
1332
1333void host_ns_s2tte_tc3(void)
1334{
1335 /***************************************************************
1336 * TEST CASE 3:
1337 *
1338 * Test host_ns_s2tte() with a valid NS S2TTE but a level
1339 * above the maximum supported.
1340 ***************************************************************/
1341
Soby Mathewb1228bb2024-12-31 17:42:46 +00001342 struct s2tt_context s2tt_ctx;
1343
1344 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001345
1346 /*
1347 * Generate the tte with an assumed PA == 0, which is aligned to
1348 * any level.
1349 */
1350 long level = S2TT_TEST_HELPERS_MAX_LVL;
1351 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
1352
1353 /* s2tte_create_assigned_ns() can receive a NULL s2tt_context pointer */
1354 unsigned long tte = s2tte_create_assigned_ns(
1355 (const struct s2tt_context *)&s2tt_ctx,
1356 0UL | host_attrs, level);
1357
1358 test_helpers_expect_assert_fail(true);
1359 /*
1360 * Initialize an s2tt_context structure for the test.
1361 * Only 'enable_lpa2' is used by the API, so the rest of fields
1362 * can be left untouched.
1363 */
1364 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1365 (void)host_ns_s2tte((const struct s2tt_context *)&s2tt_ctx, tte, level + 1L);
1366 test_helpers_fail_if_no_assert_failed();
1367}
1368
1369void host_ns_s2tte_tc4(void)
1370{
1371 /***************************************************************
1372 * TEST CASE 4:
1373 *
1374 * Test host_ns_s2tte() passing a NULL pointer to an
1375 * s2tt_context structure.
1376 ***************************************************************/
1377
1378 /* Test for each possible level */
1379 long level = s2tt_test_helpers_min_block_lvl();
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001380 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001381 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
1382
Soby Mathewb1228bb2024-12-31 17:42:46 +00001383 struct s2tt_context s2tt_ctx;
1384
1385 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Soby Mathew217748d2024-10-02 11:02:19 +01001386
1387 /*
1388 * Initialize an s2tt_context structure for the test.
1389 * Only 'enable_lpa2' is used by the API, so the rest of fields
1390 * can be left untouched.
1391 */
1392 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1393
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001394 unsigned long val_tte = s2tte_create_assigned_ns(
Soby Mathew217748d2024-10-02 11:02:19 +01001395 (const struct s2tt_context *)&s2tt_ctx,
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001396 s2tt_test_helpers_pa_to_s2tte(pa, level) |
1397 host_attrs, level);
1398 test_helpers_expect_assert_fail(true);
1399 (void)host_ns_s2tte((const struct s2tt_context *)NULL, val_tte, level);
1400 test_helpers_fail_if_no_assert_failed();
1401}
1402
1403void s2tte_has_ripas_tc1(void)
1404{
1405 /***************************************************************
1406 * TEST CASE 1:
1407 *
1408 * For each valid level at which a TTE can have RIPAS, generate
1409 * a set of assigned/unassigned S2TTEs with different RIPAS and
1410 * validate the output of s2tte_has_ripas().
1411 ***************************************************************/
1412
1413 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1414 S2TTE_INVALID_RIPAS_RAM,
1415 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001416 struct s2tt_context s2tt_ctx;
1417
1418 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001419
1420 /*
1421 * Initialize an s2tt_context structure for the test.
1422 * Only 'enable_lpa2' is used by the API, so the rest of fields
1423 * can be left untouched.
1424 */
1425 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1426
1427 for (long level = s2tt_test_helpers_min_block_lvl();
1428 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1429 for (unsigned int i = 0U; i < ARRAY_SIZE(ripas); i++) {
1430
1431 unsigned long tte;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001432 unsigned long pa = s2tt_test_helpers_gen_addr(level,
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001433 true);
1434
1435 /* Validate with an assigned S2TTE */
1436 tte = s2tt_test_create_assigned(
1437 (const struct s2tt_context *)&s2tt_ctx,
1438 pa, level, ripas[i]);
1439 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
1440 tte, level) == true);
1441
1442 /* Validate with an unassigned S2TTE */
1443 tte = s2tt_test_create_unassigned((
1444 const struct s2tt_context *)&s2tt_ctx,
1445 ripas[i]);
1446 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
1447 tte, level) == true);
1448 }
1449 }
1450}
1451
1452void s2tte_has_ripas_tc2(void)
1453{
1454 /***************************************************************
1455 * TEST CASE 2:
1456 *
1457 * For each valid level generate a set of negative tests:
1458 *
1459 * - For each valid level at which a TTE can have RIPAS,
1460 * generate a set of NS-S2TTEs (assigned and unassigned)
1461 * and validate that s2tte_has_ripas() returns
1462 * the expected error.
1463 * - For each valid level at which a table can exist,
1464 * Generate a table and verify that s2tte_has_ripas()
1465 * returns the expected value.
1466 ***************************************************************/
1467
1468 unsigned long tte;
Soby Mathewb1228bb2024-12-31 17:42:46 +00001469 struct s2tt_context s2tt_ctx;
1470
1471 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001472
1473 /*
1474 * Initialize an s2tt_context structure for the test.
1475 * Only 'enable_lpa2' is used by the API, so the rest of fields
1476 * can be left untouched.
1477 */
1478 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1479
1480 /* Generate a set of NS S2TTEs per valid level */
1481 for (long level = s2tt_test_helpers_min_block_lvl();
1482 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1483
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001484 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001485 unsigned long host_attr = s2tt_test_helpers_gen_ns_attrs(true,
1486 false);
1487 tte = s2tte_create_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1488 host_attr | s2tt_test_helpers_pa_to_s2tte(pa, level),
1489 level);
1490 /* Validate with assigned-ns S2TTE */
1491 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
1492 tte, level) == false);
1493
1494 /* Validate with unassigned-ns S2TTE */
1495 tte = s2tte_create_unassigned_ns((const struct s2tt_context *)&s2tt_ctx);
1496 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)NULL,
1497 tte, level) == false);
1498 }
1499
1500 for (long level = s2tt_test_helpers_min_table_lvl();
1501 level < s2tt_test_helpers_min_block_lvl(); level++) {
1502
1503 /* Use Addr 0UL as it is valid on any level */
1504 tte = s2tte_create_table((const struct s2tt_context *)&s2tt_ctx,
1505 0UL, level);
1506
1507 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
1508 tte, level) == false);
1509 }
1510}
1511
1512void s2tte_is_unassigned_tc1(void)
1513{
1514 /***************************************************************
1515 * TEST CASE 1:
1516 *
1517 * This test case cover positive tests for s2tt_is_unassigned()
1518 * as well as a number of negative tests.
1519 ***************************************************************/
1520
1521 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1522 S2TTE_INVALID_RIPAS_RAM,
1523 S2TTE_INVALID_RIPAS_DESTROYED,
1524 S2TTE_NS};
1525
1526 /* pickup a random type of unassigned S2TTE to test with */
1527 unsigned int ripas_idx = (unsigned int)test_helpers_get_rand_in_range(
1528 0UL, ARRAY_SIZE(ripas) - 1UL);
1529 unsigned long inv_tte, tte = s2tt_test_create_unassigned(
1530 (const struct s2tt_context *)NULL, ripas[ripas_idx]);
1531
1532 /* Validate s2tt_is_unassigned with an unassigned TTE. */
1533 CHECK_TRUE(s2tte_is_unassigned((const struct s2tt_context *)NULL, tte) == true);
1534
1535 /* Negative test: Set DESC_TYPE to a valid descriptor */
1536 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1537 CHECK_TRUE(s2tte_is_unassigned((const struct s2tt_context *)NULL, inv_tte) == false);
1538
1539 /* Negative test: Change the HIPAS to ASSIGNED */
1540 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1541 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1542 CHECK_TRUE(s2tte_is_unassigned((const struct s2tt_context *)NULL, inv_tte) == false);
1543}
1544
1545void s2tte_is_unassigned_empty_tc1(void)
1546{
1547 /***************************************************************
1548 * TEST CASE 1:
1549 *
1550 * This test case cover positive tests for
1551 * is_unassigned_empty() as well as a number of negative tests.
1552 ***************************************************************/
1553
1554 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_RAM,
1555 S2TTE_INVALID_RIPAS_DESTROYED,
1556 S2TTE_NS};
1557
1558 unsigned int idx;
1559 unsigned long inv_tte;
1560 unsigned long tte = s2tte_create_unassigned_empty(
1561 (const struct s2tt_context *)NULL);
1562
1563 /* Validate s2tt_is_unassigned_empty with an unassigned TTE */
1564 CHECK_TRUE(s2tte_is_unassigned_empty((const struct s2tt_context *)NULL, tte) == true);
1565
1566 /* Negative test: Set DESC_TYPE to a valid descriptor */
1567 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1568 CHECK_TRUE(s2tte_is_unassigned_empty((const struct s2tt_context *)NULL, inv_tte) == false);
1569
1570 /* Negative test: Change the HIPAS to ASSIGNED */
1571 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1572 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1573 CHECK_TRUE(s2tte_is_unassigned_empty((const struct s2tt_context *)NULL, inv_tte) == false);
1574
1575 /* Negative test: Test with a different type of unassigned TTE but having RIPAS */
1576 idx = (unsigned int)test_helpers_get_rand_in_range(
1577 0UL, ARRAY_SIZE(ripas) - 1UL);
1578 inv_tte = s2tt_test_create_unassigned((const struct s2tt_context *)NULL, ripas[idx]);
1579 CHECK_TRUE(s2tte_is_unassigned_empty((const struct s2tt_context *)NULL, inv_tte) == false);
1580}
1581
1582void s2tte_is_unassigned_ram_tc1(void)
1583{
1584 /***************************************************************
1585 * TEST CASE 1:
1586 *
1587 * This test case cover positive tests for
1588 * is_unassigned_ram() as well as a number of negative tests.
1589 ***************************************************************/
1590
1591 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1592 S2TTE_INVALID_RIPAS_DESTROYED,
1593 S2TTE_NS};
1594 unsigned int idx;
1595 unsigned long inv_tte;
1596 unsigned long tte = s2tte_create_unassigned_ram(
1597 (const struct s2tt_context *)NULL);
1598
1599 /* Validate s2tt_is_unassigned_ram with an unassigned ram TTE */
1600 CHECK_TRUE(s2tte_is_unassigned_ram((const struct s2tt_context *)NULL, tte) == true);
1601
1602 /* Negative test: Set DESC_TYPE to a valid descriptor */
1603 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1604 CHECK_TRUE(s2tte_is_unassigned_ram((const struct s2tt_context *)NULL, inv_tte) == false);
1605
1606 /* Negative test: Change the HIPAS to ASSIGNED */
1607 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1608 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1609 CHECK_TRUE(s2tte_is_unassigned_ram((const struct s2tt_context *)NULL, inv_tte) == false);
1610
1611 /* Negative test: Test with a different type of unassigned TTE */
1612 idx = (unsigned int)test_helpers_get_rand_in_range(
1613 0UL, ARRAY_SIZE(ripas) - 1UL);
1614 inv_tte = s2tt_test_create_unassigned((const struct s2tt_context *)NULL, ripas[idx]);
1615 CHECK_TRUE(s2tte_is_unassigned_ram((const struct s2tt_context *)NULL, inv_tte) == false);
1616}
1617
1618void s2tte_is_unassigned_ns_tc1(void)
1619{
1620 /***************************************************************
1621 * TEST CASE 1:
1622 *
1623 * This test case cover positive tests for
1624 * is_unassigned_ns() as well as a number of negative tests.
1625 ***************************************************************/
1626
1627 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1628 S2TTE_INVALID_RIPAS_DESTROYED,
1629 S2TTE_INVALID_RIPAS_RAM};
1630 unsigned int idx;
1631 unsigned long inv_tte;
1632 unsigned long tte = s2tte_create_unassigned_ns((
1633 const struct s2tt_context *)NULL);
1634
1635 /* Validate s2tt_is_unassigned_ns with an unassigned ns TTE */
1636 CHECK_TRUE(s2tte_is_unassigned_ns((const struct s2tt_context *)NULL, tte) == true);
1637
1638 /* Negative test: Set DESC_TYPE to a valid descriptor */
1639 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1640 CHECK_TRUE(s2tte_is_unassigned_ns((const struct s2tt_context *)NULL, inv_tte) == false);
1641
1642 /* Negative test: Change the HIPAS to ASSIGNED */
1643 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1644 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1645 CHECK_TRUE(s2tte_is_unassigned_ns((const struct s2tt_context *)NULL, inv_tte) == false);
1646
1647 /* Negative test: Test with a different type of unassigned TTE */
1648 idx = (unsigned int)test_helpers_get_rand_in_range(
1649 0UL, ARRAY_SIZE(ripas) - 1UL);
1650 inv_tte = s2tt_test_create_unassigned((const struct s2tt_context *)NULL, ripas[idx]);
1651 CHECK_TRUE(s2tte_is_unassigned_ns((const struct s2tt_context *)NULL, inv_tte) == false);
1652}
1653
1654void s2tte_is_unassigned_destroyed_tc1(void)
1655{
1656 /***************************************************************
1657 * TEST CASE 1:
1658 *
1659 * This test case cover positive tests for
1660 * is_unassigned_destroyed() as well as a number of
1661 * negative tests.
1662 ***************************************************************/
1663
1664 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1665 S2TTE_NS,
1666 S2TTE_INVALID_RIPAS_RAM};
1667 unsigned int idx;
1668 unsigned long inv_tte;
1669 unsigned long tte = s2tte_create_unassigned_destroyed(
1670 (const struct s2tt_context *)NULL);
1671
1672 /* Validate s2tt_is_unassigned_destroyed with an unassigned destroyed TTE */
1673 CHECK_TRUE(s2tte_is_unassigned_destroyed(
1674 (const struct s2tt_context *)NULL, tte) == true);
1675
1676 /* Negative test: Set DESC_TYPE to a valid descriptor */
1677 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1678 CHECK_TRUE(s2tte_is_unassigned_destroyed(
1679 (const struct s2tt_context *)NULL, inv_tte) == false);
1680
1681 /* Negative test: Change the HIPAS to ASSIGNED */
1682 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1683 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1684 CHECK_TRUE(s2tte_is_unassigned_destroyed(
1685 (const struct s2tt_context *)NULL, inv_tte) == false);
1686
1687 /* Negative test: Test with a different type of unassigned TTE */
1688 idx = (unsigned int)test_helpers_get_rand_in_range(
1689 0UL, ARRAY_SIZE(ripas) - 1UL);
1690 inv_tte = s2tt_test_create_unassigned((const struct s2tt_context *)NULL, ripas[idx]);
1691 CHECK_FALSE(s2tte_is_unassigned_destroyed((const struct s2tt_context *)NULL, inv_tte));
1692}
1693
1694void s2tte_is_assigned_empty_tc1(void)
1695{
1696 /***************************************************************
1697 * TEST CASE 1:
1698 *
1699 * This test case cover positive tests for is_assigned_empty()
1700 * as well as a number of negative tests for each valid level.
1701 ***************************************************************/
1702
1703 unsigned long ripas[] = {S2TTE_NS,
1704 S2TTE_INVALID_RIPAS_RAM,
1705 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001706 struct s2tt_context s2tt_ctx;
1707
1708 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001709
1710 /*
1711 * Initialize an s2tt_context structure for the test.
1712 * Only 'enable_lpa2' is used by the API, so the rest of fields
1713 * can be left untouched.
1714 */
1715 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1716
1717 for (long level = s2tt_test_helpers_min_block_lvl();
1718 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1719 unsigned int idx;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001720 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001721 unsigned long inv_tte, tte =
1722 s2tte_create_assigned_empty(
1723 (const struct s2tt_context *)&s2tt_ctx,
1724 pa, level);
1725
1726 /* Validate s2tt_is_assigned_empty with an unassigned empty TTE */
1727 CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
1728 tte, level) == true);
1729
1730 /* Negative test: Set DESC_TYPE to a valid descriptor */
1731 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1732 CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
1733 inv_tte, level) == false);
1734
1735 /* Negative test: Change the HIPAS to UNASSIGNED */
1736 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1737 inv_tte |= S2TTE_INVALID_HIPAS_UNASSIGNED;
1738 CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
1739 inv_tte, level) == false);
1740
1741 /* Negative test: Test with a different type of assigned TTE */
1742 idx = (unsigned int)test_helpers_get_rand_in_range(
1743 0UL, ARRAY_SIZE(ripas) - 1UL);
1744 inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
1745 pa, level, ripas[idx]);
1746 CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
1747 inv_tte, level) == false);
1748 }
1749}
1750
1751void s2tte_is_assigned_ns_tc1(void)
1752{
1753 /***************************************************************
1754 * TEST CASE 1:
1755 *
1756 * This test case cover positive tests for is_assigned_ns()
1757 * as well as a number of negative tests for each valid level.
1758 ***************************************************************/
1759
1760 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1761 S2TTE_INVALID_RIPAS_RAM,
1762 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001763 struct s2tt_context s2tt_ctx;
1764
1765 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
1766
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001767 /*
1768 * Initialize an s2tt_context structure for the test.
1769 * Only 'enable_lpa2' is used by the API, so the rest of fields
1770 * can be left untouched.
1771 */
1772 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1773
1774 for (long level = s2tt_test_helpers_min_block_lvl();
1775 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1776 unsigned int idx;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001777 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001778 unsigned long inv_tte, tte =
1779 s2tt_test_helpers_gen_ns_attrs(true, false);
1780
1781 tte = s2tte_create_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1782 s2tt_test_helpers_pa_to_s2tte(pa, level) | tte,
1783 level);
1784
1785 /* Validate s2tt_is_assigned_ns with an assigned ns TTE */
1786 CHECK_TRUE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1787 tte, level) == true);
1788
1789 /*
1790 * Negative test: Test using UNASSIGNED_NS TTE
1791 */
1792 inv_tte = s2tte_create_unassigned_ns(
1793 (const struct s2tt_context *)&s2tt_ctx);
1794 CHECK_TRUE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1795 inv_tte, level) == false);
1796
1797 /*
1798 * Negative test: Test with a different type of assigned TTE
1799 * which has RIPAS.
1800 */
1801 idx = (unsigned int)test_helpers_get_rand_in_range(
1802 0UL, ARRAY_SIZE(ripas) - 1UL);
1803 inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
1804 pa, level, ripas[idx]);
1805 CHECK_TRUE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1806 inv_tte, level) == false);
1807 }
1808}
1809
1810void s2tte_is_assigned_ns_tc2(void)
1811{
1812 /***************************************************************
1813 * TEST CASE 2:
1814 *
1815 * Test s2tte_is_assigned_ns() with invalid levels.
1816 ***************************************************************/
1817 unsigned long pa = 0UL;
1818 unsigned long tte = s2tt_test_helpers_gen_ns_attrs(true, false);
1819 long level = s2tt_test_helpers_min_block_lvl();
Soby Mathewb1228bb2024-12-31 17:42:46 +00001820 struct s2tt_context s2tt_ctx;
1821
1822 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001823
1824 /*
1825 * Initialize an s2tt_context structure for the test.
1826 * Only 'enable_lpa2' is used by the API, so the rest of fields
1827 * can be left untouched.
1828 */
1829 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1830
1831 tte = s2tte_create_assigned_ns(
1832 (const struct s2tt_context *)&s2tt_ctx,
1833 s2tt_test_helpers_pa_to_s2tte(pa, level) | tte,
1834 level);
1835
1836 /* Validate s2tt_is_assigned_ns with an assigned ns TTE */
1837 CHECK_FALSE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx, tte,
1838 s2tt_test_helpers_min_table_lvl()));
1839 CHECK_FALSE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx, tte,
1840 S2TT_TEST_HELPERS_MAX_LVL));
1841}
1842
1843void s2tte_is_assigned_ram_tc1(void)
1844{
1845 /***************************************************************
1846 * TEST CASE 1:
1847 *
1848 * This test case cover positive tests for is_assigned_ram()
1849 * as well as a number of negative tests for each valid level.
1850 ***************************************************************/
1851
1852 unsigned long ripas[] = {S2TTE_NS,
1853 S2TTE_INVALID_RIPAS_EMPTY,
1854 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001855 struct s2tt_context s2tt_ctx;
1856
1857 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001858
1859 /*
1860 * Initialize an s2tt_context structure for the test.
1861 * Only 'enable_lpa2' is used by the API, so the rest of fields
1862 * can be left untouched.
1863 */
1864 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1865
1866 for (long level = s2tt_test_helpers_min_block_lvl();
1867 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1868 unsigned int idx;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001869 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001870 unsigned long inv_tte, tte =
1871 s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1872 pa, level);
1873
1874 /* Validate s2tt_is_assigned_empty with an assigned ram TTE */
1875 CHECK_TRUE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1876 tte, level) == true);
1877
1878 /*
1879 * Negative test: Test with UNASSIGNED-RAM
1880 * We test with UNASSIGNED-RAM as in the current RMM implementation,
1881 * an ASSIGNED-RAM S2TTE does not have HIPAS field, so we pick
1882 * up an S2TTE with a HIPAS other than ASSIGNED.
1883 */
1884 inv_tte = s2tte_create_unassigned_ram(
1885 (const struct s2tt_context *)&s2tt_ctx);
1886 CHECK_TRUE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1887 inv_tte, level) == false);
1888
1889 /* Negative test: Test with a different type of RIPAS */
1890 idx = (unsigned int)test_helpers_get_rand_in_range(
1891 0UL, ARRAY_SIZE(ripas) - 1UL);
1892 inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
1893 pa, level, ripas[idx]);
1894 CHECK_TRUE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1895 inv_tte, level) == false);
1896 }
1897}
1898
1899void s2tte_is_assigned_ram_tc2(void)
1900{
1901 /***************************************************************
1902 * TEST CASE 2:
1903 *
1904 * Test s2tte_is_assigned_ram() with invalid levels.
1905 ***************************************************************/
1906 unsigned long pa = 0UL;
1907 unsigned long tte;
Soby Mathewb1228bb2024-12-31 17:42:46 +00001908 struct s2tt_context s2tt_ctx;
1909
1910 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001911
1912 /*
1913 * Initialize an s2tt_context structure for the test.
1914 * Only 'enable_lpa2' is used by the API, so the rest of fields
1915 * can be left untouched.
1916 */
1917 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1918
1919 tte = s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1920 pa, s2tt_test_helpers_min_block_lvl());
1921
1922 /* Validate s2tt_is_assigned_ram with an assigned ram TTE */
1923 CHECK_FALSE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1924 tte, s2tt_test_helpers_min_block_lvl() - 1L));
1925 CHECK_FALSE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1926 tte, S2TT_TEST_HELPERS_MAX_LVL));
1927}
1928
1929void s2tte_is_assigned_destroyed_tc1(void)
1930{
1931 /***************************************************************
1932 * TEST CASE 1:
1933 *
1934 * This test case cover positive tests for
1935 * is_assigned_destroyed() as well as a number of negative
1936 * tests for each valid level.
1937 ***************************************************************/
1938
1939 unsigned long ripas[] = {S2TTE_NS,
1940 S2TTE_INVALID_RIPAS_RAM,
1941 S2TTE_INVALID_RIPAS_EMPTY};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001942 struct s2tt_context s2tt_ctx;
1943
1944 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001945
1946 /*
1947 * Initialize an s2tt_context structure for the test.
1948 * Only 'enable_lpa2' is used by the API, so the rest of fields
1949 * can be left untouched.
1950 */
1951 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1952
1953 for (long level = s2tt_test_helpers_min_block_lvl();
1954 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1955 unsigned int idx;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001956 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001957 unsigned long inv_tte, tte =
1958 s2tte_create_assigned_destroyed(
1959 (const struct s2tt_context *)&s2tt_ctx,
1960 pa, level);
1961
1962 /* Validate s2tt_is_assigned_destroyed with an assigned destroyed TTE */
1963 CHECK_TRUE(s2tte_is_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
1964 tte, level) == true);
1965
1966 /* Negative test: Set DESC_TYPE to a valid descriptor */
1967 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1968 CHECK_TRUE(s2tte_is_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
1969 inv_tte, level) == false);
1970
1971 /* Negative test: Change the HIPAS to UNASSIGNED */
1972 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1973 inv_tte |= S2TTE_INVALID_HIPAS_UNASSIGNED;
1974 CHECK_TRUE(s2tte_is_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
1975 inv_tte, level) == false);
1976
1977 /* Negative test: Test with a different RIPAS */
1978 idx = (unsigned int)test_helpers_get_rand_in_range(
1979 0UL, ARRAY_SIZE(ripas) - 1UL);
1980 inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
1981 pa, level, ripas[idx]);
1982 CHECK_TRUE(s2tte_is_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
1983 inv_tte, level) == false);
1984 }
1985}
1986
1987void s2tte_is_table_tc1(void)
1988{
1989 /***************************************************************
1990 * TEST CASE 1:
1991 *
1992 * This test case cover positive tests for is_table() as well
1993 * as a number of negative tests for each valid level.
1994 ***************************************************************/
1995
Soby Mathewb1228bb2024-12-31 17:42:46 +00001996 struct s2tt_context s2tt_ctx;
1997
1998 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001999
2000 /*
2001 * Initialize an s2tt_context structure for the test.
2002 * Only 'enable_lpa2' is used by the API, so the rest of fields
2003 * can be left untouched.
2004 */
2005 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2006
2007 for (long level = s2tt_test_helpers_min_table_lvl();
2008 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2009 unsigned long pa, inv_tte, tte = 0UL;
2010
2011 if (level <= S2TT_TEST_HELPERS_MAX_TABLE_LVL) {
2012 /* Validate s2tt_is_table with a valid table TTE */
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002013 pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002014 tte = s2tte_create_table(
2015 (const struct s2tt_context *)&s2tt_ctx,
2016 pa, level);
2017 CHECK_TRUE(s2tte_is_table((const struct s2tt_context *)&s2tt_ctx,
2018 tte, level) == true);
2019 } else {
2020 /*
2021 * Per aarch64 VMSA, PAGE and TABLE S2TTEs share the
2022 * same descriptor type ID, but the PAGE will only be
2023 * allowed into the last supported level. So reuse the
2024 * previous tte and test again with the PAGE level.
2025 */
2026 CHECK_TRUE(s2tte_is_table((const struct s2tt_context *)&s2tt_ctx,
2027 tte, level) == false);
2028 }
2029
2030 /* Negative test: Set DESC_TYPE to INVALID */
2031 inv_tte = tte & ~S2TT_TEST_DESC_TYPE_MASK;
2032 inv_tte = inv_tte | S2TT_TEST_INVALID_DESC;
2033 CHECK_TRUE(s2tte_is_table((const struct s2tt_context *)&s2tt_ctx,
2034 inv_tte, level) == false);
2035
2036 /* Negative test: Set DESC_TYPE to BLOCK */
2037 inv_tte = tte & ~S2TT_TEST_DESC_TYPE_MASK;
2038 inv_tte = inv_tte | S2TT_TEST_BLOCK_DESC;
2039 CHECK_TRUE(s2tte_is_table((const struct s2tt_context *)&s2tt_ctx,
2040 inv_tte, level) == false);
2041 }
2042}
2043
2044void s2tte_get_ripas_tc1(void)
2045{
2046 /***************************************************************
2047 * TEST CASE 1:
2048 *
2049 * For all possible RIPAS types, generate a HIPAS ASSIGNED and
2050 * a HIPAS UNASSIGNED S2TTE and verify that s2tt_get_ripas()
2051 * returns the right RIPAS
2052 ***************************************************************/
2053
2054 unsigned long tte, pa;
2055 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
2056 S2TTE_INVALID_RIPAS_RAM,
2057 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00002058 struct s2tt_context s2tt_ctx;
2059
2060 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002061
2062 /*
2063 * Initialize an s2tt_context structure for the test.
2064 * Only 'enable_lpa2' is used by the API, so the rest of fields
2065 * can be left untouched.
2066 */
2067 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2068
2069 for (unsigned int i = 0U; i < ARRAY_SIZE(ripas); i++) {
2070 /* HIPAS = UNASSIGNED */
2071 tte = s2tt_test_create_unassigned(
2072 (const struct s2tt_context *)&s2tt_ctx, ripas[i]);
2073 UNSIGNED_LONGS_EQUAL((unsigned int)s2tte_get_ripas(
2074 (const struct s2tt_context *)&s2tt_ctx, tte),
2075 EXTRACT(S2TTE_INVALID_RIPAS, ripas[i]));
2076
2077 /* HIPAS = ASSIGNED */
2078 for (long level = s2tt_test_helpers_min_block_lvl();
2079 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002080 pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002081 tte = s2tt_test_create_assigned(
2082 (const struct s2tt_context *)&s2tt_ctx,
2083 pa, level, ripas[i]);
2084 UNSIGNED_LONGS_EQUAL(
2085 (unsigned int)s2tte_get_ripas(
2086 (const struct s2tt_context *)&s2tt_ctx, tte),
2087 EXTRACT(S2TTE_INVALID_RIPAS, ripas[i]));
2088 }
2089 }
2090}
2091
2092void s2tte_get_ripas_tc2(void)
2093{
2094 /***************************************************************
2095 * TEST CASE 2:
2096 *
2097 * Test s2tte_get_ripas() with an invalid S2TTE and an invalid
2098 * HIPAS.
2099 ***************************************************************/
2100
2101 unsigned long tte = s2tte_create_unassigned_destroyed(
2102 (const struct s2tt_context *)NULL);
2103 tte &= ~S2TTE_INVALID_HIPAS_MASK;
2104
2105 /*
2106 * As per s2tt_pvt_defs.h, HIPAS field is 3 bits wide with
2107 * only the first bit used.
2108 */
2109 tte |= INPLACE(S2TTE_INVALID_HIPAS,
2110 EXTRACT(S2TTE_INVALID_HIPAS, S2TTE_INVALID_HIPAS_ASSIGNED) + 1UL);
2111
2112 test_helpers_expect_assert_fail(true);
2113 (void)s2tte_get_ripas((const struct s2tt_context *)NULL, tte);
2114 test_helpers_fail_if_no_assert_failed();
2115}
2116
2117void s2tt_init_unassigned_empty_tc1(void)
2118{
2119 /***************************************************************
2120 * TEST CASE 1:
2121 *
2122 * Initialize a table with unassigned empty S2TTEs and validate
2123 * its content.
2124 ***************************************************************/
2125
2126 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
2127 unsigned long val_s2tt[S2TTES_PER_S2TT];
2128
2129 /* Generate the validation table */
2130 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2131 val_s2tt[i] =
2132 s2tte_create_unassigned_empty(
2133 (const struct s2tt_context *)NULL);
2134 }
2135
2136 /*
2137 * Generate the test table. Note that s2tt_init_unassigned_empty()
2138 * can take a NULL s2tt_context pointer.
2139 */
2140 s2tt_init_unassigned_empty((const struct s2tt_context *)NULL, &s2tt[0]);
2141
2142 /* Validate */
2143 MEMCMP_EQUAL(val_s2tt, s2tt, sizeof(s2tt));
2144}
2145
2146void s2tt_init_unassigned_empty_tc2(void)
2147{
2148 /***************************************************************
2149 * TEST CASE 2:
2150 *
2151 * Invoke s2tt_init_unassigned_empty() passing a NULL
2152 * s2tt pointer.
2153 *
2154 * Note that s2tt_init_unassigned_empty() can take a NULL
2155 * s2tt_context pointer.
2156 ***************************************************************/
2157
2158 test_helpers_expect_assert_fail(true);
2159 s2tt_init_unassigned_empty((const struct s2tt_context *)NULL, NULL);
2160 test_helpers_fail_if_no_assert_failed();
2161}
2162
2163void s2tt_init_unassigned_ram_tc1(void)
2164{
2165 /***************************************************************
2166 * TEST CASE 1:
2167 *
2168 * Initialize a table with unassigned ram S2TTEs and validate its
2169 * content.
2170 ***************************************************************/
2171
2172 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
2173 unsigned long val_s2tt[S2TTES_PER_S2TT];
2174
2175 /* Generate the validation table */
2176 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2177 val_s2tt[i] = s2tte_create_unassigned_ram(
2178 (const struct s2tt_context *)NULL);
2179 }
2180
2181 /*
2182 * Generate the test table. Note that s2tt_init_unassigned_ram()
2183 * can take a NULL pointer to struct s2tt_context.
2184 */
2185 s2tt_init_unassigned_ram((const struct s2tt_context *)NULL, &s2tt[0]);
2186
2187 /* Validate */
2188 MEMCMP_EQUAL(val_s2tt, s2tt, sizeof(s2tt));
2189}
2190
2191void s2tt_init_unassigned_ram_tc2(void)
2192{
2193 /***************************************************************
2194 * TEST CASE 2:
2195 *
2196 * Invoke init_unassigned_ram() passing a NULL pointer.
2197 *
2198 * Note that s2tt_init_unassigned_ram() can take a NULL pointer
2199 * to struct s2tt_context.
2200 ***************************************************************/
2201
2202 test_helpers_expect_assert_fail(true);
2203 s2tt_init_unassigned_ram((const struct s2tt_context *)NULL, NULL);
2204 test_helpers_fail_if_no_assert_failed();
2205}
2206
2207void s2tt_init_unassigned_ns_tc1(void)
2208{
2209 /***************************************************************
2210 * TEST CASE 1:
2211 *
2212 * Initialize a table with unassigned ns S2TTEs and validate
2213 * its content.
2214 ***************************************************************/
2215
2216 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
2217 unsigned long val_s2tt[S2TTES_PER_S2TT];
2218
2219 /* Generate the validation table */
2220 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2221 val_s2tt[i] = s2tte_create_unassigned_ns(
2222 (const struct s2tt_context *)NULL);
2223 }
2224
2225 /*
2226 * Generate the test table. Note that s2tt_init_unassigned_ns()
2227 * can take a NULL s2tt_context pointer.
2228 */
2229 s2tt_init_unassigned_ns((const struct s2tt_context *)NULL, &s2tt[0]);
2230
2231 /* Validate */
2232 MEMCMP_EQUAL(val_s2tt, s2tt, sizeof(s2tt));
2233}
2234
2235void s2tt_init_unassigned_ns_tc2(void)
2236{
2237 /***************************************************************
2238 * TEST CASE 2:
2239 *
2240 * Invoke init_unassigned_ns() passing a NULL pointer.
2241 *
2242 * Note that s2tt_init_unassigned_ns() can take a NULL
2243 * struct s2tt_context pointer.
2244 ***************************************************************/
2245
2246 test_helpers_expect_assert_fail(true);
2247 s2tt_init_unassigned_ns((const struct s2tt_context *)NULL, NULL);
2248 test_helpers_fail_if_no_assert_failed();
2249}
2250
2251void s2tt_init_unassigned_destroyed_tc1(void)
2252{
2253 /***************************************************************
2254 * TEST CASE 1:
2255 *
2256 * Initialize a table with unassigned destroyed S2TTEs
2257 * and validate its content.
2258 ***************************************************************/
2259
2260 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
2261 unsigned long val_s2tt[S2TTES_PER_S2TT];
2262
2263 /* Generate the validation table */
2264 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2265 val_s2tt[i] =
2266 s2tte_create_unassigned_destroyed(
2267 (const struct s2tt_context *)NULL);
2268 }
2269
2270 /*
2271 * Generate the test table. Note that s2tt_init_unassigned_destroyed()
2272 * can take a NULL s2tt_context pointer.
2273 */
2274 s2tt_init_unassigned_destroyed((const struct s2tt_context *)NULL,
2275 &s2tt[0]);
2276
2277 /* Validate */
2278 MEMCMP_EQUAL(val_s2tt, s2tt, sizeof(s2tt));
2279}
2280
2281void s2tt_init_unassigned_destroyed_tc2(void)
2282{
2283 /***************************************************************
2284 * TEST CASE 2:
2285 *
2286 * Invoke s2tt_init_unassigned_destroyed() passing a NULL pointer.
2287 *
2288 * Note that s2tt_init_unassigned_destroyed() can take a NULL
2289 * pointer to struct s2tt_context.
2290 ***************************************************************/
2291
2292 test_helpers_expect_assert_fail(true);
2293 s2tt_init_unassigned_destroyed((const struct s2tt_context *)NULL, NULL);
2294 test_helpers_fail_if_no_assert_failed();
2295}
2296
2297void s2tt_init_assigned_empty_tc1(void)
2298{
2299 /***************************************************************
2300 * TEST CASE 1:
2301 *
2302 * For each valid level, initialize a table with assigned-empty
2303 * S2TTEs and validate its contents.
2304 ***************************************************************/
2305
Soby Mathewb1228bb2024-12-31 17:42:46 +00002306 struct s2tt_context s2tt_ctx;
2307
2308 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002309
2310 /*
2311 * Generate an s2tt context to be used for the test. Only
2312 * enable_lpa2 field is needed for the current test.
2313 */
2314 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2315
2316 for (long level = s2tt_test_helpers_min_block_lvl();
2317 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2318
2319 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002320 unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002321
2322 /* Generate the table */
2323 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2324 &s2tt[0], pa, level);
2325
2326 /* Validate the content of the table */
2327 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2328 unsigned long s2tte;
2329
2330 s2tte = s2tte_create_assigned_empty(
2331 (const struct s2tt_context *)&s2tt_ctx,
2332 pa, level);
2333 pa += s2tte_map_size(level);
2334
2335 UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
2336 }
2337 }
2338}
2339
2340void s2tt_init_assigned_empty_tc2(void)
2341{
2342 /***************************************************************
2343 * TEST CASE 2:
2344 *
2345 * For a valid address, try to create an assigned-empty S2TT
2346 * with a level above the maximum.
2347 ***************************************************************/
2348
2349 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2350 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
2351 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002352 struct s2tt_context s2tt_ctx;
2353
2354 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002355
2356 /*
2357 * Generate an s2tt context to be used for the test. Only
2358 * enable_lpa2 field is needed for the current test.
2359 */
2360 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2361
2362 test_helpers_expect_assert_fail(true);
2363 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2364 &s2tt[0U], pa, level);
2365 test_helpers_fail_if_no_assert_failed();
2366}
2367
2368void s2tt_init_assigned_empty_tc3(void)
2369{
2370 /***************************************************************
2371 * TEST CASE 3:
2372 *
2373 * For a valid address, try to create an assigned-empty S2TT
2374 * with a level below the minimum.
2375 ***************************************************************/
2376
2377 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2378 long level = s2tt_test_helpers_min_block_lvl() - 1L;
2379 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002380 struct s2tt_context s2tt_ctx;
2381
2382 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002383
2384 /*
2385 * Generate an s2tt context to be used for the test. Only
2386 * enable_lpa2 field is needed for the current test.
2387 */
2388 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2389
2390 test_helpers_expect_assert_fail(true);
2391 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2392 &s2tt[0U], pa, level);
2393 test_helpers_fail_if_no_assert_failed();
2394}
2395
2396void s2tt_init_assigned_empty_tc4(void)
2397{
2398 /***************************************************************
2399 * TEST CASE 4:
2400 *
2401 * Invoke s2tt_init_assigned_empty() with a NULL table pointer.
2402 ***************************************************************/
2403
2404 long level = s2tt_test_helpers_min_block_lvl();
2405 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002406 struct s2tt_context s2tt_ctx;
2407
2408 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002409
2410 /*
2411 * Generate an s2tt context to be used for the test. Only
2412 * enable_lpa2 field is needed for the current test.
2413 */
2414 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2415
2416 test_helpers_expect_assert_fail(true);
2417 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2418 NULL, pa, level);
2419 test_helpers_fail_if_no_assert_failed();
2420}
2421
2422void s2tt_init_assigned_empty_tc5(void)
2423{
2424 /***************************************************************
2425 * TEST CASE 5:
2426 *
2427 * Invoke s2tt_init_assigned_empty() with an unaligned address.
2428 ***************************************************************/
2429
2430 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2431 long level =
2432 test_helpers_get_rand_in_range(s2tt_test_helpers_min_block_lvl(),
2433 S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002434 unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002435 test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
Soby Mathewb1228bb2024-12-31 17:42:46 +00002436 struct s2tt_context s2tt_ctx;
2437
2438 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002439
2440 /*
2441 * Generate an s2tt context to be used for the test. Only
2442 * enable_lpa2 field is needed for the current test.
2443 */
2444 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2445
2446 test_helpers_expect_assert_fail(true);
2447 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2448 &s2tt[0U], pa, level);
2449 test_helpers_fail_if_no_assert_failed();
2450}
2451
2452void s2tt_init_assigned_empty_tc6(void)
2453{
2454 /***************************************************************
2455 * TEST CASE 6:
2456 *
2457 * Invoke s2tt_init_assigned_empty() with a NULL s2tt_context
2458 * structure.
2459 ***************************************************************/
2460 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2461 long level = s2tt_test_helpers_min_block_lvl();
2462 unsigned long pa = 0UL; /* Valid for any level */
2463
2464 test_helpers_expect_assert_fail(true);
2465 s2tt_init_assigned_empty((const struct s2tt_context *)NULL,
2466 &s2tt[0U], pa, level);
2467 test_helpers_fail_if_no_assert_failed();
2468}
2469
2470void s2tt_init_assigned_ram_tc1(void)
2471{
2472 /***************************************************************
2473 * TEST CASE 1:
2474 *
2475 * For each valid level, initialize a table with assigned-ram
2476 * S2TTEs and validate its contents.
2477 ***************************************************************/
2478
Soby Mathewb1228bb2024-12-31 17:42:46 +00002479 struct s2tt_context s2tt_ctx;
2480
2481 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002482
2483 /*
2484 * Generate an s2tt context to be used for the test. Only
2485 * enable_lpa2 field is needed for the current test.
2486 */
2487 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2488
2489 for (long level = s2tt_test_helpers_min_block_lvl();
2490 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2491
2492 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002493 unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002494
2495 /* Generate the table */
2496 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2497 &s2tt[0], pa, level);
2498
2499 /* Validate the content of the table */
2500 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2501 unsigned long s2tte;
2502
2503 s2tte = s2tte_create_assigned_ram(
2504 (const struct s2tt_context *)&s2tt_ctx,
2505 pa, level);
2506 pa += s2tte_map_size(level);
2507
2508 UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
2509 }
2510 }
2511}
2512
2513void s2tt_init_assigned_ram_tc2(void)
2514{
2515 /***************************************************************
2516 * TEST CASE 2:
2517 *
2518 * For a valid address, try to create an assigned-ram S2TT
2519 * with a level above the maximum.
2520 ***************************************************************/
2521
2522 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2523 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
2524 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002525 struct s2tt_context s2tt_ctx;
2526
2527 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002528
2529 /*
2530 * Generate an s2tt context to be used for the test. Only
2531 * enable_lpa2 field is needed for the current test.
2532 */
2533 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2534
2535 test_helpers_expect_assert_fail(true);
2536 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2537 &s2tt[0U], pa, level);
2538 test_helpers_fail_if_no_assert_failed();
2539}
2540
2541void s2tt_init_assigned_ram_tc3(void)
2542{
2543 /***************************************************************
2544 * TEST CASE 3:
2545 *
2546 * For a valid address, try to create an assigned-ram S2TT
2547 * with a level below the minimum.
2548 ***************************************************************/
2549
2550 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2551 long level = s2tt_test_helpers_min_block_lvl() - 1L;
2552 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002553 struct s2tt_context s2tt_ctx;
2554
2555 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002556
2557 /*
2558 * Generate an s2tt context to be used for the test. Only
2559 * enable_lpa2 field is needed for the current test.
2560 */
2561 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2562
2563 test_helpers_expect_assert_fail(true);
2564 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2565 &s2tt[0U], pa, level);
2566 test_helpers_fail_if_no_assert_failed();
2567}
2568
2569void s2tt_init_assigned_ram_tc4(void)
2570{
2571 /***************************************************************
2572 * TEST CASE 4:
2573 *
2574 * Invoke s2tt_init_assigned_ram() with a NULL table pointer.
2575 ***************************************************************/
2576
2577 long level = s2tt_test_helpers_min_block_lvl();
2578 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002579 struct s2tt_context s2tt_ctx;
2580
2581 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002582
2583 /*
2584 * Generate an s2tt context to be used for the test. Only
2585 * enable_lpa2 field is needed for the current test.
2586 */
2587 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2588
2589 test_helpers_expect_assert_fail(true);
2590 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2591 NULL, pa, level);
2592 test_helpers_fail_if_no_assert_failed();
2593}
2594
2595void s2tt_init_assigned_ram_tc5(void)
2596{
2597 /***************************************************************
2598 * TEST CASE 5:
2599 *
2600 * Invoke s2tt_init_assigned_ram() with an unaligned address.
2601 ***************************************************************/
2602
2603 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2604 long level =
2605 test_helpers_get_rand_in_range(s2tt_test_helpers_min_block_lvl(),
2606 S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002607 unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002608 test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
Soby Mathewb1228bb2024-12-31 17:42:46 +00002609 struct s2tt_context s2tt_ctx;
2610
2611 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002612
2613 /*
2614 * Generate an s2tt context to be used for the test. Only
2615 * enable_lpa2 field is needed for the current test.
2616 */
2617 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2618
2619 test_helpers_expect_assert_fail(true);
2620 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2621 &s2tt[0U], pa, level);
2622 test_helpers_fail_if_no_assert_failed();
2623}
2624
2625void s2tt_init_assigned_ram_tc6(void)
2626{
2627 /***************************************************************
2628 * TEST CASE 6:
2629 *
2630 * Call s2tt_init_assigned_ram() with a NULL s2tt_context
2631 * pointer.
2632 ***************************************************************/
2633
2634 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2635 long level = s2tt_test_helpers_min_block_lvl();
2636 unsigned long pa = 0UL; /* Valid for any level */
2637
2638 test_helpers_expect_assert_fail(true);
2639 s2tt_init_assigned_ram((const struct s2tt_context *)NULL,
2640 &s2tt[0U], pa, level);
2641 test_helpers_fail_if_no_assert_failed();
2642}
2643
2644void s2tt_init_assigned_ns_tc1(void)
2645{
2646 /***************************************************************
2647 * TEST CASE 1:
2648 *
2649 * For each valid level, initialize a table with assigned-ns
2650 * S2TTEs and validate its contents.
2651 ***************************************************************/
2652
Soby Mathewb1228bb2024-12-31 17:42:46 +00002653 struct s2tt_context s2tt_ctx;
2654
2655 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002656
2657 /*
2658 * Generate an s2tt context to be used for the test. Only
2659 * enable_lpa2 field is needed for the current test.
2660 */
2661 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2662
2663 for (long level = s2tt_test_helpers_min_block_lvl();
2664 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2665
2666 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002667 unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002668
2669 /*
2670 * s2tt_init_assigned_ns() does not verify that the
2671 * host-side attributes are architecturally valid.
2672 * Nevertheless, pass a valid set of them.
2673 */
2674 unsigned long attrs =
2675 s2tt_test_helpers_gen_ns_attrs(true, false);
2676
2677 /*
2678 * s2tt_init_assigned_ns() should mask out everything other
2679 * than the host-side attributes, so generate a whole parent
2680 * s2tte to pass to the former to verify it does what it is
2681 * expected.
2682 */
2683 unsigned long parent_s2tte = attrs |
2684 s2tt_test_helpers_gen_ns_attrs(false, false) |
2685 s2tt_test_helpers_pa_to_s2tte(
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002686 s2tt_test_helpers_gen_addr(level, true),
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002687 level);
2688
2689 /*
2690 * Generate the table. Note that s2tt_init_assigned_ns() can
2691 * take a NULL struct s2tt_context pointer.
2692 */
2693 s2tt_init_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
2694 &s2tt[0], parent_s2tte, pa, level);
2695
2696 /* Validate the content of the table */
2697 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2698 unsigned long s2tte =
2699 s2tt_test_helpers_pa_to_s2tte(pa, level);
2700
2701 s2tte = s2tte_create_assigned_ns(
2702 (const struct s2tt_context *)&s2tt_ctx,
2703 s2tte | attrs, level);
2704 pa += s2tte_map_size(level);
2705
2706 UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
2707 }
2708 }
2709}
2710
2711void s2tt_init_assigned_ns_tc2(void)
2712{
2713 /***************************************************************
2714 * TEST CASE 2:
2715 *
2716 * For a valid address, try to create an assigned-ns S2TT
2717 * with a level above the maximum.
2718 *
2719 * Note that s2tt_init_assigned_ns() can take a NULL
2720 * struct s2tt_context pointer.
2721 ***************************************************************/
2722
2723 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2724 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
2725 unsigned long pa = 0UL; /* Valid for any level */
2726 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
2727
2728 test_helpers_expect_assert_fail(true);
2729 s2tt_init_assigned_ns((const struct s2tt_context *)NULL,
2730 &s2tt[0U], attrs, pa, level);
2731 test_helpers_fail_if_no_assert_failed();
2732}
2733
2734void s2tt_init_assigned_ns_tc3(void)
2735{
2736 /***************************************************************
2737 * TEST CASE 3:
2738 *
2739 * For a valid address, try to create an assigned-ns S2TT
2740 * with a level below the minimum.
2741 *
2742 * Note that s2tt_init_assigned_ns() can take a NULL
2743 * struct s2tt_context pointer.
2744 ***************************************************************/
2745
2746 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2747 long level = s2tt_test_helpers_min_block_lvl() - 1L;
2748 unsigned long pa = 0UL; /* Valid for any level */
2749 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
2750
2751 test_helpers_expect_assert_fail(true);
2752 s2tt_init_assigned_ns((const struct s2tt_context *)NULL,
2753 &s2tt[0U], attrs, pa, level);
2754 test_helpers_fail_if_no_assert_failed();
2755}
2756
2757void s2tt_init_assigned_ns_tc4(void)
2758{
2759 /***************************************************************
2760 * TEST CASE 4:
2761 *
2762 * Invoke s2tt_init_assigned_ns() with a NULL table pointer.
2763 *
2764 * Note that s2tt_init_assigned_ns() can take a NULL
2765 * struct s2tt_context_pointer.
2766 ***************************************************************/
2767
2768 long level = s2tt_test_helpers_min_block_lvl();
2769 unsigned long pa = 0UL; /* Valid for any level */
2770 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
2771
2772 test_helpers_expect_assert_fail(true);
2773 s2tt_init_assigned_ns((const struct s2tt_context *)NULL,
2774 NULL, attrs, pa, level);
2775 test_helpers_fail_if_no_assert_failed();
2776}
2777
2778void s2tt_init_assigned_ns_tc5(void)
2779{
2780 /***************************************************************
2781 * TEST CASE 5:
2782 *
2783 * Invoke s2tt_init_assigned_ns() with an unaligned address.
2784 *
2785 * Note that s2tt_init_assigned_ns() can take a NULL
2786 * struct s2tt_context pointer.
2787 ***************************************************************/
2788
2789 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2790 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
2791 long level =
2792 test_helpers_get_rand_in_range(s2tt_test_helpers_min_block_lvl(),
2793 S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002794 unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002795 test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
2796
2797 test_helpers_expect_assert_fail(true);
2798 s2tt_init_assigned_ns((const struct s2tt_context *)NULL,
2799 &s2tt[0U], attrs, pa, level);
2800 test_helpers_fail_if_no_assert_failed();
2801}
2802
2803void s2tt_init_assigned_destroyed_tc1(void)
2804{
2805 /***************************************************************
2806 * TEST CASE 1:
2807 *
2808 * For each valid level, initialize a table with
2809 * assigned-destroyed S2TTEs and validate its contents.
2810 ***************************************************************/
Soby Mathewb1228bb2024-12-31 17:42:46 +00002811 struct s2tt_context s2tt_ctx;
2812
2813 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002814
2815 /*
2816 * Generate an s2tt context to be used for the test. Only
2817 * enable_lpa2 field is needed for the current test.
2818 */
2819 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2820
2821 for (long level = s2tt_test_helpers_min_block_lvl();
2822 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2823
2824 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002825 unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002826
2827 /* Generate the table */
2828 s2tt_init_assigned_destroyed(
2829 (const struct s2tt_context *)&s2tt_ctx,
2830 &s2tt[0], pa, level);
2831
2832 /* Validate the content of the table */
2833 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2834 unsigned long s2tte;
2835
2836 s2tte = s2tte_create_assigned_destroyed(
2837 (const struct s2tt_context *)&s2tt_ctx,
2838 pa, level);
2839 pa += s2tte_map_size(level);
2840
2841 UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
2842 }
2843 }
2844}
2845
2846void s2tt_init_assigned_destroyed_tc2(void)
2847{
2848 /***************************************************************
2849 * TEST CASE 2:
2850 *
2851 * For a valid address, try to create an assigned-destroyed
2852 * S2TT with a level above the maximum.
2853 ***************************************************************/
2854
2855 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2856 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
2857 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002858 struct s2tt_context s2tt_ctx;
2859
2860 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002861
2862 /*
2863 * Generate an s2tt context to be used for the test. Only
2864 * enable_lpa2 field is needed for the current test.
2865 */
2866 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2867
2868 test_helpers_expect_assert_fail(true);
2869 s2tt_init_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
2870 &s2tt[0U], pa, level);
2871 test_helpers_fail_if_no_assert_failed();
2872}
2873
2874void s2tt_init_assigned_destroyed_tc3(void)
2875{
2876 /***************************************************************
2877 * TEST CASE 3:
2878 *
2879 * For a valid address, try to create an assigned-destroyed
2880 * S2TT with a level below the minimum.
2881 ***************************************************************/
2882
2883 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2884 long level = s2tt_test_helpers_min_block_lvl() - 1L;
2885 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002886 struct s2tt_context s2tt_ctx;
2887
2888 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002889
2890 /*
2891 * Generate an s2tt context to be used for the test. Only
2892 * enable_lpa2 field is needed for the current test.
2893 */
2894 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2895
2896 test_helpers_expect_assert_fail(true);
2897 s2tt_init_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
2898 &s2tt[0U], pa, level);
2899 test_helpers_fail_if_no_assert_failed();
2900}
2901
2902void s2tt_init_assigned_destroyed_tc4(void)
2903{
2904 /***************************************************************
2905 * TEST CASE 4:
2906 *
2907 * Invoke s2tt_init_assigned_destroyed() with a NULL table
2908 * pointer.
2909 ***************************************************************/
2910
2911 long level = s2tt_test_helpers_min_block_lvl();
2912 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002913 struct s2tt_context s2tt_ctx;
2914
2915 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002916
2917 /*
2918 * Generate an s2tt context to be used for the test. Only
2919 * enable_lpa2 field is needed for the current test.
2920 */
2921 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2922
2923 test_helpers_expect_assert_fail(true);
2924 s2tt_init_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
2925 NULL, pa, level);
2926 test_helpers_fail_if_no_assert_failed();
2927}
2928
2929void s2tt_init_assigned_destroyed_tc5(void)
2930{
2931 /***************************************************************
2932 * TEST CASE 5:
2933 *
2934 * Invoke s2tt_init_assigned_destroyed() with an unaligned
2935 * address.
2936 ***************************************************************/
2937
2938 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2939 long level =
2940 test_helpers_get_rand_in_range(s2tt_test_helpers_min_block_lvl(),
2941 S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002942 unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002943 test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
Soby Mathewb1228bb2024-12-31 17:42:46 +00002944 struct s2tt_context s2tt_ctx;
2945
2946 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002947
2948 /*
2949 * Generate an s2tt context to be used for the test. Only
2950 * enable_lpa2 field is needed for the current test.
2951 */
2952 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2953
2954 test_helpers_expect_assert_fail(true);
2955 s2tt_init_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
2956 &s2tt[0U], pa, level);
2957 test_helpers_fail_if_no_assert_failed();
2958}
2959
2960void s2tt_init_assigned_destroyed_tc6(void)
2961{
2962 /***************************************************************
2963 * TEST CASE 6:
2964 *
2965 * Call s2tt_init_assigned_destroyed() with a NULL
2966 * struct s2tt_context pointer.
2967 ***************************************************************/
2968
2969 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2970 long level = s2tt_test_helpers_min_block_lvl();
2971 unsigned long pa = 0UL; /* Valid for any level */
2972
2973 test_helpers_expect_assert_fail(true);
2974 s2tt_init_assigned_destroyed((const struct s2tt_context *)NULL,
2975 &s2tt[0U], pa, level);
2976 test_helpers_fail_if_no_assert_failed();
2977}
2978
2979void s2tte_pa_tc1(void)
2980{
2981 /***************************************************************
2982 * TEST CASE 1:
2983 *
2984 * For each valid level, generate an assigned s2tte or table
2985 * and verify that s2tte_pa() returns the right address
2986 ***************************************************************/
2987
2988 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
2989 S2TTE_INVALID_RIPAS_RAM,
2990 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00002991 struct s2tt_context s2tt_ctx;
2992
2993 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002994
2995 /*
2996 * Generate an s2tt context to be used for the test. Only
2997 * enable_lpa2 field is needed for the current test.
2998 */
2999 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3000
3001 for (long level = s2tt_test_helpers_min_table_lvl();
3002 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
3003 unsigned long tte;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01003004 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003005
3006 if (level < s2tt_test_helpers_min_block_lvl()) {
3007 tte = s2tte_create_table(
3008 (const struct s2tt_context *)&s2tt_ctx,
3009 pa, level);
3010 } else {
3011 /*
3012 * pickup a random type of assigned S2TTE
3013 * to test with
3014 */
3015 unsigned int idx =
3016 (unsigned int)test_helpers_get_rand_in_range(
3017 0UL, ARRAY_SIZE(ripas) - 1UL);
3018
3019 tte = s2tt_test_create_assigned(
3020 (const struct s2tt_context *)&s2tt_ctx,
3021 pa, level, ripas[idx]);
3022 }
3023
3024 /* Verify the address returned by s2tte_pa() */
3025 UNSIGNED_LONGS_EQUAL(pa, s2tte_pa(
3026 (const struct s2tt_context *)&s2tt_ctx,
3027 tte, level));
3028 }
3029}
3030
3031void s2tte_pa_tc2(void)
3032{
3033 /***************************************************************
3034 * TEST CASE 2:
3035 *
3036 * For a given level and unassigned s2tte (which doesn't have
3037 * a PA), verify that s2tte_pa() behaves as expected.
3038 ***************************************************************/
3039
3040 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
3041 S2TTE_INVALID_RIPAS_RAM,
3042 S2TTE_INVALID_RIPAS_DESTROYED};
3043 long level = test_helpers_get_rand_in_range(
3044 s2tt_test_helpers_min_block_lvl(),
3045 S2TT_TEST_HELPERS_MAX_LVL);
Soby Mathewb1228bb2024-12-31 17:42:46 +00003046 struct s2tt_context s2tt_ctx;
3047
3048 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003049
3050 /*
3051 * Generate an s2tt context to be used for the test. Only
3052 * enable_lpa2 field is needed for the current test.
3053 */
3054 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3055
3056 /* pickup a random type of unassigned S2TTE to test with */
3057 unsigned int idx = (unsigned int)test_helpers_get_rand_in_range(
3058 0UL, ARRAY_SIZE(ripas) - 1UL);
3059 unsigned long tte = s2tt_test_create_unassigned(
3060 (const struct s2tt_context *)&s2tt_ctx, ripas[idx]);
3061
3062 test_helpers_expect_assert_fail(true);
3063 (void)s2tte_pa((const struct s2tt_context *)&s2tt_ctx, tte, level);
3064 test_helpers_fail_if_no_assert_failed();
3065}
3066
3067void s2tte_pa_tc3(void)
3068{
3069 /***************************************************************
3070 * TEST CASE 3:
3071 *
3072 * With a valid assigned S2TTE, call s2tte_pa() with a level
3073 * above the maximum supported one.
3074 **************************************************************/
3075
3076 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
3077 S2TTE_INVALID_RIPAS_RAM,
3078 S2TTE_INVALID_RIPAS_DESTROYED};
3079
3080 long level = S2TT_TEST_HELPERS_MAX_LVL;
3081 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00003082 struct s2tt_context s2tt_ctx;
3083
3084 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003085
3086 /*
3087 * Generate an s2tt context to be used for the test. Only
3088 * enable_lpa2 field is needed for the current test.
3089 */
3090 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3091
3092 /* pickup a random type of assigned S2TTE to test with */
3093 unsigned int idx = (unsigned int)test_helpers_get_rand_in_range(
3094 0UL, ARRAY_SIZE(ripas) - 1UL);
3095 unsigned long tte = s2tt_test_create_assigned(
3096 (const struct s2tt_context *)&s2tt_ctx,
3097 pa, level, ripas[idx]);
3098
3099 test_helpers_expect_assert_fail(true);
3100 (void)s2tte_pa((const struct s2tt_context *)&s2tt_ctx, tte, level + 1U);
3101 test_helpers_fail_if_no_assert_failed();
3102}
3103
3104void s2tte_pa_tc4(void)
3105{
3106 /***************************************************************
3107 * TEST CASE 4:
3108 *
3109 * With a valid assigned S2TTE, call s2tte_pa() with a level
3110 * below the minimum supported one.
3111 **************************************************************/
3112
3113 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
3114 S2TTE_INVALID_RIPAS_RAM,
3115 S2TTE_INVALID_RIPAS_DESTROYED};
3116
3117 long level = S2TT_TEST_HELPERS_MAX_LVL;
3118 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00003119 struct s2tt_context s2tt_ctx;
3120
3121 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003122
3123 /*
3124 * Generate an s2tt context to be used for the test. Only
3125 * enable_lpa2 field is needed for the current test.
3126 */
3127 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3128
3129 /* pickup a random type of assigned S2TTE to test with */
3130 unsigned int idx = (unsigned int)test_helpers_get_rand_in_range(
3131 0UL, ARRAY_SIZE(ripas) - 1UL);
3132 unsigned long tte = s2tt_test_create_assigned(
3133 (const struct s2tt_context *)&s2tt_ctx,
3134 pa, level, ripas[idx]);
3135
3136 test_helpers_expect_assert_fail(true);
3137 (void)s2tte_pa((const struct s2tt_context *)&s2tt_ctx,
3138 tte, s2tt_test_helpers_min_table_lvl() - 1L);
3139 test_helpers_fail_if_no_assert_failed();
3140}
3141
3142void s2tte_pa_tc5(void)
3143{
3144 /***************************************************************
3145 * TEST CASE 5:
3146 *
3147 * Call s2tte_pa() with a NULL s2tt_context pointer.
3148 **************************************************************/
3149
3150 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
3151 S2TTE_INVALID_RIPAS_RAM,
3152 S2TTE_INVALID_RIPAS_DESTROYED};
3153
3154 long level = s2tt_test_helpers_min_block_lvl();
3155 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00003156 struct s2tt_context s2tt_ctx;
3157
3158 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003159
3160 /*
3161 * Generate an s2tt context to be used for the test. Only
3162 * enable_lpa2 field is needed for the current test.
3163 */
3164 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3165
3166 /* pickup a random type of assigned S2TTE to test with */
3167 unsigned int idx = (unsigned int)test_helpers_get_rand_in_range(
3168 0UL, ARRAY_SIZE(ripas) - 1UL);
3169 unsigned long tte = s2tt_test_create_assigned(
3170 (const struct s2tt_context *)&s2tt_ctx,
3171 pa, level, ripas[idx]);
3172
3173 test_helpers_expect_assert_fail(true);
3174 (void)s2tte_pa((const struct s2tt_context *)NULL,
3175 tte, s2tt_test_helpers_min_table_lvl() - 1L);
3176 test_helpers_fail_if_no_assert_failed();
3177}