• 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: pandasm_header
16    template: |
17      .language PandaAssembly
18
19      .record panda.Class <external>
20      .record panda.Object <external>
21      .record panda.String <external>
22      .record panda.ClassCastException <external>
23      .record R {}
24  - name: java
25    template: |
26      .language Java
27  - name: java_header
28    template: |
29      .language Java
30
31      .record java.lang.Class <external>
32      .record java.lang.Object <external>
33      .record java.lang.String <external>
34      .record java.io.Serializable <external>
35      .record java.lang.NullPointerException <external>
36
37      .record R <> {}
38      .record I <java.interface> {}
39      .record Q <java.extends=R, java.implements=I> {}
40      .record A <java.annotation, java.annotation.type=runtime> {}
41      .record J <java.interface, java.implements=I> {}
42
43  - name: NegativeArraySize_p
44    template: |
45      .record panda.NegativeArraySizeException <external>
46  - name: NegativeArraySize_j
47    template: |
48      .language Java
49      .record java.lang.NegativeArraySizeException <external>
50
51  - name: oome_p
52    template: |
53      .record panda.OutOfMemoryError <external>
54  - name: oome_j
55    template: |
56      .record java.lang.OutOfMemoryError <external>
57
58tests:
59  - file-name: 'newarr'
60    isa:
61      title: Create new array
62      description: >
63        Create a new single-dimensional array of given type and size and put a reference to it into register.
64        Elements of array are initialized to a default value, i.e. 0 for primitive types and null for objects.
65      verification:
66        - type_id_array
67        - v2_i32
68
69    commands:
70      - file-name: 'of_prim'
71        isa:
72          instructions:
73            - sig: newarr v1:out:ref, v2:in:i32, type_id
74              acc: none
75              format: [op_v1_4_v2_4_id_16]
76          description: >
77            Create a new single-dimensional array of given type and size and put a reference to it into register.
78        bugid: ['1805', '2678']
79        header-template: ['main']
80        code-template: |
81            #
82                movi v0, *s
83                mov v1, v0
84                newarr v0, v0, %s
85            # Check array length
86                lenarr v0
87                jeq v1, length_is_correct
88                ldai 1
89                return
90            length_is_correct:
91                ##- Check array type
92                lda.obj v0
93                isinstance %s
94                jnez type_is_correct
95                ldai 2
96                return
97            type_is_correct:
98
99        description: Check `newarr` creates array of specified size and primitive type.
100        check-type: exit-positive
101        tags: ['tsan']
102        template-cases:
103          - values: ['u1[]', 'u1[]']
104          - values: ['i8[]', 'i8[]']
105          - values: ['u8[]', 'u8[]']
106          - values: ['i16[]', 'i16[]']
107          - values: ['u16[]', 'u16[]']
108          - values: ['i32[]', 'i32[]']
109          - values: ['u32[]', 'u32[]']
110          - values: ['i64[]', 'i64[]']
111          - values: ['u64[]', 'u64[]']
112          - values: ['f32[]', 'f32[]']
113          - values: ['f64[]', 'f64[]']
114        cases:
115          - values: [0]
116          - values: [1]
117          - values: [16]
118          - values: [0x8000]
119          - values: [0x100000]
120
121      - file-name: "acceptable_primitive_types_p"
122        isa:
123          instructions:
124            - sig: newarr v1:out:ref, v2:in:i32, type_id
125              acc: none
126              format: [op_v1_4_v2_4_id_16]
127        tags: ['tsan', 'verifier']
128        description: Check acceptable array of primitive types for newarr instruction in Panda Assembly context.
129        code-template: |
130          #
131              movi v0, 1
132              newarr v0, v0, %s
133        check-type: exit-positive
134        runner-options: ['verifier-only', 'verifier-debug-config']
135        cases:
136          - values: ['u1[]']
137          - values: ['i8[]']
138          - values: ['u8[]']
139          - values: ['i16[]']
140          - values: ['u16[]']
141          - values: ['i32[]']
142          - values: ['u32[]']
143          - values: ['i64[]']
144          - values: ['u64[]']
145          - values: ['f32[]']
146          - values: ['f64[]']
147
148      - file-name: "acceptable_ref_primitive_types_p"
149        isa:
150          instructions:
151            - sig: newarr v1:out:ref, v2:in:i32, type_id
152              acc: none
153              format: [op_v1_4_v2_4_id_16]
154        tags: ['tsan', 'verifier']
155        description: Check acceptable array of references to primitive types for newarr instruction in Panda Assembly context.
156        code-template: |
157          #
158              movi v0, 1
159              newarr v0, v0, %s
160        check-type: exit-positive
161        runner-options: ['verifier-only', 'verifier-debug-config']
162        cases:
163          - values: ['u1[][]']
164          - values: ['i8[][][]']
165          - values: ['u8[][][][]']
166          - values: ['i16[][][][][]']
167          - values: ['u16[][][][][][]']
168          - values: ['i32[][][][][][][]']
169          - values: ['u32[][][][][][][][]']
170          - values: ['i64[][][][][][][][][]']
171          - values: ['u64[][][][][][][][][][]']
172          - values: ['f32[][][][][][][][][][][]']
173          - values: ['f64[][][][][][][][][][][][]']
174
175      - file-name: 'of_obj_p'
176        isa:
177          instructions:
178            - sig: newarr v1:out:ref, v2:in:i32, type_id
179              acc: none
180              format: [op_v1_4_v2_4_id_16]
181          description: >
182            Create a new single-dimensional array of given type and size and put a reference to it into register.
183        bugid: ['1805', '2678']
184        header-template: ['pandasm_header', 'main']
185        code-template: |
186            #
187                movi v0, *s
188                mov v1, v0
189                newarr v0, v0, %s
190            # Check array length
191                lenarr v0
192                jeq v1, length_is_correct
193                ldai 1
194                return
195            length_is_correct:
196                ##- Check array type
197                lda.obj v0
198                isinstance %s
199                jnez type_is_correct
200                ldai 2
201                return
202            type_is_correct:
203
204        description: Check `newarr` creates array of specified size and object type in Panda Assembly context.
205        check-type: exit-positive
206        tags: ['tsan']
207        template-cases:
208          - values: ['panda.Class[]', 'panda.Class[]']
209          - values: ['panda.Object[]', 'panda.Object[]']
210          - values: ['panda.String[]', 'panda.String[]']
211          - values: ['panda.ClassCastException[]', 'panda.ClassCastException[]']
212          - values: ['R[]', 'R[]']
213          - values: ['panda.Class[][]', 'panda.Class[][]']
214          - values: ['panda.Object[][][]', 'panda.Object[][][]']
215          - values: ['panda.String[][][][]', 'panda.String[][][][]']
216          - values: ['panda.ClassCastException[][][][][]', 'panda.ClassCastException[][][][][]']
217          - values: ['R[][][][][][]', 'R[][][][][][]']
218          - values: ['u1[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]', 'u1[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]']
219          - values: ['u16[][][][]', 'u16[][][][]']
220          - values: ['i32[][][]', 'i32[][][]']
221          - values: ['f32[][][][][][][][][][][][][][][][]', 'f32[][][][][][][][][][][][][][][][]']
222          - values: ['f64[][][][]', 'f64[][][][]']
223
224        cases:
225          - values: [0]
226          - values: [1]
227          - values: [0x10000]
228          - values: [0x100000]
229
230      - file-name: 'type_v2'
231        isa:
232          instructions:
233            - sig: newarr v1:out:ref, v2:in:i32, type_id
234              acc: none
235              format: [op_v1_4_v2_4_id_16]
236          verification:
237            - v2_i32
238        tags: ['verifier']
239        runner-options: ['verifier-failure', 'verifier-debug-config']
240        header-template: []
241        code-template: |
242          #
243          .record B {}
244          .record panda.String <external>
245          .record panda.Object <external>
246          .function i32 main() {
247              %s
248              newarr v0, v0, *s
249        check-type: no-check
250        description: Check 'newarr' with incorrect register type.
251        template-cases:
252          - values:
253              - movi.64 v0, 0
254          - values:
255              - fmovi.64 v0, 0
256          - values:
257              - |
258                #
259                    lda.type B
260                    sta.obj v0
261          - values:
262              - |
263                #
264                    lda.type B[]
265                    sta.obj v0
266          - values:
267              - |
268                #
269                    lda.type panda.String
270                    sta.obj v0
271          - values:
272              - |
273                #
274                    lda.str "string"
275                    sta.obj v0
276          - values:
277              - |
278                #
279                    lda.type panda.Object
280                    sta.obj v0
281          - values:
282              - |
283                #
284                    movi v0, 10
285                    newarr v0, v0, i32[]
286          - values:
287              - mov.null v0
288        cases:
289          - values: ['i32[]']
290          - values: ['f64[][]']
291          - values: ['panda.String[][][]']
292          - values: ['panda.Object[][][][]']
293
294      - file-name: 'type_id_array'
295        isa:
296          instructions:
297            - sig: newarr v1:out:ref, v2:in:i32, type_id
298              acc: none
299              format: [op_v1_4_v2_4_id_16]
300          verification:
301            - type_id_array
302        runner-options: [compile-failure]
303        header-template: []
304        code-template: |
305          #
306          .record B {
307            field: i32
308          }
309          .record panda.String <external>
310          .record panda.Object <external>
311          .function i32 main() {
312              movi v0, 1
313              newarr v0, v0, %s
314        check-type: no-check
315        description: Check 'newarr' with incorrect array type.
316        cases:
317          - values: ['u1']
318          - values: ['i8']
319          - values: ['u8']
320          - values: ['i16']
321          - values: ['u16']
322          - values: ['i32']
323          - values: ['u32']
324          - values: ['i64']
325          - values: ['u64']
326          - values: ['f32']
327          - values: ['f64']
328          - values: ['panda.Object']
329          - values: ['panda.String']
330          - values: ['void']
331          - values: ['null']
332          - values: ['"string"']
333          - values: ['unknown_type[]']
334          - values: ['B.field']
335          - values: ['B.field[]']
336          - values: ['main']
337          - values: ['main[]']
338
339      - file-name: 'with_invalid_reg_v1'
340        isa:
341          instructions:
342            - sig: newarr v1:out:ref, v2:in:i32, type_id
343              acc: none
344              format: [op_v1_4_v2_4_id_16]
345        description: Check newarr with different register numbers, uninitialized registers, incorrect registers.
346        runner-options: ['compile-failure']
347        header-template: []
348        code-template: |
349            #
350            .function i32 main() {
351                movi v0, 1
352                newarr %s, v0, i32[]
353        check-type: exit-positive
354        cases:
355          - values: ['v16']
356          - values: ['v128']
357          - values: ['v255']
358          - values: ['v256']
359          - values: ['v65535']
360          - values: ['"a"']
361          - values: ['a0']
362          - values: ['void']
363          - values: ['null']
364          - values: ['vv0']
365
366      - file-name: 'with_invalid_reg_v2'
367        isa:
368          instructions:
369            - sig: newarr v1:out:ref, v2:in:i32, type_id
370              acc: none
371              format: [op_v1_4_v2_4_id_16]
372        description: Check newarr with different register numbers, uninitialized registers, incorrect registers.
373        tags: ['verifier']
374        runner-options: ['verifier-failure', 'verifier-debug-config']
375        header-template: []
376        code-template: |
377            #
378            .function i32 main() {
379                newarr v0, %s, i32[]
380        check-type: exit-positive
381        cases:
382          - values: ['v0']
383          - values: ['v15']
384          - values: ['v16']
385            runner-options: [compile-failure]
386          - values: ['v128']
387            runner-options: [compile-failure]
388          - values: ['v255']
389            runner-options: [compile-failure]
390          - values: ['v256']
391            runner-options: [compile-failure]
392          - values: ['v65535']
393            runner-options: [compile-failure]
394          - values: ['"a"']
395            runner-options: [compile-failure]
396          - values: ['a0']
397            runner-options: [compile-failure]
398          - values: ['void']
399            runner-options: [compile-failure]
400          - values: ['null']
401            runner-options: [compile-failure]
402
403      - file-name: 'negative_size_p'
404        isa:
405          exceptions:
406            - x_negsize
407        description: Check newarr with negative array size.
408        header-template: [NegativeArraySize_p]
409        code-template: |
410          *s
411          .function i32 main() {
412          #
413              movi v0, %s
414          begin:
415              newarr v0, v0, *s
416          end:
417              ldai 1 # Should not reach this line
418              return
419
420          catch_NAS:
421              ldai 0 # Expected panda.NegativeArraySizeException
422              return
423
424          catch_all:
425              ldai 2 # Unexpected exception, test failed
426              return
427
428          .catch panda.NegativeArraySizeException, begin, end, catch_NAS
429          .catchall begin, end, catch_all
430        check-type: none
431        template-cases:
432          - values: [-1]
433          - values: [-10]
434          - values: [-10000]
435          - values: [0x80000000]
436        cases:
437          - values: ['##-', 'i32[]']
438          - values: ['##-', 'i8[]']
439          - values: ['.record panda.Object<external>', 'panda.Object[]']
440
441      - file-name: 'prim_is_0_p'
442        isa:
443          instructions:
444            - sig: newarr v1:out:ref, v2:in:i32, type_id
445              acc: none
446              format: [op_v1_4_v2_4_id_16]
447          description: >
448            Elements of array are initialized to a default value, i.e. 0 for primitive types and null for objects.
449        header-template: ['main']
450        code-template: |
451            #
452                movi v0, 256
453                mov v1, v0
454                newarr v0, v0, %s
455                movi v2, 0 # index
456            loop:
457                lda v2
458                %s
459                jeqz next_item
460                ldai 1
461                return
462            next_item:
463                inci v2, 1
464                lda v2
465                jne v1, loop
466        description: Check `newarr` creates array of primitives which is filled by 0 in Panda context.
467        check-type: exit-positive
468        tags: ['tsan']
469        cases:
470          - values:
471            - 'u1[]'
472            - |
473              #
474                  ldarru.8 v0
475            bugid: ['2702']
476          - values:
477            - 'i8[]'
478            - |
479              #
480                  ldarr.8 v0
481          - values:
482            - 'u8[]'
483            - |
484              #
485                  ldarru.8 v0
486            bugid: ['2702']
487          - values:
488            - 'i16[]'
489            - |
490              #
491                  ldarr.16 v0
492          - values:
493            - 'u16[]'
494            - |
495              #
496                  ldarru.16 v0
497            bugid: ['2702']
498          - values:
499            - 'i32[]'
500            - |
501              #
502                  ldarr v0
503          - values:
504            - 'u32[]'
505            - |
506              #
507                  ldarr v0
508            bugid: ['2702']
509          - values:
510            - 'i64[]'
511            - |
512              #
513                  ldarr.64 v0
514                  movi.64 v3, 0
515                  cmp.64 v3
516          - values:
517            - 'u64[]'
518            - |
519              #
520                  ldarr.64 v0
521                  movi.64 v3, 0
522                  ucmp.64 v3
523          - values:
524            - 'f32[]'
525            - |
526              #
527                  fldarr.32 v0
528                  fmovi v3, 0
529                  fcmpg v3
530          - values:
531            - 'f64[]'
532            - |
533              #
534                  fldarr.64 v0
535                  fmovi.64 v3, 0
536                  fcmpg.64 v3
537
538      - file-name: 'obj_is_null_p'
539        isa:
540          instructions:
541            - sig: newarr v1:out:ref, v2:in:i32, type_id
542              acc: none
543              format: [op_v1_4_v2_4_id_16]
544          description: >
545            Elements of array are initialized to a default value, i.e. 0 for primitive types and null for objects.
546        header-template: ['pandasm_header', 'main']
547        code-template: |
548            #
549                movi v0, 256
550                mov v1, v0
551                newarr v0, v0, %s
552                movi v2, 0 # index
553            loop:
554                lda v2
555                ldarr.obj v0
556                jeqz.obj next_item
557                ldai 1
558                return
559            next_item:
560                inci v2, 1
561                lda v2
562                jne v1, loop
563        description: Check `newarr` creates array of objects which is filled by null.
564        check-type: exit-positive
565        tags: ['tsan']
566        cases:
567          - values:
568            - 'u1[][]'
569          - values:
570            - 'i8[][][]'
571            tags: ['tsan']
572          - values:
573            - 'u8[][][][]'
574          - values:
575            - 'i16[][][][]'
576          - values:
577            - 'u16[][][][][]'
578          - values:
579            - 'i32[][][][][][]'
580            tags: ['tsan']
581          - values:
582            - 'u32[][][][][][][]'
583          - values:
584            - 'f32[][][][][][][][]'
585          - values:
586            - 'f64[][][][][][][][][]'
587          - values:
588            - 'panda.Class[]'
589            tags: ['tsan']
590          - values:
591            - 'panda.Object[]'
592          - values:
593            - 'panda.String[]'
594          - values:
595            - 'panda.ClassCastException[]'
596          - values:
597            - 'R[]'
598            tags: ['tsan']
599
600      - file-name: 'oome_p'
601        isa:
602          exceptions:
603            - x_oom
604        header-template: ['pandasm_header', 'oome_p', 'main']
605        code-template: |
606          #
607              movi v0, 0x7FFFFFFF
608          begin:
609              newarr v0, v0, %s
610          end:
611              ldai 1 # Should not reach this line
612              return
613          catch_OOME:
614              ldai 0 # Expected panda.OutOfMemoryError
615              return
616
617          catch_all:
618              ldai 2 # Unexpected exception, test failed
619              return
620
621          .catch panda.OutOfMemoryError, begin, end, catch_OOME
622          .catchall begin, end, catch_all
623        check-type: none
624
625        description: |
626          Check `newarr` throws OutOfMemoryError in Panda Assembly context.
627          Test assumes that available memory for panda is default limited value.
628
629        cases:
630          - values: ['u1[]']
631          - values: ['i8[]']
632          - values: ['u8[]']
633          - values: ['i16[]']
634            tags: ['tsan']
635          - values: ['u16[]']
636          - values: ['i32[]']
637          - values: ['u32[][]']
638          - values: ['i64[][][]']
639            tags: ['tsan']
640          - values: ['u64[][][][]']
641          - values: ['f32[][][][][]']
642          - values: ['f64[][][][][][]']
643          - values: ['panda.Object[]']
644            tags: ['tsan']
645          - values: ['panda.Class[][]']
646          - values: ['panda.String[][][]']
647          - values: ['panda.ClassCastException[][][][]']
648            tags: ['tsan']
649          - values: ['R[][][][][]']
650
651