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