• 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        R              fR         <static>
43        R[]            fRArray    <static>
44        panda.Object   fObj       <static>
45        panda.Object[] fObjArray  <static>
46      }
47      .function void R.ctor(R a0) <ctor> {
48        return.void
49      }
50
51  - name: java_header
52    template: |
53      .language Java
54
55      .record java.lang.Object <external>
56      .function void java.lang.Object.ctor(java.lang.Object a0) <external, ctor>
57
58      .record I <java.interface> {}
59
60      .record Q <java.implements=I> {}
61      .function void Q.ctor(Q a0) <ctor> {
62        return.void
63      }
64
65      .record R <java.extends=Q> {
66        u1                 fu1       <static>
67        i8                 fi8       <static>
68        u16                fu16      <static>
69        i16                fi16      <static>
70        i32                fi32      <static>
71        i64                fi64      <static>
72        f32                ff32      <static>
73        f64                ff64      <static>
74        # objects
75        i32[]              fi32Array <static>
76        Q                  fQ        <static>
77        Q[]                fQArray   <static>
78        R                  fR        <static>
79        R[]                fRArray   <static>
80        I                  fI        <static>
81        I[]                fIArray   <static>
82        java.lang.Object   fObj      <static>
83        java.lang.Object   fObj2     <static>
84        java.lang.Object[] fObjArray <static>
85      }
86      .function void R.ctor(R a0) <ctor> {
87        return.void
88      }
89
90tests:
91  - file-name: "ldstatic.obj"
92    isa:
93      title: Get static field
94      description: >
95        Get static field value by field_id and put it into accumulator.
96      instructions:
97        - sig: ldstatic.obj field_id
98          acc: out:ref
99          format: [op_id_16]
100    commands:
101
102      - file-name: "with_non_static_field_id"
103        description: Check that verifier reports error when the field doesn't resolve to a static valid field
104        isa:
105          verification:
106            - field_id_static
107        header-template: []
108        check-type: exit-positive
109        code-template: |
110          .record W {
111            u1    fu1
112            i8    fi8
113            u16   fu16
114            i16   fi16
115            i32   fi32
116            i64   fi64
117            f32   ff32
118            f64   ff64
119            W     fW
120            i32[] fi32Array
121            W[]   fWArray
122          }
123          .function void W.object_function(W a0) {
124            return.void
125          }
126          .function void static_function() {
127            return.void
128          }
129
130          .function i32 main() {
131            ldstatic.obj %s
132        cases:
133          - values:
134            - W.fu1
135            tags: [verifier]
136            runner-options: ['verifier-failure', 'verifier-debug-config']
137            bugid: ['1324', '1828']
138          - values:
139            - W.fi8
140            tags: [verifier]
141            runner-options: ['verifier-failure', 'verifier-debug-config']
142            bugid: ['1324', '1828']
143          - values:
144            - W.fu16
145            tags: [verifier]
146            runner-options: ['verifier-failure', 'verifier-debug-config']
147            bugid: ['1324', '1828']
148          - values:
149            - W.fi16
150            tags: [verifier]
151            runner-options: ['verifier-failure', 'verifier-debug-config']
152            bugid: ['1324', '1828']
153          - values:
154            - W.fi32
155            tags: [verifier]
156            runner-options: ['verifier-failure', 'verifier-debug-config']
157            bugid: ['1324', '1828']
158          - values:
159            - W.fi64
160            tags: [verifier]
161            runner-options: ['verifier-failure', 'verifier-debug-config']
162            bugid: ['1324', '1828']
163          - values:
164            - W.ff32
165            tags: [verifier]
166            runner-options: ['verifier-failure', 'verifier-debug-config']
167            bugid: ['1324', '1828']
168          - values:
169            - W.ff64
170            tags: [verifier]
171            runner-options: ['verifier-failure', 'verifier-debug-config']
172            bugid: ['1324', '1828']
173          - values:
174            - W.fW
175            tags: [verifier]
176            runner-options: ['verifier-failure', 'verifier-debug-config']
177            bugid: ['1324', '1828']
178          - values:
179            - W.fi32Array
180            tags: [verifier]
181            runner-options: ['verifier-failure', 'verifier-debug-config']
182            bugid: ['1324', '1828']
183          - values:
184            - W.fWArray
185            tags: [verifier]
186            runner-options: ['verifier-failure', 'verifier-debug-config']
187            bugid: ['1324', '1828']
188          - values:
189            - W
190            runner-options: [compile-failure]
191          - values:
192            - W.object_function
193            runner-options: [compile-failure]
194          - values:
195            - static_function
196            runner-options: [compile-failure]
197          - values:
198            - unknown_function
199            runner-options: [compile-failure]
200          - values:
201            - 0
202            runner-options: [compile-failure]
203          - values:
204            - -1.1
205            runner-options: [compile-failure]
206          - values:
207            - "null"
208            runner-options: [compile-failure]
209          - values:
210            - "\"abc\""
211            runner-options: [compile-failure]
212
213
214      - file-name: "with_wrong_field_size_or_type_p"
215        description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode in PandaAssembly context.
216        isa:
217          verification:
218            - field_id_size
219        header-template: [pandasm_header]
220        check-type: exit-positive
221        tags: [verifier]
222        runner-options: ['verifier-failure', 'verifier-debug-config']
223        bugid: ['1834', '2088']
224        code-template: |
225
226          .function i32 main() {
227            ldstatic.obj %s
228        cases:
229          - values:
230            - R.fu1
231          - values:
232            - R.fu8
233          - values:
234            - R.fi8
235          - values:
236            - R.fu16
237          - values:
238            - R.fi16
239          - values:
240            - R.fu32
241          - values:
242            - R.fi32
243          - values:
244            - R.fu64
245          - values:
246            - R.fi64
247          - values:
248            - R.ff32
249          - values:
250            - R.ff64
251
252
253      - file-name: "from_all_field_types_pa"
254        description: Check that accumulator value is loaded from field into accumulator in PandaAssembly context. More tests on ldstatic.obj can be found in ststatic.obj tests
255        isa:
256          description: Get static field value by field_id and put it into accumulator.
257        header-template: [pandasm_header]
258        check-type: exit-positive
259        tags: ['tsan']
260        code-template: |
261
262          .function i32 main() {
263            # store null into Q type field
264            lda.null
265            sta.obj v3
266            ststatic.obj R.fQ
267            # store null into Q[] type field
268            lda.null
269            sta.obj v4
270            ststatic.obj R.fQArray
271            # store R object into R type field
272            initobj R.ctor
273            sta.obj v5
274            ststatic.obj R.fR
275            # store R[] into R[] type field
276            movi v1, 10
277            newarr v6, v1, R[]
278            lda.obj v6
279            ststatic.obj R.fRArray
280          label0:
281            # load null from Q type field
282            ldstatic.obj R.fQ
283            jeq.obj v3, label1
284            ldai 1
285            return
286          label1:
287            # load null from Q[] type field
288            ldstatic.obj R.fQArray
289            jeq.obj v4, label2
290            ldai 2
291            return
292          label2:
293            # load R object from R type field
294            ldstatic.obj R.fR
295            jeq.obj v5, label3
296            ldai 3
297            return
298          label3:
299            # load R[] from R[] type field
300            ldstatic.obj R.fRArray
301            jeq.obj v6, success
302            ldai 4
303            return
304          success:
305
306      - file-name: "x_init_p"
307        description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer.
308        isa:
309          exceptions:
310            - x_init
311        header-template: []
312        check-type: empty
313        tags: ['tsan']
314        bugid: ['5330']
315        ignore: true
316        code-template: |
317
318          .language PandaAssembly
319
320          .record panda.ExceptionInInitializerError <external>
321          .record panda.NullPointerException <external>
322          .record E1 {}
323          .record R {
324              E1     fObj    <static>
325          }
326
327          .function void R.func() <cctor> {
328              %s
329              return.void
330          }
331
332          .function i32 main() {
333          begin:
334              ldstatic R.fObj
335              ldai 2
336              return
337          end:
338          catch:
339              ldai 0
340              return
341          catch_all:
342              ldai 1
343              return
344          .catch panda.ExceptionInInitializerError, begin, end, catch
345          .catchall begin, end, catch_all
346          }
347        cases:
348          - values:
349            - |
350              #
351                  newobj v0, E1
352                  throw v0
353          - values:
354            - |
355              #
356                  newobj v0, panda.NullPointerException
357                  throw v0
358          - values:
359            - |
360              #
361                  movi v1, 0
362                  ldai 1
363                  div2 v1     # divide by zero
364          - values:
365            - |
366              #
367                  movi v1, 10
368                  newarr v1, v1, i32[]
369                  ldai 10
370                  ldarr v1    # get ArrayIndexOutOfBoundsException
371
372