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_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 <static> 28 u8 fu8 <static> 29 i8 fi8 <static> 30 u16 fu16 <static> 31 i16 fi16 <static> 32 u32 fu32 <static> 33 i32 fi32 <static> 34 u64 fu64 <static> 35 i64 fi64 <static> 36 f32 ff32 <static> 37 f64 ff64 <static> 38 # objects: 39 i32[] fi32Array <static> 40 Q fQ <static> 41 Q[] fQArray <static> 42 panda.Object fObj <static> 43 panda.Object[] fObjArray <static> 44 } 45 46tests: 47 - file-name: "ststatic" 48 isa: 49 title: Store to static field 50 description: > 51 Store accumulator content into static field by field_id. For non-object variant the size of actually stored 52 value is determined by field_id, other accumulator bits are discarded. 53 instructions: 54 - sig: ststatic field_id 55 acc: in:b32 56 format: [op_id_16] 57 commands: 58 59 - file-name: "check_if_acc_initialized" 60 description: Check that verifier reports an error if accumulator is not initialized 61 isa: 62 description: Store accumulator content into static field by field_id. 63 header-template: ['pandasm_header'] 64 check-type: exit-positive 65 tags: ['verifier'] 66 bugid: ['1324'] 67 runner-options: ['verifier-failure', 'verifier-config'] 68 code-template: | 69 70 .function i32 main() { 71 # acc (value) not initialized, verifier error expected 72 ststatic R.fi32 73 74 75 - file-name: "with_non_static_field_id" 76 description: Check that verifier reports an error if the field_id doesn't resolve to a static valid field 77 isa: 78 verification: 79 - field_id_static 80 header-template: [] 81 check-type: exit-positive 82 code-template: | 83 .record W { 84 u1 fu1 85 i8 fi8 86 u16 fu16 87 i16 fi16 88 i32 fi32 89 i64 fi64 90 f32 ff32 91 f64 ff64 92 W fW 93 i32[] fi32Array 94 W[] fWArray 95 } 96 .function void W.object_function(W a0) { 97 return.void 98 } 99 .function void static_function() { 100 return.void 101 } 102 103 .function i32 main() { 104 ldai 1 105 ststatic %s 106 cases: 107 - values: 108 - W.fu1 109 tags: [verifier] 110 runner-options: ['verifier-failure', 'verifier-config'] 111 bugid: ['1324', '1828'] 112 - values: 113 - W.fi8 114 tags: [verifier] 115 runner-options: ['verifier-failure', 'verifier-config'] 116 bugid: ['1324', '1828'] 117 - values: 118 - W.fu16 119 tags: [verifier] 120 runner-options: ['verifier-failure', 'verifier-config'] 121 bugid: ['1324', '1828'] 122 - values: 123 - W.fi16 124 tags: [verifier] 125 runner-options: ['verifier-failure', 'verifier-config'] 126 bugid: ['1324', '1828'] 127 - values: 128 - W.fi32 129 tags: [verifier] 130 runner-options: ['verifier-failure', 'verifier-config'] 131 bugid: ['1324', '1828'] 132 - values: 133 - W.fi64 134 tags: [verifier] 135 runner-options: ['verifier-failure', 'verifier-config'] 136 bugid: ['1324', '1828'] 137 - values: 138 - W.ff32 139 tags: [verifier] 140 runner-options: ['verifier-failure', 'verifier-config'] 141 bugid: ['1324', '1828'] 142 - values: 143 - W.ff64 144 tags: [verifier] 145 runner-options: ['verifier-failure', 'verifier-config'] 146 bugid: ['1324', '1828'] 147 - values: 148 - W.fW 149 tags: [verifier] 150 runner-options: ['verifier-failure', 'verifier-config'] 151 bugid: ['1324', '1828'] 152 - values: 153 - W.fi32Array 154 tags: [verifier] 155 runner-options: ['verifier-failure', 'verifier-config'] 156 bugid: ['1324', '1828'] 157 - values: 158 - W.fWArray 159 tags: [verifier] 160 runner-options: ['verifier-failure', 'verifier-config'] 161 bugid: ['1324', '1828'] 162 - values: 163 - W 164 runner-options: ['compile-failure'] 165 - values: 166 - W.object_function 167 runner-options: ['compile-failure'] 168 - values: 169 - static_function 170 runner-options: ['compile-failure'] 171 - values: 172 - unknown_function 173 runner-options: ['compile-failure'] 174 - values: 175 - 0 176 runner-options: ['compile-failure'] 177 - values: 178 - -1.1 179 runner-options: ['compile-failure'] 180 - values: 181 - "null" 182 runner-options: ['compile-failure'] 183 - values: 184 - "\"abc\"" 185 runner-options: ['compile-failure'] 186 187 188 - file-name: "with_wrong_field_size" 189 description: Check that verifier reports an error when the field_id resolves to a field with size that is not corresponding to bytecode 190 isa: 191 verification: 192 - field_id_size 193 header-template: ['pandasm_header'] 194 check-type: exit-positive 195 tags: ['verifier'] 196 runner-options: ['verifier-failure', 'verifier-config'] 197 bugid: ['1834'] 198 code-template: | 199 200 .function i32 main() { 201 %s 202 ststatic *s 203 template-cases: 204 - values: 205 - ldai 0 206 - values: 207 - fldai 0 208 cases: 209 - values: 210 - R.fi64 211 - values: 212 - R.fu64 213 - values: 214 - R.ff64 215 - values: 216 - R.fObj 217 - values: 218 - R.fObjArray 219 - values: 220 - R.fi32Array 221 222 223 - file-name: "with_wrong_acc_type" 224 description: Check that verifier reports an error when the accumulator contains a value of type not corresponding to the bytecode 225 isa: 226 verification: 227 - acc_type 228 header-template: ['pandasm_header'] 229 check-type: exit-positive 230 tags: ['verifier'] 231 runner-options: ['verifier-failure', 'verifier-config'] 232 code-template: | 233 .function i32 main() { 234 *s 235 ststatic %s 236 cases: 237 - values: 238 - ldai 1 239 id: i32 240 - values: 241 - fldai 1.1 242 id: f32 243 - values: 244 - ldai.64 0xF000F000F000F000 245 bugid: ['4166'] 246 - values: 247 - fldai.64 1.1 248 - values: 249 - lda.null 250 - values: 251 - lda.str "abc" 252 - values: 253 - | 254 # 255 movi v1, 10 256 newarr v1, v1, i32[] 257 lda.obj v1 258 template-cases: 259 - values: 260 - R.fu1 261 exclude: [i32] 262 - values: 263 - R.fi8 264 exclude: [i32] 265 - values: 266 - R.fu8 267 exclude: [i32] 268 - values: 269 - R.fi16 270 exclude: [i32] 271 - values: 272 - R.fu16 273 exclude: [i32] 274 - values: 275 - R.fi32 276 exclude: [i32] 277 - values: 278 - R.fu32 279 exclude: [i32] 280 - values: 281 - R.ff32 282 exclude: [f32] 283 bugid: ['6094'] 284 285 286 - file-name: "into_all_field_types" 287 description: Check that accumulator value is properly stored in field 288 isa: 289 description: If field type size is less than 32, then accumulator content will be trunctated to field size before storing. 290 header-template: ['pandasm_header'] 291 check-type: exit-positive 292 tags: ['tsan', 'irtoc_ignore'] 293 code-template: | 294 295 .function i32 main() { 296 %s 297 ststatic R.%s 298 lda.null 299 ldstatic R.%s 300 %s v1, %s 301 %s v1 302 %s 303 jeqz success 304 ldai 1 305 return 306 success: 307 cases: 308 # u1 309 - values: ['ldai 0x00000000', 'fu1', 'fu1', 'movi', 0, 'ucmp', ''] 310 - values: ['ldai 0xffffffff', 'fu1', 'fu1', 'movi', 1, 'ucmp', ''] 311 bugid: ['1848'] 312 ignore: true 313 - values: ['ldai 0x00000001', 'fu1', 'fu1', 'movi', 1, 'ucmp', ''] 314 - values: ['ldai 0xfffffffe', 'fu1', 'fu1', 'movi', 0, 'ucmp', ''] 315 bugid: ['1848'] 316 ignore: true 317 - values: ['ldai 0x11111111', 'fu1', 'fu1', 'movi', 1, 'ucmp', ''] 318 bugid: ['1848'] 319 ignore: true 320 - values: ['ldai 0x88888888', 'fu1', 'fu1', 'movi', 0, 'ucmp', ''] 321 bugid: ['1848'] 322 ignore: true 323 # u8 324 - values: ['ldai 0x00000000', 'fu8', 'fu8', 'movi', 0, 'ucmp', ''] 325 - values: ['ldai 0xffffffff', 'fu8', 'fu8', 'movi', 255, 'ucmp', ''] 326 - values: ['ldai 0x000000ff', 'fu8', 'fu8', 'movi', 255, 'ucmp', ''] 327 - values: ['ldai 0xffffff00', 'fu8', 'fu8', 'movi', 0, 'ucmp', ''] 328 - values: ['ldai 0x11111111', 'fu8', 'fu8', 'movi', 17, 'ucmp', ''] 329 - values: ['ldai 0x88888888', 'fu8', 'fu8', 'movi', 136, 'ucmp', ''] 330 # u16 331 - values: ['ldai 0x00000000', 'fu16', 'fu16', 'movi', 0, 'ucmp', ''] 332 - values: ['ldai 0xffffffff', 'fu16', 'fu16', 'movi', 65535, 'ucmp', ''] 333 - values: ['ldai 0x0000ffff', 'fu16', 'fu16', 'movi', 65535, 'ucmp', ''] 334 - values: ['ldai 0xffff0000', 'fu16', 'fu16', 'movi', 0, 'ucmp', ''] 335 - values: ['ldai 0x11111111', 'fu16', 'fu16', 'movi', 4369, 'ucmp', ''] 336 - values: ['ldai 0x88888888', 'fu16', 'fu16', 'movi', 34952, 'ucmp', ''] 337 # u32 338 - values: ['ldai 0x00000000', 'fu32', 'fu32', 'movi', 0, 'ucmp', ''] 339 - values: ['ldai 0xffffffff', 'fu32', 'fu32', 'movi', 4294967295, 'ucmp', ''] 340 - values: ['ldai 0x11111111', 'fu32', 'fu32', 'movi', 286331153, 'ucmp', ''] 341 - values: ['ldai 0x88888888', 'fu32', 'fu32', 'movi', 2290649224, 'ucmp', ''] 342 # f32 343 - values: ['fldai 0.0', 'ff32', 'ff32', 'fmovi', 0.0, 'fcmpg', ''] 344 - values: ['fldai -6510615.0', 'ff32', 'ff32', 'fmovi', -6510615.0, 'fcmpg', ''] 345 - values: ['fldai 0x7fffffff', 'ff32', 'ff32', 'fmovi', 0, 'fcmpg', 'subi 1'] 346 - values: ['fldai 0x7f800000', 'ff32', 'ff32', 'fmovi', '0x7f800000', 'fcmpg', ''] 347 - values: ['fldai 0xff800000', 'ff32', 'ff32', 'fmovi', '0xff800000', 'fcmpg', ''] 348 349 - file-name: "into_all_field_types_int" 350 description: Version for signed integer types 351 isa: 352 description: If field type size is less than 32, then accumulator content will be trunctated to field size before storing. 353 header-template: ['pandasm_header'] 354 check-type: exit-positive 355 tags: ['tsan', 'irtoc_ignore'] 356 code-template: | 357 358 .function i32 main() { 359 %s 360 ststatic R.%s 361 lda.null 362 ldstatic R.%s 363 movi v1, %s 364 jeq v1, success 365 ldai 1 366 return 367 success: 368 cases: 369 # i8 370 - values: ['ldai 0x00000000', 'fi8', 'fi8', 0] 371 - values: ['ldai 0xffffffff', 'fi8', 'fi8', -1] 372 - values: ['ldai 0x000000ff', 'fi8', 'fi8', -1] 373 - values: ['ldai 0xffffff00', 'fi8', 'fi8', 0] 374 - values: ['ldai 0x11111111', 'fi8', 'fi8', 17] 375 - values: ['ldai 0x88888888', 'fi8', 'fi8', -120] 376 # i16 377 - values: ['ldai 0x00000000', 'fi16', 'fi16', 0] 378 - values: ['ldai 0xffffffff', 'fi16', 'fi16', -1] 379 - values: ['ldai 0x0000ffff', 'fi16', 'fi16', -1] 380 - values: ['ldai 0xffff0000', 'fi16', 'fi16', 0] 381 - values: ['ldai 0x11111111', 'fi16', 'fi16', 4369] 382 - values: ['ldai 0x88888888', 'fi16', 'fi16', -30584] 383 # i32 384 - values: ['ldai 0x00000000', 'fi32', 'fi32', 0] 385 - values: ['ldai 0xffffffff', 'fi32', 'fi32', -1] 386 - values: ['ldai 0x11111111', 'fi32', 'fi32', 286331153] 387 - values: ['ldai 0x88888888', 'fi32', 'fi32', -2004318072] 388 389 - file-name: "x_init_p" 390 description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer. 391 isa: 392 exceptions: 393 - x_init 394 header-template: [] 395 check-type: empty 396 tags: ['tsan', 'irtoc_ignore'] 397 bugid: ['5330'] 398 code-template: | 399 400 .language PandaAssembly 401 402 .record panda.ExceptionInInitializerError <external> 403 .record panda.NullPointerException <external> 404 .record E1 {} 405 .record R { 406 i32 fi32 <static> 407 } 408 409 .function void R.func() <cctor> { 410 %s 411 return.void 412 } 413 414 .function i32 main() { 415 begin: 416 ldai 123 417 ststatic R.fi32 418 ldai 2 419 return 420 end: 421 catch: 422 ldai 0 423 return 424 catch_all: 425 ldai 1 426 return 427 .catch panda.ExceptionInInitializerError, begin, end, catch 428 .catchall begin, end, catch_all 429 } 430 cases: 431 - values: 432 - | 433 # 434 newobj v0, E1 435 throw v0 436 - values: 437 - | 438 # 439 newobj v0, panda.NullPointerException 440 throw v0 441 - values: 442 - | 443 # 444 movi v1, 0 445 ldai 1 446 div2 v1 # divide by zero 447 - values: 448 - | 449 # 450 movi v1, 10 451 newarr v1, v1, i32[] 452 ldai 10 453 ldarr v1 # get ArrayIndexOutOfBoundsException 454 455 - file-name: "x_init_j" 456 description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer. 457 isa: 458 exceptions: 459 - x_init 460 header-template: [] 461 check-type: empty 462 tags: ['tsan', 'irtoc_ignore'] 463 runner-options: ['use-pa'] 464 code-template: | 465 466 .language PandaAssembly 467 468 .record panda.ExceptionInInitializerError <external> 469 .record panda.NullPointerException <external> 470 .record E1 {} 471 .record R { 472 i32 fi32 <static> 473 } 474 .record Q <panda.extends=R> { 475 i32 fi32 <static> 476 } 477 .function void R.func() <cctor> { 478 %s 479 return.void 480 } 481 482 .function i32 main() { 483 begin: 484 ldai 123 485 ststatic Q.fi32 486 ldai 2 487 return 488 end: 489 catch: 490 ldai 0 491 return 492 catch_all: 493 ldai 1 494 return 495 .catch panda.ExceptionInInitializerError, begin, end, catch 496 .catchall begin, end, catch_all 497 } 498 cases: 499 - values: 500 - | 501 # 502 newobj v0, E1 503 throw v0 504 - values: 505 - | 506 # 507 newobj v0, panda.NullPointerException 508 throw v0 509 - values: 510 - | 511 # 512 movi v1, 0 513 ldai 1 514 div2 v1 # divide by zero 515 - values: 516 - | 517 # 518 movi v1, 10 519 newarr v1, v1, i32[] 520 ldai 10 521 ldarr v1 # get ArrayIndexOutOfBoundsException 522