v8/test/wasm-api-tests/multi-return.cc
Clemens Backes 91b102c763 [test][cleanup] Rename WASM_*_LOCAL to WASM_LOCAL_*
The opcodes were renamed long ago, but the macros were still using the
old syntax.

This CL was created using the following command (for WASM_GET_LOCAL,
    WASM_SET_LOCAL, and WASM_TEE_LOCAL):
ag -l WASM_GET_LOCAL | xargs -L 1 sed -i 's/\bWASM_SET_LOCAL\b/WASM_LOCAL_SET/g'

R=ahaas@chromium.org

Bug: v8:11074
Change-Id: I0018bea185030be29344e66e59706fed183cc2f1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2595446
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71835}
2020-12-17 21:19:14 +00:00

59 lines
1.8 KiB
C++

// Copyright 2019 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 "test/wasm-api-tests/wasm-api-test.h"
namespace v8 {
namespace internal {
namespace wasm {
using ::wasm::I32;
using ::wasm::I64;
namespace {
own<Trap> Callback(const Val args[], Val results[]) {
results[0] = args[3].copy();
results[1] = args[1].copy();
results[2] = args[2].copy();
results[3] = args[0].copy();
return nullptr;
}
} // namespace
TEST_F(WasmCapiTest, MultiReturn) {
ValueType reps[] = {kWasmI32, kWasmI64, kWasmI64, kWasmI32,
kWasmI32, kWasmI64, kWasmI64, kWasmI32};
FunctionSig sig(4, 4, reps);
uint32_t func_index = builder()->AddImport(CStrVector("f"), &sig);
byte code[] = {WASM_CALL_FUNCTION(func_index, WASM_LOCAL_GET(0),
WASM_LOCAL_GET(2), WASM_LOCAL_GET(1),
WASM_LOCAL_GET(3))};
AddExportedFunction(CStrVector("g"), code, sizeof(code), &sig);
ownvec<ValType> types =
ownvec<ValType>::make(ValType::make(I32), ValType::make(I64),
ValType::make(I64), ValType::make(I32));
own<FuncType> func_type =
FuncType::make(types.deep_copy(), types.deep_copy());
own<Func> callback = Func::make(store(), func_type.get(), Callback);
Extern* imports[] = {callback.get()};
Instantiate(imports);
Func* run_func = GetExportedFunction(0);
Val args[] = {Val::i32(1), Val::i64(2), Val::i64(3), Val::i32(4)};
Val results[4];
own<Trap> trap = run_func->call(args, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(4, results[0].i32());
EXPECT_EQ(3, results[1].i64());
EXPECT_EQ(2, results[2].i64());
EXPECT_EQ(1, results[3].i32());
}
} // namespace wasm
} // namespace internal
} // namespace v8