• 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: java_header
16    template: |
17      .language Java
18
19      .record java.lang.Class <external>
20      .record java.lang.Object <external>
21      .record java.lang.String <external>
22      .record java.io.Serializable <external>
23      .record java.lang.NullPointerException <external>
24
25      .record R <> {}
26      .record I <java.interface> {}
27      .record Q <java.extends=R, java.implements=I> {}
28      .record A <java.annotation, java.annotation.type=runtime> {}
29      .record J <java.interface, java.implements=I> {}
30
31  - name: pandasm_header
32    template: |
33      .language PandaAssembly
34
35      .record panda.Class <external>
36      .record panda.Object <external>
37      .record panda.String <external>
38      .record panda.ClassCastException <external>
39
40      .record R {}
41      .record Q {}
42
43
44tests:
45  - file-name: "isinstance"
46    isa:
47      title: Is instance
48      description: >
49        Resolve object type by specified id and if an object in accumulator is an instance of the resolved type,
50        put 1 into accumulator, otherwise put 0.
51        Object of type O is instance of type T if O is the same as T or is subtype of T. For arrays T should be a root
52        type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements.
53      instructions:
54        - sig: isinstance type_id
55          acc: inout:ref->i32
56          format: [op_id_16]
57    commands:
58
59      - file-name: "of_null_pa"
60        description: Check that null object reference is not an instance of any class
61        isa:
62          description: >
63            'null' object is not an instance of any class.
64        header-template: ['pandasm_header']
65        check-type: empty
66        code-template: |
67
68          .function i32 main() {
69            lda.null
70            isinstance %s
71            return
72          }
73        cases:
74          - values: ['panda.Class']
75          - values: ['panda.Object']
76          - values: ['R']
77
78
79      - file-name: "with_wrong_typeid_pa"
80        description: Check that compiler fails when type_id cannot be resolved to object type
81        isa:
82          verification:
83            - type_id_any_object
84        header-template: ['pandasm_header']
85        runner-options: ['compile-failure']
86        check-type: exit-positive
87        code-template: |
88
89          .function i32 main() {
90            %s
91            isinstance %s
92        cases:
93          - values:
94            - lda.null
95            - panda.XYZObj
96          - values:
97            - lda.null
98            - "null"
99          - values:
100            - |
101              newobj v0, panda.Object
102              lda.obj v0
103            - XYZObj
104          - values:
105            - |
106              newobj v0, panda.Object
107              lda.obj v0
108            - "\"xyz\""
109          - values:
110            - |
111              newobj v0, panda.Object
112              lda.obj v0
113            - i32
114          - values:
115            - ldai 1
116            - 1
117          - values:
118            - ldai.64 0xC0BAC0BAC0BA
119            - 0xC0BAC0BAC0BA
120          - values:
121            - fldai.64 2.7182818284590452353603
122            - 2.7182818284590452353603
123
124
125      - file-name: "with_wrong_acc_value_pa"
126        description: Check that verifier fails when accumulator contains wrong value - neither object, nor null
127        isa:
128          verification:
129            - acc_obj_or_null
130        header-template: ['pandasm_header']
131        runner-options: ['verifier-failure', 'verifier-debug-config']
132        tags: ['verifier']
133        check-type: exit-positive
134        code-template: |
135
136          .function i32 main() {
137            %s
138            isinstance %s
139        cases:
140          - values:
141            - ldai 1
142            - panda.Object
143          - values:
144            - ldai.64 0xC0BAC0BAC0BA
145            - panda.Object
146          - values:
147            - fldai.64 2.7182818284590452353603
148            - panda.Object
149
150
151      - file-name: "when_1_is_expected_pa"
152        description: Check that the instruction sets accumulator to 1 when expected
153        isa:
154          description: >
155            Resolve object type by specified id and if an object in accumulator is an instance of the resolved type,
156            put 1 into accumulator, otherwise put 0.
157            Object of type O is instance of type T if O is the same as T or is subtype of T. For arrays T should be a root
158            type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements.
159        header-template: ['pandasm_header']
160        check-type: empty
161        tags: ['tsan']
162        code-template: |
163
164          .function i32 main() {
165            %s
166            isinstance %s
167            subi 1
168            return
169          }
170        cases:
171          # O has a type of T
172          - values:
173            - |
174              # O and T are of the same type, std object
175                newobj v0, panda.Object
176                lda.obj v0
177            - panda.Object
178          - values:
179            - |
180              # O and T are of the same type, custom object
181                newobj v0, R
182                lda.obj v0
183            - R
184          - values:
185            - |
186              # O and T are of the same type, string
187                lda.str "xyz"
188            - panda.String
189          - values:
190            - |
191              # O and T are of the same type, type
192                lda.type R
193            - panda.Class
194          # O is a subtype of T
195          - values:
196            - |
197              # O is a subtype of T, std object
198                newobj v0, panda.ClassCastException
199                lda.obj v0
200            - panda.Object
201          - values:
202            - |
203              # O is a subtype of T, custom object
204                newobj v0, R
205                lda.obj v0
206            - panda.Object
207          - values:
208            - |
209              # O is a subtype of T, string
210                lda.str "xyz"
211            - panda.Object
212          - values:
213            - |
214              # O is a subtype of T, type
215                lda.type R
216            - panda.Object
217          # O[] has a type of T[]
218          - values:
219            - |
220              # O and T are of the same type, both arrays, std object
221                movi v0, 10
222                newarr v0, v0, panda.Object[]
223                lda.obj v0
224            - panda.Object[]
225            bugid: ["1805"]
226          - values:
227            - |
228              # O and T are of the same type, both arrays, custom object
229                movi v0, 10
230                newarr v0, v0, R[]
231                lda.obj v0
232            - R[]
233            bugid: ["1805"]
234          - values:
235            - |
236              # O and T are of the same type, both arrays, string
237                movi v0, 10
238                newarr v0, v0, panda.String[]
239                lda.obj v0
240            - panda.String[]
241            bugid: ["1805"]
242          # O[] is a subtype of T[]
243          - values:
244            - |
245              # O is a subtype of T, both arrays, std object
246                movi v0, 10
247                newarr v0, v0, panda.ClassCastException[]
248                lda.obj v0
249            - panda.Object[]
250            bugid: ["1805"]
251          - values:
252            - |
253              # O is a subtype of T, both arrays, custom object
254                movi v0, 10
255                newarr v0, v0, R[]
256                lda.obj v0
257            - panda.Object[]
258            bugid: ["1805"]
259          # T is a root type for O[]
260          - values:
261            - |
262              # T is a root type for O[], std object
263                movi v0, 10
264                newarr v0, v0, panda.ClassCastException[]
265                lda.obj v0
266            - panda.Object
267          - values:
268            - |
269              # T is a root type for O[], custom object
270                movi v0, 10
271                newarr v0, v0, R[]
272                lda.obj v0
273            - panda.Object
274
275
276      - file-name: "when_0_is_expected_pa"
277        description: Check that the instruction sets accumulator to 0 when expected
278        isa:
279          description: >
280            Resolve object type by specified id and if an object in accumulator is an instance of the resolved type,
281            put 1 into accumulator, otherwise put 0.
282            Object of type O is instance of type T if O is the same as T or is subtype of T. For arrays T should be a root
283            type in type hierarchy or T is such array that O array elements are the same or subtype of T array elements.
284        header-template: ['pandasm_header']
285        check-type: empty
286        code-template: |
287
288          .function i32 main() {
289            %s
290            isinstance %s
291            return
292          }
293        cases:
294          # O is not related to T
295          - values:
296            - |
297              # O and T are of unrelated types, std object
298                newobj v0, panda.ClassCastException
299                lda.obj v0
300            - R
301          - values:
302            - |
303              # O and T are of unrelated types, custom object
304                newobj v0, R
305                lda.obj v0
306            - Q
307          - values:
308            - |
309              # O and T are of unrelated types, string
310                lda.str "xyz"
311            - R
312          - values:
313            - |
314              # O and T are of unrelated types, type
315                lda.type R
316            - panda.ClassCastException
317          # O is a supertype of T
318          - values:
319            - |
320              # O is a supertype of T, std object
321                newobj v0, panda.Object
322                lda.obj v0
323            - panda.ClassCastException
324          - values:
325            - |
326              # O is a supertype of T, custom object
327                newobj v0, panda.Object
328                lda.obj v0
329            - R
330          # O[] is not related to T[]
331          - values:
332            - |
333              # O and T are of unrelated types, both arrays, std object
334                movi v0, 10
335                newarr v0, v0, panda.ClassCastException[]
336                lda.obj v0
337            - R[]
338            bugid: ["1805"]
339          - values:
340            - |
341              # O and T are of unrelated types, both arrays, custom object
342                movi v0, 10
343                newarr v0, v0, R[]
344                lda.obj v0
345            - Q[]
346            bugid: ["1805"]
347          # O[] is a supertype of T[]
348          - values:
349            - |
350              # O is a supertype of T, both arrays, std object
351                movi v0, 10
352                newarr v0, v0, panda.Object[]
353                lda.obj v0
354            - panda.ClassCastException[]
355            bugid: ["1805"]
356          - values:
357            - |
358              # O is a supertype of T, both arrays, custom object
359                movi v0, 10
360                newarr v0, v0, panda.Object[]
361                lda.obj v0
362            - R[]
363            bugid: ["1805"]
364          # T is not a root type for O[]
365          - values:
366            - |
367              # T is a not a root type for O[], std object
368                movi v0, 10
369                newarr v0, v0, panda.ClassCastException[]
370                lda.obj v0
371            - panda.String
372          - values:
373            - |
374              # T is a not a root type for O[], custom object
375                movi v0, 10
376                newarr v0, v0, R[]
377                lda.obj v0
378            - panda.ClassCastException
379
380
381      - file-name: "with_nodef_typeid_pa"
382        description: Check that NoClassDefFoundError is thrown when expected
383        isa:
384          exceptions:
385            - x_classdef
386        header-template: ['pandasm_header']
387        check-type: empty
388        bugid: ['5385']
389        ignore: true
390        code-template: |
391          .record panda.NoClassDefFoundError <external>
392          .record panda.XYZObj <external>
393
394          .function i32 main() {
395          begin:
396            %s
397            isinstance %s
398            ldai 1
399            return
400          end:
401          catch_NCDFE:
402            ldai 0
403            return
404          catch_all:
405            ldai 2
406            return
407          .catch panda.NoClassDefFoundError, begin, end, catch_NCDFE
408          .catchall begin, end, catch_all
409          }
410        cases:
411          - values:
412            - lda.null
413            - panda.XYZObj
414          - values:
415            - lda.null
416            - panda.XYZObj[]
417          - values:
418            - |
419              #
420                newobj v0, panda.Object
421                lda.obj v0
422            - panda.XYZObj
423          - values:
424            - |
425              #
426                movi v0, 10
427                newarr v0, v0, panda.Object
428                lda.obj v0
429            - panda.XYZObj[]
430
431