blob: 3104f39acb6ab73abf916a5db0b2c89bd5aff7c5 [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 */
1104 host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false) |
1105 test_helpers_get_rand_in_range(1UL, ULONG_MAX);
1106 tte = s2tt_test_helpers_pa_to_s2tte(pa, level) | host_attrs;
1107
1108 CHECK_FALSE(host_ns_s2tte_is_valid(
1109 (const struct s2tt_context *)&s2tt_ctx,
1110 tte, level));
1111 }
1112}
1113
1114void host_ns_s2tte_is_valid_tc3(void)
1115{
1116 /***************************************************************
1117 * TEST CASE 3:
1118 *
1119 * Test host_ns_s2tte_is_valid() with a valid NS S2TTE but a
1120 * level below the minimum supported. This should cause an
1121 * assert fail even if the PA is not aligned to the invalid
1122 * level.
1123 ***************************************************************/
1124
Soby Mathewb1228bb2024-12-31 17:42:46 +00001125 struct s2tt_context s2tt_ctx;
1126
1127 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001128
1129 /*
1130 * Initialize an s2tt_context structure for the test.
1131 * Only 'enable_lpa2' is used by the API, so the rest of fields
1132 * can be left untouched.
1133 */
1134 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1135
1136 /*
1137 * Generate the tte with an assumed PA == 0, which is aligned to
1138 * any level.
1139 */
1140 unsigned long tte = s2tt_test_helpers_gen_ns_attrs(true, false);
1141 long level = s2tt_test_helpers_min_block_lvl() - 1L;
1142
1143 test_helpers_expect_assert_fail(true);
1144 (void)host_ns_s2tte_is_valid((const struct s2tt_context *)&s2tt_ctx,
1145 tte, level);
1146 test_helpers_fail_if_no_assert_failed();
1147}
1148
1149void host_ns_s2tte_is_valid_tc4(void)
1150{
1151 /***************************************************************
1152 * TEST CASE 4:
1153 *
1154 * Test host_ns_s2tte_is_valid() with a valid NS S2TTE but a
1155 * level above the maximum supported. This should cause an
1156 * assert fail even if the PA is not aligned to the invalid
1157 * level.
1158 ***************************************************************/
1159
Soby Mathewb1228bb2024-12-31 17:42:46 +00001160 struct s2tt_context s2tt_ctx;
1161
1162 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001163
1164 /*
1165 * Initialize an s2tt_context structure for the test.
1166 * Only 'enable_lpa2' is used by the API, so the rest of fields
1167 * can be left untouched.
1168 */
1169 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1170
1171 /*
1172 * Generate the tte with an assumed PA == 0, which is aligned to
1173 * any level.
1174 */
1175 unsigned long tte = s2tt_test_helpers_gen_ns_attrs(true, false);
1176 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
1177
1178 test_helpers_expect_assert_fail(true);
1179 (void)host_ns_s2tte_is_valid((const struct s2tt_context *)&s2tt_ctx,
1180 tte, level);
1181 test_helpers_fail_if_no_assert_failed();
1182}
1183
1184void host_ns_s2tte_is_valid_tc5(void)
1185{
1186 /***************************************************************
1187 * TEST CASE 5:
1188 *
1189 * Test host_ns_s2tte_is_valid() with valid parameters but a
1190 * NULL s2tt_context struct pointer.
1191 ***************************************************************/
1192
1193 long level = s2tt_test_helpers_min_block_lvl();
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001194 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001195 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
1196 unsigned long tte = s2tt_test_helpers_pa_to_s2tte(pa, level) | host_attrs;
1197
1198 test_helpers_expect_assert_fail(true);
1199 (void)host_ns_s2tte_is_valid((const struct s2tt_context *)NULL,
1200 tte, level);
1201 test_helpers_fail_if_no_assert_failed();
1202}
1203
Shruti Guptac5a3c202024-09-23 13:43:22 +01001204void host_ns_s2tte_is_valid_tc6(void)
1205{
1206 /***************************************************************
1207 * TEST CASE 6:
1208 *
1209 * Test host_ns_s2tte_is_valid() with invalid PA >= 48 bits
1210 * when LPA2 is disabled
1211 **************************************************************/
1212
Soby Mathewb1228bb2024-12-31 17:42:46 +00001213 struct s2tt_context s2tt_ctx;
1214
1215 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
1216
Shruti Guptac5a3c202024-09-23 13:43:22 +01001217 unsigned long host_attrs;
1218 unsigned long tte;
1219 long level = s2tt_test_helpers_min_block_lvl();
1220 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
1221
1222 if (is_feat_lpa2_4k_2_present() == false) {
1223 CHECK_TRUE(true);
1224 return;
1225 }
1226
1227 pa = pa | (1UL << S2TT_MAX_PA_BITS);
1228 host_attrs =
1229 s2tt_test_helpers_gen_ns_attrs(true, false);
1230 tte = s2tt_test_helpers_pa_to_s2tte(pa, level) |
1231 host_attrs;
1232
1233 CHECK_TRUE(s2tt_test_helpers_s2tte_to_pa(tte, level) >= (1UL << S2TT_MAX_PA_BITS));
1234 CHECK_FALSE(host_ns_s2tte_is_valid((const struct s2tt_context *)&s2tt_ctx,
1235 tte, level));
1236}
1237
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001238void host_ns_s2tte_tc1(void)
1239{
1240 /***************************************************************
1241 * TEST CASE 1:
1242 *
1243 * Create an assigned-NS S2TTE with valid parameters and
1244 * verify that host_ns_s2tte() returns the portion of the S2TTE
1245 * has been set by the host.
1246 ***************************************************************/
1247
Soby Mathewb1228bb2024-12-31 17:42:46 +00001248 struct s2tt_context s2tt_ctx;
1249
1250 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001251
1252 /*
1253 * Initialize an s2tt_context structure for the test.
1254 * Only 'enable_lpa2' is used by the API, so the rest of fields
1255 * can be left untouched.
1256 */
1257 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1258
1259 /* Test for each possible level */
1260 for (long level = s2tt_test_helpers_min_block_lvl();
1261 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001262 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001263 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true,
1264 false);
1265 unsigned long val_tte = s2tte_create_assigned_ns(
1266 (const struct s2tt_context *)&s2tt_ctx,
1267 s2tt_test_helpers_pa_to_s2tte(pa, level) |
1268 host_attrs, level);
1269 unsigned long tte = host_ns_s2tte((const struct s2tt_context *)&s2tt_ctx,
1270 val_tte, level);
1271
1272 /* Validate the address */
1273 UNSIGNED_LONGS_EQUAL(s2tt_test_helpers_s2tte_to_pa(val_tte, level),
1274 s2tt_test_helpers_s2tte_to_pa(tte, level));
1275
1276 /*
1277 * Validate that the rest of the S2TTE (excluding the PA)
1278 * matches the host_attrs (and therefore any other bit is '0')
1279 */
1280 UNSIGNED_LONGS_EQUAL(host_attrs,
1281 (tte & ~s2tt_test_helpers_s2tte_oa_mask()));
1282 }
1283}
1284
1285void host_ns_s2tte_tc2(void)
1286{
1287 /***************************************************************
1288 * TEST CASE 2:
1289 *
1290 * Test host_ns_s2tte() with a valid NS S2TTE but a level
1291 * below the minimum supported.
1292 ***************************************************************/
1293
Soby Mathewb1228bb2024-12-31 17:42:46 +00001294 struct s2tt_context s2tt_ctx;
1295
1296 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001297
1298 /*
1299 * Initialize an s2tt_context structure for the test.
1300 * Only 'enable_lpa2' is used by the API, so the rest of fields
1301 * can be left untouched.
1302 */
1303 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1304
1305 /*
1306 * Generate the tte with an assumed PA == 0, which is aligned to
1307 * any level.
1308 */
1309 long level = s2tt_test_helpers_min_block_lvl();
1310 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
1311
1312 /* s2tte_create_assigned_ns() can receive a NULL s2tt_context pointer */
1313 unsigned long tte = s2tte_create_assigned_ns(
1314 (const struct s2tt_context *)&s2tt_ctx,
1315 0UL | host_attrs, level);
1316
1317 test_helpers_expect_assert_fail(true);
1318
1319 /*
1320 * Initialize an s2tt_context structure for the test.
1321 * Only 'enable_lpa2' is used by the API, so the rest of fields
1322 * can be left untouched.
1323 */
1324 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1325 (void)host_ns_s2tte((const struct s2tt_context *)&s2tt_ctx, tte, level - 1L);
1326 test_helpers_fail_if_no_assert_failed();
1327}
1328
1329void host_ns_s2tte_tc3(void)
1330{
1331 /***************************************************************
1332 * TEST CASE 3:
1333 *
1334 * Test host_ns_s2tte() with a valid NS S2TTE but a level
1335 * above the maximum supported.
1336 ***************************************************************/
1337
Soby Mathewb1228bb2024-12-31 17:42:46 +00001338 struct s2tt_context s2tt_ctx;
1339
1340 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001341
1342 /*
1343 * Generate the tte with an assumed PA == 0, which is aligned to
1344 * any level.
1345 */
1346 long level = S2TT_TEST_HELPERS_MAX_LVL;
1347 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
1348
1349 /* s2tte_create_assigned_ns() can receive a NULL s2tt_context pointer */
1350 unsigned long tte = s2tte_create_assigned_ns(
1351 (const struct s2tt_context *)&s2tt_ctx,
1352 0UL | host_attrs, level);
1353
1354 test_helpers_expect_assert_fail(true);
1355 /*
1356 * Initialize an s2tt_context structure for the test.
1357 * Only 'enable_lpa2' is used by the API, so the rest of fields
1358 * can be left untouched.
1359 */
1360 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1361 (void)host_ns_s2tte((const struct s2tt_context *)&s2tt_ctx, tte, level + 1L);
1362 test_helpers_fail_if_no_assert_failed();
1363}
1364
1365void host_ns_s2tte_tc4(void)
1366{
1367 /***************************************************************
1368 * TEST CASE 4:
1369 *
1370 * Test host_ns_s2tte() passing a NULL pointer to an
1371 * s2tt_context structure.
1372 ***************************************************************/
1373
1374 /* Test for each possible level */
1375 long level = s2tt_test_helpers_min_block_lvl();
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001376 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001377 unsigned long host_attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
1378
Soby Mathewb1228bb2024-12-31 17:42:46 +00001379 struct s2tt_context s2tt_ctx;
1380
1381 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Soby Mathew217748d2024-10-02 11:02:19 +01001382
1383 /*
1384 * Initialize an s2tt_context structure for the test.
1385 * Only 'enable_lpa2' is used by the API, so the rest of fields
1386 * can be left untouched.
1387 */
1388 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1389
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001390 unsigned long val_tte = s2tte_create_assigned_ns(
Soby Mathew217748d2024-10-02 11:02:19 +01001391 (const struct s2tt_context *)&s2tt_ctx,
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001392 s2tt_test_helpers_pa_to_s2tte(pa, level) |
1393 host_attrs, level);
1394 test_helpers_expect_assert_fail(true);
1395 (void)host_ns_s2tte((const struct s2tt_context *)NULL, val_tte, level);
1396 test_helpers_fail_if_no_assert_failed();
1397}
1398
1399void s2tte_has_ripas_tc1(void)
1400{
1401 /***************************************************************
1402 * TEST CASE 1:
1403 *
1404 * For each valid level at which a TTE can have RIPAS, generate
1405 * a set of assigned/unassigned S2TTEs with different RIPAS and
1406 * validate the output of s2tte_has_ripas().
1407 ***************************************************************/
1408
1409 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1410 S2TTE_INVALID_RIPAS_RAM,
1411 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001412 struct s2tt_context s2tt_ctx;
1413
1414 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001415
1416 /*
1417 * Initialize an s2tt_context structure for the test.
1418 * Only 'enable_lpa2' is used by the API, so the rest of fields
1419 * can be left untouched.
1420 */
1421 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1422
1423 for (long level = s2tt_test_helpers_min_block_lvl();
1424 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1425 for (unsigned int i = 0U; i < ARRAY_SIZE(ripas); i++) {
1426
1427 unsigned long tte;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001428 unsigned long pa = s2tt_test_helpers_gen_addr(level,
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001429 true);
1430
1431 /* Validate with an assigned S2TTE */
1432 tte = s2tt_test_create_assigned(
1433 (const struct s2tt_context *)&s2tt_ctx,
1434 pa, level, ripas[i]);
1435 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
1436 tte, level) == true);
1437
1438 /* Validate with an unassigned S2TTE */
1439 tte = s2tt_test_create_unassigned((
1440 const struct s2tt_context *)&s2tt_ctx,
1441 ripas[i]);
1442 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
1443 tte, level) == true);
1444 }
1445 }
1446}
1447
1448void s2tte_has_ripas_tc2(void)
1449{
1450 /***************************************************************
1451 * TEST CASE 2:
1452 *
1453 * For each valid level generate a set of negative tests:
1454 *
1455 * - For each valid level at which a TTE can have RIPAS,
1456 * generate a set of NS-S2TTEs (assigned and unassigned)
1457 * and validate that s2tte_has_ripas() returns
1458 * the expected error.
1459 * - For each valid level at which a table can exist,
1460 * Generate a table and verify that s2tte_has_ripas()
1461 * returns the expected value.
1462 ***************************************************************/
1463
1464 unsigned long tte;
Soby Mathewb1228bb2024-12-31 17:42:46 +00001465 struct s2tt_context s2tt_ctx;
1466
1467 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001468
1469 /*
1470 * Initialize an s2tt_context structure for the test.
1471 * Only 'enable_lpa2' is used by the API, so the rest of fields
1472 * can be left untouched.
1473 */
1474 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1475
1476 /* Generate a set of NS S2TTEs per valid level */
1477 for (long level = s2tt_test_helpers_min_block_lvl();
1478 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1479
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001480 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001481 unsigned long host_attr = s2tt_test_helpers_gen_ns_attrs(true,
1482 false);
1483 tte = s2tte_create_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1484 host_attr | s2tt_test_helpers_pa_to_s2tte(pa, level),
1485 level);
1486 /* Validate with assigned-ns S2TTE */
1487 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
1488 tte, level) == false);
1489
1490 /* Validate with unassigned-ns S2TTE */
1491 tte = s2tte_create_unassigned_ns((const struct s2tt_context *)&s2tt_ctx);
1492 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)NULL,
1493 tte, level) == false);
1494 }
1495
1496 for (long level = s2tt_test_helpers_min_table_lvl();
1497 level < s2tt_test_helpers_min_block_lvl(); level++) {
1498
1499 /* Use Addr 0UL as it is valid on any level */
1500 tte = s2tte_create_table((const struct s2tt_context *)&s2tt_ctx,
1501 0UL, level);
1502
1503 CHECK_TRUE(s2tte_has_ripas((const struct s2tt_context *)&s2tt_ctx,
1504 tte, level) == false);
1505 }
1506}
1507
1508void s2tte_is_unassigned_tc1(void)
1509{
1510 /***************************************************************
1511 * TEST CASE 1:
1512 *
1513 * This test case cover positive tests for s2tt_is_unassigned()
1514 * as well as a number of negative tests.
1515 ***************************************************************/
1516
1517 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1518 S2TTE_INVALID_RIPAS_RAM,
1519 S2TTE_INVALID_RIPAS_DESTROYED,
1520 S2TTE_NS};
1521
1522 /* pickup a random type of unassigned S2TTE to test with */
1523 unsigned int ripas_idx = (unsigned int)test_helpers_get_rand_in_range(
1524 0UL, ARRAY_SIZE(ripas) - 1UL);
1525 unsigned long inv_tte, tte = s2tt_test_create_unassigned(
1526 (const struct s2tt_context *)NULL, ripas[ripas_idx]);
1527
1528 /* Validate s2tt_is_unassigned with an unassigned TTE. */
1529 CHECK_TRUE(s2tte_is_unassigned((const struct s2tt_context *)NULL, tte) == true);
1530
1531 /* Negative test: Set DESC_TYPE to a valid descriptor */
1532 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1533 CHECK_TRUE(s2tte_is_unassigned((const struct s2tt_context *)NULL, inv_tte) == false);
1534
1535 /* Negative test: Change the HIPAS to ASSIGNED */
1536 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1537 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1538 CHECK_TRUE(s2tte_is_unassigned((const struct s2tt_context *)NULL, inv_tte) == false);
1539}
1540
1541void s2tte_is_unassigned_empty_tc1(void)
1542{
1543 /***************************************************************
1544 * TEST CASE 1:
1545 *
1546 * This test case cover positive tests for
1547 * is_unassigned_empty() as well as a number of negative tests.
1548 ***************************************************************/
1549
1550 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_RAM,
1551 S2TTE_INVALID_RIPAS_DESTROYED,
1552 S2TTE_NS};
1553
1554 unsigned int idx;
1555 unsigned long inv_tte;
1556 unsigned long tte = s2tte_create_unassigned_empty(
1557 (const struct s2tt_context *)NULL);
1558
1559 /* Validate s2tt_is_unassigned_empty with an unassigned TTE */
1560 CHECK_TRUE(s2tte_is_unassigned_empty((const struct s2tt_context *)NULL, tte) == true);
1561
1562 /* Negative test: Set DESC_TYPE to a valid descriptor */
1563 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1564 CHECK_TRUE(s2tte_is_unassigned_empty((const struct s2tt_context *)NULL, inv_tte) == false);
1565
1566 /* Negative test: Change the HIPAS to ASSIGNED */
1567 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1568 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1569 CHECK_TRUE(s2tte_is_unassigned_empty((const struct s2tt_context *)NULL, inv_tte) == false);
1570
1571 /* Negative test: Test with a different type of unassigned TTE but having RIPAS */
1572 idx = (unsigned int)test_helpers_get_rand_in_range(
1573 0UL, ARRAY_SIZE(ripas) - 1UL);
1574 inv_tte = s2tt_test_create_unassigned((const struct s2tt_context *)NULL, ripas[idx]);
1575 CHECK_TRUE(s2tte_is_unassigned_empty((const struct s2tt_context *)NULL, inv_tte) == false);
1576}
1577
1578void s2tte_is_unassigned_ram_tc1(void)
1579{
1580 /***************************************************************
1581 * TEST CASE 1:
1582 *
1583 * This test case cover positive tests for
1584 * is_unassigned_ram() as well as a number of negative tests.
1585 ***************************************************************/
1586
1587 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1588 S2TTE_INVALID_RIPAS_DESTROYED,
1589 S2TTE_NS};
1590 unsigned int idx;
1591 unsigned long inv_tte;
1592 unsigned long tte = s2tte_create_unassigned_ram(
1593 (const struct s2tt_context *)NULL);
1594
1595 /* Validate s2tt_is_unassigned_ram with an unassigned ram TTE */
1596 CHECK_TRUE(s2tte_is_unassigned_ram((const struct s2tt_context *)NULL, tte) == true);
1597
1598 /* Negative test: Set DESC_TYPE to a valid descriptor */
1599 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1600 CHECK_TRUE(s2tte_is_unassigned_ram((const struct s2tt_context *)NULL, inv_tte) == false);
1601
1602 /* Negative test: Change the HIPAS to ASSIGNED */
1603 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1604 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1605 CHECK_TRUE(s2tte_is_unassigned_ram((const struct s2tt_context *)NULL, inv_tte) == false);
1606
1607 /* Negative test: Test with a different type of unassigned TTE */
1608 idx = (unsigned int)test_helpers_get_rand_in_range(
1609 0UL, ARRAY_SIZE(ripas) - 1UL);
1610 inv_tte = s2tt_test_create_unassigned((const struct s2tt_context *)NULL, ripas[idx]);
1611 CHECK_TRUE(s2tte_is_unassigned_ram((const struct s2tt_context *)NULL, inv_tte) == false);
1612}
1613
1614void s2tte_is_unassigned_ns_tc1(void)
1615{
1616 /***************************************************************
1617 * TEST CASE 1:
1618 *
1619 * This test case cover positive tests for
1620 * is_unassigned_ns() as well as a number of negative tests.
1621 ***************************************************************/
1622
1623 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1624 S2TTE_INVALID_RIPAS_DESTROYED,
1625 S2TTE_INVALID_RIPAS_RAM};
1626 unsigned int idx;
1627 unsigned long inv_tte;
1628 unsigned long tte = s2tte_create_unassigned_ns((
1629 const struct s2tt_context *)NULL);
1630
1631 /* Validate s2tt_is_unassigned_ns with an unassigned ns TTE */
1632 CHECK_TRUE(s2tte_is_unassigned_ns((const struct s2tt_context *)NULL, tte) == true);
1633
1634 /* Negative test: Set DESC_TYPE to a valid descriptor */
1635 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1636 CHECK_TRUE(s2tte_is_unassigned_ns((const struct s2tt_context *)NULL, inv_tte) == false);
1637
1638 /* Negative test: Change the HIPAS to ASSIGNED */
1639 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1640 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1641 CHECK_TRUE(s2tte_is_unassigned_ns((const struct s2tt_context *)NULL, inv_tte) == false);
1642
1643 /* Negative test: Test with a different type of unassigned TTE */
1644 idx = (unsigned int)test_helpers_get_rand_in_range(
1645 0UL, ARRAY_SIZE(ripas) - 1UL);
1646 inv_tte = s2tt_test_create_unassigned((const struct s2tt_context *)NULL, ripas[idx]);
1647 CHECK_TRUE(s2tte_is_unassigned_ns((const struct s2tt_context *)NULL, inv_tte) == false);
1648}
1649
1650void s2tte_is_unassigned_destroyed_tc1(void)
1651{
1652 /***************************************************************
1653 * TEST CASE 1:
1654 *
1655 * This test case cover positive tests for
1656 * is_unassigned_destroyed() as well as a number of
1657 * negative tests.
1658 ***************************************************************/
1659
1660 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1661 S2TTE_NS,
1662 S2TTE_INVALID_RIPAS_RAM};
1663 unsigned int idx;
1664 unsigned long inv_tte;
1665 unsigned long tte = s2tte_create_unassigned_destroyed(
1666 (const struct s2tt_context *)NULL);
1667
1668 /* Validate s2tt_is_unassigned_destroyed with an unassigned destroyed TTE */
1669 CHECK_TRUE(s2tte_is_unassigned_destroyed(
1670 (const struct s2tt_context *)NULL, tte) == true);
1671
1672 /* Negative test: Set DESC_TYPE to a valid descriptor */
1673 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1674 CHECK_TRUE(s2tte_is_unassigned_destroyed(
1675 (const struct s2tt_context *)NULL, inv_tte) == false);
1676
1677 /* Negative test: Change the HIPAS to ASSIGNED */
1678 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1679 inv_tte |= S2TTE_INVALID_HIPAS_ASSIGNED;
1680 CHECK_TRUE(s2tte_is_unassigned_destroyed(
1681 (const struct s2tt_context *)NULL, inv_tte) == false);
1682
1683 /* Negative test: Test with a different type of unassigned TTE */
1684 idx = (unsigned int)test_helpers_get_rand_in_range(
1685 0UL, ARRAY_SIZE(ripas) - 1UL);
1686 inv_tte = s2tt_test_create_unassigned((const struct s2tt_context *)NULL, ripas[idx]);
1687 CHECK_FALSE(s2tte_is_unassigned_destroyed((const struct s2tt_context *)NULL, inv_tte));
1688}
1689
1690void s2tte_is_assigned_empty_tc1(void)
1691{
1692 /***************************************************************
1693 * TEST CASE 1:
1694 *
1695 * This test case cover positive tests for is_assigned_empty()
1696 * as well as a number of negative tests for each valid level.
1697 ***************************************************************/
1698
1699 unsigned long ripas[] = {S2TTE_NS,
1700 S2TTE_INVALID_RIPAS_RAM,
1701 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001702 struct s2tt_context s2tt_ctx;
1703
1704 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001705
1706 /*
1707 * Initialize an s2tt_context structure for the test.
1708 * Only 'enable_lpa2' is used by the API, so the rest of fields
1709 * can be left untouched.
1710 */
1711 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1712
1713 for (long level = s2tt_test_helpers_min_block_lvl();
1714 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1715 unsigned int idx;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001716 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001717 unsigned long inv_tte, tte =
1718 s2tte_create_assigned_empty(
1719 (const struct s2tt_context *)&s2tt_ctx,
1720 pa, level);
1721
1722 /* Validate s2tt_is_assigned_empty with an unassigned empty TTE */
1723 CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
1724 tte, level) == true);
1725
1726 /* Negative test: Set DESC_TYPE to a valid descriptor */
1727 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1728 CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
1729 inv_tte, level) == false);
1730
1731 /* Negative test: Change the HIPAS to UNASSIGNED */
1732 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1733 inv_tte |= S2TTE_INVALID_HIPAS_UNASSIGNED;
1734 CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
1735 inv_tte, level) == false);
1736
1737 /* Negative test: Test with a different type of assigned TTE */
1738 idx = (unsigned int)test_helpers_get_rand_in_range(
1739 0UL, ARRAY_SIZE(ripas) - 1UL);
1740 inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
1741 pa, level, ripas[idx]);
1742 CHECK_TRUE(s2tte_is_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
1743 inv_tte, level) == false);
1744 }
1745}
1746
1747void s2tte_is_assigned_ns_tc1(void)
1748{
1749 /***************************************************************
1750 * TEST CASE 1:
1751 *
1752 * This test case cover positive tests for is_assigned_ns()
1753 * as well as a number of negative tests for each valid level.
1754 ***************************************************************/
1755
1756 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
1757 S2TTE_INVALID_RIPAS_RAM,
1758 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001759 struct s2tt_context s2tt_ctx;
1760
1761 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
1762
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001763 /*
1764 * Initialize an s2tt_context structure for the test.
1765 * Only 'enable_lpa2' is used by the API, so the rest of fields
1766 * can be left untouched.
1767 */
1768 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1769
1770 for (long level = s2tt_test_helpers_min_block_lvl();
1771 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1772 unsigned int idx;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001773 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001774 unsigned long inv_tte, tte =
1775 s2tt_test_helpers_gen_ns_attrs(true, false);
1776
1777 tte = s2tte_create_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1778 s2tt_test_helpers_pa_to_s2tte(pa, level) | tte,
1779 level);
1780
1781 /* Validate s2tt_is_assigned_ns with an assigned ns TTE */
1782 CHECK_TRUE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1783 tte, level) == true);
1784
1785 /*
1786 * Negative test: Test using UNASSIGNED_NS TTE
1787 */
1788 inv_tte = s2tte_create_unassigned_ns(
1789 (const struct s2tt_context *)&s2tt_ctx);
1790 CHECK_TRUE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1791 inv_tte, level) == false);
1792
1793 /*
1794 * Negative test: Test with a different type of assigned TTE
1795 * which has RIPAS.
1796 */
1797 idx = (unsigned int)test_helpers_get_rand_in_range(
1798 0UL, ARRAY_SIZE(ripas) - 1UL);
1799 inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
1800 pa, level, ripas[idx]);
1801 CHECK_TRUE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
1802 inv_tte, level) == false);
1803 }
1804}
1805
1806void s2tte_is_assigned_ns_tc2(void)
1807{
1808 /***************************************************************
1809 * TEST CASE 2:
1810 *
1811 * Test s2tte_is_assigned_ns() with invalid levels.
1812 ***************************************************************/
1813 unsigned long pa = 0UL;
1814 unsigned long tte = s2tt_test_helpers_gen_ns_attrs(true, false);
1815 long level = s2tt_test_helpers_min_block_lvl();
Soby Mathewb1228bb2024-12-31 17:42:46 +00001816 struct s2tt_context s2tt_ctx;
1817
1818 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001819
1820 /*
1821 * Initialize an s2tt_context structure for the test.
1822 * Only 'enable_lpa2' is used by the API, so the rest of fields
1823 * can be left untouched.
1824 */
1825 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1826
1827 tte = s2tte_create_assigned_ns(
1828 (const struct s2tt_context *)&s2tt_ctx,
1829 s2tt_test_helpers_pa_to_s2tte(pa, level) | tte,
1830 level);
1831
1832 /* Validate s2tt_is_assigned_ns with an assigned ns TTE */
1833 CHECK_FALSE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx, tte,
1834 s2tt_test_helpers_min_table_lvl()));
1835 CHECK_FALSE(s2tte_is_assigned_ns((const struct s2tt_context *)&s2tt_ctx, tte,
1836 S2TT_TEST_HELPERS_MAX_LVL));
1837}
1838
1839void s2tte_is_assigned_ram_tc1(void)
1840{
1841 /***************************************************************
1842 * TEST CASE 1:
1843 *
1844 * This test case cover positive tests for is_assigned_ram()
1845 * as well as a number of negative tests for each valid level.
1846 ***************************************************************/
1847
1848 unsigned long ripas[] = {S2TTE_NS,
1849 S2TTE_INVALID_RIPAS_EMPTY,
1850 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001851 struct s2tt_context s2tt_ctx;
1852
1853 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001854
1855 /*
1856 * Initialize an s2tt_context structure for the test.
1857 * Only 'enable_lpa2' is used by the API, so the rest of fields
1858 * can be left untouched.
1859 */
1860 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1861
1862 for (long level = s2tt_test_helpers_min_block_lvl();
1863 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1864 unsigned int idx;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001865 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001866 unsigned long inv_tte, tte =
1867 s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1868 pa, level);
1869
1870 /* Validate s2tt_is_assigned_empty with an assigned ram TTE */
1871 CHECK_TRUE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1872 tte, level) == true);
1873
1874 /*
1875 * Negative test: Test with UNASSIGNED-RAM
1876 * We test with UNASSIGNED-RAM as in the current RMM implementation,
1877 * an ASSIGNED-RAM S2TTE does not have HIPAS field, so we pick
1878 * up an S2TTE with a HIPAS other than ASSIGNED.
1879 */
1880 inv_tte = s2tte_create_unassigned_ram(
1881 (const struct s2tt_context *)&s2tt_ctx);
1882 CHECK_TRUE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1883 inv_tte, level) == false);
1884
1885 /* Negative test: Test with a different type of RIPAS */
1886 idx = (unsigned int)test_helpers_get_rand_in_range(
1887 0UL, ARRAY_SIZE(ripas) - 1UL);
1888 inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
1889 pa, level, ripas[idx]);
1890 CHECK_TRUE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1891 inv_tte, level) == false);
1892 }
1893}
1894
1895void s2tte_is_assigned_ram_tc2(void)
1896{
1897 /***************************************************************
1898 * TEST CASE 2:
1899 *
1900 * Test s2tte_is_assigned_ram() with invalid levels.
1901 ***************************************************************/
1902 unsigned long pa = 0UL;
1903 unsigned long tte;
Soby Mathewb1228bb2024-12-31 17:42:46 +00001904 struct s2tt_context s2tt_ctx;
1905
1906 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001907
1908 /*
1909 * Initialize an s2tt_context structure for the test.
1910 * Only 'enable_lpa2' is used by the API, so the rest of fields
1911 * can be left untouched.
1912 */
1913 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1914
1915 tte = s2tte_create_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1916 pa, s2tt_test_helpers_min_block_lvl());
1917
1918 /* Validate s2tt_is_assigned_ram with an assigned ram TTE */
1919 CHECK_FALSE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1920 tte, s2tt_test_helpers_min_block_lvl() - 1L));
1921 CHECK_FALSE(s2tte_is_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
1922 tte, S2TT_TEST_HELPERS_MAX_LVL));
1923}
1924
1925void s2tte_is_assigned_destroyed_tc1(void)
1926{
1927 /***************************************************************
1928 * TEST CASE 1:
1929 *
1930 * This test case cover positive tests for
1931 * is_assigned_destroyed() as well as a number of negative
1932 * tests for each valid level.
1933 ***************************************************************/
1934
1935 unsigned long ripas[] = {S2TTE_NS,
1936 S2TTE_INVALID_RIPAS_RAM,
1937 S2TTE_INVALID_RIPAS_EMPTY};
Soby Mathewb1228bb2024-12-31 17:42:46 +00001938 struct s2tt_context s2tt_ctx;
1939
1940 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001941
1942 /*
1943 * Initialize an s2tt_context structure for the test.
1944 * Only 'enable_lpa2' is used by the API, so the rest of fields
1945 * can be left untouched.
1946 */
1947 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
1948
1949 for (long level = s2tt_test_helpers_min_block_lvl();
1950 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
1951 unsigned int idx;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01001952 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001953 unsigned long inv_tte, tte =
1954 s2tte_create_assigned_destroyed(
1955 (const struct s2tt_context *)&s2tt_ctx,
1956 pa, level);
1957
1958 /* Validate s2tt_is_assigned_destroyed with an assigned destroyed TTE */
1959 CHECK_TRUE(s2tte_is_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
1960 tte, level) == true);
1961
1962 /* Negative test: Set DESC_TYPE to a valid descriptor */
1963 inv_tte = tte | S2TT_TEST_PAGE_DESC;
1964 CHECK_TRUE(s2tte_is_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
1965 inv_tte, level) == false);
1966
1967 /* Negative test: Change the HIPAS to UNASSIGNED */
1968 inv_tte = tte & ~S2TTE_INVALID_HIPAS_MASK;
1969 inv_tte |= S2TTE_INVALID_HIPAS_UNASSIGNED;
1970 CHECK_TRUE(s2tte_is_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
1971 inv_tte, level) == false);
1972
1973 /* Negative test: Test with a different RIPAS */
1974 idx = (unsigned int)test_helpers_get_rand_in_range(
1975 0UL, ARRAY_SIZE(ripas) - 1UL);
1976 inv_tte = s2tt_test_create_assigned((const struct s2tt_context *)&s2tt_ctx,
1977 pa, level, ripas[idx]);
1978 CHECK_TRUE(s2tte_is_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
1979 inv_tte, level) == false);
1980 }
1981}
1982
1983void s2tte_is_table_tc1(void)
1984{
1985 /***************************************************************
1986 * TEST CASE 1:
1987 *
1988 * This test case cover positive tests for is_table() as well
1989 * as a number of negative tests for each valid level.
1990 ***************************************************************/
1991
Soby Mathewb1228bb2024-12-31 17:42:46 +00001992 struct s2tt_context s2tt_ctx;
1993
1994 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01001995
1996 /*
1997 * Initialize an s2tt_context structure for the test.
1998 * Only 'enable_lpa2' is used by the API, so the rest of fields
1999 * can be left untouched.
2000 */
2001 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2002
2003 for (long level = s2tt_test_helpers_min_table_lvl();
2004 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2005 unsigned long pa, inv_tte, tte = 0UL;
2006
2007 if (level <= S2TT_TEST_HELPERS_MAX_TABLE_LVL) {
2008 /* Validate s2tt_is_table with a valid table TTE */
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002009 pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002010 tte = s2tte_create_table(
2011 (const struct s2tt_context *)&s2tt_ctx,
2012 pa, level);
2013 CHECK_TRUE(s2tte_is_table((const struct s2tt_context *)&s2tt_ctx,
2014 tte, level) == true);
2015 } else {
2016 /*
2017 * Per aarch64 VMSA, PAGE and TABLE S2TTEs share the
2018 * same descriptor type ID, but the PAGE will only be
2019 * allowed into the last supported level. So reuse the
2020 * previous tte and test again with the PAGE level.
2021 */
2022 CHECK_TRUE(s2tte_is_table((const struct s2tt_context *)&s2tt_ctx,
2023 tte, level) == false);
2024 }
2025
2026 /* Negative test: Set DESC_TYPE to INVALID */
2027 inv_tte = tte & ~S2TT_TEST_DESC_TYPE_MASK;
2028 inv_tte = inv_tte | S2TT_TEST_INVALID_DESC;
2029 CHECK_TRUE(s2tte_is_table((const struct s2tt_context *)&s2tt_ctx,
2030 inv_tte, level) == false);
2031
2032 /* Negative test: Set DESC_TYPE to BLOCK */
2033 inv_tte = tte & ~S2TT_TEST_DESC_TYPE_MASK;
2034 inv_tte = inv_tte | S2TT_TEST_BLOCK_DESC;
2035 CHECK_TRUE(s2tte_is_table((const struct s2tt_context *)&s2tt_ctx,
2036 inv_tte, level) == false);
2037 }
2038}
2039
2040void s2tte_get_ripas_tc1(void)
2041{
2042 /***************************************************************
2043 * TEST CASE 1:
2044 *
2045 * For all possible RIPAS types, generate a HIPAS ASSIGNED and
2046 * a HIPAS UNASSIGNED S2TTE and verify that s2tt_get_ripas()
2047 * returns the right RIPAS
2048 ***************************************************************/
2049
2050 unsigned long tte, pa;
2051 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
2052 S2TTE_INVALID_RIPAS_RAM,
2053 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00002054 struct s2tt_context s2tt_ctx;
2055
2056 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002057
2058 /*
2059 * Initialize an s2tt_context structure for the test.
2060 * Only 'enable_lpa2' is used by the API, so the rest of fields
2061 * can be left untouched.
2062 */
2063 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2064
2065 for (unsigned int i = 0U; i < ARRAY_SIZE(ripas); i++) {
2066 /* HIPAS = UNASSIGNED */
2067 tte = s2tt_test_create_unassigned(
2068 (const struct s2tt_context *)&s2tt_ctx, ripas[i]);
2069 UNSIGNED_LONGS_EQUAL((unsigned int)s2tte_get_ripas(
2070 (const struct s2tt_context *)&s2tt_ctx, tte),
2071 EXTRACT(S2TTE_INVALID_RIPAS, ripas[i]));
2072
2073 /* HIPAS = ASSIGNED */
2074 for (long level = s2tt_test_helpers_min_block_lvl();
2075 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002076 pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002077 tte = s2tt_test_create_assigned(
2078 (const struct s2tt_context *)&s2tt_ctx,
2079 pa, level, ripas[i]);
2080 UNSIGNED_LONGS_EQUAL(
2081 (unsigned int)s2tte_get_ripas(
2082 (const struct s2tt_context *)&s2tt_ctx, tte),
2083 EXTRACT(S2TTE_INVALID_RIPAS, ripas[i]));
2084 }
2085 }
2086}
2087
2088void s2tte_get_ripas_tc2(void)
2089{
2090 /***************************************************************
2091 * TEST CASE 2:
2092 *
2093 * Test s2tte_get_ripas() with an invalid S2TTE and an invalid
2094 * HIPAS.
2095 ***************************************************************/
2096
2097 unsigned long tte = s2tte_create_unassigned_destroyed(
2098 (const struct s2tt_context *)NULL);
2099 tte &= ~S2TTE_INVALID_HIPAS_MASK;
2100
2101 /*
2102 * As per s2tt_pvt_defs.h, HIPAS field is 3 bits wide with
2103 * only the first bit used.
2104 */
2105 tte |= INPLACE(S2TTE_INVALID_HIPAS,
2106 EXTRACT(S2TTE_INVALID_HIPAS, S2TTE_INVALID_HIPAS_ASSIGNED) + 1UL);
2107
2108 test_helpers_expect_assert_fail(true);
2109 (void)s2tte_get_ripas((const struct s2tt_context *)NULL, tte);
2110 test_helpers_fail_if_no_assert_failed();
2111}
2112
2113void s2tt_init_unassigned_empty_tc1(void)
2114{
2115 /***************************************************************
2116 * TEST CASE 1:
2117 *
2118 * Initialize a table with unassigned empty S2TTEs and validate
2119 * its content.
2120 ***************************************************************/
2121
2122 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
2123 unsigned long val_s2tt[S2TTES_PER_S2TT];
2124
2125 /* Generate the validation table */
2126 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2127 val_s2tt[i] =
2128 s2tte_create_unassigned_empty(
2129 (const struct s2tt_context *)NULL);
2130 }
2131
2132 /*
2133 * Generate the test table. Note that s2tt_init_unassigned_empty()
2134 * can take a NULL s2tt_context pointer.
2135 */
2136 s2tt_init_unassigned_empty((const struct s2tt_context *)NULL, &s2tt[0]);
2137
2138 /* Validate */
2139 MEMCMP_EQUAL(val_s2tt, s2tt, sizeof(s2tt));
2140}
2141
2142void s2tt_init_unassigned_empty_tc2(void)
2143{
2144 /***************************************************************
2145 * TEST CASE 2:
2146 *
2147 * Invoke s2tt_init_unassigned_empty() passing a NULL
2148 * s2tt pointer.
2149 *
2150 * Note that s2tt_init_unassigned_empty() can take a NULL
2151 * s2tt_context pointer.
2152 ***************************************************************/
2153
2154 test_helpers_expect_assert_fail(true);
2155 s2tt_init_unassigned_empty((const struct s2tt_context *)NULL, NULL);
2156 test_helpers_fail_if_no_assert_failed();
2157}
2158
2159void s2tt_init_unassigned_ram_tc1(void)
2160{
2161 /***************************************************************
2162 * TEST CASE 1:
2163 *
2164 * Initialize a table with unassigned ram S2TTEs and validate its
2165 * content.
2166 ***************************************************************/
2167
2168 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
2169 unsigned long val_s2tt[S2TTES_PER_S2TT];
2170
2171 /* Generate the validation table */
2172 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2173 val_s2tt[i] = s2tte_create_unassigned_ram(
2174 (const struct s2tt_context *)NULL);
2175 }
2176
2177 /*
2178 * Generate the test table. Note that s2tt_init_unassigned_ram()
2179 * can take a NULL pointer to struct s2tt_context.
2180 */
2181 s2tt_init_unassigned_ram((const struct s2tt_context *)NULL, &s2tt[0]);
2182
2183 /* Validate */
2184 MEMCMP_EQUAL(val_s2tt, s2tt, sizeof(s2tt));
2185}
2186
2187void s2tt_init_unassigned_ram_tc2(void)
2188{
2189 /***************************************************************
2190 * TEST CASE 2:
2191 *
2192 * Invoke init_unassigned_ram() passing a NULL pointer.
2193 *
2194 * Note that s2tt_init_unassigned_ram() can take a NULL pointer
2195 * to struct s2tt_context.
2196 ***************************************************************/
2197
2198 test_helpers_expect_assert_fail(true);
2199 s2tt_init_unassigned_ram((const struct s2tt_context *)NULL, NULL);
2200 test_helpers_fail_if_no_assert_failed();
2201}
2202
2203void s2tt_init_unassigned_ns_tc1(void)
2204{
2205 /***************************************************************
2206 * TEST CASE 1:
2207 *
2208 * Initialize a table with unassigned ns S2TTEs and validate
2209 * its content.
2210 ***************************************************************/
2211
2212 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
2213 unsigned long val_s2tt[S2TTES_PER_S2TT];
2214
2215 /* Generate the validation table */
2216 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2217 val_s2tt[i] = s2tte_create_unassigned_ns(
2218 (const struct s2tt_context *)NULL);
2219 }
2220
2221 /*
2222 * Generate the test table. Note that s2tt_init_unassigned_ns()
2223 * can take a NULL s2tt_context pointer.
2224 */
2225 s2tt_init_unassigned_ns((const struct s2tt_context *)NULL, &s2tt[0]);
2226
2227 /* Validate */
2228 MEMCMP_EQUAL(val_s2tt, s2tt, sizeof(s2tt));
2229}
2230
2231void s2tt_init_unassigned_ns_tc2(void)
2232{
2233 /***************************************************************
2234 * TEST CASE 2:
2235 *
2236 * Invoke init_unassigned_ns() passing a NULL pointer.
2237 *
2238 * Note that s2tt_init_unassigned_ns() can take a NULL
2239 * struct s2tt_context pointer.
2240 ***************************************************************/
2241
2242 test_helpers_expect_assert_fail(true);
2243 s2tt_init_unassigned_ns((const struct s2tt_context *)NULL, NULL);
2244 test_helpers_fail_if_no_assert_failed();
2245}
2246
2247void s2tt_init_unassigned_destroyed_tc1(void)
2248{
2249 /***************************************************************
2250 * TEST CASE 1:
2251 *
2252 * Initialize a table with unassigned destroyed S2TTEs
2253 * and validate its content.
2254 ***************************************************************/
2255
2256 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
2257 unsigned long val_s2tt[S2TTES_PER_S2TT];
2258
2259 /* Generate the validation table */
2260 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2261 val_s2tt[i] =
2262 s2tte_create_unassigned_destroyed(
2263 (const struct s2tt_context *)NULL);
2264 }
2265
2266 /*
2267 * Generate the test table. Note that s2tt_init_unassigned_destroyed()
2268 * can take a NULL s2tt_context pointer.
2269 */
2270 s2tt_init_unassigned_destroyed((const struct s2tt_context *)NULL,
2271 &s2tt[0]);
2272
2273 /* Validate */
2274 MEMCMP_EQUAL(val_s2tt, s2tt, sizeof(s2tt));
2275}
2276
2277void s2tt_init_unassigned_destroyed_tc2(void)
2278{
2279 /***************************************************************
2280 * TEST CASE 2:
2281 *
2282 * Invoke s2tt_init_unassigned_destroyed() passing a NULL pointer.
2283 *
2284 * Note that s2tt_init_unassigned_destroyed() can take a NULL
2285 * pointer to struct s2tt_context.
2286 ***************************************************************/
2287
2288 test_helpers_expect_assert_fail(true);
2289 s2tt_init_unassigned_destroyed((const struct s2tt_context *)NULL, NULL);
2290 test_helpers_fail_if_no_assert_failed();
2291}
2292
2293void s2tt_init_assigned_empty_tc1(void)
2294{
2295 /***************************************************************
2296 * TEST CASE 1:
2297 *
2298 * For each valid level, initialize a table with assigned-empty
2299 * S2TTEs and validate its contents.
2300 ***************************************************************/
2301
Soby Mathewb1228bb2024-12-31 17:42:46 +00002302 struct s2tt_context s2tt_ctx;
2303
2304 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002305
2306 /*
2307 * Generate an s2tt context to be used for the test. Only
2308 * enable_lpa2 field is needed for the current test.
2309 */
2310 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2311
2312 for (long level = s2tt_test_helpers_min_block_lvl();
2313 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2314
2315 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002316 unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002317
2318 /* Generate the table */
2319 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2320 &s2tt[0], pa, level);
2321
2322 /* Validate the content of the table */
2323 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2324 unsigned long s2tte;
2325
2326 s2tte = s2tte_create_assigned_empty(
2327 (const struct s2tt_context *)&s2tt_ctx,
2328 pa, level);
2329 pa += s2tte_map_size(level);
2330
2331 UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
2332 }
2333 }
2334}
2335
2336void s2tt_init_assigned_empty_tc2(void)
2337{
2338 /***************************************************************
2339 * TEST CASE 2:
2340 *
2341 * For a valid address, try to create an assigned-empty S2TT
2342 * with a level above the maximum.
2343 ***************************************************************/
2344
2345 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2346 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
2347 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002348 struct s2tt_context s2tt_ctx;
2349
2350 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002351
2352 /*
2353 * Generate an s2tt context to be used for the test. Only
2354 * enable_lpa2 field is needed for the current test.
2355 */
2356 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2357
2358 test_helpers_expect_assert_fail(true);
2359 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2360 &s2tt[0U], pa, level);
2361 test_helpers_fail_if_no_assert_failed();
2362}
2363
2364void s2tt_init_assigned_empty_tc3(void)
2365{
2366 /***************************************************************
2367 * TEST CASE 3:
2368 *
2369 * For a valid address, try to create an assigned-empty S2TT
2370 * with a level below the minimum.
2371 ***************************************************************/
2372
2373 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2374 long level = s2tt_test_helpers_min_block_lvl() - 1L;
2375 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002376 struct s2tt_context s2tt_ctx;
2377
2378 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002379
2380 /*
2381 * Generate an s2tt context to be used for the test. Only
2382 * enable_lpa2 field is needed for the current test.
2383 */
2384 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2385
2386 test_helpers_expect_assert_fail(true);
2387 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2388 &s2tt[0U], pa, level);
2389 test_helpers_fail_if_no_assert_failed();
2390}
2391
2392void s2tt_init_assigned_empty_tc4(void)
2393{
2394 /***************************************************************
2395 * TEST CASE 4:
2396 *
2397 * Invoke s2tt_init_assigned_empty() with a NULL table pointer.
2398 ***************************************************************/
2399
2400 long level = s2tt_test_helpers_min_block_lvl();
2401 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002402 struct s2tt_context s2tt_ctx;
2403
2404 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002405
2406 /*
2407 * Generate an s2tt context to be used for the test. Only
2408 * enable_lpa2 field is needed for the current test.
2409 */
2410 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2411
2412 test_helpers_expect_assert_fail(true);
2413 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2414 NULL, pa, level);
2415 test_helpers_fail_if_no_assert_failed();
2416}
2417
2418void s2tt_init_assigned_empty_tc5(void)
2419{
2420 /***************************************************************
2421 * TEST CASE 5:
2422 *
2423 * Invoke s2tt_init_assigned_empty() with an unaligned address.
2424 ***************************************************************/
2425
2426 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2427 long level =
2428 test_helpers_get_rand_in_range(s2tt_test_helpers_min_block_lvl(),
2429 S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002430 unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002431 test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
Soby Mathewb1228bb2024-12-31 17:42:46 +00002432 struct s2tt_context s2tt_ctx;
2433
2434 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002435
2436 /*
2437 * Generate an s2tt context to be used for the test. Only
2438 * enable_lpa2 field is needed for the current test.
2439 */
2440 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2441
2442 test_helpers_expect_assert_fail(true);
2443 s2tt_init_assigned_empty((const struct s2tt_context *)&s2tt_ctx,
2444 &s2tt[0U], pa, level);
2445 test_helpers_fail_if_no_assert_failed();
2446}
2447
2448void s2tt_init_assigned_empty_tc6(void)
2449{
2450 /***************************************************************
2451 * TEST CASE 6:
2452 *
2453 * Invoke s2tt_init_assigned_empty() with a NULL s2tt_context
2454 * structure.
2455 ***************************************************************/
2456 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2457 long level = s2tt_test_helpers_min_block_lvl();
2458 unsigned long pa = 0UL; /* Valid for any level */
2459
2460 test_helpers_expect_assert_fail(true);
2461 s2tt_init_assigned_empty((const struct s2tt_context *)NULL,
2462 &s2tt[0U], pa, level);
2463 test_helpers_fail_if_no_assert_failed();
2464}
2465
2466void s2tt_init_assigned_ram_tc1(void)
2467{
2468 /***************************************************************
2469 * TEST CASE 1:
2470 *
2471 * For each valid level, initialize a table with assigned-ram
2472 * S2TTEs and validate its contents.
2473 ***************************************************************/
2474
Soby Mathewb1228bb2024-12-31 17:42:46 +00002475 struct s2tt_context s2tt_ctx;
2476
2477 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002478
2479 /*
2480 * Generate an s2tt context to be used for the test. Only
2481 * enable_lpa2 field is needed for the current test.
2482 */
2483 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2484
2485 for (long level = s2tt_test_helpers_min_block_lvl();
2486 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2487
2488 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002489 unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002490
2491 /* Generate the table */
2492 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2493 &s2tt[0], pa, level);
2494
2495 /* Validate the content of the table */
2496 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2497 unsigned long s2tte;
2498
2499 s2tte = s2tte_create_assigned_ram(
2500 (const struct s2tt_context *)&s2tt_ctx,
2501 pa, level);
2502 pa += s2tte_map_size(level);
2503
2504 UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
2505 }
2506 }
2507}
2508
2509void s2tt_init_assigned_ram_tc2(void)
2510{
2511 /***************************************************************
2512 * TEST CASE 2:
2513 *
2514 * For a valid address, try to create an assigned-ram S2TT
2515 * with a level above the maximum.
2516 ***************************************************************/
2517
2518 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2519 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
2520 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002521 struct s2tt_context s2tt_ctx;
2522
2523 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002524
2525 /*
2526 * Generate an s2tt context to be used for the test. Only
2527 * enable_lpa2 field is needed for the current test.
2528 */
2529 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2530
2531 test_helpers_expect_assert_fail(true);
2532 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2533 &s2tt[0U], pa, level);
2534 test_helpers_fail_if_no_assert_failed();
2535}
2536
2537void s2tt_init_assigned_ram_tc3(void)
2538{
2539 /***************************************************************
2540 * TEST CASE 3:
2541 *
2542 * For a valid address, try to create an assigned-ram S2TT
2543 * with a level below the minimum.
2544 ***************************************************************/
2545
2546 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2547 long level = s2tt_test_helpers_min_block_lvl() - 1L;
2548 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002549 struct s2tt_context s2tt_ctx;
2550
2551 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002552
2553 /*
2554 * Generate an s2tt context to be used for the test. Only
2555 * enable_lpa2 field is needed for the current test.
2556 */
2557 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2558
2559 test_helpers_expect_assert_fail(true);
2560 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2561 &s2tt[0U], pa, level);
2562 test_helpers_fail_if_no_assert_failed();
2563}
2564
2565void s2tt_init_assigned_ram_tc4(void)
2566{
2567 /***************************************************************
2568 * TEST CASE 4:
2569 *
2570 * Invoke s2tt_init_assigned_ram() with a NULL table pointer.
2571 ***************************************************************/
2572
2573 long level = s2tt_test_helpers_min_block_lvl();
2574 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002575 struct s2tt_context s2tt_ctx;
2576
2577 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002578
2579 /*
2580 * Generate an s2tt context to be used for the test. Only
2581 * enable_lpa2 field is needed for the current test.
2582 */
2583 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2584
2585 test_helpers_expect_assert_fail(true);
2586 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2587 NULL, pa, level);
2588 test_helpers_fail_if_no_assert_failed();
2589}
2590
2591void s2tt_init_assigned_ram_tc5(void)
2592{
2593 /***************************************************************
2594 * TEST CASE 5:
2595 *
2596 * Invoke s2tt_init_assigned_ram() with an unaligned address.
2597 ***************************************************************/
2598
2599 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2600 long level =
2601 test_helpers_get_rand_in_range(s2tt_test_helpers_min_block_lvl(),
2602 S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002603 unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002604 test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
Soby Mathewb1228bb2024-12-31 17:42:46 +00002605 struct s2tt_context s2tt_ctx;
2606
2607 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002608
2609 /*
2610 * Generate an s2tt context to be used for the test. Only
2611 * enable_lpa2 field is needed for the current test.
2612 */
2613 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2614
2615 test_helpers_expect_assert_fail(true);
2616 s2tt_init_assigned_ram((const struct s2tt_context *)&s2tt_ctx,
2617 &s2tt[0U], pa, level);
2618 test_helpers_fail_if_no_assert_failed();
2619}
2620
2621void s2tt_init_assigned_ram_tc6(void)
2622{
2623 /***************************************************************
2624 * TEST CASE 6:
2625 *
2626 * Call s2tt_init_assigned_ram() with a NULL s2tt_context
2627 * pointer.
2628 ***************************************************************/
2629
2630 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2631 long level = s2tt_test_helpers_min_block_lvl();
2632 unsigned long pa = 0UL; /* Valid for any level */
2633
2634 test_helpers_expect_assert_fail(true);
2635 s2tt_init_assigned_ram((const struct s2tt_context *)NULL,
2636 &s2tt[0U], pa, level);
2637 test_helpers_fail_if_no_assert_failed();
2638}
2639
2640void s2tt_init_assigned_ns_tc1(void)
2641{
2642 /***************************************************************
2643 * TEST CASE 1:
2644 *
2645 * For each valid level, initialize a table with assigned-ns
2646 * S2TTEs and validate its contents.
2647 ***************************************************************/
2648
Soby Mathewb1228bb2024-12-31 17:42:46 +00002649 struct s2tt_context s2tt_ctx;
2650
2651 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002652
2653 /*
2654 * Generate an s2tt context to be used for the test. Only
2655 * enable_lpa2 field is needed for the current test.
2656 */
2657 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2658
2659 for (long level = s2tt_test_helpers_min_block_lvl();
2660 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2661
2662 unsigned long s2tt[S2TTES_PER_S2TT] = { 0UL };
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002663 unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002664
2665 /*
2666 * s2tt_init_assigned_ns() does not verify that the
2667 * host-side attributes are architecturally valid.
2668 * Nevertheless, pass a valid set of them.
2669 */
2670 unsigned long attrs =
2671 s2tt_test_helpers_gen_ns_attrs(true, false);
2672
2673 /*
2674 * s2tt_init_assigned_ns() should mask out everything other
2675 * than the host-side attributes, so generate a whole parent
2676 * s2tte to pass to the former to verify it does what it is
2677 * expected.
2678 */
2679 unsigned long parent_s2tte = attrs |
2680 s2tt_test_helpers_gen_ns_attrs(false, false) |
2681 s2tt_test_helpers_pa_to_s2tte(
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002682 s2tt_test_helpers_gen_addr(level, true),
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002683 level);
2684
2685 /*
2686 * Generate the table. Note that s2tt_init_assigned_ns() can
2687 * take a NULL struct s2tt_context pointer.
2688 */
2689 s2tt_init_assigned_ns((const struct s2tt_context *)&s2tt_ctx,
2690 &s2tt[0], parent_s2tte, pa, level);
2691
2692 /* Validate the content of the table */
2693 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2694 unsigned long s2tte =
2695 s2tt_test_helpers_pa_to_s2tte(pa, level);
2696
2697 s2tte = s2tte_create_assigned_ns(
2698 (const struct s2tt_context *)&s2tt_ctx,
2699 s2tte | attrs, level);
2700 pa += s2tte_map_size(level);
2701
2702 UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
2703 }
2704 }
2705}
2706
2707void s2tt_init_assigned_ns_tc2(void)
2708{
2709 /***************************************************************
2710 * TEST CASE 2:
2711 *
2712 * For a valid address, try to create an assigned-ns S2TT
2713 * with a level above the maximum.
2714 *
2715 * Note that s2tt_init_assigned_ns() can take a NULL
2716 * struct s2tt_context pointer.
2717 ***************************************************************/
2718
2719 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2720 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
2721 unsigned long pa = 0UL; /* Valid for any level */
2722 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
2723
2724 test_helpers_expect_assert_fail(true);
2725 s2tt_init_assigned_ns((const struct s2tt_context *)NULL,
2726 &s2tt[0U], attrs, pa, level);
2727 test_helpers_fail_if_no_assert_failed();
2728}
2729
2730void s2tt_init_assigned_ns_tc3(void)
2731{
2732 /***************************************************************
2733 * TEST CASE 3:
2734 *
2735 * For a valid address, try to create an assigned-ns S2TT
2736 * with a level below the minimum.
2737 *
2738 * Note that s2tt_init_assigned_ns() can take a NULL
2739 * struct s2tt_context pointer.
2740 ***************************************************************/
2741
2742 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2743 long level = s2tt_test_helpers_min_block_lvl() - 1L;
2744 unsigned long pa = 0UL; /* Valid for any level */
2745 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
2746
2747 test_helpers_expect_assert_fail(true);
2748 s2tt_init_assigned_ns((const struct s2tt_context *)NULL,
2749 &s2tt[0U], attrs, pa, level);
2750 test_helpers_fail_if_no_assert_failed();
2751}
2752
2753void s2tt_init_assigned_ns_tc4(void)
2754{
2755 /***************************************************************
2756 * TEST CASE 4:
2757 *
2758 * Invoke s2tt_init_assigned_ns() with a NULL table pointer.
2759 *
2760 * Note that s2tt_init_assigned_ns() can take a NULL
2761 * struct s2tt_context_pointer.
2762 ***************************************************************/
2763
2764 long level = s2tt_test_helpers_min_block_lvl();
2765 unsigned long pa = 0UL; /* Valid for any level */
2766 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
2767
2768 test_helpers_expect_assert_fail(true);
2769 s2tt_init_assigned_ns((const struct s2tt_context *)NULL,
2770 NULL, attrs, pa, level);
2771 test_helpers_fail_if_no_assert_failed();
2772}
2773
2774void s2tt_init_assigned_ns_tc5(void)
2775{
2776 /***************************************************************
2777 * TEST CASE 5:
2778 *
2779 * Invoke s2tt_init_assigned_ns() with an unaligned address.
2780 *
2781 * Note that s2tt_init_assigned_ns() can take a NULL
2782 * struct s2tt_context pointer.
2783 ***************************************************************/
2784
2785 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2786 unsigned long attrs = s2tt_test_helpers_gen_ns_attrs(true, false);
2787 long level =
2788 test_helpers_get_rand_in_range(s2tt_test_helpers_min_block_lvl(),
2789 S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002790 unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002791 test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
2792
2793 test_helpers_expect_assert_fail(true);
2794 s2tt_init_assigned_ns((const struct s2tt_context *)NULL,
2795 &s2tt[0U], attrs, pa, level);
2796 test_helpers_fail_if_no_assert_failed();
2797}
2798
2799void s2tt_init_assigned_destroyed_tc1(void)
2800{
2801 /***************************************************************
2802 * TEST CASE 1:
2803 *
2804 * For each valid level, initialize a table with
2805 * assigned-destroyed S2TTEs and validate its contents.
2806 ***************************************************************/
Soby Mathewb1228bb2024-12-31 17:42:46 +00002807 struct s2tt_context s2tt_ctx;
2808
2809 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002810
2811 /*
2812 * Generate an s2tt context to be used for the test. Only
2813 * enable_lpa2 field is needed for the current test.
2814 */
2815 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2816
2817 for (long level = s2tt_test_helpers_min_block_lvl();
2818 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2819
2820 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002821 unsigned long pa = s2tt_test_helpers_gen_addr(level - 1L, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002822
2823 /* Generate the table */
2824 s2tt_init_assigned_destroyed(
2825 (const struct s2tt_context *)&s2tt_ctx,
2826 &s2tt[0], pa, level);
2827
2828 /* Validate the content of the table */
2829 for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) {
2830 unsigned long s2tte;
2831
2832 s2tte = s2tte_create_assigned_destroyed(
2833 (const struct s2tt_context *)&s2tt_ctx,
2834 pa, level);
2835 pa += s2tte_map_size(level);
2836
2837 UNSIGNED_LONGS_EQUAL(s2tte, s2tt[i]);
2838 }
2839 }
2840}
2841
2842void s2tt_init_assigned_destroyed_tc2(void)
2843{
2844 /***************************************************************
2845 * TEST CASE 2:
2846 *
2847 * For a valid address, try to create an assigned-destroyed
2848 * S2TT with a level above the maximum.
2849 ***************************************************************/
2850
2851 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2852 long level = S2TT_TEST_HELPERS_MAX_LVL + 1;
2853 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002854 struct s2tt_context s2tt_ctx;
2855
2856 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002857
2858 /*
2859 * Generate an s2tt context to be used for the test. Only
2860 * enable_lpa2 field is needed for the current test.
2861 */
2862 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2863
2864 test_helpers_expect_assert_fail(true);
2865 s2tt_init_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
2866 &s2tt[0U], pa, level);
2867 test_helpers_fail_if_no_assert_failed();
2868}
2869
2870void s2tt_init_assigned_destroyed_tc3(void)
2871{
2872 /***************************************************************
2873 * TEST CASE 3:
2874 *
2875 * For a valid address, try to create an assigned-destroyed
2876 * S2TT with a level below the minimum.
2877 ***************************************************************/
2878
2879 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2880 long level = s2tt_test_helpers_min_block_lvl() - 1L;
2881 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002882 struct s2tt_context s2tt_ctx;
2883
2884 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002885
2886 /*
2887 * Generate an s2tt context to be used for the test. Only
2888 * enable_lpa2 field is needed for the current test.
2889 */
2890 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2891
2892 test_helpers_expect_assert_fail(true);
2893 s2tt_init_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
2894 &s2tt[0U], pa, level);
2895 test_helpers_fail_if_no_assert_failed();
2896}
2897
2898void s2tt_init_assigned_destroyed_tc4(void)
2899{
2900 /***************************************************************
2901 * TEST CASE 4:
2902 *
2903 * Invoke s2tt_init_assigned_destroyed() with a NULL table
2904 * pointer.
2905 ***************************************************************/
2906
2907 long level = s2tt_test_helpers_min_block_lvl();
2908 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00002909 struct s2tt_context s2tt_ctx;
2910
2911 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002912
2913 /*
2914 * Generate an s2tt context to be used for the test. Only
2915 * enable_lpa2 field is needed for the current test.
2916 */
2917 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2918
2919 test_helpers_expect_assert_fail(true);
2920 s2tt_init_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
2921 NULL, pa, level);
2922 test_helpers_fail_if_no_assert_failed();
2923}
2924
2925void s2tt_init_assigned_destroyed_tc5(void)
2926{
2927 /***************************************************************
2928 * TEST CASE 5:
2929 *
2930 * Invoke s2tt_init_assigned_destroyed() with an unaligned
2931 * address.
2932 ***************************************************************/
2933
2934 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2935 long level =
2936 test_helpers_get_rand_in_range(s2tt_test_helpers_min_block_lvl(),
2937 S2TT_TEST_HELPERS_MAX_LVL);
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01002938 unsigned long pa = s2tt_test_helpers_gen_addr(level, true) +
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002939 test_helpers_get_rand_in_range(1UL, (unsigned long)GRANULE_SIZE - 1UL);
Soby Mathewb1228bb2024-12-31 17:42:46 +00002940 struct s2tt_context s2tt_ctx;
2941
2942 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002943
2944 /*
2945 * Generate an s2tt context to be used for the test. Only
2946 * enable_lpa2 field is needed for the current test.
2947 */
2948 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2949
2950 test_helpers_expect_assert_fail(true);
2951 s2tt_init_assigned_destroyed((const struct s2tt_context *)&s2tt_ctx,
2952 &s2tt[0U], pa, level);
2953 test_helpers_fail_if_no_assert_failed();
2954}
2955
2956void s2tt_init_assigned_destroyed_tc6(void)
2957{
2958 /***************************************************************
2959 * TEST CASE 6:
2960 *
2961 * Call s2tt_init_assigned_destroyed() with a NULL
2962 * struct s2tt_context pointer.
2963 ***************************************************************/
2964
2965 unsigned long s2tt[S2TTES_PER_S2TT] = {0};
2966 long level = s2tt_test_helpers_min_block_lvl();
2967 unsigned long pa = 0UL; /* Valid for any level */
2968
2969 test_helpers_expect_assert_fail(true);
2970 s2tt_init_assigned_destroyed((const struct s2tt_context *)NULL,
2971 &s2tt[0U], pa, level);
2972 test_helpers_fail_if_no_assert_failed();
2973}
2974
2975void s2tte_pa_tc1(void)
2976{
2977 /***************************************************************
2978 * TEST CASE 1:
2979 *
2980 * For each valid level, generate an assigned s2tte or table
2981 * and verify that s2tte_pa() returns the right address
2982 ***************************************************************/
2983
2984 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
2985 S2TTE_INVALID_RIPAS_RAM,
2986 S2TTE_INVALID_RIPAS_DESTROYED};
Soby Mathewb1228bb2024-12-31 17:42:46 +00002987 struct s2tt_context s2tt_ctx;
2988
2989 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01002990
2991 /*
2992 * Generate an s2tt context to be used for the test. Only
2993 * enable_lpa2 field is needed for the current test.
2994 */
2995 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
2996
2997 for (long level = s2tt_test_helpers_min_table_lvl();
2998 level <= S2TT_TEST_HELPERS_MAX_LVL; level++) {
2999 unsigned long tte;
Javier Almansa Sobrino9810a8e2024-06-03 15:17:25 +01003000 unsigned long pa = s2tt_test_helpers_gen_addr(level, true);
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003001
3002 if (level < s2tt_test_helpers_min_block_lvl()) {
3003 tte = s2tte_create_table(
3004 (const struct s2tt_context *)&s2tt_ctx,
3005 pa, level);
3006 } else {
3007 /*
3008 * pickup a random type of assigned S2TTE
3009 * to test with
3010 */
3011 unsigned int idx =
3012 (unsigned int)test_helpers_get_rand_in_range(
3013 0UL, ARRAY_SIZE(ripas) - 1UL);
3014
3015 tte = s2tt_test_create_assigned(
3016 (const struct s2tt_context *)&s2tt_ctx,
3017 pa, level, ripas[idx]);
3018 }
3019
3020 /* Verify the address returned by s2tte_pa() */
3021 UNSIGNED_LONGS_EQUAL(pa, s2tte_pa(
3022 (const struct s2tt_context *)&s2tt_ctx,
3023 tte, level));
3024 }
3025}
3026
3027void s2tte_pa_tc2(void)
3028{
3029 /***************************************************************
3030 * TEST CASE 2:
3031 *
3032 * For a given level and unassigned s2tte (which doesn't have
3033 * a PA), verify that s2tte_pa() behaves as expected.
3034 ***************************************************************/
3035
3036 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
3037 S2TTE_INVALID_RIPAS_RAM,
3038 S2TTE_INVALID_RIPAS_DESTROYED};
3039 long level = test_helpers_get_rand_in_range(
3040 s2tt_test_helpers_min_block_lvl(),
3041 S2TT_TEST_HELPERS_MAX_LVL);
Soby Mathewb1228bb2024-12-31 17:42:46 +00003042 struct s2tt_context s2tt_ctx;
3043
3044 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003045
3046 /*
3047 * Generate an s2tt context to be used for the test. Only
3048 * enable_lpa2 field is needed for the current test.
3049 */
3050 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3051
3052 /* pickup a random type of unassigned S2TTE to test with */
3053 unsigned int idx = (unsigned int)test_helpers_get_rand_in_range(
3054 0UL, ARRAY_SIZE(ripas) - 1UL);
3055 unsigned long tte = s2tt_test_create_unassigned(
3056 (const struct s2tt_context *)&s2tt_ctx, ripas[idx]);
3057
3058 test_helpers_expect_assert_fail(true);
3059 (void)s2tte_pa((const struct s2tt_context *)&s2tt_ctx, tte, level);
3060 test_helpers_fail_if_no_assert_failed();
3061}
3062
3063void s2tte_pa_tc3(void)
3064{
3065 /***************************************************************
3066 * TEST CASE 3:
3067 *
3068 * With a valid assigned S2TTE, call s2tte_pa() with a level
3069 * above the maximum supported one.
3070 **************************************************************/
3071
3072 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
3073 S2TTE_INVALID_RIPAS_RAM,
3074 S2TTE_INVALID_RIPAS_DESTROYED};
3075
3076 long level = S2TT_TEST_HELPERS_MAX_LVL;
3077 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00003078 struct s2tt_context s2tt_ctx;
3079
3080 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003081
3082 /*
3083 * Generate an s2tt context to be used for the test. Only
3084 * enable_lpa2 field is needed for the current test.
3085 */
3086 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3087
3088 /* pickup a random type of assigned S2TTE to test with */
3089 unsigned int idx = (unsigned int)test_helpers_get_rand_in_range(
3090 0UL, ARRAY_SIZE(ripas) - 1UL);
3091 unsigned long tte = s2tt_test_create_assigned(
3092 (const struct s2tt_context *)&s2tt_ctx,
3093 pa, level, ripas[idx]);
3094
3095 test_helpers_expect_assert_fail(true);
3096 (void)s2tte_pa((const struct s2tt_context *)&s2tt_ctx, tte, level + 1U);
3097 test_helpers_fail_if_no_assert_failed();
3098}
3099
3100void s2tte_pa_tc4(void)
3101{
3102 /***************************************************************
3103 * TEST CASE 4:
3104 *
3105 * With a valid assigned S2TTE, call s2tte_pa() with a level
3106 * below the minimum supported one.
3107 **************************************************************/
3108
3109 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
3110 S2TTE_INVALID_RIPAS_RAM,
3111 S2TTE_INVALID_RIPAS_DESTROYED};
3112
3113 long level = S2TT_TEST_HELPERS_MAX_LVL;
3114 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00003115 struct s2tt_context s2tt_ctx;
3116
3117 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003118
3119 /*
3120 * Generate an s2tt context to be used for the test. Only
3121 * enable_lpa2 field is needed for the current test.
3122 */
3123 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3124
3125 /* pickup a random type of assigned S2TTE to test with */
3126 unsigned int idx = (unsigned int)test_helpers_get_rand_in_range(
3127 0UL, ARRAY_SIZE(ripas) - 1UL);
3128 unsigned long tte = s2tt_test_create_assigned(
3129 (const struct s2tt_context *)&s2tt_ctx,
3130 pa, level, ripas[idx]);
3131
3132 test_helpers_expect_assert_fail(true);
3133 (void)s2tte_pa((const struct s2tt_context *)&s2tt_ctx,
3134 tte, s2tt_test_helpers_min_table_lvl() - 1L);
3135 test_helpers_fail_if_no_assert_failed();
3136}
3137
3138void s2tte_pa_tc5(void)
3139{
3140 /***************************************************************
3141 * TEST CASE 5:
3142 *
3143 * Call s2tte_pa() with a NULL s2tt_context pointer.
3144 **************************************************************/
3145
3146 unsigned long ripas[] = {S2TTE_INVALID_RIPAS_EMPTY,
3147 S2TTE_INVALID_RIPAS_RAM,
3148 S2TTE_INVALID_RIPAS_DESTROYED};
3149
3150 long level = s2tt_test_helpers_min_block_lvl();
3151 unsigned long pa = 0UL; /* Valid for any level */
Soby Mathewb1228bb2024-12-31 17:42:46 +00003152 struct s2tt_context s2tt_ctx;
3153
3154 (void)memset(&s2tt_ctx, 0, sizeof(s2tt_ctx));
Javier Almansa Sobrino4389c342024-04-10 12:12:13 +01003155
3156 /*
3157 * Generate an s2tt context to be used for the test. Only
3158 * enable_lpa2 field is needed for the current test.
3159 */
3160 s2tt_ctx.enable_lpa2 = s2tt_test_helpers_lpa2_enabled();
3161
3162 /* pickup a random type of assigned S2TTE to test with */
3163 unsigned int idx = (unsigned int)test_helpers_get_rand_in_range(
3164 0UL, ARRAY_SIZE(ripas) - 1UL);
3165 unsigned long tte = s2tt_test_create_assigned(
3166 (const struct s2tt_context *)&s2tt_ctx,
3167 pa, level, ripas[idx]);
3168
3169 test_helpers_expect_assert_fail(true);
3170 (void)s2tte_pa((const struct s2tt_context *)NULL,
3171 tte, s2tt_test_helpers_min_table_lvl() - 1L);
3172 test_helpers_fail_if_no_assert_failed();
3173}