• 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        panda.Object   fObj
43        panda.Object[] fObjArray
44      }
45      .function void R.ctor(R a0) <ctor> {
46        return.void
47      }
48
49  - name: java_header
50    template: |
51      .language Java
52
53      .record java.lang.Object <external>
54
55      .record Q {}
56      .function void Q.ctor(Q a0) <ctor> {
57        return.void
58      }
59
60      .record R {
61        u1             fu1
62        i8             fi8
63        u16            fu16
64        i16            fi16
65        i32            fi32
66        i64            fi64
67        f32            ff32
68        f64            ff64
69        # objects:
70        i32[]          fi32Array
71        Q              fQ
72        Q[]            fQArray
73        java.lang.Object   fObj
74        java.lang.Object[] fObjArray
75      }
76      .function void R.ctor(R a0) <ctor> {
77        return.void
78      }
79  - name: get_null_R
80    template: |
81      .function R get_null_R() {
82          lda.null
83          return.obj
84      }
85
86tests:
87  - file-name: "ldobj"
88    isa:
89      title: Get field from object to accumulator
90      description: >
91        Get field value from an object by field id and put it into accumulator.
92      instructions:
93        - sig: ldobj v:in:ref, field_id
94          acc: out:b32
95          format: [op_v_8_id_16]
96    commands:
97
98      - file-name: "check_if_regs_initialized"
99        description: Check that verifier reports error if source registers are not initialized
100        isa:
101          instructions:
102            - sig: ldobj v:in:ref, field_id
103              acc: out:b32
104              format: [op_v_8_id_16]
105        header-template: ['pandasm_header']
106        check-type: exit-positive
107        tags: ['verifier']
108        bugid: ['1324', '2084']
109        runner-options: ['verifier-failure', 'verifier-debug-config']
110        code-template: |
111
112          .function i32 main() {
113            %s  # verifier error expected, because the register is not initialized
114        cases:
115          - values:
116            - 'ldobj v0, R.fu1'
117          - values:
118            - 'ldobj v1, R.fu8'
119          - values:
120            - 'ldobj v15, R.fi8'
121          - values:
122            - 'ldobj v240, R.fu16'
123          - values:
124            - 'ldobj v255, R.fi16'
125
126
127      - file-name: "with_null_ref_p"
128        description: Check that NullPointerException is thrown if object ref is null in Panda context.
129        isa:
130          exceptions:
131            - x_null
132        header-template: ['pandasm_header', 'get_null_R']
133        check-type: empty
134        tags: ['tsan']
135        code-template: |
136          .record panda.NullPointerException <external>
137
138          .function i32 main() {
139            call.short get_null_R
140            sta.obj v0
141          try_begin:
142            ldobj v0, %s
143            ldai 1
144            return
145          try_end:
146            ldai 0
147            return
148          .catch panda.NullPointerException, try_begin, try_end, try_end
149          }
150        cases:
151          - values:
152            - R.fu1
153          - values:
154            - R.fu8
155          - values:
156            - R.fi8
157          - values:
158            - R.fu16
159          - values:
160            - R.fi16
161          - values:
162            - R.fu32
163          - values:
164            - R.fi32
165
166      - file-name: "with_non_object_ref"
167        description: Check that verifier reports an error when the 1st operand is not a ref to an object (other than array)
168        isa:
169          verification:
170            - v1_object
171        header-template: ['pandasm_header']
172        check-type: empty
173        tags: ['verifier']
174        bugid: ['2085']
175        runner-options: ['verifier-failure', 'verifier-debug-config']
176        code-template: |
177
178          .function i32 main() {
179            %s
180          try_begin:
181            ldobj v0, R.fu1
182          try_end:
183            ldai 0
184            return
185          .catchall try_begin, try_end, try_end
186          }
187        cases:
188          - values:
189            - movi v0, 0
190            tags: ['release', 'clang_release_sanitizer']
191            bugid: ['1324', '1826']
192          - values:
193            - movi v0, 1
194          - values:
195            - movi.64 v0, 0x00
196            tags: ['release', 'clang_release_sanitizer']
197            bugid: ['1324', '1826']
198          - values:
199            - movi.64 v0, 0xCAFECAFECAFECAFE
200          - values:
201            - fmovi.64 v0, 0.0
202            tags: ['release', 'clang_release_sanitizer']
203            bugid: ['1324', '1826']
204          - values:
205            - fmovi.64 v0, 6.62607015
206          - values:
207            - |
208                movi v1, 10
209                  newarr v0, v1, R[]
210            bugid: ['1827']
211
212
213      - file-name: "with_static_field_id"
214        description: Check that verifier reports an error if the field doesn't resolve to a non-static valid object field
215        isa:
216          verification:
217            - field_id_non_static
218        header-template: []
219        check-type: exit-positive
220        code-template: |
221          .record W {
222            i32   static_field  <static>
223          }
224          .function void W.ctor(W a0) <ctor> {
225            return.void
226          }
227          .record random_record_name {
228            i32 random_field_name
229          }
230          .function void random_function_name() {
231            return.void
232          }
233
234          .function i32 main() {
235            initobj W.ctor
236            sta.obj v0
237            ldobj v0, %s
238        cases:
239          - values:
240            - W.static_field
241            tags: ['verifier']
242            runner-options: ['verifier-failure', 'verifier-debug-config']
243            bugid: ['1324', '1828', '2086']
244          - values:
245            - random_record_name
246            runner-options: ['compile-failure']
247          - values:
248            - random_function_name
249            runner-options: ['compile-failure']
250          - values:
251            - W.field_not_exists
252            runner-options: ['compile-failure']
253          - values:
254            - random_record_name.random_field_name
255            tags: ['verifier']
256            runner-options: ['verifier-failure', 'verifier-debug-config']
257            bugid: ['1833', '2086', '3536']
258            ignore: true
259          - values:
260            - 0
261            runner-options: ['compile-failure']
262          - values:
263            - -1.1
264            runner-options: ['compile-failure']
265          - values:
266            - "null"
267            runner-options: ['compile-failure']
268          - values:
269            - "\"abc\""
270            runner-options: ['compile-failure']
271
272
273      - file-name: "with_wrong_field_size_or_type"
274        description: Check that verifier reports an error when the field resolves to a field with size or type that is not corresponding to bytecode
275        isa:
276          verification:
277            - field_id_size
278        header-template: ['pandasm_header']
279        check-type: exit-positive
280        tags: ['verifier']
281        runner-options: ['verifier-failure', 'verifier-debug-config']
282        bugid: ['1834', '2088']
283        code-template: |
284
285          .function i32 main() {
286            initobj R.ctor
287            sta.obj v0
288            ldobj v0, %s
289        cases:
290          - values:
291            - R.fi64
292          - values:
293            - R.fu64
294          - values:
295            - R.ff64
296          - values:
297            - R.ff32
298          - values:
299            - R.fObj
300          - values:
301            - R.fObjArray
302          - values:
303            - R.fi32Array
304
305
306      - file-name: "op_v_8_id_16"
307        description: Check that compiler reports an error when the register number is out of 8 bit size
308        isa:
309          instructions:
310            - sig: ldobj v:in:ref, field_id
311              acc: out:b32
312              format: [op_v_8_id_16]
313        header-template: ['pandasm_header']
314        runner-options: ['compile-failure']
315        check-type: exit-positive
316        code-template: |
317
318          .function i32 main() {
319            ldobj %s, R.fi32
320        cases:
321          - values: ['v255']
322            runner-options: ['compile-only']
323          - values: ['v256']
324          - values: ['v65535']
325          - values: ['a0']
326          - values: ['a1']
327          - values: ['null']
328          - values: ['1']
329          - values: ['"0"']
330
331      - file-name: "from_all_field_types"
332        description: Check that field value is loaded into accumulator. More tests on ldobj can be found in stobj tests
333        isa:
334          description: >
335            For non-object variant, the size of the field is determined by the field_id,
336            most significant bits are sign or unsigned extended based on the field type to fit accumulator size.
337            If field type is less than 32, then loaded value is sign or zero extended to i32 depending on field type.
338        header-template: ['pandasm_header']
339        check-type: exit-positive
340        tags: ['tsan']
341        code-template: |
342
343          .function i32 main() {
344            initobj.short R.ctor
345            sta.obj v0
346            ldai %s
347            stobj v0, R.f%s
348            lda.null
349            movi v15, %s
350            ldobj v0, R.f%s
351            %s v15
352            jeqz success
353            ldai 1
354            return
355          success:
356        cases:
357          # u1
358          - values: [0, 'u1', 0, 'u1', 'ucmp']
359          - values: [1, 'u1', 1, 'u1', 'ucmp']
360          # u8
361          - values: [0, 'u8', 0, 'u8', 'ucmp']
362          - values: [0x000000ff, 'u8', 0x000000ff, 'u8', 'ucmp']
363          - values: [0x000000a5, 'u8', 0x000000a5, 'u8', 'ucmp']
364          # u16
365          - values: [0, 'u16', 0, 'u16', 'ucmp']
366          - values: [0x0000ffff, 'u16', 0x0000ffff, 'u16', 'ucmp']
367          - values: [0x0000a5a5, 'u16', 0x0000a5a5, 'u16', 'ucmp']
368          # u32
369          - values: [0, 'u32', 0, 'u32', 'ucmp']
370          - values: [0xffffffff, 'u32', 0xffffffff, 'u32', 'ucmp']
371          - values: [0xa5a5a5a5, 'u32', 0xa5a5a5a5, 'u32', 'ucmp']
372
373      - file-name: "from_all_field_types_int"
374        description: Version for signed integer types
375        isa:
376          description: >
377            For non-object variant, the size of the field is determined by the field_id,
378            most significant bits are sign or unsigned extended based on the field type to fit accumulator size.
379            If field type is less than 32, then loaded value is sign or zero extended to i32 depending on field type.
380        header-template: ['pandasm_header']
381        check-type: exit-positive
382        tags: ['tsan']
383        code-template: |
384
385          .function i32 main() {
386            initobj.short R.ctor
387            sta.obj v0
388            ldai %s
389            stobj v0, R.f%s
390            lda.null
391            movi v15, %s
392            ldobj v0, R.f%s
393            jeq v15, success
394            ldai 1
395            return
396          success:
397        cases:
398          # i8
399          - values: [0, 'i8', 0, 'i8']
400          - values: [0x000000ff, 'i8', 0xffffffff, 'i8']
401          - values: [0x000000a5, 'i8', 0xffffffa5, 'i8']
402          - values: [0x0000005a, 'i8', 0x0000005a, 'i8']
403          # i16
404          - values: [0, 'i16', 0, 'i16']
405          - values: [0x0000ffff, 'i16', 0xffffffff, 'i16']
406          - values: [0x0000a5a5, 'i16', 0xffffa5a5, 'i16']
407          - values: [0x00005a5a, 'i16', 0x00005a5a, 'i16']
408          # i32
409          - values: [0, 'i32', 0, 'i32']
410          - values: [0xffffffff, 'i32', 0xffffffff, 'i32']
411          - values: [0xa5a5a5a5, 'i32', 0xa5a5a5a5, 'i32']
412          - values: [0x5a5a5a5a, 'i32', 0x5a5a5a5a, 'i32']
413
414      - file-name: "from_float_field_type"
415        description: Check that accumulator value is loaded from field into accumulator. More tests on ldobj can be found in stobj tests
416        isa:
417          instructions:
418            - sig: ldobj v:in:ref, field_id
419              acc: out:b32
420              format: [op_v_8_id_16]
421        header-template: ['pandasm_header']
422        bugid: ['3292']
423        check-type: exit-positive
424        code-template: |
425
426          .function i32 main() {
427            initobj.short R.ctor
428            sta.obj v0
429            %s
430            stobj v0, R.ff32
431            lda.null
432            %s
433            ldobj v0, R.ff32
434            fcmpg v15
435            %s
436            jeqz success
437            ldai 1
438            return
439          success:
440        cases:
441          # f32
442          - values: ['fldai 0.0', 'fmovi v15, 0.0', '']
443          - values: ['fldai -6510615.0', 'fmovi v15, -6510615.0', '']
444          - values: ['fldai 0x7FFFFFFF', 'fmovi v15, 0x7FFFFFFF', 'subi 1']    # NaN
445          - values: ['fldai 0x7f800000', 'fmovi v15, 0x7f800000', '']    # + Inf
446          - values: ['fldai 0xff800000', 'fmovi v15, 0xff800000', '']    # - Inf
447