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

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

Issue 2173403002: Replace SmartArrayPointer<T> with unique_ptr<T[]> (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 5 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/test-regexp.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 5 #include <stdint.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <memory>
10
9 #include "src/wasm/wasm-macro-gen.h" 11 #include "src/wasm/wasm-macro-gen.h"
10 12
11 #include "src/wasm/wasm-interpreter.h" 13 #include "src/wasm/wasm-interpreter.h"
12 14
13 #include "test/cctest/cctest.h" 15 #include "test/cctest/cctest.h"
14 #include "test/cctest/compiler/value-helper.h" 16 #include "test/cctest/compiler/value-helper.h"
15 #include "test/cctest/wasm/test-signatures.h" 17 #include "test/cctest/wasm/test-signatures.h"
16 #include "test/cctest/wasm/wasm-run-utils.h" 18 #include "test/cctest/wasm/wasm-run-utils.h"
17 19
18 using namespace v8::base; 20 using namespace v8::base;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 133
132 CHECK_EQ(11, r.Call(1, 1)); 134 CHECK_EQ(11, r.Call(1, 1));
133 CHECK_EQ(12, r.Call(1, 0)); 135 CHECK_EQ(12, r.Call(1, 0));
134 CHECK_EQ(13, r.Call(0, 1)); 136 CHECK_EQ(13, r.Call(0, 1));
135 CHECK_EQ(14, r.Call(0, 0)); 137 CHECK_EQ(14, r.Call(0, 0));
136 } 138 }
137 139
138 // Make tests more robust by not hard-coding offsets of various operations. 140 // Make tests more robust by not hard-coding offsets of various operations.
139 // The {Find} method finds the offsets for the given bytecodes, returning 141 // The {Find} method finds the offsets for the given bytecodes, returning
140 // the offsets in an array. 142 // the offsets in an array.
141 SmartArrayPointer<int> Find(byte* code, size_t code_size, int n, ...) { 143 std::unique_ptr<int[]> Find(byte* code, size_t code_size, int n, ...) {
142 va_list vl; 144 va_list vl;
143 va_start(vl, n); 145 va_start(vl, n);
144 146
145 SmartArrayPointer<int> offsets(new int[n]); 147 std::unique_ptr<int[]> offsets(new int[n]);
146 148
147 for (int i = 0; i < n; i++) { 149 for (int i = 0; i < n; i++) {
148 offsets[i] = -1; 150 offsets[i] = -1;
149 } 151 }
150 152
151 int pos = 0; 153 int pos = 0;
152 WasmOpcode current = static_cast<WasmOpcode>(va_arg(vl, int)); 154 WasmOpcode current = static_cast<WasmOpcode>(va_arg(vl, int));
153 for (size_t i = 0; i < code_size; i++) { 155 for (size_t i = 0; i < code_size; i++) {
154 if (code[i] == current) { 156 if (code[i] == current) {
155 offsets[pos++] = static_cast<int>(i); 157 offsets[pos++] = static_cast<int>(i);
156 if (pos == n) break; 158 if (pos == n) break;
157 current = static_cast<WasmOpcode>(va_arg(vl, int)); 159 current = static_cast<WasmOpcode>(va_arg(vl, int));
158 } 160 }
159 } 161 }
160 va_end(vl); 162 va_end(vl);
161 163
162 return offsets; 164 return offsets;
163 } 165 }
164 166
165 TEST(Breakpoint_I32Add) { 167 TEST(Breakpoint_I32Add) {
166 static const int kLocalsDeclSize = 1; 168 static const int kLocalsDeclSize = 1;
167 static const int kNumBreakpoints = 3; 169 static const int kNumBreakpoints = 3;
168 byte code[] = {WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; 170 byte code[] = {WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
169 SmartArrayPointer<int> offsets = 171 std::unique_ptr<int[]> offsets =
170 Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal, 172 Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal,
171 kExprI32Add); 173 kExprI32Add);
172 174
173 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), 175 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
174 MachineType::Uint32()); 176 MachineType::Uint32());
175 177
176 r.Build(code, code + arraysize(code)); 178 r.Build(code, code + arraysize(code));
177 179
178 WasmInterpreter* interpreter = r.interpreter(); 180 WasmInterpreter* interpreter = r.interpreter();
179 WasmInterpreter::Thread* thread = interpreter->GetThread(0); 181 WasmInterpreter::Thread* thread = interpreter->GetThread(0);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 uint32_t expected = (*a) * (b); 240 uint32_t expected = (*a) * (b);
239 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>()); 241 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
240 } 242 }
241 } 243 }
242 } 244 }
243 245
244 TEST(Breakpoint_I32And_disable) { 246 TEST(Breakpoint_I32And_disable) {
245 static const int kLocalsDeclSize = 1; 247 static const int kLocalsDeclSize = 1;
246 static const int kNumBreakpoints = 1; 248 static const int kNumBreakpoints = 1;
247 byte code[] = {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; 249 byte code[] = {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
248 SmartArrayPointer<int> offsets = 250 std::unique_ptr<int[]> offsets =
249 Find(code, sizeof(code), kNumBreakpoints, kExprI32And); 251 Find(code, sizeof(code), kNumBreakpoints, kExprI32And);
250 252
251 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), 253 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
252 MachineType::Uint32()); 254 MachineType::Uint32());
253 255
254 r.Build(code, code + arraysize(code)); 256 r.Build(code, code + arraysize(code));
255 257
256 WasmInterpreter* interpreter = r.interpreter(); 258 WasmInterpreter* interpreter = r.interpreter();
257 WasmInterpreter::Thread* thread = interpreter->GetThread(0); 259 WasmInterpreter::Thread* thread = interpreter->GetThread(0);
258 260
(...skipping 21 matching lines...) Expand all
280 uint32_t expected = (*a) & (b); 282 uint32_t expected = (*a) & (b);
281 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>()); 283 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
282 } 284 }
283 } 285 }
284 } 286 }
285 } 287 }
286 288
287 } // namespace wasm 289 } // namespace wasm
288 } // namespace internal 290 } // namespace internal
289 } // namespace v8 291 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-regexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698