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