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