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