1# Copyright (c) 2021-2022 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: PandaAssembly 16 template: | 17 .language PandaAssembly 18 - name: aoobe_p 19 template: | 20 .record panda.ArrayIndexOutOfBoundsException<external> 21 - name: aoobe_j 22 template: | 23 .record panda.ArrayIndexOutOfBoundsException<external> 24 - name: npe_p 25 template: | 26 .record panda.NullPointerException <external> 27 - name: npe_j 28 template: | 29 .record panda.NullPointerException <external> 30tests: 31 - file-name: "ldarr.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: ldarr.8 v:in:i8[] 42 acc: inout:i32 43 format: [op_v_8] 44 description: Check ldarr.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 ldarr.8 v0 51 check-type: exit-positive 52 template-cases: 53 - values: ['u1[]'] 54 - values: ['i8[]'] 55 cases: 56 - values: ['1'] 57 - values: ['255'] 58 tags: ['tsan'] 59 - values: ['65536'] 60 61 - file-name: "read_arr_j" 62 isa: 63 instructions: 64 - sig: ldarr.8 v:in:i8[] 65 acc: inout:i32 66 format: [op_v_8] 67 description: Check ldarr.8 reads items from array of different size and type in PandaAssembly context. 68 header-template: [PandaAssembly, main] 69 code-template: | 70 # 71 movi v0, *s 72 newarr v0, v0, %s 73 ldai 0 74 ldarr.8 v0 75 check-type: exit-positive 76 runner-options: ['use-pa'] 77 template-cases: 78 - values: ['u1[]'] 79 - values: ['i8[]'] 80 cases: 81 - values: ['1'] 82 - values: ['255'] 83 tags: ['tsan'] 84 - values: ['65536'] 85 86 - file-name: "primitive_types_p" 87 isa: 88 instructions: 89 - sig: ldarr.8 v:in:i8[] 90 acc: inout:i32 91 format: [op_v_8] 92 tags: ['tsan', 'verifier'] 93 bugid: ['3052'] 94 description: Check array of primitive types for 'ldarr.8' instruction in Panda Assembly context. 95 header-template: [] 96 code-template: | 97 .array arr_u1 u1 1 { 1 } 98 .array arr_i8 i8 1 { 1 } 99 .array arr_u8 u8 1 { 1 } 100 .array arr_i16 i16 1 { 1 } 101 .array arr_u16 u16 1 { 1 } 102 .array arr_i32 i32 1 { 1 } 103 .array arr_u32 u32 1 { 1 } 104 .array arr_i64 i64 1 { 1 } 105 .array arr_u64 u64 1 { 1 } 106 .array arr_f32 f32 1 { 1 } 107 .array arr_f64 f64 1 { 1 } 108 .function i32 main() { 109 %s 110 ldai 0 111 ldarr.8 v0 112 check-type: exit-positive 113 runner-options: ['verifier-failure', 'verifier-config'] 114 template-cases: 115 - values: 116 - | 117 # 118 movi v0, 1 119 newarr v0, v0, %s[] 120 - values: 121 - | 122 # 123 lda.const v0, arr_%s 124 cases: 125 - values: [u1] 126 runner-options: [verifier-only, verifier-config] 127 - values: [i8] 128 runner-options: [verifier-only, verifier-config] 129 - values: [u8] 130 bugid: ['7431'] 131 - values: [i16] 132 - values: [u16] 133 - values: [i32] 134 - values: [u32] 135 - values: [i64] 136 - values: [u64] 137 - values: [f32] 138 - values: [f64] 139 140 - file-name: "primitive_types_j" 141 isa: 142 instructions: 143 - sig: ldarr.8 v:in:i8[] 144 acc: inout:i32 145 format: [op_v_8] 146 tags: ['tsan', 'verifier', 'pa-verifier'] 147 bugid: ['3052'] 148 description: Check array of primitive types for 'ldarr.8' instruction in PandaAssembly context. 149 header-template: [PandaAssembly] 150 code-template: | 151 .array arr_u1 u1 1 { 1 } 152 .array arr_i8 i8 1 { 1 } 153 .array arr_i16 i16 1 { 1 } 154 .array arr_u16 u16 1 { 1 } 155 .array arr_i32 i32 1 { 1 } 156 .array arr_i64 i64 1 { 1 } 157 .array arr_f32 f32 1 { 1 } 158 .array arr_f64 f64 1 { 1 } 159 .function i32 main() { 160 %s 161 ldai 0 162 ldarr.8 v0 163 check-type: exit-positive 164 runner-options: [verifier-failure, verifier-config, use-pa] 165 template-cases: 166 - values: 167 - | 168 # 169 movi v0, 1 170 newarr v0, v0, %s[] 171 - values: 172 - | 173 # 174 lda.const v0, arr_%s 175 cases: 176 - values: [u1] 177 runner-options: [verifier-only, verifier-config, use-pa] 178 - values: [i8] 179 runner-options: [verifier-only, verifier-config, use-pa] 180 - values: [i16] 181 - values: [u16] 182 - values: [i32] 183 - values: [i64] 184 - values: [f32] 185 - values: [f64] 186 187 - file-name: "read_values" 188 isa: 189 instructions: 190 - sig: ldarr.8 v:in:i8[] 191 acc: inout:i32 192 format: [op_v_8] 193 description: Check ldarr.8 reads correct items from array of primitives. 194 header-template: [xorshift32, main] 195 code-template: | 196 # 197 movi v3, 10000 # iterations 198 movi v2, *s # index 199 movi v0, *s 200 # array size 201 newarr v1, v0, %s # v1 - testable array 202 203 movi v0, 1 # initial random number 204 loop: 205 call.short nextRand, v0 206 sta v0 # v0 - next random number 207 # 208 starr.8 v1, v2 # save random number in v1[v2] 209 lda v2 210 ldarr.8 v1 # get v1[v2] 211 andi 255 # Keep only low 8 bits 212 sta v4 # v4 = v1[v2] 213 214 lda v0 215 andi 255 # acc = v0 & 255 (random number) 216 ucmp v4 # Compare random number and stored value from array 217 jeqz passed 218 ldai 1 219 return 220 passed: 221 inci v3, -1 222 lda v3 223 jnez loop 224 check-type: exit-positive 225 template-cases: 226 - values: ['u1[]'] 227 - values: ['i8[]'] 228 cases: 229 - values: ['0', '1'] 230 - values: ['254', '255'] 231 - values: ['65535', '65536'] 232 - values: ['7', '16'] 233 - values: ['123', '255'] 234 - values: ['49151', '65536'] 235 236 - file-name: "read_all_values" 237 isa: 238 instructions: 239 - sig: ldarr.8 v:in:i8[] 240 acc: inout:i32 241 format: [op_v_8] 242 description: Check ldarr.8 reads correct items from array of primitives. Inspect different indexes and values. 243 code-template: | 244 # 245 movi v1, 0 # v1 - index 246 movi v0, *s 247 # v0 is array size 248 mov v2, v0 # v2 is size too 249 newarr v0, v0, %s # v0 - testable array 250 fill_array: 251 lda v1 252 starr.8 v0, v1 # v0[v1] = v1 253 addi 1 254 sta v1 # v1 = v1 + 1 255 jne v2, fill_array 256 257 movi v1, 0 # index 258 check_array: 259 lda v1 260 ldarr.8 v0 261 andi 255 262 sta v3 263 lda v1 264 andi 255 265 ucmp v3 266 jeqz ok 267 ldai 1 268 return 269 ok: 270 inci v1, 1 271 lda v1 272 jne v2, check_array 273 check-type: exit-positive 274 template-cases: 275 - values: ['u1[]'] 276 - values: ['i8[]'] 277 cases: 278 - values: ['100'] 279 - values: ['255'] 280 tags: ['tsan'] 281 - values: ['65535'] 282 tags: ['tsan'] 283 284 - file-name: "reg_number" 285 isa: 286 instructions: 287 - sig: ldarr.8 v:in:i8[] 288 acc: inout:i32 289 format: [op_v_8] 290 check-type: empty 291 runner-options: [compile-only] 292 description: Check 'ldarr.8' instruction with different registers numbers. 293 header-template: [] 294 code-template: | 295 # 296 .function i32 main() { 297 ldarr.8 %s 298 } 299 cases: 300 - values: [v0] 301 - values: [v16] 302 - values: [v128] 303 - values: [v255] 304 - values: [v256] 305 runner-options: [compile-failure] 306 - values: [v65535] 307 runner-options: [compile-failure] 308 - case-template: | 309 # 310 .function void f1(i32 a0) { 311 ldarr.8 a0 # valid name of register 312 } 313 314 .function i32 main() { 315 movi v0, 0 316 call.short f1, v0 317 } 318 - case-template: | 319 # 320 .function void f1(i32 a0) { 321 ldarr.8 a1 # invalid name of register 322 } 323 324 .function i32 main() { 325 movi v0, 0 326 call.short f1, v0 327 } 328 runner-options: [compile-failure] 329 - values: [a0] 330 runner-options: [compile-failure] 331 - values: [a255] 332 runner-options: [compile-failure] 333 - values: ['null'] 334 runner-options: [compile-failure] 335 - values: [0] 336 runner-options: [compile-failure] 337 - values: [1.1] 338 runner-options: [compile-failure] 339 - values: ['2.2'] 340 runner-options: [compile-failure] 341 342 - file-name: "arr_type" 343 isa: 344 instructions: 345 - sig: ldarr.8 v:in:i8[] 346 acc: inout:i32 347 format: [op_v_8] 348 verification: 349 - v1_array_type 350 tags: ['verifier'] 351 bugid: ['2816'] 352 runner-options: ['verifier-failure', 'verifier-config'] 353 header-template: [] 354 code-template: | 355 # 356 .record A {} 357 .record panda.String <external> 358 .record panda.Object <external> 359 .function i32 main() { 360 %s 361 ldai 0 362 ldarr.8 v0 363 check-type: exit-positive 364 description: Check 'ldarr.8' with incorrect array type. See also "rejectable_primitive_types" tests. 365 cases: 366 - values: 367 - movi v0, 0 368 - values: 369 - movi.64 v0, 0 370 - values: 371 - fmovi v0, 0 372 - values: 373 - fmovi.64 v0, 0 374 - values: 375 - | 376 # 377 lda.type A 378 sta.obj v0 379 - values: 380 - | 381 # 382 lda.type A[] 383 sta.obj v0 384 - values: 385 - | 386 # 387 lda.type panda.String 388 sta.obj v0 389 - values: 390 - | 391 # 392 lda.type panda.String[] 393 sta.obj v0 394 - values: 395 - | 396 # 397 lda.type panda.Object 398 sta.obj v0 399 - values: 400 - | 401 # 402 lda.type panda.Object[] 403 sta.obj v0 404 - values: 405 - | 406 # 407 lda.str "string" 408 sta.obj v0 409 - values: 410 - | 411 # 412 movi v0, 1 413 newarr v0, v0, panda.Object[] 414 - values: 415 - | 416 # 417 movi v0, 1 418 newarr v0, v0, panda.String[] 419 420 - file-name: "acc_type" 421 isa: 422 instructions: 423 - sig: ldarr.8 v:in:i8[] 424 acc: inout:i32 425 format: [op_v_8] 426 verification: 427 - acc_i32 428 tags: ['verifier'] 429 bugid: ['2817'] 430 runner-options: ['verifier-failure', 'verifier-config'] 431 header-template: [] 432 code-template: | 433 # 434 .record A {} 435 .record panda.String <external> 436 .record panda.Object <external> 437 .function i32 main() { 438 movi v0, 1 439 newarr v0, v0, i8[] 440 %s 441 ldarr.8 v0 442 check-type: exit-positive 443 description: Check 'ldarr.8' with incorrect index type. 444 cases: 445 - values: 446 - ldai.64 0 447 - values: 448 - fldai 0 449 - values: 450 - fldai.64 0 451 - values: 452 - lda.null 453 - values: 454 - | 455 # 456 lda.type A 457 - values: 458 - | 459 # 460 lda.type A[] 461 - values: 462 - | 463 # 464 lda.type panda.String 465 - values: 466 - | 467 # 468 lda.type panda.String[] 469 - values: 470 - | 471 # 472 lda.type panda.Object 473 - values: 474 - | 475 # 476 lda.type panda.Object[] 477 - values: 478 - | 479 # 480 lda.str "string" 481 - values: 482 - | 483 # 484 movi v1, 1 485 newarr v1, v1, panda.Object[] 486 lda.obj v1 487 - values: 488 - | 489 # 490 movi v1, 1 491 newarr v1, v1, panda.String[] 492 lda.obj v1 493 494 - file-name: "arr_acc_type" 495 isa: 496 instructions: 497 - sig: ldarr.8 v:in:i8[] 498 acc: inout:i32 499 format: [op_v_8] 500 verification: 501 - v1_array_type 502 tags: ['verifier'] 503 bugid: ['2816', '2817'] 504 runner-options: ['verifier-failure', 'verifier-config'] 505 header-template: [] 506 code-template: | 507 # 508 .record A {} 509 .record panda.String <external> 510 .record panda.Object <external> 511 .function i32 main() { 512 %s 513 *s 514 ldarr.8 v0 515 check-type: exit-positive 516 description: Check 'ldarr.8' with incorrect register and accumulator types. 517 template-cases: 518 - values: 519 - movi v0, 0 520 - values: 521 - movi.64 v0, 0 522 - values: 523 - fmovi v0, 0 524 - values: 525 - fmovi.64 v0, 0 526 - values: 527 - | 528 # 529 lda.type A 530 sta.obj v0 531 - values: 532 - | 533 # 534 lda.type A[] 535 sta.obj v0 536 - values: 537 - | 538 # 539 lda.type panda.String 540 sta.obj v0 541 - values: 542 - | 543 # 544 lda.type panda.String[] 545 sta.obj v0 546 - values: 547 - | 548 # 549 lda.type panda.Object 550 sta.obj v0 551 - values: 552 - | 553 # 554 lda.type panda.Object[] 555 sta.obj v0 556 - values: 557 - | 558 # 559 lda.str "string" 560 sta.obj v0 561 - values: 562 - | 563 # 564 movi v0, 1 565 newarr v0, v0, panda.Object[] 566 - values: 567 - | 568 # 569 movi v0, 1 570 newarr v0, v0, panda.String[] 571 cases: 572 - values: 573 - ldai 0 574 - values: 575 - ldai.64 0 576 - values: 577 - fldai 0 578 - values: 579 - fldai.64 0 580 - values: 581 - lda.null 582 - values: 583 - | 584 # 585 lda.type A 586 - values: 587 - | 588 # 589 lda.type A[] 590 - values: 591 - | 592 # 593 lda.type panda.String 594 - values: 595 - | 596 # 597 lda.type panda.String[] 598 - values: 599 - | 600 # 601 lda.type panda.Object 602 - values: 603 - | 604 # 605 lda.type panda.Object[] 606 - values: 607 - | 608 # 609 lda.str "string" 610 - values: 611 - | 612 # 613 movi v1, 1 614 newarr v1, v1, panda.Object[] 615 lda.obj v1 616 - values: 617 - | 618 # 619 movi v1, 1 620 newarr v1, v1, panda.String[] 621 lda.obj v1 622 623 - file-name: uninitialized_acc_regs 624 isa: 625 instructions: 626 - sig: ldarr.8 v:in:i8[] 627 acc: inout:i32 628 format: [op_v_8] 629 description: Check 'ldarr.8' with uninitialized register and accumulator. 630 tags: ['verifier'] 631 bugid: ['2818'] 632 runner-options: ['verifier-failure', 'verifier-config'] 633 code-template: | 634 # 635 %s 636 ldarr.8 v0 637 check-type: exit-positive 638 cases: 639 - values: ['ldai 0'] 640 - values: 641 - | 642 # 643 movi v0, 1 644 newarr v0, v0, i8[] 645 - values: [''] 646 647 - file-name: array_out_of_bound_exception_p 648 isa: 649 instructions: 650 - sig: ldarr.8 v:in:i8[] 651 acc: inout:i32 652 format: [op_v_8] 653 exceptions: 654 - x_bounds 655 description: Check 'ldarr.8' behavior when index is out of array bounds. 656 tags: ['irtoc_ignore'] 657 header-template: [aoobe_p, main] 658 code-template: | 659 # 660 movi v0, *s 661 newarr v0, v0, %s 662 ldai *s 663 begin: 664 ldarr.8 v0 665 end: 666 ldai 1 # Should not reach this line 667 return 668 669 catch_AOOBE: 670 ldai 0 # Expected panda.ArrayIndexOutOfBoundsException 671 return 672 673 catch_all: 674 ldai 2 # Unexpected exception, test failed 675 return 676 677 .catch panda.ArrayIndexOutOfBoundsException, begin, end, catch_AOOBE 678 .catchall begin, end, catch_all 679 check-type: none 680 template-cases: 681 - values: ['u1[]'] 682 - values: ['i8[]'] 683 cases: 684 - values: [0, 0] 685 tags: ['tsan'] 686 - values: [0, 1] 687 - values: [10, 10] 688 - values: [10, 128] 689 - values: [255, 255] 690 - values: [254, 255] 691 - values: [65535, 65535] 692 tags: ['tsan'] 693 - values: [65535, 65536] 694 - values: [10, 0xFFFFFFFF] 695 - values: [256, 0xFFFFFFFE] 696 - values: [65536, 0xFFFFFFFD] 697 tags: ['tsan'] 698 - values: [0x100000, 0xFFFFFFFC] 699 - values: [10, 0x80000000] 700 - values: [256, 0x80000001] 701 - values: [65536, 0x80000002] 702 tags: ['tsan'] 703 - values: [0x100000, 0x80000003] 704 705 - file-name: array_out_of_bound_exception_j 706 isa: 707 instructions: 708 - sig: ldarr.8 v:in:i8[] 709 acc: inout:i32 710 format: [op_v_8] 711 exceptions: 712 - x_bounds 713 description: Check 'ldarr.8' behavior when index is out of array bounds. 714 tags: ['irtoc_ignore'] 715 runner-options: [use-pa] 716 header-template: [PandaAssembly, aoobe_j, main] 717 code-template: | 718 # 719 movi v0, *s 720 newarr v0, v0, %s 721 ldai *s 722 begin: 723 ldarr.8 v0 724 end: 725 ldai 1 # Should not reach this line 726 return 727 728 catch_AOOBE: 729 ldai 0 # Expected panda.ArrayIndexOutOfBoundsException 730 return 731 732 catch_all: 733 ldai 2 # Unexpected exception, test failed 734 return 735 736 .catch panda.ArrayIndexOutOfBoundsException, begin, end, catch_AOOBE 737 .catchall begin, end, catch_all 738 check-type: none 739 template-cases: 740 - values: ['u1[]'] 741 - values: ['i8[]'] 742 cases: 743 - values: [0, 0] 744 tags: ['tsan'] 745 - values: [0, 1] 746 - values: [10, 10] 747 - values: [10, 128] 748 - values: [255, 255] 749 - values: [254, 255] 750 - values: [65535, 65535] 751 tags: ['tsan'] 752 - values: [65535, 65536] 753 - values: [10, 0xFFFFFFFF] 754 - values: [256, 0xFFFFFFFE] 755 - values: [65536, 0xFFFFFFFD] 756 tags: ['tsan'] 757 - values: [0x100000, 0xFFFFFFFC] 758 - values: [10, 0x80000000] 759 - values: [256, 0x80000001] 760 - values: [65536, 0x80000002] 761 tags: ['tsan'] 762 - values: [0x100000, 0x80000003] 763 764 - file-name: null_pointer_p 765 isa: 766 instructions: 767 - sig: ldarr.8 v:in:i8[] 768 acc: inout:i32 769 format: [op_v_8] 770 exceptions: 771 - x_null 772 description: Check 'ldarr.8' behavior when array is null reference. 773 tags: ['irtoc_ignore'] 774 header-template: [npe_p] 775 code-template: | 776 .function %s get_null() { 777 lda.null 778 return.obj 779 } 780 781 .function i32 main() { 782 call.short get_null 783 sta.obj v0 784 ldai *s 785 begin: 786 ldarr.8 v0 787 end: 788 ldai 1 # Should not reach this line 789 return 790 791 catch_NPE: 792 ldai 0 # Expected panda.NullPointerException 793 return 794 795 catch_all: 796 ldai 2 # Unexpected exception, test failed 797 return 798 799 .catch panda.NullPointerException, begin, end, catch_NPE 800 .catchall begin, end, catch_all 801 check-type: none 802 template-cases: 803 - values: ['u1[]'] 804 - values: ['i8[]'] 805 cases: 806 - values: [0] 807 tags: ['tsan'] 808 - values: [1] 809 - values: [10] 810 - values: [128] 811 - values: [255] 812 - values: [65535] 813 tags: ['tsan'] 814 - values: [0x7FFFFFFF] 815 - values: [0xFFFFFFFF] 816 - values: [0x80000000] 817 818 - file-name: null_pointer_j 819 isa: 820 instructions: 821 - sig: ldarr.8 v:in:i8[] 822 acc: inout:i32 823 format: [op_v_8] 824 exceptions: 825 - x_null 826 description: Check 'ldarr.8' behavior when array is null reference. 827 tags: ['irtoc_ignore'] 828 header-template: [PandaAssembly, npe_j] 829 runner-options: [use-pa] 830 bugid: ['3047'] 831 code-template: | 832 .function %s get_null() { 833 lda.null 834 return.obj 835 } 836 837 .function i32 main() { 838 call.short get_null 839 sta.obj v0 840 ldai *s 841 begin: 842 ldarr.8 v0 843 end: 844 ldai 1 # Should not reach this line 845 return 846 847 catch_NPE: 848 ldai 0 # Expected panda.NullPointerException 849 return 850 851 catch_all: 852 ldai 2 # Unexpected exception, test failed 853 return 854 855 .catch panda.NullPointerException, begin, end, catch_NPE 856 .catchall begin, end, catch_all 857 check-type: none 858 template-cases: 859 - values: ['u1[]'] 860 - values: ['i8[]'] 861 cases: 862 - values: [0] 863 tags: ['tsan'] 864 - values: [1] 865 - values: [10] 866 - values: [128] 867 - values: [255] 868 - values: [65535] 869 tags: ['tsan'] 870 - values: [0x7FFFFFFF] 871 - values: [0xFFFFFFFF] 872 - values: [0x80000000] 873