[test] Move test/cctest/test-platform to test/unittests/

... base/platform/platform-unittest.

Bug: v8:12781
Change-Id: I05902bfa5ad6f391f7b7ffa8b22b46627c244fef
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3688893
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81068}
This commit is contained in:
jameslahm 2022-06-10 20:37:20 +08:00 committed by V8 LUCI CQ
parent 64936c8859
commit 1a06c0077d
6 changed files with 90 additions and 61 deletions

View File

@ -202,7 +202,6 @@ v8_source_set("cctest_sources") {
"test-orderedhashtable.cc",
"test-parsing.cc",
"test-persistent-handles.cc",
"test-platform.cc",
"test-profile-generator.cc",
"test-property-details.cc",
"test-ptr-compr-cage.cc",

View File

@ -97,9 +97,6 @@
# BUG(v8:8739). Wasm interpreter does not create proper stack traces.
'test-wasm-stack/RunWasmInterpreter_CollectDetailedWasmStack_WasmError': [SKIP],
# https://crbug.com/v8/8919
'test-platform/StackAlignment': [PASS, ['not is_clang', SKIP]],
# Test that misuse of PopAndReturn does not compile.
'test-code-stub-assembler/PopAndReturnFromJSBuiltinWithStackParameters' : [FAIL],
'test-code-stub-assembler/PopAndReturnFromTFCBuiltinWithStackParameters' : [FAIL],

View File

@ -1,57 +0,0 @@
// Copyright 2013 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 "include/v8-function.h"
#include "src/base/build_config.h"
#include "src/base/platform/platform.h"
#include "test/cctest/cctest-utils.h"
#include "test/cctest/cctest.h"
using OS = v8::base::OS;
namespace v8 {
namespace internal {
#ifdef V8_CC_GNU
static uintptr_t sp_addr = 0;
void GetStackPointerCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
GET_STACK_POINTER_TO(sp_addr);
args.GetReturnValue().Set(v8::Integer::NewFromUnsigned(
args.GetIsolate(), static_cast<uint32_t>(sp_addr)));
}
TEST(StackAlignment) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::ObjectTemplate> global_template =
v8::ObjectTemplate::New(isolate);
global_template->Set(
isolate, "get_stack_pointer",
v8::FunctionTemplate::New(isolate, GetStackPointerCallback));
LocalContext env(nullptr, global_template);
CompileRun(
"function foo() {"
" return get_stack_pointer();"
"}");
v8::Local<v8::Object> global_object = env->Global();
v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
global_object->Get(isolate->GetCurrentContext(), v8_str("foo"))
.ToLocalChecked());
v8::Local<v8::Value> result =
foo->Call(isolate->GetCurrentContext(), global_object, 0, nullptr)
.ToLocalChecked();
CHECK_EQ(0u, result->Uint32Value(isolate->GetCurrentContext()).FromJust() %
OS::ActivationFrameAlignment());
}
#endif // V8_CC_GNU
} // namespace internal
} // namespace v8

View File

@ -7,7 +7,9 @@
#include <cstdio>
#include <cstring>
#include "include/v8-function.h"
#include "src/base/build_config.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#ifdef V8_TARGET_OS_LINUX
@ -237,4 +239,46 @@ TEST(StackTest, StackVariableInBounds) {
#endif // !V8_OS_FUCHSIA
} // namespace base
namespace {
#ifdef V8_CC_GNU
static uintptr_t sp_addr = 0;
void GetStackPointerCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
GET_STACK_POINTER_TO(sp_addr);
args.GetReturnValue().Set(v8::Integer::NewFromUnsigned(
args.GetIsolate(), static_cast<uint32_t>(sp_addr)));
}
using PlatformTest = v8::TestWithIsolate;
TEST_F(PlatformTest, StackAlignment) {
Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate());
global_template->Set(
isolate(), "get_stack_pointer",
FunctionTemplate::New(isolate(), GetStackPointerCallback));
Local<Context> context = Context::New(isolate(), nullptr, global_template);
Context::Scope context_scope(context);
TryRunJS(
"function foo() {"
" return get_stack_pointer();"
"}");
Local<Object> global_object = context->Global();
Local<Function> foo = v8::Local<v8::Function>::Cast(
global_object->Get(isolate()->GetCurrentContext(), NewString("foo"))
.ToLocalChecked());
Local<v8::Value> result =
foo->Call(isolate()->GetCurrentContext(), global_object, 0, nullptr)
.ToLocalChecked();
CHECK_EQ(0u, result->Uint32Value(isolate()->GetCurrentContext()).FromJust() %
base::OS::ActivationFrameAlignment());
}
#endif // V8_CC_GNU
} // namespace
} // namespace v8

View File

@ -531,6 +531,49 @@ Handle<FeedbackVector> NewFeedbackVector(Isolate* isolate, Spec* spec) {
return FeedbackVector::New(isolate, shared, closure_feedback_cell_array,
&is_compiled_scope);
}
#ifdef V8_CC_GNU
#if V8_HOST_ARCH_X64
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("mov %%rsp, %0" : "=g"(sp_addr))
#elif V8_HOST_ARCH_IA32
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("mov %%esp, %0" : "=g"(sp_addr))
#elif V8_HOST_ARCH_ARM
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("str sp, %0" : "=g"(sp_addr))
#elif V8_HOST_ARCH_ARM64
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("mov x16, sp; str x16, %0" : "=g"(sp_addr))
#elif V8_HOST_ARCH_MIPS
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("sw $sp, %0" : "=g"(sp_addr))
#elif V8_HOST_ARCH_MIPS64
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("sd $sp, %0" : "=g"(sp_addr))
#elif defined(__s390x__) || defined(_ARCH_S390X)
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("stg %%r15, %0" : "=m"(sp_addr))
#elif defined(__s390__) || defined(_ARCH_S390)
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("st 15, %0" : "=m"(sp_addr))
#elif defined(__PPC64__) || defined(_ARCH_PPC64)
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("std 1, %0" : "=m"(sp_addr))
#elif defined(__PPC__) || defined(_ARCH_PPC)
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("stw 1, %0" : "=m"(sp_addr))
#elif V8_TARGET_ARCH_RISCV64
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("add %0, sp, x0" : "=r"(sp_addr))
#elif V8_HOST_ARCH_LOONG64
#define GET_STACK_POINTER_TO(sp_addr) \
__asm__ __volatile__("st.d $sp, %0" : "=m"(sp_addr))
#else
#error Host architecture was not detected as supported by v8
#endif
#endif // V8_CC_GNU
} // namespace internal
} // namespace v8

View File

@ -10,6 +10,9 @@
# This tests only the type system, no point in running several variants.
'TypesTest.*': [PASS, NO_VARIANTS],
# https://crbug.com/v8/8919
'PlatformTest.StackAlignment': [PASS, ['not is_clang', SKIP]],
}], # ALWAYS
##############################################################################