• 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.Object <external>
20
21      .record Q {}
22      .function void Q.ctor(Q a0) <ctor> {
23        return.void
24      }
25
26      .record R {
27        u1             fu1        <static>
28        u8             fu8        <static>
29        i8             fi8        <static>
30        u16            fu16       <static>
31        i16            fi16       <static>
32        u32            fu32       <static>
33        i32            fi32       <static>
34        u64            fu64       <static>
35        i64            fi64       <static>
36        f32            ff32       <static>
37        f64            ff64       <static>
38        # objects:
39        i32[]          fi32Array  <static>
40        Q              fQ         <static>
41        Q[]            fQArray    <static>
42        panda.Object   fObj       <static>
43        panda.Object[] fObjArray  <static>
44      }
45
46tests:
47  - file-name: "ststatic.64"
48    isa:
49      title: Store to static field
50      description: >
51        Store accumulator content into static field by field_id. For non-object variant the size of actually stored
52        value is determined by field_id, other accumulator bits are discarded.
53      instructions:
54        - sig: ststatic.64 field_id
55          acc: in:b64
56          format: [op_id_16]
57    commands:
58
59      - file-name: "check_if_acc_initialized"
60        description: Check that verifier reports an error if accumulator is not initialized
61        isa:
62          description: Store accumulator content into static field by field_id.
63        header-template: ['pandasm_header']
64        check-type: exit-positive
65        tags: ['verifier']
66        bugid: ['1324']
67        runner-options: ['verifier-failure', 'verifier-debug-config']
68        code-template: |
69
70          .function i32 main() {
71            # acc (value) not initialized, verifier error expected
72            ststatic.64 R.fi64
73
74
75      - file-name: "with_non_static_field_id"
76        description: Check that verifier reports an error when the field_id doesn't resolve to a static valid field
77        isa:
78          verification:
79            - field_id_static
80        header-template: []
81        check-type: exit-positive
82        code-template: |
83          .record W {
84            u1    fu1
85            i8    fi8
86            u16   fu16
87            i16   fi16
88            i32   fi32
89            i64   fi64
90            f32   ff32
91            f64   ff64
92            W     fW
93            i32[] fi32Array
94            W[]   fWArray
95          }
96          .function void W.object_function(W a0) {
97            return.void
98          }
99          .function void static_function() {
100            return.void
101          }
102
103          .function i32 main() {
104            ldai.64 1
105            ststatic.64 %s
106        cases:
107          - values:
108            - W.fu1
109            tags: [verifier]
110            runner-options: ['verifier-failure', 'verifier-debug-config']
111            bugid: ['1324', '1828']
112          - values:
113            - W.fi8
114            tags: [verifier]
115            runner-options: ['verifier-failure', 'verifier-debug-config']
116            bugid: ['1324', '1828']
117          - values:
118            - W.fu16
119            tags: [verifier]
120            runner-options: ['verifier-failure', 'verifier-debug-config']
121            bugid: ['1324', '1828']
122          - values:
123            - W.fi16
124            tags: [verifier]
125            runner-options: ['verifier-failure', 'verifier-debug-config']
126            bugid: ['1324', '1828']
127          - values:
128            - W.fi32
129            tags: [verifier]
130            runner-options: ['verifier-failure', 'verifier-debug-config']
131            bugid: ['1324', '1828']
132          - values:
133            - W.fi64
134            tags: [verifier]
135            runner-options: ['verifier-failure', 'verifier-debug-config']
136            bugid: ['1324', '1828']
137          - values:
138            - W.ff32
139            tags: [verifier]
140            runner-options: ['verifier-failure', 'verifier-debug-config']
141            bugid: ['1324', '1828']
142          - values:
143            - W.ff64
144            tags: [verifier]
145            runner-options: ['verifier-failure', 'verifier-debug-config']
146            bugid: ['1324', '1828']
147          - values:
148            - W.fW
149            tags: [verifier]
150            runner-options: ['verifier-failure', 'verifier-debug-config']
151            bugid: ['1324', '1828']
152          - values:
153            - W.fi32Array
154            tags: [verifier]
155            runner-options: ['verifier-failure', 'verifier-debug-config']
156            bugid: ['1324', '1828']
157          - values:
158            - W.fWArray
159            tags: [verifier]
160            runner-options: ['verifier-failure', 'verifier-debug-config']
161            bugid: ['1324', '1828']
162          - values:
163            - W
164            runner-options: ['compile-failure']
165          - values:
166            - W.object_function
167            runner-options: ['compile-failure']
168          - values:
169            - static_function
170            runner-options: ['compile-failure']
171          - values:
172            - unknown_function
173            runner-options: ['compile-failure']
174          - values:
175            - 0
176            runner-options: ['compile-failure']
177          - values:
178            - -1.1
179            runner-options: ['compile-failure']
180          - values:
181            - "null"
182            runner-options: ['compile-failure']
183          - values:
184            - "\"abc\""
185            runner-options: ['compile-failure']
186
187
188      - file-name: "with_wrong_field_size"
189        description: Check that verifier reports an error when the field_id resolves to a field with size that is not corresponding to bytecode
190        isa:
191          verification:
192            - field_id_size
193        header-template: ['pandasm_header']
194        check-type: exit-positive
195        tags: ['verifier']
196        runner-options: ['verifier-failure', 'verifier-debug-config']
197        bugid: ['1834']
198        code-template: |
199
200          .function i32 main() {
201            ldai.64 0x5a5a5a5a5a5a5a5a
202            ststatic.64 %s
203        cases:
204          - values:
205            - R.fu1
206          - values:
207            - R.fu8
208          - values:
209            - R.fi8
210          - values:
211            - R.fu16
212          - values:
213            - R.fi16
214          - values:
215            - R.fu32
216          - values:
217            - R.fi32
218          - values:
219            - R.ff32
220          - values:
221            - R.fObj
222          - values:
223            - R.fObjArray
224          - values:
225            - R.fi32Array
226
227
228      - file-name: "with_wrong_acc_type"
229        description: Check that verifier reports error when the accumulator contains a value of type not corresponding to the bytecode
230        isa:
231          verification:
232            - acc_type
233        header-template: ['pandasm_header']
234        check-type: exit-positive
235        tags: ['verifier']
236        runner-options: ['verifier-failure', 'verifier-debug-config']
237        bugid: ['1834']
238        code-template: |
239
240          .function i32 main() {
241            %s
242            ststatic.64 %s
243        cases:
244          # u64
245          - values:
246            - ldai 0
247            - R.fu64
248          - values:
249            - ldai 0xCAFECAFE
250            - R.fu64
251          - values:
252            - fldai.64 1.1
253            - R.fu64
254          - values:
255            - lda.null
256            - R.fu64
257          - values:
258            - initobj Q.ctor
259            - R.fu64
260          - values:
261            - |
262              movi v1, 10
263                newarr v1, v1, i32[]
264                lda.obj v1
265            - R.fu64
266          # i64
267          - values:
268            - ldai 0
269            - R.fi64
270          - values:
271            - ldai 0xCAFECAFE
272            - R.fi64
273          - values:
274            - fldai.64 1.1
275            - R.fi64
276          - values:
277            - lda.null
278            - R.fi64
279          - values:
280            - initobj Q.ctor
281            - R.fi64
282          - values:
283            - |
284              movi v1, 10
285                newarr v1, v1, i32[]
286                lda.obj v1
287            - R.fi64
288          # f64
289          - values:
290            - ldai 0
291            - R.ff64
292          - values:
293            - ldai 0xCAFECAFE
294            - R.ff64
295          - values:
296            - ldai.64 1
297            - R.ff64
298          - values:
299            - lda.null
300            - R.ff64
301          - values:
302            - initobj Q.ctor
303            - R.ff64
304          - values:
305            - |
306              movi v1, 10
307                newarr v1, v1, i32[]
308                lda.obj v1
309            - R.ff64
310
311
312      - file-name: "into_all_field_types"
313        description: Check that accumulator value is stored in field
314        isa:
315          instructions:
316            - sig: ststatic.64 field_id
317              acc: in:b64
318              format: [op_id_16]
319        header-template: ['pandasm_header']
320        check-type: exit-positive
321        tags: ['tsan']
322        code-template: |
323
324          .function i32 main() {
325            %s
326            ststatic.64 R.%s
327            lda.null
328            ldstatic.64 R.%s
329            %s
330            jeqz success
331            ldai 1
332            return
333          success:
334        cases:
335          # u64
336          - values:
337            - ldai.64 0x0000000000000000
338            - fu64
339            - fu64
340            - |
341                movi.64 v1, 0x0000000000000000
342                  ucmp.64 v1
343          - values:
344            - ldai.64 0xffffffffffffffff
345            - fu64
346            - fu64
347            - |
348                movi.64 v1, 0xffffffffffffffff
349                  ucmp.64 v1
350          - values:
351            - ldai.64 0xa5a5a5a5a5a5a5a5
352            - fu64
353            - fu64
354            - |
355                movi.64 v1, 0xa5a5a5a5a5a5a5a5
356                  ucmp.64 v1
357          # i64
358          - values:
359            - ldai.64 0
360            - fi64
361            - fi64
362            - |
363                movi.64 v1, 0
364                  cmp.64 v1
365          - values:
366            - ldai.64 -1
367            - fi64
368            - fi64
369            - |
370                movi.64 v1, -1
371                  cmp.64 v1
372          - values:
373            - ldai.64 -6510615555426900571
374            - fi64
375            - fi64
376            - |
377                movi.64 v1, -6510615555426900571
378                  cmp.64 v1
379          # f64
380          - values:
381            - fldai.64 0.0
382            - ff64
383            - ff64
384            - |
385                fmovi.64 v1, 0.0
386                  fcmpg.64 v1
387          - values:
388            - fldai.64 -6510615555426900571.0
389            - ff64
390            - ff64
391            - |
392                fmovi.64 v1, -6510615555426900571.0
393                  fcmpg.64 v1
394          - values:
395            - fldai.64 0x7FFFFFFFFFFFFFFF  # NaN
396            - ff64
397            - ff64
398            - |
399                fmovi.64 v1, 0.0
400                  fcmpg.64 v1
401                  subi 1
402          - values:
403            - fldai.64 0x7ff0000000000000  # + Inf
404            - ff64
405            - ff64
406            - |
407                fmovi.64 v1, 0x7ff0000000000000
408                  fcmpg.64 v1
409          - values:
410            - fldai.64 0xfff0000000000000  # - Inf
411            - ff64
412            - ff64
413            - |
414                fmovi.64 v1, 0xfff0000000000000
415                  fcmpg.64 v1
416
417      - file-name: "x_init_p"
418        description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer.
419        isa:
420          exceptions:
421            - x_init
422        header-template: []
423        check-type: empty
424        tags: ['tsan']
425        bugid: ['5330']
426        ignore: true
427        code-template: |
428
429          .language PandaAssembly
430
431          .record panda.ExceptionInInitializerError <external>
432          .record panda.NullPointerException <external>
433          .record E1 {}
434          .record R {
435              f64     ff64    <static>
436          }
437
438          .function void R.func() <cctor> {
439              %s
440              return.void
441          }
442
443          .function i32 main() {
444          begin:
445              fldai.64 3.1415926
446              ststatic.64 R.ff64
447              ldai 2
448              return
449          end:
450          catch:
451              ldai 0
452              return
453          catch_all:
454              ldai 1
455              return
456          .catch panda.ExceptionInInitializerError, begin, end, catch
457          .catchall begin, end, catch_all
458          }
459        cases:
460          - values:
461            - |
462              #
463                  newobj v0, E1
464                  throw v0
465          - values:
466            - |
467              #
468                  newobj v0, panda.NullPointerException
469                  throw v0
470          - values:
471            - |
472              #
473                  movi v1, 0
474                  ldai 1
475                  div2 v1     # divide by zero
476          - values:
477            - |
478              #
479                  movi v1, 10
480                  newarr v1, v1, i32[]
481                  ldai 10
482                  ldarr v1    # get ArrayIndexOutOfBoundsException
483
484