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

Side by Side Diff: test/cctest/wasm/test-run-wasm-interpreter.cc

Issue 1972153002: [wasm] Implement an interpreter for WASM. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 7 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
« no previous file with comments | « test/cctest/wasm/test-run-wasm-asmjs.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include "src/wasm/wasm-macro-gen.h"
10
11 #include "src/wasm/wasm-interpreter.h"
12
13 #include "test/cctest/cctest.h"
14 #include "test/cctest/compiler/value-helper.h"
15 #include "test/cctest/wasm/test-signatures.h"
16 #include "test/cctest/wasm/wasm-run-utils.h"
17
18 using namespace v8::base;
19 using namespace v8::internal;
20 using namespace v8::internal::compiler;
21 using namespace v8::internal::wasm;
22
23 namespace v8 {
24 namespace internal {
25 namespace wasm {
26
27 TEST(Run_WasmInt8Const_i) {
28 WasmRunner<int32_t> r(kExecuteInterpreted);
29 const byte kExpectedValue = 109;
30 // return(kExpectedValue)
31 BUILD(r, WASM_I8(kExpectedValue));
32 CHECK_EQ(kExpectedValue, r.Call());
33 }
34
35 TEST(Run_WasmIfElse) {
36 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
37 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10)));
38 CHECK_EQ(10, r.Call(0));
39 CHECK_EQ(9, r.Call(1));
40 }
41
42 TEST(Run_WasmIfReturn) {
43 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
44 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65));
45 CHECK_EQ(65, r.Call(0));
46 CHECK_EQ(77, r.Call(1));
47 }
48
49 TEST(Run_WasmNopsN) {
50 const int kMaxNops = 10;
51 byte code[kMaxNops + 2];
52 for (int nops = 0; nops < kMaxNops; nops++) {
53 byte expected = static_cast<byte>(20 + nops);
54 memset(code, kExprNop, sizeof(code));
55 code[nops] = kExprI8Const;
56 code[nops + 1] = expected;
57
58 WasmRunner<int32_t> r(kExecuteInterpreted);
59 r.Build(code, code + nops + 2);
60 CHECK_EQ(expected, r.Call());
61 }
62 }
63
64 TEST(Run_WasmConstsN) {
65 const int kMaxConsts = 10;
66 byte code[kMaxConsts * 2];
67 for (int count = 1; count < kMaxConsts; count++) {
68 for (int i = 0; i < count; i++) {
69 code[i * 2] = kExprI8Const;
70 code[i * 2 + 1] = static_cast<byte>(count * 10 + i);
71 }
72 byte expected = static_cast<byte>(count * 11 - 1);
73
74 WasmRunner<int32_t> r(kExecuteInterpreted);
75 r.Build(code, code + (count * 2));
76 CHECK_EQ(expected, r.Call());
77 }
78 }
79
80 TEST(Run_WasmBlocksN) {
81 const int kMaxNops = 10;
82 const int kExtra = 4;
83 byte code[kMaxNops + kExtra];
84 for (int nops = 0; nops < kMaxNops; nops++) {
85 byte expected = static_cast<byte>(30 + nops);
86 memset(code, kExprNop, sizeof(code));
87 code[0] = kExprBlock;
88 code[1 + nops] = kExprI8Const;
89 code[1 + nops + 1] = expected;
90 code[1 + nops + 2] = kExprEnd;
91
92 WasmRunner<int32_t> r(kExecuteInterpreted);
93 r.Build(code, code + nops + kExtra);
94 CHECK_EQ(expected, r.Call());
95 }
96 }
97
98 TEST(Run_WasmBlockBreakN) {
99 const int kMaxNops = 10;
100 const int kExtra = 6;
101 byte code[kMaxNops + kExtra];
102 for (int nops = 0; nops < kMaxNops; nops++) {
103 // Place the break anywhere within the block.
104 for (int index = 0; index < nops; index++) {
105 memset(code, kExprNop, sizeof(code));
106 code[0] = kExprBlock;
107 code[sizeof(code) - 1] = kExprEnd;
108
109 int expected = nops * 11 + index;
110 code[1 + index + 0] = kExprI8Const;
111 code[1 + index + 1] = static_cast<byte>(expected);
112 code[1 + index + 2] = kExprBr;
113 code[1 + index + 3] = ARITY_1;
114 code[1 + index + 4] = 0;
115
116 WasmRunner<int32_t> r(kExecuteInterpreted);
117 r.Build(code, code + kMaxNops + kExtra);
118 CHECK_EQ(expected, r.Call());
119 }
120 }
121 }
122
123 TEST(Run_Wasm_nested_ifs_i) {
124 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(),
125 MachineType::Int32());
126
127 BUILD(r, WASM_IF_ELSE(
128 WASM_GET_LOCAL(0),
129 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)),
130 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14))));
131
132 CHECK_EQ(11, r.Call(1, 1));
133 CHECK_EQ(12, r.Call(1, 0));
134 CHECK_EQ(13, r.Call(0, 1));
135 CHECK_EQ(14, r.Call(0, 0));
136 }
137
138 TEST(Step_I32Add) {
139 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(),
140 MachineType::Int32());
141 BUILD(r, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
142
143 WasmInterpreter* interpreter = r.interpreter();
144 interpreter->SetBreakpoint(r.function(), 0, true);
145
146 r.Call(1, 1);
147 interpreter->Run();
148 CHECK_EQ(2, interpreter->GetThread(0).GetReturnValue().to<int32_t>());
149 }
150
151 } // namespace wasm
152 } // namespace internal
153 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-asmjs.cc ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698