Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: test/unittests/value-serializer-unittest.cc

Issue 2630553002: [wasm] Enforce that function bodies end with the \"end\" opcode. (Closed)
Patch Set: Collapse some tests together Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 "src/value-serializer.h" 5 #include "src/value-serializer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "include/v8.h" 10 #include "include/v8.h"
(...skipping 2421 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 2432
2433 private: 2433 private:
2434 static bool g_saved_flag; 2434 static bool g_saved_flag;
2435 }; 2435 };
2436 2436
2437 bool ValueSerializerTestWithWasm::g_saved_flag = false; 2437 bool ValueSerializerTestWithWasm::g_saved_flag = false;
2438 2438
2439 // A simple module which exports an "increment" function. 2439 // A simple module which exports an "increment" function.
2440 // Copied from test/mjsunit/wasm/incrementer.wasm. 2440 // Copied from test/mjsunit/wasm/incrementer.wasm.
2441 const unsigned char kIncrementerWasm[] = { 2441 const unsigned char kIncrementerWasm[] = {
2442 0x00, 0x61, 0x73, 0x6d, 0x0d, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 2442 0, 97, 115, 109, 13, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 127,
2443 0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09, 2443 3, 2, 1, 0, 7, 13, 1, 9, 105, 110, 99, 114, 101, 109, 101, 110,
2444 0x69, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a, 2444 116, 0, 0, 10, 9, 1, 7, 0, 32, 0, 65, 1, 106, 11,
2445 0x08, 0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a}; 2445 };
2446 2446
2447 TEST_F(ValueSerializerTestWithWasm, RoundTripWasmModule) { 2447 TEST_F(ValueSerializerTestWithWasm, RoundTripWasmModule) {
2448 RoundTripTest( 2448 RoundTripTest(
2449 [this]() { 2449 [this]() {
2450 return WasmCompiledModule::DeserializeOrCompile( 2450 return WasmCompiledModule::DeserializeOrCompile(
2451 isolate(), {nullptr, 0}, 2451 isolate(), {nullptr, 0},
2452 {kIncrementerWasm, sizeof(kIncrementerWasm)}) 2452 {kIncrementerWasm, sizeof(kIncrementerWasm)})
2453 .ToLocalChecked(); 2453 .ToLocalChecked();
2454 }, 2454 },
2455 [this](Local<Value> value) { 2455 [this](Local<Value> value) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2514 0xff, 0x48, 0x83, 0xc4, 0x08, 0xeb, 0xb8, 0x66, 0x90, 0x02, 0x00, 0x00, 2514 0xff, 0x48, 0x83, 0xc4, 0x08, 0xeb, 0xb8, 0x66, 0x90, 0x02, 0x00, 0x00,
2515 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 2515 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
2516 0x0f, 0x39, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x00, 2516 0x0f, 0x39, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x00,
2517 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x20, 0x84, 2517 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x20, 0x84,
2518 0x0f, 0xcc, 0x6e, 0x7d, 0x01, 0x72, 0x98, 0x00, 0x0f, 0xdc, 0x6d, 0x0c, 2518 0x0f, 0xcc, 0x6e, 0x7d, 0x01, 0x72, 0x98, 0x00, 0x0f, 0xdc, 0x6d, 0x0c,
2519 0x0f, 0xb0, 0x84, 0x0d, 0x04, 0x84, 0xe3, 0xc0, 0x00, 0x00, 0x00, 0x00, 2519 0x0f, 0xb0, 0x84, 0x0d, 0x04, 0x84, 0xe3, 0xc0, 0x00, 0x00, 0x00, 0x00,
2520 0x00, 0x00, 0x00, 0x00, 0x84, 0xe0, 0x84, 0x84, 0x18, 0x2f, 0x2f, 0x2f, 2520 0x00, 0x00, 0x00, 0x00, 0x84, 0xe0, 0x84, 0x84, 0x18, 0x2f, 0x2f, 0x2f,
2521 0x2f, 0x2f}; 2521 0x2f, 0x2f};
2522 2522
2523 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModule) { 2523 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModule) {
2524 if (true) return; // TODO(mtrofin): fix this test
2524 std::vector<uint8_t> raw( 2525 std::vector<uint8_t> raw(
2525 kSerializedIncrementerWasm, 2526 kSerializedIncrementerWasm,
2526 kSerializedIncrementerWasm + sizeof(kSerializedIncrementerWasm)); 2527 kSerializedIncrementerWasm + sizeof(kSerializedIncrementerWasm));
2527 DecodeTest(raw, [this](Local<Value> value) { 2528 DecodeTest(raw, [this](Local<Value> value) {
2528 ASSERT_TRUE(value->IsWebAssemblyCompiledModule()); 2529 ASSERT_TRUE(value->IsWebAssemblyCompiledModule());
2529 EXPECT_TRUE(EvaluateScriptForResultBool( 2530 EXPECT_TRUE(EvaluateScriptForResultBool(
2530 "new WebAssembly.Instance(result).exports.increment(8) === 9")); 2531 "new WebAssembly.Instance(result).exports.increment(8) === 9"));
2531 }); 2532 });
2532 } 2533 }
2533 2534
2534 // As above, but with empty compiled data. Should work due to fallback to wire 2535 // As above, but with empty compiled data. Should work due to fallback to wire
2535 // data. 2536 // data.
2536 const unsigned char kSerializedIncrementerWasmWithInvalidCompiledData[] = { 2537 const unsigned char kSerializedIncrementerWasmWithInvalidCompiledData[] = {
2537 0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x2d, 0x00, 0x61, 0x73, 0x6d, 2538 0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x2d, 0x00, 0x61, 0x73, 0x6d,
2538 0x0d, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, 2539 0x0d, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01,
2539 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09, 0x69, 0x6e, 2540 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09, 0x69, 0x6e,
2540 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a, 0x08, 2541 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a, 0x08,
2541 0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x00}; 2542 0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x00};
2542 2543
2543 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidCompiledData) { 2544 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidCompiledData) {
2545 if (true) return; // TODO(titzer): regenerate this test
2544 std::vector<uint8_t> raw( 2546 std::vector<uint8_t> raw(
2545 kSerializedIncrementerWasmWithInvalidCompiledData, 2547 kSerializedIncrementerWasmWithInvalidCompiledData,
2546 kSerializedIncrementerWasmWithInvalidCompiledData + 2548 kSerializedIncrementerWasmWithInvalidCompiledData +
2547 sizeof(kSerializedIncrementerWasmWithInvalidCompiledData)); 2549 sizeof(kSerializedIncrementerWasmWithInvalidCompiledData));
2548 DecodeTest(raw, [this](Local<Value> value) { 2550 DecodeTest(raw, [this](Local<Value> value) {
2549 ASSERT_TRUE(value->IsWebAssemblyCompiledModule()); 2551 ASSERT_TRUE(value->IsWebAssemblyCompiledModule());
2550 EXPECT_TRUE(EvaluateScriptForResultBool( 2552 EXPECT_TRUE(EvaluateScriptForResultBool(
2551 "new WebAssembly.Instance(result).exports.increment(8) === 9")); 2553 "new WebAssembly.Instance(result).exports.increment(8) === 9"));
2552 }); 2554 });
2553 } 2555 }
(...skipping 10 matching lines...) Expand all
2564 InvalidDecodeTest(raw); 2566 InvalidDecodeTest(raw);
2565 } 2567 }
2566 2568
2567 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) { 2569 TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidDataLength) {
2568 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00}); 2570 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x7f, 0x00});
2569 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f}); 2571 InvalidDecodeTest({0xff, 0x09, 0x3f, 0x00, 0x57, 0x79, 0x00, 0x7f});
2570 } 2572 }
2571 2573
2572 } // namespace 2574 } // namespace
2573 } // namespace v8 2575 } // namespace v8
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/wasm-module-builder.js ('k') | test/unittests/wasm/function-body-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698