• 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_obj
16    template: |
17      .record panda.Object <external>
18      .record panda.String <external>
19      .record panda.NullPointerException <external>
20      .record R {}
21
22  - name: java_obj
23    template: |
24      .language Java
25
26      .record java.lang.Class <external>
27      .record java.lang.Object <external>
28      .record java.lang.String <external>
29      .record java.lang.NullPointerException <external>
30
31      .record R <> {}
32      .record I <java.interface> {}
33      .record Q <java.extends=R, java.implements=I> {}
34      .record A <java.annotation, java.annotation.type=runtime> {}
35      .record J <java.interface, java.implements=I> {}
36  - name: java
37    template: |
38      .language Java
39  - name: NPE_p
40    template: |
41      .record panda.NullPointerException <external>
42  - name: NPE_j
43    template: |
44      .language Java
45      .record java.lang.NullPointerException <external>
46
47tests:
48  - file-name: "lenarr"
49    isa:
50      title: Array length
51      description: Get length of an array and put it into accumulator.
52    commands:
53      - file-name: "prim_array"
54        description: Check 'lenarr' returns correct array lenght with array of primitives.
55        isa:
56          instructions:
57            - sig: lenarr v:in:top[]
58              acc: out:i32
59              format: [op_v_8]
60        check-type: none
61        code-template: |
62          #
63              movi v0, *s
64              mov v1, v0
65              newarr %s, v0, %s
66              lenarr %s
67              jne v1, exit_failure
68                ldai 0
69                return
70            exit_failure:
71                ldai 1
72                return
73        template-cases:
74          - values: ['v2', 'u1[]', 'v2']
75          - values: ['v7', 'i8[]', 'v7']
76          - values: ['v15', 'u8[]', 'v15']
77          - values: ['v0', 'f64[]', 'v0']
78        cases:
79          - values: [0]
80          - values: [1]
81          - values: [16]
82          - values: [0x8000]
83          - values: [0x100000]
84
85      - file-name: "ref_array_p"
86        description: Check 'lenarr' returns correct array lenght with array of objects in Panda Assembly context.
87        isa:
88          instructions:
89            - sig: lenarr v:in:top[]
90              acc: out:i32
91              format: [op_v_8]
92        check-type: none
93        header-template: ['pandasm_obj', 'main']
94        code-template: |
95          #
96              movi v0, *s
97              mov v1, v0
98              newarr v0, v0, %s
99              lenarr v0
100              jne v1, exit_failure
101              ldai 0
102              return
103            exit_failure:
104              ldai 1
105              return
106        template-cases:
107          - values: ['u1[][]']
108          - values: ['i8[][][]']
109          - values: ['u8[][][][]']
110          - values: ['i16[][][][][]']
111          - values: ['u16[][][][][][]']
112          - values: ['i32[][][][][][][]']
113          - values: ['u32[][][][][][][][]']
114          - values: ['i64[][][][][][][][][]']
115          - values: ['u64[][][][][][][][][][]']
116          - values: ['f32[][][][][][][][][][][]']
117          - values: ['f64[][][][][][][][][][][][]']
118          - values: ['panda.Object[]']
119          - values: ['panda.Object[][]']
120          - values: ['panda.String[]']
121          - values: ['panda.String[][][]']
122          - values: ['panda.NullPointerException[]']
123          - values: ['panda.NullPointerException[][][][]']
124          - values: ['R[]']
125          - values: ['R[][][][][]']
126        cases:
127          - values: [0]
128          - values: [1]
129          - values: [0x8000]
130          - values: [0x100000]
131
132      - file-name: "npe_p"
133        description: Check 'lenarr' throws NPE when null is passed as argument with Panda Assembly context.
134        isa:
135          instructions:
136            - sig: lenarr v:in:top[]
137              acc: out:i32
138              format: [op_v_8]
139          exceptions:
140            - x_null
141        check-type: none
142        header-template: ['NPE_p', 'main']
143        code-template: |
144          #
145              mov.null %s
146          begin:
147              lenarr %s
148          end:
149              ldai 1 # Should not reach this line
150              return
151
152          catch_NPE:
153              ldai 0 # Expected panda.NullPointerException
154              return
155
156          catch_all:
157              ldai 2 # Unexpected exception, test failed
158              return
159
160          .catch panda.NullPointerException, begin, end, catch_NPE
161          .catchall begin, end, catch_all
162
163        cases:
164          - values: ['v0', 'v0']
165          - values: ['v1', 'v1']
166          - values: ['v128', 'v128']
167          - values: ['v255', 'v255']
168
169      - file-name: "incorrect_reg"
170        description: Check 'lenarr' instruction with incorrect register.
171        isa:
172          instructions:
173            - sig: lenarr v:in:top[]
174              acc: out:i32
175              format: [op_v_8]
176        runner-options: [compile-failure]
177        check-type: none
178        code-template: |
179          #
180              lenarr %s
181        cases:
182          - values: [v256]
183          - values: [v65535]
184          - values: [a0]
185          - values: [a255]
186          - values: [null]
187          - values: [0]
188          - values: [1.1]
189          - values: ['2.2']
190
191      - file-name: "reg_number"
192        isa:
193          instructions:
194            - sig: lenarr v:in:top[]
195              acc: out:i32
196              format: [op_v_8]
197        check-type: none
198        runner-options: [compile-only]
199        description: Check 'lenarr' instruction with correct register number.
200        code-template: |
201          #
202              lenarr %s
203        cases:
204          - values: [v0]
205          - values: [v16]
206          - values: [v128]
207          - values: [v255]
208
209      - file-name: "type"
210        isa:
211            instructions:
212              - sig: lenarr v:in:top[]
213                acc: out:i32
214                format: [op_v_8]
215            verification:
216              - v1_array
217        tags: ['verifier']
218        runner-options: ['verifier-failure', 'verifier-debug-config']
219        header-template: []
220        code-template: |
221          #
222          .record A {}
223          .record panda.String <external>
224          .record panda.Object <external>
225          .function i32 main() {
226              %s
227              lenarr v0
228        check-type: exit-positive
229        description: Check 'lenarr' with incorrect register type.
230        cases:
231          - values:
232              - movi v0, 0
233          - values:
234              - movi.64 v0, 0
235          - values:
236              - fmovi.64 v0, 0
237          - values:
238              - |
239                #
240                    lda.type A
241                    sta.obj v0
242          - values:
243              - |
244                #
245                    lda.type A[]
246                    sta.obj v0
247            bugid: ['2740']
248          - values:
249              - |
250                #
251                    lda.type panda.String
252                    sta.obj v0
253          - values:
254              - |
255                #
256                    lda.type panda.String[]
257                    sta.obj v0
258            bugid: ['2740']
259          - values:
260              - |
261                #
262                    lda.type panda.Object
263                    sta.obj v0
264          - values:
265              - |
266                #
267                    lda.type panda.Object[]
268                    sta.obj v0
269            bugid: ['2740']
270          - values:
271              - |
272                #
273                    lda.str "string"
274                    sta.obj v0
275
276      - file-name: uninitialized_regs
277        isa:
278          instructions:
279            - sig: lenarr v:in:top[]
280              acc: out:i32
281              format: [op_v_8]
282        description: Check 'lenarr' with uninitialized register.
283        tags: ['verifier']
284        runner-options: ['verifier-failure', 'verifier-debug-config']
285        header-template: []
286        code-template: |
287            #
288            .function i32 main() {
289                lenarr %s
290        check-type: exit-positive
291        cases:
292          - values: ['v0']
293          - values: ['v1']
294          - values: ['v128']
295          - values: ['v255']
296