OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/wasm/module-decoder.h" | 7 #include "src/wasm/module-decoder.h" |
8 #include "src/wasm/wasm-opcodes.h" | 8 #include "src/wasm/wasm-opcodes.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 EXPECT_EQ(1, result.val->functions->size()); | 335 EXPECT_EQ(1, result.val->functions->size()); |
336 EXPECT_EQ(0, result.val->data_segments->size()); | 336 EXPECT_EQ(0, result.val->data_segments->size()); |
337 EXPECT_EQ(0, result.val->function_table->size()); | 337 EXPECT_EQ(0, result.val->function_table->size()); |
338 | 338 |
339 WasmFunction* function = &result.val->functions->back(); | 339 WasmFunction* function = &result.val->functions->back(); |
340 | 340 |
341 EXPECT_EQ(9, function->name_offset); | 341 EXPECT_EQ(9, function->name_offset); |
342 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 342 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
343 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 343 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
344 | 344 |
345 EXPECT_EQ(523, function->local_int32_count); | 345 EXPECT_EQ(523, function->local_i32_count); |
346 EXPECT_EQ(1037, function->local_int64_count); | 346 EXPECT_EQ(1037, function->local_i64_count); |
347 EXPECT_EQ(1551, function->local_float32_count); | 347 EXPECT_EQ(1551, function->local_f32_count); |
348 EXPECT_EQ(2065, function->local_float64_count); | 348 EXPECT_EQ(2065, function->local_f64_count); |
349 | 349 |
350 EXPECT_TRUE(function->exported); | 350 EXPECT_TRUE(function->exported); |
351 EXPECT_FALSE(function->external); | 351 EXPECT_FALSE(function->external); |
352 | 352 |
353 if (result.val) delete result.val; | 353 if (result.val) delete result.val; |
354 } | 354 } |
355 | 355 |
356 for (size_t size = 5; size < arraysize(data); size++) { | 356 for (size_t size = 5; size < arraysize(data); size++) { |
357 // Should fall off end of module bytes. | 357 // Should fall off end of module bytes. |
358 ModuleResult result = DecodeModule(data, data + size); | 358 ModuleResult result = DecodeModule(data, data + size); |
(...skipping 16 matching lines...) Expand all Loading... |
375 | 375 |
376 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 376 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
377 EXPECT_TRUE(result.ok()); | 377 EXPECT_TRUE(result.ok()); |
378 EXPECT_EQ(1, result.val->functions->size()); | 378 EXPECT_EQ(1, result.val->functions->size()); |
379 WasmFunction* function = &result.val->functions->back(); | 379 WasmFunction* function = &result.val->functions->back(); |
380 | 380 |
381 EXPECT_EQ(0, function->name_offset); | 381 EXPECT_EQ(0, function->name_offset); |
382 EXPECT_EQ(0, function->code_start_offset); | 382 EXPECT_EQ(0, function->code_start_offset); |
383 EXPECT_EQ(0, function->code_end_offset); | 383 EXPECT_EQ(0, function->code_end_offset); |
384 | 384 |
385 EXPECT_EQ(0, function->local_int32_count); | 385 EXPECT_EQ(0, function->local_i32_count); |
386 EXPECT_EQ(0, function->local_int64_count); | 386 EXPECT_EQ(0, function->local_i64_count); |
387 EXPECT_EQ(0, function->local_float32_count); | 387 EXPECT_EQ(0, function->local_f32_count); |
388 EXPECT_EQ(0, function->local_float64_count); | 388 EXPECT_EQ(0, function->local_f64_count); |
389 | 389 |
390 EXPECT_FALSE(function->exported); | 390 EXPECT_FALSE(function->exported); |
391 EXPECT_TRUE(function->external); | 391 EXPECT_TRUE(function->external); |
392 | 392 |
393 if (result.val) delete result.val; | 393 if (result.val) delete result.val; |
394 } | 394 } |
395 | 395 |
396 | 396 |
397 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) { | 397 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) { |
398 static const byte kCodeStartOffset = 11; | 398 static const byte kCodeStartOffset = 11; |
(...skipping 13 matching lines...) Expand all Loading... |
412 | 412 |
413 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 413 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
414 EXPECT_TRUE(result.ok()); | 414 EXPECT_TRUE(result.ok()); |
415 EXPECT_EQ(1, result.val->functions->size()); | 415 EXPECT_EQ(1, result.val->functions->size()); |
416 WasmFunction* function = &result.val->functions->back(); | 416 WasmFunction* function = &result.val->functions->back(); |
417 | 417 |
418 EXPECT_EQ(0, function->name_offset); | 418 EXPECT_EQ(0, function->name_offset); |
419 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 419 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
420 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 420 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
421 | 421 |
422 EXPECT_EQ(0, function->local_int32_count); | 422 EXPECT_EQ(0, function->local_i32_count); |
423 EXPECT_EQ(0, function->local_int64_count); | 423 EXPECT_EQ(0, function->local_i64_count); |
424 EXPECT_EQ(0, function->local_float32_count); | 424 EXPECT_EQ(0, function->local_f32_count); |
425 EXPECT_EQ(0, function->local_float64_count); | 425 EXPECT_EQ(0, function->local_f64_count); |
426 | 426 |
427 EXPECT_FALSE(function->exported); | 427 EXPECT_FALSE(function->exported); |
428 EXPECT_FALSE(function->external); | 428 EXPECT_FALSE(function->external); |
429 | 429 |
430 if (result.val) delete result.val; | 430 if (result.val) delete result.val; |
431 } | 431 } |
432 | 432 |
433 | 433 |
434 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) { | 434 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) { |
435 static const byte kCodeStartOffset = 19; | 435 static const byte kCodeStartOffset = 19; |
(...skipping 16 matching lines...) Expand all Loading... |
452 | 452 |
453 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 453 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
454 EXPECT_TRUE(result.ok()); | 454 EXPECT_TRUE(result.ok()); |
455 EXPECT_EQ(1, result.val->functions->size()); | 455 EXPECT_EQ(1, result.val->functions->size()); |
456 WasmFunction* function = &result.val->functions->back(); | 456 WasmFunction* function = &result.val->functions->back(); |
457 | 457 |
458 EXPECT_EQ(0, function->name_offset); | 458 EXPECT_EQ(0, function->name_offset); |
459 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 459 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
460 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 460 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
461 | 461 |
462 EXPECT_EQ(513, function->local_int32_count); | 462 EXPECT_EQ(513, function->local_i32_count); |
463 EXPECT_EQ(1027, function->local_int64_count); | 463 EXPECT_EQ(1027, function->local_i64_count); |
464 EXPECT_EQ(1541, function->local_float32_count); | 464 EXPECT_EQ(1541, function->local_f32_count); |
465 EXPECT_EQ(2055, function->local_float64_count); | 465 EXPECT_EQ(2055, function->local_f64_count); |
466 | 466 |
467 EXPECT_FALSE(function->exported); | 467 EXPECT_FALSE(function->exported); |
468 EXPECT_FALSE(function->external); | 468 EXPECT_FALSE(function->external); |
469 | 469 |
470 if (result.val) delete result.val; | 470 if (result.val) delete result.val; |
471 } | 471 } |
472 | 472 |
473 | 473 |
474 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { | 474 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { |
475 static const byte kDeclMemorySize = 4; | 475 static const byte kDeclMemorySize = 4; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 data + arraysize(data)); | 917 data + arraysize(data)); |
918 EXPECT_TRUE(result.ok()); | 918 EXPECT_TRUE(result.ok()); |
919 | 919 |
920 if (result.val && result.ok()) { | 920 if (result.val && result.ok()) { |
921 WasmFunction* function = result.val; | 921 WasmFunction* function = result.val; |
922 EXPECT_EQ(0, function->sig->parameter_count()); | 922 EXPECT_EQ(0, function->sig->parameter_count()); |
923 EXPECT_EQ(0, function->sig->return_count()); | 923 EXPECT_EQ(0, function->sig->return_count()); |
924 EXPECT_EQ(0, function->name_offset); | 924 EXPECT_EQ(0, function->name_offset); |
925 EXPECT_EQ(arraysize(data) - 1, function->code_start_offset); | 925 EXPECT_EQ(arraysize(data) - 1, function->code_start_offset); |
926 EXPECT_EQ(arraysize(data), function->code_end_offset); | 926 EXPECT_EQ(arraysize(data), function->code_end_offset); |
927 EXPECT_EQ(3, function->local_int32_count); | 927 EXPECT_EQ(3, function->local_i32_count); |
928 EXPECT_EQ(4, function->local_int64_count); | 928 EXPECT_EQ(4, function->local_i64_count); |
929 EXPECT_EQ(5, function->local_float32_count); | 929 EXPECT_EQ(5, function->local_f32_count); |
930 EXPECT_EQ(6, function->local_float64_count); | 930 EXPECT_EQ(6, function->local_f64_count); |
931 EXPECT_FALSE(function->external); | 931 EXPECT_FALSE(function->external); |
932 EXPECT_FALSE(function->exported); | 932 EXPECT_FALSE(function->exported); |
933 } | 933 } |
934 | 934 |
935 if (result.val) delete result.val; | 935 if (result.val) delete result.val; |
936 } | 936 } |
937 | 937 |
938 | 938 |
939 TEST_F(WasmModuleVerifyTest, WLLSectionNoLen) { | 939 TEST_F(WasmModuleVerifyTest, WLLSectionNoLen) { |
940 const byte data[] = { | 940 const byte data[] = { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 kDeclWLL, | 1004 kDeclWLL, |
1005 0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa | 1005 0xfa, 0xff, 0xff, 0xff, 0x0f, // LEB128 0xfffffffa |
1006 1, 2, 3, 4, // 4 byte section | 1006 1, 2, 3, 4, // 4 byte section |
1007 }; | 1007 }; |
1008 EXPECT_FAILURE(data); | 1008 EXPECT_FAILURE(data); |
1009 } | 1009 } |
1010 | 1010 |
1011 } // namespace wasm | 1011 } // namespace wasm |
1012 } // namespace internal | 1012 } // namespace internal |
1013 } // namespace v8 | 1013 } // namespace v8 |
OLD | NEW |