1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14definitions: 15 - name: java 16 template: | 17 .language Java 18 - name: aoobe_p 19 template: | 20 .record panda.ArrayIndexOutOfBoundsException<external> 21 - name: aoobe_j 22 template: | 23 .record java.lang.ArrayIndexOutOfBoundsException<external> 24 - name: npe_p 25 template: | 26 .record panda.NullPointerException <external> 27 - name: npe_j 28 template: | 29 .record java.lang.NullPointerException <external> 30tests: 31 - file-name: "ldarru.8" 32 isa: 33 title: Load from array 34 description: > 35 Load an element from array using accumulator as an index and puts it into accumulator. 36 If element size is smaller then 32 bits, it will be zero or sign extended (depending on bytecode) to i32. 37 commands: 38 - file-name: "read_arr_p" 39 isa: 40 instructions: 41 - sig: ldarru.8 v:in:u8[] 42 acc: inout:i32 43 format: [op_v_8] 44 description: Check ldarru.8 reads items from array of different size and type in Panda Assembly context. 45 code-template: | 46 # 47 movi v0, *s 48 newarr v0, v0, %s 49 ldai 0 50 ldarru.8 v0 51 check-type: exit-positive 52 template-cases: 53 - values: ['u1[]'] 54 - values: ['u8[]'] 55 cases: 56 - values: ['1'] 57 - values: ['255'] 58 tags: ['tsan'] 59 - values: ['65536'] 60 61 - file-name: "acceptable_primitive_types_p" 62 isa: 63 instructions: 64 - sig: ldarru.8 v:in:u8[] 65 acc: inout:i32 66 format: [op_v_8] 67 tags: ['tsan', 'verifier'] 68 bugid: ['3052'] 69 description: Check acceptable array of primitive types for ldarru.8 instruction in Panda Assembly context. 70 code-template: | 71 # 72 movi v0, 1 73 newarr v0, v0, %s 74 ldai 0 75 ldarru.8 v0 76 check-type: exit-positive 77 runner-options: ['verifier-only', 'verifier-debug-config'] 78 cases: 79 - values: ['u1[]'] 80 - values: ['u8[]'] 81 82 - file-name: "rejectable_primitive_types_p" 83 isa: 84 instructions: 85 - sig: ldarru.8 v:in:u8[] 86 acc: inout:i32 87 format: [op_v_8] 88 description: Check rejectable array of primitive types for ldarru.8 instruction in Panda Assembly context. 89 code-template: | 90 # 91 movi v0, 1 92 newarr v0, v0, %s 93 ldai 0 94 ldarru.8 v0 95 96 check-type: exit-positive 97 tags: ['verifier'] 98 runner-options: ['verifier-failure', 'verifier-debug-config'] 99 cases: 100 - values: ['i8[]'] 101 - values: ['i16[]'] 102 - values: ['u16[]'] 103 - values: ['i32[]'] 104 - values: ['u32[]'] 105 - values: ['i64[]'] 106 - values: ['u64[]'] 107 - values: ['f32[]'] 108 - values: ['f64[]'] 109 110 - file-name: "read_values" 111 isa: 112 instructions: 113 - sig: ldarru.8 v:in:u8[] 114 acc: inout:i32 115 format: [op_v_8] 116 description: Check ldarru.8 reads correct items from array of primitives. 117 header-template: [xorshift32, main] 118 code-template: | 119 # 120 movi v3, 10000 # iterations 121 movi v2, *s # index 122 movi v0, *s 123 # array size 124 newarr v1, v0, %s # v1 - testable array 125 126 movi v0, 1 # initial random number 127 loop: 128 call.short nextRand, v0 129 sta v0 # v0 - next random number 130 # 131 starr.8 v1, v2 # save random number in v1[v2] 132 lda v2 133 ldarru.8 v1 # get v1[v2] 134 andi 255 # Keep only low 8 bits 135 sta v4 # v4 = v1[v2] 136 137 lda v0 138 andi 255 # acc = v0 & 255 (random number) 139 ucmp v4 # Compare random number and stored value from array 140 jeqz passed 141 ldai 1 142 return 143 passed: 144 inci v3, -1 145 lda v3 146 jnez loop 147 check-type: exit-positive 148 template-cases: 149 - values: ['u1[]'] 150 - values: ['u8[]'] 151 cases: 152 - values: ['0', '1'] 153 - values: ['254', '255'] 154 - values: ['65535', '65536'] 155 - values: ['7', '16'] 156 - values: ['123', '255'] 157 - values: ['49151', '65536'] 158 159 - file-name: "read_all_values" 160 isa: 161 instructions: 162 - sig: ldarru.8 v:in:u8[] 163 acc: inout:i32 164 format: [op_v_8] 165 description: Check ldarru.8 reads correct items from array of primitives. Inspect different indexes and values. 166 code-template: | 167 # 168 movi v1, 0 # v1 - index 169 movi v0, *s 170 # v0 is array size 171 mov v2, v0 # v2 is size too 172 newarr v0, v0, %s # v0 - testable array 173 fill_array: 174 lda v1 175 starr.8 v0, v1 # v0[v1] = v1 176 addi 1 177 sta v1 # v1 = v1 + 1 178 jne v2, fill_array 179 movi v1, 0 # index 180 check_array: 181 lda v1 182 ldarru.8 v0 183 andi 255 184 sta v3 185 lda v1 186 andi 255 187 ucmp v3 188 jeqz ok 189 ldai 1 190 return 191 ok: 192 inci v1, 1 193 lda v1 194 jne v2, check_array 195 check-type: exit-positive 196 template-cases: 197 - values: ['u1[]'] 198 - values: ['u8[]'] 199 cases: 200 - values: ['100'] 201 - values: ['255'] 202 tags: ['tsan'] 203 - values: ['65535'] 204 tags: ['tsan'] 205 206 - file-name: "reg_number" 207 isa: 208 instructions: 209 - sig: ldarru.8 v:in:u8[] 210 acc: inout:i32 211 format: [op_v_8] 212 check-type: empty 213 runner-options: [compile-only] 214 description: Check 'ldarru.8' instruction with different registers numbers. 215 header-template: [] 216 code-template: | 217 # 218 .function i32 main() { 219 ldarru.8 %s 220 } 221 cases: 222 - values: [v0] 223 - values: [v16] 224 - values: [v128] 225 - values: [v255] 226 - values: [v256] 227 runner-options: [compile-failure] 228 - values: [v65535] 229 runner-options: [compile-failure] 230 - case-template: | 231 # 232 .function void f1(i32 a0) { 233 ldarru.8 a0 # valid name of register 234 } 235 236 .function i32 main() { 237 movi v0, 0 238 call.short f1, v0 239 } 240 - case-template: | 241 # 242 .function void f1(i32 a0) { 243 ldarru.8 a1 # invalid name of register 244 } 245 246 .function i32 main() { 247 movi v0, 0 248 call.short f1, v0 249 } 250 runner-options: [compile-failure] 251 - values: [a0] 252 runner-options: [compile-failure] 253 - values: [a255] 254 runner-options: [compile-failure] 255 - values: [null] 256 runner-options: [compile-failure] 257 - values: [0] 258 runner-options: [compile-failure] 259 - values: [1.1] 260 runner-options: [compile-failure] 261 - values: ['2.2'] 262 runner-options: [compile-failure] 263 264 - file-name: "arr_type" 265 isa: 266 instructions: 267 - sig: ldarru.8 v:in:u8[] 268 acc: inout:i32 269 format: [op_v_8] 270 verification: 271 - v1_array_type 272 tags: ['verifier'] 273 bugid: ['2816'] 274 runner-options: ['verifier-failure', 'verifier-debug-config'] 275 header-template: [] 276 code-template: | 277 # 278 .record A {} 279 .record panda.String <external> 280 .record panda.Object <external> 281 .function i32 main() { 282 %s 283 ldai 0 284 ldarru.8 v0 285 check-type: exit-positive 286 description: Check 'ldarru.8' with incorrect array type. See also "rejectable_primitive_types" tests. 287 cases: 288 - values: 289 - movi v0, 0 290 - values: 291 - movi.64 v0, 0 292 - values: 293 - fmovi.64 v0, 0 294 - values: 295 - | 296 # 297 lda.type A 298 sta.obj v0 299 - values: 300 - | 301 # 302 lda.type A[] 303 sta.obj v0 304 - values: 305 - | 306 # 307 lda.type panda.String 308 sta.obj v0 309 - values: 310 - | 311 # 312 lda.type panda.String[] 313 sta.obj v0 314 - values: 315 - | 316 # 317 lda.type panda.Object 318 sta.obj v0 319 - values: 320 - | 321 # 322 lda.type panda.Object[] 323 sta.obj v0 324 - values: 325 - | 326 # 327 lda.str "string" 328 sta.obj v0 329 - values: 330 - | 331 # 332 movi v0, 1 333 newarr v0, v0, panda.Object[] 334 - values: 335 - | 336 # 337 movi v0, 1 338 newarr v0, v0, panda.String[] 339 340 - file-name: "acc_type" 341 isa: 342 instructions: 343 - sig: ldarru.8 v:in:u8[] 344 acc: inout:i32 345 format: [op_v_8] 346 verification: 347 - acc_i32 348 tags: ['verifier'] 349 bugid: ['2817'] 350 runner-options: ['verifier-failure', 'verifier-debug-config'] 351 header-template: [] 352 code-template: | 353 # 354 .record A {} 355 .record panda.String <external> 356 .record panda.Object <external> 357 .function i32 main() { 358 movi v0, 1 359 newarr v0, v0, u8[] 360 %s 361 ldarru.8 v0 362 check-type: exit-positive 363 description: Check 'ldarru.8' with incorrect index type. 364 cases: 365 - values: 366 - ldai.64 0 367 - values: 368 - fldai.64 0 369 - values: 370 - | 371 # 372 lda.type A 373 - values: 374 - | 375 # 376 lda.type A[] 377 - values: 378 - | 379 # 380 lda.type panda.String 381 - values: 382 - | 383 # 384 lda.type panda.String[] 385 - values: 386 - | 387 # 388 lda.type panda.Object 389 - values: 390 - | 391 # 392 lda.type panda.Object[] 393 - values: 394 - | 395 # 396 lda.str "string" 397 - values: 398 - | 399 # 400 movi v1, 1 401 newarr v1, v1, panda.Object[] 402 lda.obj v1 403 - values: 404 - | 405 # 406 movi v1, 1 407 newarr v1, v1, panda.String[] 408 lda.obj v1 409 410 - file-name: "arr_acc_type" 411 isa: 412 instructions: 413 - sig: ldarru.8 v:in:u8[] 414 acc: inout:i32 415 format: [op_v_8] 416 verification: 417 - v1_array_type 418 tags: ['verifier'] 419 bugid: ['2816', '2817'] 420 runner-options: ['verifier-failure', 'verifier-debug-config'] 421 header-template: [] 422 code-template: | 423 # 424 .record A {} 425 .record panda.String <external> 426 .record panda.Object <external> 427 .function i32 main() { 428 %s 429 *s 430 ldarru.8 v0 431 check-type: exit-positive 432 description: Check 'ldarru.8' with incorrect register and accumulator types. 433 template-cases: 434 - values: 435 - movi v0, 0 436 - values: 437 - movi.64 v0, 0 438 - values: 439 - fmovi.64 v0, 0 440 - values: 441 - | 442 # 443 lda.type A 444 sta.obj v0 445 - values: 446 - | 447 # 448 lda.type A[] 449 sta.obj v0 450 - values: 451 - | 452 # 453 lda.type panda.String 454 sta.obj v0 455 - values: 456 - | 457 # 458 lda.type panda.String[] 459 sta.obj v0 460 - values: 461 - | 462 # 463 lda.type panda.Object 464 sta.obj v0 465 - values: 466 - | 467 # 468 lda.type panda.Object[] 469 sta.obj v0 470 - values: 471 - | 472 # 473 lda.str "string" 474 sta.obj v0 475 - values: 476 - | 477 # 478 movi v0, 1 479 newarr v0, v0, panda.Object[] 480 - values: 481 - | 482 # 483 movi v0, 1 484 newarr v0, v0, panda.String[] 485 cases: 486 - values: 487 - ldai 0 488 - values: 489 - ldai.64 0 490 - values: 491 - fldai.64 0 492 - values: 493 - | 494 # 495 lda.type A 496 - values: 497 - | 498 # 499 lda.type A[] 500 - values: 501 - | 502 # 503 lda.type panda.String 504 - values: 505 - | 506 # 507 lda.type panda.String[] 508 - values: 509 - | 510 # 511 lda.type panda.Object 512 - values: 513 - | 514 # 515 lda.type panda.Object[] 516 - values: 517 - | 518 # 519 lda.str "string" 520 - values: 521 - | 522 # 523 movi v1, 1 524 newarr v1, v1, panda.Object[] 525 lda.obj v1 526 - values: 527 - | 528 # 529 movi v1, 1 530 newarr v1, v1, panda.String[] 531 lda.obj v1 532 533 - file-name: uninitialized_acc_regs 534 isa: 535 instructions: 536 - sig: ldarru.8 v:in:u8[] 537 acc: inout:i32 538 format: [op_v_8] 539 description: Check 'ldarru.8' with uninitialized register and accumulator. 540 tags: ['verifier'] 541 bugid: ['2818'] 542 runner-options: ['verifier-failure', 'verifier-debug-config'] 543 header-template: [] 544 code-template: | 545 # 546 .function i32 main() { 547 %s 548 ldarru.8 v0 549 check-type: exit-positive 550 cases: 551 - values: ['ldai 0'] 552 - values: [''] 553 554 - file-name: array_out_of_bound_exception_p 555 isa: 556 instructions: 557 - sig: ldarru.8 v:in:u8[] 558 acc: inout:i32 559 format: [op_v_8] 560 exceptions: 561 - x_bounds 562 description: Check 'ldarru.8' behavior when index is out of array bounds. 563 header-template: [aoobe_p, main] 564 code-template: | 565 # 566 movi v0, *s 567 newarr v0, v0, %s 568 ldai *s 569 begin: 570 ldarru.8 v0 571 end: 572 ldai 1 # Should not reach this line 573 return 574 575 catch_AOOBE: 576 ldai 0 # Expected panda.ArrayIndexOutOfBoundsException 577 return 578 579 catch_all: 580 ldai 2 # Unexpected exception, test failed 581 return 582 583 .catch panda.ArrayIndexOutOfBoundsException, begin, end, catch_AOOBE 584 .catchall begin, end, catch_all 585 check-type: none 586 template-cases: 587 - values: ['u1[]'] 588 - values: ['u8[]'] 589 cases: 590 - values: [0, 0] 591 tags: ['tsan'] 592 - values: [0, 1] 593 - values: [10, 10] 594 - values: [10, 128] 595 - values: [255, 255] 596 - values: [254, 255] 597 - values: [65535, 65535] 598 tags: ['tsan'] 599 - values: [65535, 65536] 600 - values: [10, 0xFFFFFFFF] 601 - values: [256, 0xFFFFFFFE] 602 - values: [65536, 0xFFFFFFFD] 603 tags: ['tsan'] 604 - values: [0x100000, 0xFFFFFFFC] 605 - values: [10, 0x80000000] 606 - values: [256, 0x80000001] 607 - values: [65536, 0x80000002] 608 tags: ['tsan'] 609 - values: [0x100000, 0x80000003] 610 611 - file-name: null_pointer_p 612 isa: 613 instructions: 614 - sig: ldarru.8 v:in:u8[] 615 acc: inout:i32 616 format: [op_v_8] 617 exceptions: 618 - x_null 619 description: Check 'ldarru.8' behavior when array is null reference. 620 header-template: [npe_p] 621 code-template: | 622 .function %s get_null() { 623 lda.null 624 return.obj 625 } 626 627 .function i32 main() { 628 call.short get_null 629 sta.obj v0 630 ldai *s 631 begin: 632 ldarru.8 v0 633 end: 634 ldai 1 # Should not reach this line 635 return 636 637 catch_NPE: 638 ldai 0 # Expected panda.NullPointerException 639 return 640 641 catch_all: 642 ldai 2 # Unexpected exception, test failed 643 return 644 645 .catch panda.NullPointerException, begin, end, catch_NPE 646 .catchall begin, end, catch_all 647 check-type: none 648 template-cases: 649 - values: ['u1[]'] 650 - values: ['u8[]'] 651 cases: 652 - values: [0] 653 tags: ['tsan'] 654 - values: [1] 655 - values: [10] 656 - values: [128] 657 - values: [255] 658 - values: [65535] 659 tags: ['tsan'] 660 - values: [0x7FFFFFFF] 661 - values: [0xFFFFFFFF] 662 - values: [0x80000000] 663 664