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 R { 22 u1 fu1 <static> 23 u8 fu8 <static> 24 i8 fi8 <static> 25 u16 fu16 <static> 26 i16 fi16 <static> 27 u32 fu32 <static> 28 i32 fi32 <static> 29 u64 fu64 <static> 30 i64 fi64 <static> 31 f32 ff32 <static> 32 f64 ff64 <static> 33 # objects: 34 i32[] fi32Array <static> 35 panda.Object fObj <static> 36 panda.Object[] fObjArray <static> 37 } 38 - name: java_header 39 template: | 40 .language Java 41 42 .record java.lang.Object <external> 43 44 .record R { 45 u1 fu1 <static> 46 i8 fi8 <static> 47 u16 fu16 <static> 48 i16 fi16 <static> 49 i32 fi32 <static> 50 i64 fi64 <static> 51 f32 ff32 <static> 52 f64 ff64 <static> 53 # objects: 54 i32[] fi32Array <static> 55 java.lang.Object fObj <static> 56 java.lang.Object[] fObjArray <static> 57 } 58 59tests: 60 - file-name: "ldstatic" 61 isa: 62 title: Get static field 63 description: > 64 Get static field value by field_id and put it into accumulator. 65 instructions: 66 - sig: ldstatic field_id 67 acc: out:i32 68 format: [op_id_16] 69 commands: 70 71 - file-name: "with_non_static_field_id" 72 description: Check that verifier reports an error if the field doesn't resolve to a static valid field 73 isa: 74 verification: 75 - field_id_static 76 header-template: [] 77 check-type: exit-positive 78 code-template: | 79 .record W { 80 u1 fu1 81 i8 fi8 82 u16 fu16 83 i16 fi16 84 i32 fi32 85 i64 fi64 86 f32 ff32 87 f64 ff64 88 W fW 89 i32[] fi32Array 90 W[] fWArray 91 } 92 .function void W.object_function(W a0) { 93 return.void 94 } 95 .function void static_function() { 96 return.void 97 } 98 99 .function i32 main() { 100 ldstatic %s 101 cases: 102 - values: 103 - W.fu1 104 tags: [verifier] 105 runner-options: ['verifier-failure', 'verifier-debug-config'] 106 bugid: ['1324', '1828'] 107 - values: 108 - W.fi8 109 tags: [verifier] 110 runner-options: ['verifier-failure', 'verifier-debug-config'] 111 bugid: ['1324', '1828'] 112 - values: 113 - W.fu16 114 tags: [verifier] 115 runner-options: ['verifier-failure', 'verifier-debug-config'] 116 bugid: ['1324', '1828'] 117 - values: 118 - W.fi16 119 tags: [verifier] 120 runner-options: ['verifier-failure', 'verifier-debug-config'] 121 bugid: ['1324', '1828'] 122 - values: 123 - W.fi32 124 tags: [verifier] 125 runner-options: ['verifier-failure', 'verifier-debug-config'] 126 bugid: ['1324', '1828'] 127 - values: 128 - W.fi64 129 tags: [verifier] 130 runner-options: ['verifier-failure', 'verifier-debug-config'] 131 bugid: ['1324', '1828'] 132 - values: 133 - W.ff32 134 tags: [verifier] 135 runner-options: ['verifier-failure', 'verifier-debug-config'] 136 bugid: ['1324', '1828'] 137 - values: 138 - W.ff64 139 tags: [verifier] 140 runner-options: ['verifier-failure', 'verifier-debug-config'] 141 bugid: ['1324', '1828'] 142 - values: 143 - W.fW 144 tags: [verifier] 145 runner-options: ['verifier-failure', 'verifier-debug-config'] 146 bugid: ['1324', '1828'] 147 - values: 148 - W.fi32Array 149 tags: [verifier] 150 runner-options: ['verifier-failure', 'verifier-debug-config'] 151 bugid: ['1324', '1828'] 152 - values: 153 - W.fWArray 154 tags: [verifier] 155 runner-options: ['verifier-failure', 'verifier-debug-config'] 156 bugid: ['1324', '1828'] 157 - values: 158 - W 159 runner-options: [compile-failure] 160 - values: 161 - W.object_function 162 runner-options: [compile-failure] 163 - values: 164 - static_function 165 runner-options: [compile-failure] 166 - values: 167 - unknown_function 168 runner-options: [compile-failure] 169 - values: 170 - 0 171 runner-options: [compile-failure] 172 - values: 173 - -1.1 174 runner-options: [compile-failure] 175 - values: 176 - "null" 177 runner-options: [compile-failure] 178 - values: 179 - "\"abc\"" 180 runner-options: [compile-failure] 181 182 183 - file-name: "with_wrong_field_size_p" 184 description: Check that verifier reports an error when the field resolves to a field with size that is not corresponding to bytecode in PandaAssembly context. 185 isa: 186 verification: 187 - field_id_size 188 header-template: [pandasm_header] 189 check-type: exit-positive 190 tags: [verifier] 191 runner-options: ['verifier-failure', 'verifier-debug-config'] 192 bugid: ['1834', '2088'] 193 code-template: | 194 195 .function i32 main() { 196 ldstatic %s 197 cases: 198 - values: 199 - R.fi64 200 - values: 201 - R.fu64 202 - values: 203 - R.ff64 204 - values: 205 - R.fObj 206 - values: 207 - R.fObjArray 208 - values: 209 - R.fi32Array 210 211 212 - file-name: "from_all_field_types_p" 213 description: Check that field value is loaded into accumulator in PandaAssembly context. More tests on ldstatic can be found in ststatic tests. 214 isa: 215 description: > 216 For non-object variant, the size of the field is determined by the field_id, 217 most significant bits are sign or unsigned extended based on the field type to fit accumulator size. 218 If field size is less then 32, result will be sign or unsigned extended to i32 depedning on field type. 219 header-template: [pandasm_header] 220 check-type: exit-positive 221 tags: ['tsan'] 222 code-template: | 223 224 .function i32 main() { 225 ldai %s 226 ststatic R.f%s 227 lda.null 228 movi v15, %s 229 ldstatic R.f%s 230 %s v15 231 jeqz success 232 ldai 1 233 return 234 success: 235 cases: 236 # u1 237 - values: [0, 'u1', 0, 'u1', 'ucmp'] 238 - values: [1, 'u1', 1, 'u1', 'ucmp'] 239 # u8 240 - values: [0, 'u8', 0, 'u8', 'ucmp'] 241 - values: [0x000000ff, 'u8', 0x000000ff, 'u8', 'ucmp'] 242 - values: [0x000000a5, 'u8', 0x000000a5, 'u8', 'ucmp'] 243 # u16 244 - values: [0, 'u16', 0, 'u16', 'ucmp'] 245 - values: [0x0000ffff, 'u16', 0x0000ffff, 'u16', 'ucmp'] 246 - values: [0x0000a5a5, 'u16', 0x0000a5a5, 'u16', 'ucmp'] 247 # u32 248 - values: [0, 'u32', 0, 'u32', 'ucmp'] 249 - values: [0xffffffff, 'u32', 0xffffffff, 'u32', 'ucmp'] 250 - values: [0xa5a5a5a5, 'u32', 0xa5a5a5a5, 'u32', 'ucmp'] 251 252 - file-name: "from_all_field_types_p_int" 253 description: Check that field value is loaded into accumulator in PandaAssembly context. Signed integer types. More tests on ldstatic can be found in ststatic tests. 254 isa: 255 description: > 256 For non-object variant, the size of the field is determined by the field_id, 257 most significant bits are sign or unsigned extended based on the field type to fit accumulator size. 258 If field size is less then 32, result will be sign or unsigned extended to i32 depedning on field type. 259 header-template: [pandasm_header] 260 check-type: exit-positive 261 tags: ['tsan'] 262 code-template: | 263 264 .function i32 main() { 265 ldai %s 266 ststatic R.f%s 267 lda.null 268 movi v15, %s 269 ldstatic R.f%s 270 jeq v15, success 271 ldai 1 272 return 273 success: 274 cases: 275 # i8 276 - values: [0, 'i8', 0, 'i8'] 277 - values: [0x000000ff, 'i8', 0xffffffff, 'i8'] 278 - values: [0x000000a5, 'i8', 0xffffffa5, 'i8'] 279 - values: [0x0000005a, 'i8', 0x0000005a, 'i8'] 280 # i16 281 - values: [0, 'i16', 0, 'i16'] 282 - values: [0x0000ffff, 'i16', 0xffffffff, 'i16'] 283 - values: [0x0000a5a5, 'i16', 0xffffa5a5, 'i16'] 284 - values: [0x00005a5a, 'i16', 0x00005a5a, 'i16'] 285 # i32 286 - values: [0, 'i32', 0, 'i32'] 287 - values: [0xffffffff, 'i32', 0xffffffff, 'i32'] 288 - values: [0xa5a5a5a5, 'i32', 0xa5a5a5a5, 'i32'] 289 - values: [0x5a5a5a5a, 'i32', 0x5a5a5a5a, 'i32'] 290 291 - file-name: "x_init_p" 292 description: Check that ExceptionInInitializerError is thrown if an unexpected exception occurs in static initializer. 293 isa: 294 exceptions: 295 - x_init 296 header-template: [] 297 check-type: empty 298 tags: ['tsan'] 299 bugid: ['5330'] 300 ignore: true 301 code-template: | 302 303 .language PandaAssembly 304 305 .record panda.ExceptionInInitializerError <external> 306 .record panda.NullPointerException <external> 307 .record E1 {} 308 .record R { 309 i32 fi32 <static> 310 } 311 312 .function void R.func() <cctor> { 313 %s 314 return.void 315 } 316 317 .function i32 main() { 318 begin: 319 ldstatic R.fi32 320 ldai 2 321 return 322 end: 323 catch: 324 ldai 0 325 return 326 catch_all: 327 ldai 1 328 return 329 .catch panda.ExceptionInInitializerError, begin, end, catch 330 .catchall begin, end, catch_all 331 } 332 cases: 333 - values: 334 - | 335 # 336 newobj v0, E1 337 throw v0 338 - values: 339 - | 340 # 341 newobj v0, panda.NullPointerException 342 throw v0 343 - values: 344 - | 345 # 346 movi v1, 0 347 ldai 1 348 div2 v1 # divide by zero 349 - values: 350 - | 351 # 352 movi v1, 10 353 newarr v1, v1, i32[] 354 ldai 10 355 ldarr v1 # get ArrayIndexOutOfBoundsException 356 357