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