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

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: 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
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 #define BUILD(r, ...) \
ahaas 2016/05/13 12:18:55 why don't you use the BUILD from wasm-run-utils.h?
titzer 2016/05/23 11:41:38 Done.
24 do { \
25 byte code[] = {__VA_ARGS__}; \
26 r.Build(code, code + arraysize(code)); \
27 } while (false)
28
29 namespace v8 {
30 namespace internal {
31 namespace wasm {
32
33 TEST(Run_WasmInt8Const_i) {
ahaas 2016/05/13 12:18:55 Except for the last test, couldn't all these tests
titzer 2016/05/23 11:41:38 Actually, I am still not sure what to do here, sin
34 WasmRunner<int32_t> r;
35 const byte kExpectedValue = 109;
36 // return(kExpectedValue)
37 BUILD(r, WASM_I8(kExpectedValue));
38 CHECK_EQ(kExpectedValue, r.Call());
39 }
40
41 TEST(Run_WasmIfElse) {
42 WasmRunner<int32_t> r(MachineType::Int32());
43 BUILD(r, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10)));
44 CHECK_EQ(10, r.Call(0));
45 CHECK_EQ(9, r.Call(1));
46 }
47
48 TEST(Run_WasmIfReturn) {
49 WasmRunner<int32_t> r(MachineType::Int32());
50 BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65));
51 CHECK_EQ(65, r.Call(0));
52 CHECK_EQ(77, r.Call(1));
53 }
54
55 TEST(Run_WasmNopsN) {
56 const int kMaxNops = 10;
57 byte code[kMaxNops + 2];
58 for (int nops = 0; nops < kMaxNops; nops++) {
59 byte expected = static_cast<byte>(20 + nops);
60 memset(code, kExprNop, sizeof(code));
61 code[nops] = kExprI8Const;
62 code[nops + 1] = expected;
63
64 WasmRunner<int32_t> r;
65 r.Build(code, code + nops + 2);
66 CHECK_EQ(expected, r.Call());
67 }
68 }
69
70 TEST(Run_WasmConstsN) {
71 const int kMaxConsts = 10;
72 byte code[kMaxConsts * 2];
73 for (int count = 1; count < kMaxConsts; count++) {
74 for (int i = 0; i < count; i++) {
75 code[i * 2] = kExprI8Const;
76 code[i * 2 + 1] = static_cast<byte>(count * 10 + i);
77 }
78 byte expected = static_cast<byte>(count * 11 - 1);
79
80 WasmRunner<int32_t> r;
81 r.Build(code, code + (count * 2));
82 CHECK_EQ(expected, r.Call());
83 }
84 }
85
86 TEST(Run_WasmBlocksN) {
87 const int kMaxNops = 10;
88 const int kExtra = 4;
89 byte code[kMaxNops + kExtra];
90 for (int nops = 0; nops < kMaxNops; nops++) {
91 byte expected = static_cast<byte>(30 + nops);
92 memset(code, kExprNop, sizeof(code));
93 code[0] = kExprBlock;
94 code[1 + nops] = kExprI8Const;
95 code[1 + nops + 1] = expected;
96 code[1 + nops + 2] = kExprEnd;
97
98 WasmRunner<int32_t> r;
99 r.Build(code, code + nops + kExtra);
100 CHECK_EQ(expected, r.Call());
101 }
102 }
103
104 TEST(Run_WasmBlockBreakN) {
105 const int kMaxNops = 10;
106 const int kExtra = 6;
107 byte code[kMaxNops + kExtra];
108 for (int nops = 0; nops < kMaxNops; nops++) {
109 // Place the break anywhere within the block.
110 for (int index = 0; index < nops; index++) {
111 memset(code, kExprNop, sizeof(code));
112 code[0] = kExprBlock;
113 code[sizeof(code) - 1] = kExprEnd;
114
115 int expected = nops * 11 + index;
116 code[1 + index + 0] = kExprI8Const;
117 code[1 + index + 1] = static_cast<byte>(expected);
118 code[1 + index + 2] = kExprBr;
119 code[1 + index + 3] = ARITY_1;
120 code[1 + index + 4] = 0;
121
122 WasmRunner<int32_t> r;
123 r.Build(code, code + kMaxNops + kExtra);
124 CHECK_EQ(expected, r.Call());
125 }
126 }
127 }
128
129 TEST(Run_Wasm_nested_ifs_i) {
130 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
131
132 BUILD(r, WASM_IF_ELSE(
133 WASM_GET_LOCAL(0),
134 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)),
135 WASM_IF_ELSE(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14))));
136
137 CHECK_EQ(11, r.Call(1, 1));
138 CHECK_EQ(12, r.Call(1, 0));
139 CHECK_EQ(13, r.Call(0, 1));
140 CHECK_EQ(14, r.Call(0, 0));
141 }
142
143 TEST(Step_I32Add) {
144 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
145 BUILD(r, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
146
147 WasmInterpreter* interpreter = r.GetInterpreter();
148 interpreter->SetBreakpoint(r.function(), 0, true);
149
150 r.Call(1, 1);
151 interpreter->Run();
152 CHECK_EQ(2, interpreter->GetThread(0).GetReturnValue().to<int32_t>());
153 }
154
155 } // namespace wasm
156 } // namespace internal
157 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698