• 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
28        u8             fu8
29        i8             fi8
30        u16            fu16
31        i16            fi16
32        u32            fu32
33        i32            fi32
34        u64            fu64
35        i64            fi64
36        f32            ff32
37        f64            ff64
38        # objects
39        i32[]          fi32Array
40        Q              fQ
41        Q[]            fQArray
42        R              fR
43        R[]            fRArray
44        panda.Object   fObj
45        panda.Object[] fObjArray
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
67        u8                 fu8
68        i8                 fi8
69        u16                fu16
70        i16                fi16
71        u32                fu32
72        i32                fi32
73        u64                fu64
74        i64                fi64
75        f32                ff32
76        f64                ff64
77        # objects
78        i32[]              fi32Array
79        Q                  fQ
80        Q[]                fQArray
81        R                  fR
82        R[]                fRArray
83        I                  fI
84        I[]                fIArray
85        java.lang.Object   fObj
86        java.lang.Object   fObj2
87        java.lang.Object[] fObjArray
88      }
89      .function void R.ctor(R a0) <ctor> {
90        return.void
91      }
92
93
94tests:
95  - file-name: "ldobj.obj"
96    isa:
97      title: Get field from object to accumulator
98      description: >
99        Get field value from an object by field id and put it into accumulator.
100      instructions:
101        - sig: ldobj.obj v:in:ref, field_id
102          acc: out:ref
103          format: [op_v_8_id_16]
104    commands:
105
106      - file-name: "check_if_regs_initialized"
107        description: Check that verifier reports error if source registers are not initialized
108        isa:
109          instructions:
110            - sig: ldobj.obj v:in:ref, field_id
111              acc: out:ref
112              format: [op_v_8_id_16]
113        header-template: [pandasm_header]
114        check-type: exit-positive
115        tags: [verifier]
116        bugid: ['1324', '2084', '3257']
117        runner-options: ['verifier-failure', 'verifier-debug-config']
118        code-template: |
119          .function i32 main() {
120            %s  # verifier error expected, because the register is not initialized
121        cases:
122          - values:
123            - 'ldobj.obj v0, R.fQ'
124          - values:
125            - 'ldobj.obj v1, R.fR'
126          - values:
127            - 'ldobj.obj v15, R.fQArray'
128          - values:
129            - 'ldobj.obj v240, R.fi32Array'
130          - values:
131            - 'ldobj.obj v255, R.fObj'
132
133      - file-name: "with_null_ref_pa"
134        description: Check that NullPointerException is thrown if source ref is null
135        isa:
136          exceptions:
137            - x_null
138        header-template: [pandasm_header]
139        check-type: empty
140        tags: ['tsan']
141        code-template: |
142          .record panda.NullPointerException <external>
143
144          .function R get_null() {
145            lda.null
146            return.obj
147          }
148
149          .function i32 main() {
150            call.short get_null
151            sta.obj v0
152          try_begin:
153            ldobj.obj v0, %s
154            ldai 1
155            return
156          try_end:
157            ldai 0
158            return
159          .catch panda.NullPointerException, try_begin, try_end, try_end
160          }
161        cases:
162          - values:
163            - R.fQ
164          - values:
165            - R.fObj
166          - values:
167            - R.fi32Array
168
169
170      - file-name: "with_non_object_ref"
171        description: Check that verifier reports error when the 1st operand is not a ref to an object (other than array)
172        isa:
173          verification:
174            - v1_object
175        header-template: [pandasm_header]
176        check-type: empty
177        tags: [verifier]
178        runner-options: ['verifier-failure', 'verifier-debug-config']
179        bugid: ['2085']
180        code-template: |
181
182          .function i32 main() {
183            %s
184          try_begin:
185            ldobj.obj v0, R.fQ
186          try_end:
187            ldai 0
188            return
189          .catchall try_begin, try_end, try_end
190          }
191        cases:
192          - values:
193            - movi v0, 0
194            bugid: ['1826']
195          - values:
196            - movi v0, 1
197          - values:
198            - movi.64 v0, 0x00
199            bugid: ['1826']
200          - values:
201            - movi.64 v0, 0xCAFECAFECAFECAFE
202          - values:
203            - fmovi.64 v0, 0.0
204            bugid: ['1826']
205          - values:
206            - fmovi.64 v0, 6.62607015
207          - values:
208            - |
209                movi v1, 10
210                  newarr v0, v1, R[]
211            bugid: ['1827']
212
213
214      - file-name: "with_static_field_id"
215        description: Check that verifier reports error when the field doesn't resolve to a non-static object field
216        isa:
217          verification:
218            - field_id_non_static
219        header-template: []
220        check-type: exit-positive
221        code-template: |
222          .record W {
223            W   static_field  <static>
224            W[] static_array  <static>
225          }
226          .function void W.ctor(W a0) <ctor> {
227            return.void
228          }
229          .function void W.object_function(W a0) {
230            return.void
231          }
232          .record random_record_name {
233            W random_field_name
234          }
235          .function void static_function() {
236            return.void
237          }
238
239          .function i32 main() {
240            initobj W.ctor
241            sta.obj v0
242            ldobj.obj v0, %s
243        cases:
244          # resolves to a static object field
245          - values:
246            - W.static_field
247            tags: [verifier]
248            runner-options: ['verifier-failure', 'verifier-debug-config']
249            bugid: ['1324', '1828']
250          # resolves to a static object array
251          - values:
252            - W.static_array
253            tags: [verifier]
254            runner-options: ['verifier-failure', 'verifier-debug-config']
255            bugid: ['1324', '1828']
256          # resolves to a non-existing object field
257          - values:
258            - W.field_not_exists
259            runner-options: [compile-failure]
260          # resolves to object's constructor
261          - values:
262            - W.ctor
263            runner-options: [compile-failure]
264          # resolves to objects's method
265          - values:
266            - W.object_function
267            runner-options: [compile-failure]
268          # resolves to some other object
269          - values:
270            - random_record_name
271            runner-options: [compile-failure]
272          # resolves to some static function
273          - values:
274            - static_function
275            runner-options: [compile-failure]
276          # resolves to a field name in a wrong object
277          - values:
278            - random_record_name.random_field_name
279            tags: [verifier]
280            runner-options: ['verifier-failure', 'verifier-debug-config']
281            bugid: ['1833', '3536']
282            ignore: true
283          # cannot resolve, because it's a i32 number
284          - values:
285            - 0
286            runner-options: [compile-failure]
287          # cannot resolve, because it's a f64 number
288          - values:
289            - -1.1
290            runner-options: [compile-failure]
291          # cannot resolve, because it's a "null" string
292          - values:
293            - "null"
294            runner-options: [compile-failure]
295
296
297      - file-name: "with_wrong_field_size_or_type"
298        description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode
299        isa:
300          verification:
301            - field_id_size
302        header-template: [pandasm_header]
303        check-type: exit-positive
304        tags: [verifier]
305        runner-options: ['verifier-failure', 'verifier-debug-config']
306        bugid: ['1834', '2088']
307        code-template: |
308
309          .function i32 main() {
310            initobj R.ctor
311            sta.obj v0
312            ldobj.obj v0, %s
313        cases:
314          - values:
315            - R.fu1
316          - values:
317            - R.fu8
318          - values:
319            - R.fi8
320          - values:
321            - R.fu16
322          - values:
323            - R.fi16
324          - values:
325            - R.fu32
326          - values:
327            - R.fi32
328          - values:
329            - R.fu64
330          - values:
331            - R.fi64
332          - values:
333            - R.ff32
334          - values:
335            - R.ff64
336
337
338      - file-name: "op_v_8_id_16"
339        description: Check that compiler reports error when the register number is out of 8 bit size
340        isa:
341          instructions:
342            - sig: ldobj.obj v:in:ref, field_id
343              acc: out:ref
344              format: [op_v_8_id_16]
345        header-template: [pandasm_header]
346        check-type: exit-positive
347        runner-options: [compile-failure]
348        code-template: |
349
350          .function i32 main() {
351            ldobj.obj %s, R.fQ
352        cases:
353          - values: ['v255']
354            runner-options: ['compile-only']
355          - values: ['v256']
356          - values: ['v65535']
357          - values: ['a0']
358          - values: ['a1']
359          - values: ['null']
360          - values: ['1']
361          - values: ['"0"']
362
363
364      - file-name: "from_all_field_types_pa"
365        description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj.obj can be found in stobj.obj tests
366        isa:
367          description: Get field value from an object by field id and put it into accumulator.
368        header-template: [pandasm_header]
369        check-type: exit-positive
370        tags: ['tsan']
371        code-template: |
372
373          .function i32 main() {
374            initobj R.ctor
375            sta.obj v0
376            # store null into Q type field
377            lda.null
378            sta.obj v3
379            stobj.obj v0, R.fQ
380            # store null into Q[] type field
381            lda.null
382            sta.obj v4
383            stobj.obj v0, R.fQArray
384            # store R object into R type field
385            initobj R.ctor
386            sta.obj v5
387            stobj.obj v0, R.fR
388            # store R[] into R[] type field
389            movi v1, 10
390            newarr v6, v1, R[]
391            lda.obj v6
392            stobj.obj v0, R.fRArray
393          label0:
394            # load null from Q type field
395            ldobj.obj v0, R.fQ
396            jeq.obj v3, label1
397            ldai 1
398            return
399          label1:
400            # load null from Q[] type field
401            ldobj.obj v0, R.fQArray
402            jeq.obj v4, label2
403            ldai 2
404            return
405          label2:
406            # load R object from R type field
407            ldobj.obj v0, R.fR
408            jeq.obj v5, label3
409            ldai 3
410            return
411          label3:
412            # load R[] from R[] type field
413            ldobj.obj v0, R.fRArray
414            jeq.obj v6, success
415            ldai 4
416            return
417          success:
418
419