• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 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.Object <external>
20
21      .record R {
22        u1             fu1       <static>
23        u8             fu8       <static>
24        i8             fi8       <static>
25        u16            fu16      <static>
26        i16            fi16      <static>
27        u32            fu32      <static>
28        i32            fi32      <static>
29        u64            fu64      <static>
30        i64            fi64      <static>
31        f32            ff32      <static>
32        f64            ff64      <static>
33        # objects:
34        i32[]          fi32Array <static>
35        panda.Object   fObj      <static>
36        panda.Object[] fObjArray <static>
37      }
38  - name: PandaAssembly_header
39    template: |
40      .language PandaAssembly
41
42      .record panda.Object <external>
43
44      .record R {
45        u1             fu1       <static>
46        i8             fi8       <static>
47        u16            fu16      <static>
48        i16            fi16      <static>
49        i32            fi32      <static>
50        i64            fi64      <static>
51        f32            ff32      <static>
52        f64            ff64      <static>
53        # objects:
54        i32[]          fi32Array <static>
55        panda.Object   fObj      <static>
56        panda.Object[] fObjArray <static>
57      }
58
59tests:
60  - file-name: "ldstatic"
61    isa:
62      title: Get static field
63      description: >
64        Get static field value by field_id and put it into accumulator.
65      instructions:
66        - sig: ldstatic field_id
67          acc: out:i32
68          format: [op_id_16]
69    commands:
70
71      - file-name: "with_non_static_field_id"
72        description: Check that verifier reports an error if the field doesn't resolve to a static valid field
73        isa:
74          verification:
75            - field_id_static
76        header-template: []
77        check-type: exit-positive
78        code-template: |
79          .record W {
80            u1    fu1
81            i8    fi8
82            u16   fu16
83            i16   fi16
84            i32   fi32
85            i64   fi64
86            f32   ff32
87            f64   ff64
88            W     fW
89            i32[] fi32Array
90            W[]   fWArray
91          }
92          .function void W.object_function(W a0) {
93            return.void
94          }
95          .function void static_function() {
96            return.void
97          }
98
99          .function i32 main() {
100              ldstatic %s
101        cases:
102          - values:
103            - W.fu1
104            tags: [verifier]
105            runner-options: ['verifier-failure', 'verifier-config']
106            bugid: ['1324', '1828']
107          - values:
108            - W.fi8
109            tags: [verifier]
110            runner-options: ['verifier-failure', 'verifier-config']
111            bugid: ['1324', '1828']
112          - values:
113            - W.fu16
114            tags: [verifier]
115            runner-options: ['verifier-failure', 'verifier-config']
116            bugid: ['1324', '1828']
117          - values:
118            - W.fi16
119            tags: [verifier]
120            runner-options: ['verifier-failure', 'verifier-config']
121            bugid: ['1324', '1828']
122          - values:
123            - W.fi32
124            tags: [verifier]
125            runner-options: ['verifier-failure', 'verifier-config']
126            bugid: ['1324', '1828']
127          - values:
128            - W.fi64
129            tags: [verifier]
130            runner-options: ['verifier-failure', 'verifier-config']
131            bugid: ['1324', '1828']
132          - values:
133            - W.ff32
134            tags: [verifier]
135            runner-options: ['verifier-failure', 'verifier-config']
136            bugid: ['1324', '1828']
137          - values:
138            - W.ff64
139            tags: [verifier]
140            runner-options: ['verifier-failure', 'verifier-config']
141            bugid: ['1324', '1828']
142          - values:
143            - W.fW
144            tags: [verifier]
145            runner-options: ['verifier-failure', 'verifier-config']
146            bugid: ['1324', '1828']
147          - values:
148            - W.fi32Array
149            tags: [verifier]
150            runner-options: ['verifier-failure', 'verifier-config']
151            bugid: ['1324', '1828']
152          - values:
153            - W.fWArray
154            tags: [verifier]
155            runner-options: ['verifier-failure', 'verifier-config']
156            bugid: ['1324', '1828']
157          - values:
158            - W
159            runner-options: [compile-failure]
160          - values:
161            - W.object_function
162            runner-options: [compile-failure]
163          - values:
164            - static_function
165            runner-options: [compile-failure]
166          - values:
167            - unknown_function
168            runner-options: [compile-failure]
169          - values:
170            - 0
171            runner-options: [compile-failure]
172          - values:
173            - -1.1
174            runner-options: [compile-failure]
175          - values:
176            - "null"
177            runner-options: [compile-failure]
178          - values:
179            - "\"abc\""
180            runner-options: [compile-failure]
181
182
183      - file-name: "with_wrong_field_size_p"
184        description: Check that verifier reports an error when the field resolves to a field with size that is not corresponding to bytecode in PandaAssembly context.
185        isa:
186          verification:
187            - field_id_size
188        header-template: [pandasm_header]
189        check-type: exit-positive
190        tags: [verifier]
191        runner-options: ['verifier-failure', 'verifier-config']
192        bugid: ['1834', '2088']
193        code-template: |
194
195          .function i32 main() {
196            ldstatic %s
197        cases:
198          - values:
199            - R.fi64
200          - values:
201            - R.fu64
202          - values:
203            - R.ff64
204          - values:
205            - R.fObj
206          - values:
207            - R.fObjArray
208          - values:
209            - R.fi32Array
210
211
212      - file-name: "with_wrong_field_size_j"
213        description: Check that verifier reports an error when the field resolves to a field with size that is not corresponding to bytecode in PandaAssembly context.
214        isa:
215          verification:
216            - field_id_size
217        header-template: [PandaAssembly_header]
218        check-type: exit-positive
219        tags: [verifier, pa-verifier]
220        runner-options: [verifier-failure, use-pa, verifier-config]
221        bugid: ["5271"]
222        code-template: |
223
224          .function i32 main() {
225            ldstatic %s
226        cases:
227          - values:
228            - R.fi64
229          - values:
230            - R.ff64
231          - values:
232            - R.fObj
233          - values:
234            - R.fObjArray
235          - values:
236            - R.fi32Array
237
238
239      - file-name: "from_all_field_types_p"
240        description: Check that field value is loaded into accumulator in PandaAssembly context. More tests on ldstatic can be found in ststatic tests.
241        isa:
242          description: >
243            For non-object variant, the size of the field is determined by the field_id,
244            most significant bits are sign or unsigned extended based on the field type to fit accumulator size.
245            If field size is less then 32, result will be sign or unsigned extended to i32 depedning on field type.
246        header-template: [pandasm_header]
247        check-type: exit-positive
248        tags: ['tsan', 'irtoc_ignore']
249        code-template: |
250
251          .function i32 main() {
252            ldai %s
253            ststatic R.f%s
254            lda.null
255            movi v15, %s
256            ldstatic R.f%s
257            %s v15
258            jeqz success
259            ldai 1
260            return
261          success:
262        cases:
263          # u1
264          - values: [0, 'u1', 0, 'u1', 'ucmp']
265          - values: [1, 'u1', 1, 'u1', 'ucmp']
266          # u8
267          - values: [0, 'u8', 0, 'u8', 'ucmp']
268          - values: [0x000000ff, 'u8', 0x000000ff, 'u8', 'ucmp']
269          - values: [0x000000a5, 'u8', 0x000000a5, 'u8', 'ucmp']
270          # u16
271          - values: [0, 'u16', 0, 'u16', 'ucmp']
272          - values: [0x0000ffff, 'u16', 0x0000ffff, 'u16', 'ucmp']
273          - values: [0x0000a5a5, 'u16', 0x0000a5a5, 'u16', 'ucmp']
274          # u32
275          - values: [0, 'u32', 0, 'u32', 'ucmp']
276          - values: [0xffffffff, 'u32', 0xffffffff, 'u32', 'ucmp']
277          - values: [0xa5a5a5a5, 'u32', 0xa5a5a5a5, 'u32', 'ucmp']
278
279      - file-name: "from_all_field_types_p_int"
280        description: Check that field value is loaded into accumulator in PandaAssembly context. Signed integer types. More tests on ldstatic can be found in ststatic tests.
281        isa:
282          description: >
283            For non-object variant, the size of the field is determined by the field_id,
284            most significant bits are sign or unsigned extended based on the field type to fit accumulator size.
285            If field size is less then 32, result will be sign or unsigned extended to i32 depedning on field type.
286        header-template: [pandasm_header]
287        check-type: exit-positive
288        tags: ['tsan', 'irtoc_ignore']
289        code-template: |
290
291          .function i32 main() {
292            ldai %s
293            ststatic R.f%s
294            lda.null
295            movi v15, %s
296            ldstatic R.f%s
297            jeq v15, success
298            ldai 1
299            return
300          success:
301        cases:
302          # i8
303          - values: [0, 'i8', 0, 'i8']
304          - values: [0x000000ff, 'i8', 0xffffffff, 'i8']
305          - values: [0x000000a5, 'i8', 0xffffffa5, 'i8']
306          - values: [0x0000005a, 'i8', 0x0000005a, 'i8']
307          # i16
308          - values: [0, 'i16', 0, 'i16']
309          - values: [0x0000ffff, 'i16', 0xffffffff, 'i16']
310          - values: [0x0000a5a5, 'i16', 0xffffa5a5, 'i16']
311          - values: [0x00005a5a, 'i16', 0x00005a5a, 'i16']
312          # i32
313          - values: [0, 'i32', 0, 'i32']
314          - values: [0xffffffff, 'i32', 0xffffffff, 'i32']
315          - values: [0xa5a5a5a5, 'i32', 0xa5a5a5a5, 'i32']
316          - values: [0x5a5a5a5a, 'i32', 0x5a5a5a5a, 'i32']
317
318      - file-name: "from_all_field_types_j"
319        description: Check that field value is loaded into accumulator in PandaAssembly context. More tests on ldstatic can be found in ststatic tests.
320        isa:
321          description: >
322            For non-object variant, the size of the field is determined by the field_id,
323            most significant bits are sign or unsigned extended based on the field type to fit accumulator size.
324            If field size is less then 32, result will be sign or unsigned extended to i32 depedning on field type.
325        header-template: [PandaAssembly_header]
326        runner-options: [use-pa]
327        check-type: exit-positive
328        tags: ['tsan']
329        code-template: |
330
331          .function i32 main() {
332            ldai %s
333            ststatic R.f%s
334            lda.null
335            movi v15, %s
336            ldstatic R.f%s
337            %s v15
338            jeqz success
339            ldai 1
340            return
341          success:
342        cases:
343          # u1
344          - values: [0, 'u1', 0, 'u1', 'ucmp']
345          - values: [1, 'u1', 1, 'u1', 'ucmp']
346          # u16
347          - values: [0, 'u16', 0, 'u16', 'ucmp']
348          - values: [0x0000ffff, 'u16', 0x0000ffff, 'u16', 'ucmp']
349          - values: [0x0000a5a5, 'u16', 0x0000a5a5, 'u16', 'ucmp']
350
351      - file-name: "from_all_field_types_j_int"
352        description: Check that field value is loaded into accumulator in PandaAssembly context. Signed integer types. More tests on ldstatic can be found in ststatic tests.
353        isa:
354          description: >
355            For non-object variant, the size of the field is determined by the field_id,
356            most significant bits are sign or unsigned extended based on the field type to fit accumulator size.
357            If field size is less then 32, result will be sign or unsigned extended to i32 depedning on field type.
358        header-template: [PandaAssembly_header]
359        runner-options: [use-pa]
360        check-type: exit-positive
361        tags: ['tsan', 'irtoc_ignore']
362        code-template: |
363
364          .function i32 main() {
365            ldai %s
366            ststatic R.f%s
367            lda.null
368            movi v15, %s
369            ldstatic R.f%s
370            jeq v15, success
371            ldai 1
372            return
373          success:
374        cases:
375          # i8
376          - values: [0, 'i8', 0, 'i8']
377          - values: [0x000000ff, 'i8', 0xffffffff, 'i8']
378          - values: [0x000000a5, 'i8', 0xffffffa5, 'i8']
379          - values: [0x0000005a, 'i8', 0x0000005a, 'i8']
380          # i16
381          - values: [0, 'i16', 0, 'i16']
382          - values: [0x0000ffff, 'i16', 0xffffffff, 'i16']
383          - values: [0x0000a5a5, 'i16', 0xffffa5a5, 'i16']
384          - values: [0x00005a5a, 'i16', 0x00005a5a, 'i16']
385          # i32
386          - values: [0, 'i32', 0, 'i32']
387          - values: [0xffffffff, 'i32', 0xffffffff, 'i32']
388          - values: [0xa5a5a5a5, 'i32', 0xa5a5a5a5, 'i32']
389          - values: [0x5a5a5a5a, 'i32', 0x5a5a5a5a, 'i32']
390
391      - file-name: "x_init_p"
392        description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer.
393        isa:
394          exceptions:
395            - x_init
396        header-template: []
397        check-type: empty
398        tags: ['tsan', 'irtoc_ignore']
399        bugid: ['5330']
400        code-template: |
401
402          .language PandaAssembly
403
404          .record panda.ExceptionInInitializerError <external>
405          .record panda.NullPointerException <external>
406          .record E1 {}
407          .record R {
408              i32     fi32    <static>
409          }
410
411          .function void R.func() <cctor> {
412              %s
413              return.void
414          }
415
416          .function i32 main() {
417          begin:
418              ldstatic R.fi32
419              ldai 2
420              return
421          end:
422          catch:
423              ldai 0
424              return
425          catch_all:
426              ldai 1
427              return
428          .catch panda.ExceptionInInitializerError, begin, end, catch
429          .catchall begin, end, catch_all
430          }
431        cases:
432          - values:
433            - |
434              #
435                  newobj v0, E1
436                  throw v0
437          - values:
438            - |
439              #
440                  newobj v0, panda.NullPointerException
441                  throw v0
442          - values:
443            - |
444              #
445                  movi v1, 0
446                  ldai 1
447                  div2 v1     # divide by zero
448          - values:
449            - |
450              #
451                  movi v1, 10
452                  newarr v1, v1, i32[]
453                  ldai 10
454                  ldarr v1    # get ArrayIndexOutOfBoundsException
455
456      - file-name: "x_init_j"
457        description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer.
458        isa:
459          exceptions:
460            - x_init
461        header-template: []
462        check-type: empty
463        tags: ['tsan', 'irtoc_ignore']
464        runner-options: ['use-pa']
465        code-template: |
466
467          .language PandaAssembly
468
469          .record panda.ExceptionInInitializerError <external>
470          .record panda.NullPointerException <external>
471          .record E1 {}
472          .record R {
473              i32     fi32    <static>
474          }
475          .record Q <panda.extends=R> {
476              i32     fi32    <static>
477          }
478          .function void R.func() <cctor> {
479              %s
480              return.void
481          }
482
483          .function i32 main() {
484          begin:
485              ldstatic Q.fi32
486              ldai 2
487              return
488          end:
489          catch:
490              ldai 0
491              return
492          catch_all:
493              ldai 1
494              return
495          .catch panda.ExceptionInInitializerError, begin, end, catch
496          .catchall begin, end, catch_all
497          }
498        cases:
499          - values:
500            - |
501              #
502                  newobj v0, E1
503                  throw v0
504          - values:
505            - |
506              #
507                  newobj v0, panda.NullPointerException
508                  throw v0
509          - values:
510            - |
511              #
512                  movi v1, 0
513                  ldai 1
514                  div2 v1     # divide by zero
515          - values:
516            - |
517              #
518                  movi v1, 10
519                  newarr v1, v1, i32[]
520                  ldai 10
521                  ldarr v1    # get ArrayIndexOutOfBoundsException
522
523      - file-name: "from_float_field_type_p"
524        description: Check that accumulator value is loaded from field into accumulator in PandaAssembly context. More tests on ldstatic can be found in ststatic tests.
525        isa:
526          instructions:
527            - sig: ldstatic field_id
528              acc: out:b32
529              format: [op_id_16]
530        header-template: [pandasm_header]
531        tags: ['irtoc_ignore']
532        check-type: exit-positive
533        code-template: |
534
535          .function i32 main() {
536            fldai %s
537            ststatic R.ff32
538            lda.null
539            fmovi v15, %s
540            ldstatic R.ff32
541            fcmpg v15
542            %s
543            jeqz success
544            ldai 1
545            return
546          success:
547        cases:
548          # f32
549          - values: ['0.0', '0.0', '']
550          - values: ['-6510615.0', '-6510615.0', '']
551          - values: ['0x7fffffff', '0x7fffffff', 'subi 1']    # NaN
552          - values: ['0x7f800000', '0x7f800000', '']    # + Inf
553          - values: ['0xff800000', '0xff800000', '']    # - Inf
554
555      - file-name: "from_float_field_type_j"
556        description: Check that accumulator value is loaded from field into accumulator in PandaAssembly context. More tests on ldstatic can be found in ststatic tests.
557        isa:
558          instructions:
559            - sig: ldstatic field_id
560              acc: out:b32
561              format: [op_id_16]
562        tags: ['irtoc_ignore']
563        header-template: [PandaAssembly_header]
564        runner-options: [use-pa]
565        check-type: exit-positive
566        code-template: |
567
568          .function i32 main() {
569            fldai %s
570            ststatic R.ff32
571            lda.null
572            fmovi v15, %s
573            ldstatic R.ff32
574            fcmpg v15
575            %s
576            jeqz success
577            ldai 1
578            return
579          success:
580        cases:
581          # f32
582          - values: ['0.0', '0.0', '']
583          - values: ['-6510615.0', '-6510615.0', '']
584          - values: ['0x7fffffff', '0x7fffffff', 'subi 1']    # NaN
585          - values: ['0x7f800000', '0x7f800000', '']    # + Inf
586          - values: ['0xff800000', '0xff800000', '']    # - Inf
587