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