1# Copyright (c) 2021-2022 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: PandaAssembly_obj 23 template: | 24 .language PandaAssembly 25 26 .record panda.Class <external> 27 .record panda.Object <external> 28 .record panda.String <external> 29 .record panda.NullPointerException <external> 30 31 .record R <> {} 32 .record I <panda.interface> {} 33 .record Q <panda.extends=R, panda.implements=I> {} 34 .record A <panda.annotation, panda.annotation.type=runtime> {} 35 .record J <panda.interface, panda.implements=I> {} 36 - name: PandaAssembly 37 template: | 38 .language PandaAssembly 39 - name: NPE_p 40 template: | 41 .record panda.NullPointerException <external> 42 - name: NPE_j 43 template: | 44 .language PandaAssembly 45 .record panda.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 length 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 mov.obj %s 67 lenarr %s 68 jne v1, exit_failure 69 ldai 0 70 return 71 exit_failure: 72 ldai 1 73 return 74 template-cases: 75 - values: ['v0', 'u1[]', 'v2, v0', 'v2' ] 76 - values: ['v2', 'i8[]', 'v7, v2', 'v7' ] 77 - values: ['v3', 'u8[]', 'v15, v3', 'v15' ] 78 - values: ['v5', 'i16[]', 'v31, v5', 'v31' ] 79 - values: ['v7', 'u16[]', 'v32, v7', 'v32' ] 80 - values: ['v8', 'i32[]', 'v63, v8', 'v63' ] 81 - values: ['v9', 'u32[]', 'v64, v9', 'v64' ] 82 - values: ['v10', 'i64[]', 'v127, v10', 'v127'] 83 - values: ['v13', 'u64[]', 'v128, v13', 'v128'] 84 - values: ['v14', 'f32[]', 'v255, v14', 'v255'] 85 - values: ['v15', 'f64[]', 'v0, v15', 'v0' ] 86 cases: 87 - values: [0] 88 - values: [1] 89 - values: [16] 90 - values: [0x8000] 91 - values: [0x100000] 92 93 - file-name: "ref_array_p" 94 description: Check 'lenarr' returns correct array length with array of objects in Panda Assembly context. 95 isa: 96 instructions: 97 - sig: lenarr v:in:top[] 98 acc: out:i32 99 format: [op_v_8] 100 check-type: none 101 header-template: ['pandasm_obj', 'main'] 102 code-template: | 103 # 104 movi v0, *s 105 mov v1, v0 106 newarr v0, v0, %s 107 lenarr v0 108 jne v1, exit_failure 109 ldai 0 110 return 111 exit_failure: 112 ldai 1 113 return 114 template-cases: 115 - values: ['u1[][]'] 116 - values: ['i8[][][]'] 117 - values: ['u8[][][][]'] 118 - values: ['i16[][][][][]'] 119 - values: ['u16[][][][][][]'] 120 - values: ['i32[][][][][][][]'] 121 - values: ['u32[][][][][][][][]'] 122 - values: ['i64[][][][][][][][][]'] 123 - values: ['u64[][][][][][][][][][]'] 124 - values: ['f32[][][][][][][][][][][]'] 125 - values: ['f64[][][][][][][][][][][][]'] 126 - values: ['panda.Object[]'] 127 - values: ['panda.Object[][]'] 128 - values: ['panda.String[]'] 129 - values: ['panda.String[][][]'] 130 - values: ['panda.NullPointerException[]'] 131 - values: ['panda.NullPointerException[][][][]'] 132 - values: ['R[]'] 133 - values: ['R[][][][][]'] 134 cases: 135 - values: [0] 136 - values: [1] 137 - values: [0x8000] 138 - values: [0x100000] 139 140 - file-name: "ref_array_j" 141 description: Check 'lenarr' returns correct array length with array of objects in PandaAssembly context. 142 isa: 143 instructions: 144 - sig: lenarr v:in:top[] 145 acc: out:i32 146 format: [op_v_8] 147 check-type: none 148 runner-options: ['use-pa'] 149 header-template: ['PandaAssembly_obj', 'main'] 150 code-template: | 151 # 152 movi v0, *s 153 mov v1, v0 154 newarr v0, v0, %s 155 lenarr v0 156 jne v1, exit_failure 157 ldai 0 158 return 159 exit_failure: 160 ldai 1 161 return 162 template-cases: 163 - values: ['panda.Class[]'] 164 - values: ['panda.Class[][]'] 165 - values: ['panda.Object[]'] 166 - values: ['panda.Object[][][]'] 167 - values: ['panda.String[]'] 168 - values: ['panda.String[][][][]'] 169 - values: ['panda.NullPointerException[]'] 170 - values: ['panda.NullPointerException[][][][][]'] 171 - values: ['R[]'] 172 - values: ['R[][][][][][]'] 173 - values: ['I[]'] 174 - values: ['I[][][][][][][]'] 175 - values: ['Q[]'] 176 - values: ['Q[][][][][][][][]'] 177 - values: ['A[]'] 178 - values: ['A[][][][][][][][][]'] 179 - values: ['J[]'] 180 - values: ['J[][][][][][][][][][]'] 181 cases: 182 - values: [0] 183 - values: [1] 184 - values: [0x8000] 185 - values: [0x100000] 186 187 - file-name: "npe_p" 188 description: Check 'lenarr' throws NPE when null is passed as argument with Panda Assembly context. 189 isa: 190 instructions: 191 - sig: lenarr v:in:top[] 192 acc: out:i32 193 format: [op_v_8] 194 exceptions: 195 - x_null 196 tags: ['irtoc_ignore'] 197 check-type: none 198 header-template: ['NPE_p', 'main'] 199 code-template: | 200 # 201 mov.null %s 202 begin: 203 lenarr %s 204 end: 205 ldai 1 # Should not reach this line 206 return 207 208 catch_NPE: 209 ldai 0 # Expected panda.NullPointerException 210 return 211 212 catch_all: 213 ldai 2 # Unexpected exception, test failed 214 return 215 216 .catch panda.NullPointerException, begin, end, catch_NPE 217 .catchall begin, end, catch_all 218 219 cases: 220 - values: ['v0', 'v0'] 221 - values: ['v1', 'v1'] 222 - values: ['v128', 'v128'] 223 - values: ['v255', 'v255'] 224 225 - file-name: "npe_j" 226 description: Check 'lenarr' throws NPE when null is passed as argument with PandaAssembly context. 227 isa: 228 instructions: 229 - sig: lenarr v:in:top[] 230 acc: out:i32 231 format: [op_v_8] 232 exceptions: 233 - x_null 234 tags: ['irtoc_ignore'] 235 check-type: none 236 runner-options: ['use-pa'] 237 header-template: ['NPE_j', 'main'] 238 code-template: | 239 # 240 mov.null %s 241 begin: 242 lenarr %s 243 end: 244 ldai 1 # Should not reach this line 245 return 246 247 catch_NPE: 248 ldai 0 # Expected panda.NullPointerException 249 return 250 251 catch_all: 252 ldai 2 # Unexpected exception, test failed 253 return 254 255 .catch panda.NullPointerException, begin, end, catch_NPE 256 .catchall begin, end, catch_all 257 258 cases: 259 - values: ['v0', 'v0'] 260 - values: ['v1', 'v1'] 261 - values: ['v128', 'v128'] 262 - values: ['v255', 'v255'] 263 264 - file-name: "incorrect_reg" 265 description: Check 'lenarr' instruction with incorrect register. 266 isa: 267 instructions: 268 - sig: lenarr v:in:top[] 269 acc: out:i32 270 format: [op_v_8] 271 runner-options: [compile-failure] 272 check-type: none 273 code-template: | 274 # 275 lenarr %s 276 cases: 277 - values: [v256] 278 - values: [v65535] 279 - values: [a0] 280 - values: [a255] 281 - values: ['null'] 282 - values: [0] 283 - values: [1.1] 284 - values: ['2.2'] 285 286 - file-name: "reg_number" 287 isa: 288 instructions: 289 - sig: lenarr v:in:top[] 290 acc: out:i32 291 format: [op_v_8] 292 check-type: none 293 runner-options: [compile-only] 294 description: Check 'lenarr' instruction with correct register number. 295 code-template: | 296 # 297 lenarr %s 298 cases: 299 - values: [v0] 300 - values: [v16] 301 - values: [v128] 302 - values: [v255] 303 304 - file-name: "type" 305 isa: 306 instructions: 307 - sig: lenarr v:in:top[] 308 acc: out:i32 309 format: [op_v_8] 310 verification: 311 - v1_array 312 tags: ['verifier'] 313 runner-options: ['verifier-failure', 'verifier-config'] 314 header-template: [] 315 code-template: | 316 # 317 .record A {} 318 .record panda.String <external> 319 .record panda.Object <external> 320 .function i32 main() { 321 %s 322 lenarr v0 323 check-type: exit-positive 324 description: Check 'lenarr' with incorrect register type. 325 cases: 326 - values: 327 - movi v0, 0 328 - values: 329 - movi.64 v0, 0 330 - values: 331 - fmovi v0, 0 332 - values: 333 - fmovi.64 v0, 0 334 - values: 335 - | 336 # 337 lda.type A 338 sta.obj v0 339 - values: 340 - | 341 # 342 lda.type A[] 343 sta.obj v0 344 bugid: ['2740'] 345 - values: 346 - | 347 # 348 lda.type panda.String 349 sta.obj v0 350 - values: 351 - | 352 # 353 lda.type panda.String[] 354 sta.obj v0 355 bugid: ['2740'] 356 - values: 357 - | 358 # 359 lda.type panda.Object 360 sta.obj v0 361 - values: 362 - | 363 # 364 lda.type panda.Object[] 365 sta.obj v0 366 bugid: ['2740'] 367 - values: 368 - | 369 # 370 lda.str "string" 371 sta.obj v0 372 373 - file-name: uninitialized_regs 374 isa: 375 instructions: 376 - sig: lenarr v:in:top[] 377 acc: out:i32 378 format: [op_v_8] 379 description: Check 'lenarr' with uninitialized register. 380 tags: ['verifier'] 381 runner-options: ['verifier-failure', 'verifier-config'] 382 code-template: | 383 # 384 lenarr %s 385 check-type: exit-positive 386 cases: 387 - values: ['v0'] 388 - values: ['v1'] 389 - values: ['v128'] 390 - values: ['v255'] 391