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