2016-05-25 08:32:37 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-07-25 10:24:45 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-05-25 08:32:37 +00:00
|
|
|
#include "src/wasm/wasm-macro-gen.h"
|
|
|
|
|
|
|
|
#include "src/wasm/wasm-interpreter.h"
|
|
|
|
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/compiler/value-helper.h"
|
|
|
|
#include "test/cctest/wasm/wasm-run-utils.h"
|
2016-10-05 11:59:47 +00:00
|
|
|
#include "test/common/wasm/test-signatures.h"
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
using namespace v8::base;
|
|
|
|
using namespace v8::internal;
|
|
|
|
using namespace v8::internal::compiler;
|
|
|
|
using namespace v8::internal::wasm;
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
|
|
|
|
TEST(Run_WasmInt8Const_i) {
|
|
|
|
WasmRunner<int32_t> r(kExecuteInterpreted);
|
|
|
|
const byte kExpectedValue = 109;
|
|
|
|
// return(kExpectedValue)
|
2017-01-09 13:57:26 +00:00
|
|
|
BUILD(r, WASM_I32V_2(kExpectedValue));
|
2016-05-25 08:32:37 +00:00
|
|
|
CHECK_EQ(kExpectedValue, r.Call());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmIfElse) {
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
|
2017-01-09 13:57:26 +00:00
|
|
|
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(10)));
|
2016-05-25 08:32:37 +00:00
|
|
|
CHECK_EQ(10, r.Call(0));
|
|
|
|
CHECK_EQ(9, r.Call(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmIfReturn) {
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
|
2017-01-09 13:57:26 +00:00
|
|
|
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I32V_2(77))),
|
|
|
|
WASM_I32V_2(65));
|
2016-05-25 08:32:37 +00:00
|
|
|
CHECK_EQ(65, r.Call(0));
|
|
|
|
CHECK_EQ(77, r.Call(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmNopsN) {
|
|
|
|
const int kMaxNops = 10;
|
|
|
|
byte code[kMaxNops + 2];
|
|
|
|
for (int nops = 0; nops < kMaxNops; nops++) {
|
|
|
|
byte expected = static_cast<byte>(20 + nops);
|
|
|
|
memset(code, kExprNop, sizeof(code));
|
2017-01-09 13:57:26 +00:00
|
|
|
code[nops] = kExprI32Const;
|
2016-05-25 08:32:37 +00:00
|
|
|
code[nops + 1] = expected;
|
|
|
|
|
|
|
|
WasmRunner<int32_t> r(kExecuteInterpreted);
|
|
|
|
r.Build(code, code + nops + 2);
|
|
|
|
CHECK_EQ(expected, r.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmConstsN) {
|
2017-01-09 13:57:26 +00:00
|
|
|
const int kMaxConsts = 5;
|
2016-09-27 20:46:10 +00:00
|
|
|
byte code[kMaxConsts * 3];
|
|
|
|
int32_t expected = 0;
|
2016-05-25 08:32:37 +00:00
|
|
|
for (int count = 1; count < kMaxConsts; count++) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
2016-09-27 20:46:10 +00:00
|
|
|
byte val = static_cast<byte>(count * 10 + i);
|
2017-01-09 13:57:26 +00:00
|
|
|
code[i * 3] = kExprI32Const;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[i * 3 + 1] = val;
|
|
|
|
if (i == (count - 1)) {
|
|
|
|
code[i * 3 + 2] = kExprNop;
|
|
|
|
expected = val;
|
|
|
|
} else {
|
|
|
|
code[i * 3 + 2] = kExprDrop;
|
|
|
|
}
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WasmRunner<int32_t> r(kExecuteInterpreted);
|
2016-09-27 20:46:10 +00:00
|
|
|
r.Build(code, code + (count * 3));
|
2016-05-25 08:32:37 +00:00
|
|
|
CHECK_EQ(expected, r.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmBlocksN) {
|
|
|
|
const int kMaxNops = 10;
|
2016-09-27 20:46:10 +00:00
|
|
|
const int kExtra = 5;
|
2016-05-25 08:32:37 +00:00
|
|
|
byte code[kMaxNops + kExtra];
|
|
|
|
for (int nops = 0; nops < kMaxNops; nops++) {
|
|
|
|
byte expected = static_cast<byte>(30 + nops);
|
|
|
|
memset(code, kExprNop, sizeof(code));
|
|
|
|
code[0] = kExprBlock;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[1] = kLocalI32;
|
2017-01-09 13:57:26 +00:00
|
|
|
code[2 + nops] = kExprI32Const;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[2 + nops + 1] = expected;
|
|
|
|
code[2 + nops + 2] = kExprEnd;
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
WasmRunner<int32_t> r(kExecuteInterpreted);
|
|
|
|
r.Build(code, code + nops + kExtra);
|
|
|
|
CHECK_EQ(expected, r.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_WasmBlockBreakN) {
|
|
|
|
const int kMaxNops = 10;
|
|
|
|
const int kExtra = 6;
|
2017-01-09 13:57:26 +00:00
|
|
|
int run = 0;
|
2016-05-25 08:32:37 +00:00
|
|
|
byte code[kMaxNops + kExtra];
|
|
|
|
for (int nops = 0; nops < kMaxNops; nops++) {
|
|
|
|
// Place the break anywhere within the block.
|
|
|
|
for (int index = 0; index < nops; index++) {
|
|
|
|
memset(code, kExprNop, sizeof(code));
|
|
|
|
code[0] = kExprBlock;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[1] = kLocalI32;
|
2016-05-25 08:32:37 +00:00
|
|
|
code[sizeof(code) - 1] = kExprEnd;
|
|
|
|
|
2017-01-09 13:57:26 +00:00
|
|
|
int expected = run++;
|
|
|
|
code[2 + index + 0] = kExprI32Const;
|
2016-09-27 20:46:10 +00:00
|
|
|
code[2 + index + 1] = static_cast<byte>(expected);
|
|
|
|
code[2 + index + 2] = kExprBr;
|
|
|
|
code[2 + index + 3] = 0;
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
WasmRunner<int32_t> r(kExecuteInterpreted);
|
|
|
|
r.Build(code, code + kMaxNops + kExtra);
|
|
|
|
CHECK_EQ(expected, r.Call());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Run_Wasm_nested_ifs_i) {
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted);
|
2016-05-25 08:32:37 +00:00
|
|
|
|
2017-01-09 13:57:26 +00:00
|
|
|
BUILD(
|
|
|
|
r,
|
|
|
|
WASM_IF_ELSE_I(
|
|
|
|
WASM_GET_LOCAL(0),
|
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(11), WASM_I32V_1(12)),
|
|
|
|
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(13), WASM_I32V_1(14))));
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
CHECK_EQ(11, r.Call(1, 1));
|
|
|
|
CHECK_EQ(12, r.Call(1, 0));
|
|
|
|
CHECK_EQ(13, r.Call(0, 1));
|
|
|
|
CHECK_EQ(14, r.Call(0, 0));
|
|
|
|
}
|
|
|
|
|
2016-05-30 10:02:34 +00:00
|
|
|
// Make tests more robust by not hard-coding offsets of various operations.
|
|
|
|
// The {Find} method finds the offsets for the given bytecodes, returning
|
|
|
|
// the offsets in an array.
|
2016-07-25 10:24:45 +00:00
|
|
|
std::unique_ptr<int[]> Find(byte* code, size_t code_size, int n, ...) {
|
2016-05-30 10:02:34 +00:00
|
|
|
va_list vl;
|
|
|
|
va_start(vl, n);
|
|
|
|
|
2016-07-25 10:24:45 +00:00
|
|
|
std::unique_ptr<int[]> offsets(new int[n]);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
offsets[i] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
WasmOpcode current = static_cast<WasmOpcode>(va_arg(vl, int));
|
|
|
|
for (size_t i = 0; i < code_size; i++) {
|
|
|
|
if (code[i] == current) {
|
|
|
|
offsets[pos++] = static_cast<int>(i);
|
|
|
|
if (pos == n) break;
|
|
|
|
current = static_cast<WasmOpcode>(va_arg(vl, int));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(vl);
|
|
|
|
|
|
|
|
return offsets;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Breakpoint_I32Add) {
|
|
|
|
static const int kLocalsDeclSize = 1;
|
|
|
|
static const int kNumBreakpoints = 3;
|
|
|
|
byte code[] = {WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
|
2016-07-25 10:24:45 +00:00
|
|
|
std::unique_ptr<int[]> offsets =
|
2016-05-30 10:02:34 +00:00
|
|
|
Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal,
|
|
|
|
kExprI32Add);
|
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
r.Build(code, code + arraysize(code));
|
2016-05-25 08:32:37 +00:00
|
|
|
|
|
|
|
WasmInterpreter* interpreter = r.interpreter();
|
2016-06-09 14:22:05 +00:00
|
|
|
WasmInterpreter::Thread* thread = interpreter->GetThread(0);
|
2016-05-30 10:02:34 +00:00
|
|
|
for (int i = 0; i < kNumBreakpoints; i++) {
|
|
|
|
interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[i],
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) {
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Reset();
|
2016-05-30 10:02:34 +00:00
|
|
|
WasmVal args[] = {WasmVal(*a), WasmVal(b)};
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->PushFrame(r.function(), args);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < kNumBreakpoints; i++) {
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Run(); // run to next breakpoint
|
2016-05-30 10:02:34 +00:00
|
|
|
// Check the thread stopped at the right pc.
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
|
2016-11-10 12:50:51 +00:00
|
|
|
CHECK_EQ(static_cast<size_t>(kLocalsDeclSize + offsets[i]),
|
|
|
|
thread->GetBreakpointPc());
|
2016-05-30 10:02:34 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Run(); // run to completion
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
// Check the thread finished with the right value.
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
|
2016-05-30 10:02:34 +00:00
|
|
|
uint32_t expected = (*a) + (b);
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
|
2016-05-30 10:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Step_I32Mul) {
|
Revert of [wasm] Enforce that function bodies end with the \"end\" opcode. (patchset #1 id:1 of https://codereview.chromium.org/2628203003/ )
Reason for revert:
OK, the failure really does seem to be due to this patch: It triggers Clang to crash
FAILED: obj/test/unittests/unittests/function-body-decoder-unittest.obj
E:\b\build\slave\cache\cipd\goma/gomacc.exe ../../third_party/llvm-build/Release+Asserts/bin/clang-cl.exe /nologo /showIncludes /FC @obj/test/unittests/unittests/function-body-decoder-unittest.obj.rsp /c ../../test/unittests/wasm/function-body-decoder-unittest.cc /Foobj/test/unittests/unittests/function-body-decoder-unittest.obj /Fd"obj/test/unittests/unittests_cc.pdb"
Assertion failed: (NumGaps == 0 || Bias < MaxDefRange) && "large ranges should not have gaps", file E:\b\build\slave\win_upload_clang\build\src\third_party\llvm\lib\MC\MCCodeView.cpp, line 531
Wrote crash dump file "C:\Users\CHROME~2\AppData\Local\Temp\goma_temp.5068\clang-cl.exe-563144.dmp"
Let's leave it out for now.
Original issue's description:
> Reland of [wasm] Enforce that function bodies end with the \"end\" opcode. (patchset #1 id:1 of https://codereview.chromium.org/2628883006/ )
>
> Reason for revert:
> Try a reland; this might not have been the source of tree-closing.
>
> Original issue's description:
> > Revert of [wasm] Enforce that function bodies end with the \"end\" opcode. (patchset #3 id:40001 of https://codereview.chromium.org/2630553002/ )
> >
> > Reason for revert:
> > Caused tree to close by failing compilation:
> >
> > https://build.chromium.org/p/client.v8/builders/V8%20Win64%20-%20clang/builds/4451
> >
> > Original issue's description:
> > > [wasm] Enforce that function bodies end with the \"end\" opcode.
> > >
> > > R=rossberg@chromium.org
> > > BUG=chromium:575167
> > >
> > > Review-Url: https://codereview.chromium.org/2630553002
> > > Cr-Commit-Position: refs/heads/master@{#42286}
> > > Committed: https://chromium.googlesource.com/v8/v8/+/fcc6e85ec6b01e5367795f98aff104b1ff23f619
> >
> > TBR=mtrofin@chromium.org,rossberg@chromium.org,jbroman@chromium.org,titzer@chromium.org
> > # Skipping CQ checks because original CL landed less than 1 days ago.
> > NOPRESUBMIT=true
> > NOTREECHECKS=true
> > NOTRY=true
> > BUG=chromium:575167
> >
> > Review-Url: https://codereview.chromium.org/2628883006
> > Cr-Commit-Position: refs/heads/master@{#42287}
> > Committed: https://chromium.googlesource.com/v8/v8/+/1d32a3989bc474745eeb618ebf094634f4efbb36
>
> TBR=mtrofin@chromium.org,rossberg@chromium.org,jbroman@chromium.org,titzer@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=chromium:575167
>
> Review-Url: https://codereview.chromium.org/2628203003
> Cr-Commit-Position: refs/heads/master@{#42296}
> Committed: https://chromium.googlesource.com/v8/v8/+/e539bd8e0eb6afc8e7c98c38584928d6bc799b5b
TBR=mtrofin@chromium.org,rossberg@chromium.org,jbroman@chromium.org,titzer@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=chromium:575167
Review-Url: https://codereview.chromium.org/2633583002
Cr-Commit-Position: refs/heads/master@{#42298}
2017-01-12 23:12:12 +00:00
|
|
|
static const int kTraceLength = 4;
|
2016-05-30 10:02:34 +00:00
|
|
|
byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
|
2016-05-25 08:32:37 +00:00
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
r.Build(code, code + arraysize(code));
|
|
|
|
|
|
|
|
WasmInterpreter* interpreter = r.interpreter();
|
2016-06-09 14:22:05 +00:00
|
|
|
WasmInterpreter::Thread* thread = interpreter->GetThread(0);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) {
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Reset();
|
2016-05-30 10:02:34 +00:00
|
|
|
WasmVal args[] = {WasmVal(*a), WasmVal(b)};
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->PushFrame(r.function(), args);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
// Run instructions one by one.
|
|
|
|
for (int i = 0; i < kTraceLength - 1; i++) {
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Step();
|
2016-05-30 10:02:34 +00:00
|
|
|
// Check the thread stopped.
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
|
2016-05-30 10:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run last instruction.
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Step();
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
// Check the thread finished with the right value.
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
|
2016-05-30 10:02:34 +00:00
|
|
|
uint32_t expected = (*a) * (b);
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
|
2016-05-30 10:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Breakpoint_I32And_disable) {
|
|
|
|
static const int kLocalsDeclSize = 1;
|
|
|
|
static const int kNumBreakpoints = 1;
|
|
|
|
byte code[] = {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
|
2016-07-25 10:24:45 +00:00
|
|
|
std::unique_ptr<int[]> offsets =
|
2016-05-30 10:02:34 +00:00
|
|
|
Find(code, sizeof(code), kNumBreakpoints, kExprI32And);
|
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
r.Build(code, code + arraysize(code));
|
|
|
|
|
|
|
|
WasmInterpreter* interpreter = r.interpreter();
|
2016-06-09 14:22:05 +00:00
|
|
|
WasmInterpreter::Thread* thread = interpreter->GetThread(0);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
FOR_UINT32_INPUTS(a) {
|
|
|
|
for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) {
|
|
|
|
// Run with and without breakpoints.
|
|
|
|
for (int do_break = 0; do_break < 2; do_break++) {
|
|
|
|
interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[0],
|
|
|
|
do_break);
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Reset();
|
2016-05-30 10:02:34 +00:00
|
|
|
WasmVal args[] = {WasmVal(*a), WasmVal(b)};
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->PushFrame(r.function(), args);
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
if (do_break) {
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Run(); // run to next breakpoint
|
2016-05-30 10:02:34 +00:00
|
|
|
// Check the thread stopped at the right pc.
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
|
2016-11-10 12:50:51 +00:00
|
|
|
CHECK_EQ(static_cast<size_t>(kLocalsDeclSize + offsets[0]),
|
|
|
|
thread->GetBreakpointPc());
|
2016-05-30 10:02:34 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 14:22:05 +00:00
|
|
|
thread->Run(); // run to completion
|
2016-05-30 10:02:34 +00:00
|
|
|
|
|
|
|
// Check the thread finished with the right value.
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
|
2016-05-30 10:02:34 +00:00
|
|
|
uint32_t expected = (*a) & (b);
|
2016-06-09 14:22:05 +00:00
|
|
|
CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
|
2016-05-30 10:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
2016-09-14 09:19:02 +00:00
|
|
|
TEST(GrowMemory) {
|
2017-01-11 17:24:00 +00:00
|
|
|
{
|
|
|
|
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
|
|
|
|
r.module().AddMemory(WasmModule::kPageSize);
|
|
|
|
r.module().SetMaxMemPages(10);
|
|
|
|
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
|
|
|
|
CHECK_EQ(1, r.Call(1));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
|
|
|
|
r.module().AddMemory(WasmModule::kPageSize);
|
|
|
|
r.module().SetMaxMemPages(10);
|
|
|
|
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
|
|
|
|
CHECK_EQ(-1, r.Call(11));
|
|
|
|
}
|
2016-09-14 09:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GrowMemoryPreservesData) {
|
|
|
|
int32_t index = 16;
|
|
|
|
int32_t value = 2335;
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
|
|
|
|
r.module().AddMemory(WasmModule::kPageSize);
|
2016-09-27 20:46:10 +00:00
|
|
|
BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
|
|
|
|
WASM_I32V(value)),
|
|
|
|
WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
|
|
|
|
WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index)));
|
2016-09-14 09:19:02 +00:00
|
|
|
CHECK_EQ(value, r.Call(1));
|
|
|
|
}
|
2016-09-15 09:26:52 +00:00
|
|
|
|
|
|
|
TEST(GrowMemoryInvalidSize) {
|
|
|
|
{
|
|
|
|
// Grow memory by an invalid amount without initial memory.
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
|
2016-09-27 20:46:10 +00:00
|
|
|
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
|
2016-09-15 09:26:52 +00:00
|
|
|
CHECK_EQ(-1, r.Call(1048575));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Grow memory by an invalid amount without initial memory.
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
|
|
|
|
r.module().AddMemory(WasmModule::kPageSize);
|
2016-09-27 20:46:10 +00:00
|
|
|
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
|
2016-09-15 09:26:52 +00:00
|
|
|
CHECK_EQ(-1, r.Call(1048575));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 14:27:23 +00:00
|
|
|
TEST(TestPossibleNondeterminism) {
|
|
|
|
{
|
|
|
|
// F32Div may produced NaN
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<float, float, float> r(kExecuteInterpreted);
|
2016-10-20 14:27:23 +00:00
|
|
|
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
|
|
|
|
r.Call(1048575.5f, 2.5f);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(0.0f, 0.0f);
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// F32Sqrt may produced NaN
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<float, float> r(kExecuteInterpreted);
|
2016-10-20 14:27:23 +00:00
|
|
|
BUILD(r, WASM_F32_SQRT(WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(16.0f);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(-1048575.5f);
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// F32Mul may produced NaN
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<float, float, float> r(kExecuteInterpreted);
|
2016-10-20 14:27:23 +00:00
|
|
|
BUILD(r, WASM_F32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
|
|
|
|
r.Call(1048575.5f, 2.5f);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(std::numeric_limits<float>::infinity(), 0.0f);
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// F64Div may produced NaN
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<double, double, double> r(kExecuteInterpreted);
|
2016-10-20 14:27:23 +00:00
|
|
|
BUILD(r, WASM_F64_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
|
|
|
|
r.Call(1048575.5, 2.5);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(0.0, 0.0);
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// F64Sqrt may produced NaN
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<double, double> r(kExecuteInterpreted);
|
2016-10-20 14:27:23 +00:00
|
|
|
BUILD(r, WASM_F64_SQRT(WASM_GET_LOCAL(0)));
|
|
|
|
r.Call(1048575.5);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(-1048575.5);
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// F64Mul may produced NaN
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmRunner<double, double, double> r(kExecuteInterpreted);
|
2016-10-20 14:27:23 +00:00
|
|
|
BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
|
|
|
|
r.Call(1048575.5, 2.5);
|
|
|
|
CHECK(!r.possible_nondeterminism());
|
|
|
|
r.Call(std::numeric_limits<double>::infinity(), 0.0);
|
|
|
|
CHECK(r.possible_nondeterminism());
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 08:32:37 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|