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