Commit 2eeed605 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] move cctest/libsampler to unittests/libsampler

This Cl moves cctest/libsampler/{test-sampler, test-signals-and-mutexes}
to unittests/libsampler/{sampler-unittest, signals-and-mutexes-unittest}.

Bug: v8:12781
Change-Id: I106e709a66d00d23df76c6868d0843dd0ac1887e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3612666
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80581}
parent e5af9c4f
......@@ -160,8 +160,6 @@ v8_source_set("cctest_sources") {
"interpreter/test-interpreter.cc",
"interpreter/test-source-positions.cc",
"libplatform/test-tracing.cc",
"libsampler/test-sampler.cc",
"libsampler/test-signals-and-mutexes.cc",
"manually-externalized-buffer.h",
"parsing/test-parse-decision.cc",
"parsing/test-preparser.cc",
......
......@@ -77,7 +77,6 @@
'test-cpu-profiler/JsNativeJsSample': [SKIP],
'test-cpu-profiler/HotDeoptNoFrameEntry': [SKIP],
'test-cpu-profiler/SampleWhenFrameIsNotSetup': [SKIP],
'test-sampler/LibSamplerCollectSample': [SKIP],
# BUG(7202). The test is flaky.
'test-cpu-profiler/NativeFrameStackTrace': [SKIP],
......
......@@ -388,6 +388,8 @@ v8_source_set("unittests_sources") {
"libplatform/single-threaded-default-platform-unittest.cc",
"libplatform/task-queue-unittest.cc",
"libplatform/worker-thread-unittest.cc",
"libsampler/sampler-unittest.cc",
"libsampler/signals-and-mutexes-unittest.cc",
"logging/counters-unittest.cc",
"logging/log-unittest.cc",
"numbers/bigint-unittest.cc",
......
......@@ -3,14 +3,19 @@
// found in the LICENSE file.
// Tests of sampler functionalities.
#include "src/libsampler/sampler.h"
#include "include/v8-external.h"
#include "include/v8-function.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
#include "src/libsampler/sampler.h"
#include "test/cctest/cctest.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
using SamplerTest = TestWithContext;
namespace sampler {
namespace {
......@@ -36,7 +41,6 @@ class TestSamplingThread : public base::Thread {
Sampler* sampler_;
};
class TestSampler : public Sampler {
public:
explicit TestSampler(Isolate* isolate) : Sampler(isolate) {}
......@@ -52,22 +56,17 @@ class TestSampler : public Sampler {
}
};
class TestApiCallbacks {
public:
TestApiCallbacks() = default;
static void Getter(v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
}
const v8::PropertyCallbackInfo<v8::Value>& info) {}
static void Setter(v8::Local<v8::String> name,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
}
static void Setter(v8::Local<v8::String> name, v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {}
};
static void RunSampler(v8::Local<v8::Context> env,
v8::Local<v8::Function> function,
v8::Local<v8::Value> argv[], int argc,
......@@ -88,49 +87,49 @@ static void RunSampler(v8::Local<v8::Context> env,
} // namespace
static const char* sampler_test_source = "function start(count) {\n"
" for (var i = 0; i < count; i++) {\n"
" var o = instance.foo;\n"
" instance.foo = o + 1;\n"
" }\n"
"}\n";
static const char* sampler_test_source =
"function start(count) {\n"
" for (var i = 0; i < count; i++) {\n"
" var o = instance.foo;\n"
" instance.foo = o + 1;\n"
" }\n"
"}\n";
static v8::Local<v8::Function> GetFunction(v8::Local<v8::Context> env,
const char* name) {
return env->Global()
->Get(env, v8_str(name))
->Get(env, String::NewFromUtf8(env->GetIsolate(), name).ToLocalChecked())
.ToLocalChecked()
.As<v8::Function>();
}
TEST(LibSamplerCollectSample) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
TEST_F(SamplerTest, LibSamplerCollectSample) {
v8::HandleScope scope(isolate());
v8::Local<v8::FunctionTemplate> func_template =
v8::FunctionTemplate::New(isolate);
v8::FunctionTemplate::New(isolate());
v8::Local<v8::ObjectTemplate> instance_template =
func_template->InstanceTemplate();
TestApiCallbacks accessors;
v8::Local<v8::External> data =
v8::External::New(isolate, &accessors);
instance_template->SetAccessor(v8_str("foo"), &TestApiCallbacks::Getter,
v8::Local<v8::External> data = v8::External::New(isolate(), &accessors);
instance_template->SetAccessor(NewString("foo"), &TestApiCallbacks::Getter,
&TestApiCallbacks::Setter, data);
v8::Local<v8::Function> func =
func_template->GetFunction(env.local()).ToLocalChecked();
func_template->GetFunction(context()).ToLocalChecked();
v8::Local<v8::Object> instance =
func->NewInstance(env.local()).ToLocalChecked();
env->Global()->Set(env.local(), v8_str("instance"), instance).FromJust();
func->NewInstance(context()).ToLocalChecked();
context()
->Global()
->Set(context(), NewString("instance"), instance)
.FromJust();
CompileRun(sampler_test_source);
v8::Local<v8::Function> function = GetFunction(env.local(), "start");
RunJS(sampler_test_source);
v8::Local<v8::Function> function = GetFunction(context(), "start");
int32_t repeat_count = 100;
v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
RunSampler(env.local(), function, args, arraysize(args), 100, 100);
v8::Local<v8::Value> args[] = {v8::Integer::New(isolate(), repeat_count)};
RunSampler(context(), function, args, arraysize(args), 100, 100);
}
#ifdef USE_SIGNALS
......@@ -149,12 +148,9 @@ class CountingSampler : public Sampler {
int sample_count_ = 0;
};
TEST(SamplerManager_AddRemoveSampler) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
TEST_F(SamplerTest, SamplerManager_AddRemoveSampler) {
SamplerManager* manager = SamplerManager::instance();
CountingSampler sampler1(isolate);
CountingSampler sampler1(isolate());
sampler1.set_active(true);
sampler1.set_should_record_sample();
CHECK_EQ(0, sampler1.sample_count());
......@@ -174,13 +170,10 @@ TEST(SamplerManager_AddRemoveSampler) {
CHECK_EQ(1, sampler1.sample_count());
}
TEST(SamplerManager_DoesNotReAdd) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
TEST_F(SamplerTest, SamplerManager_DoesNotReAdd) {
// Add the same sampler twice, but check we only get one sample for it.
SamplerManager* manager = SamplerManager::instance();
CountingSampler sampler1(isolate);
CountingSampler sampler1(isolate());
sampler1.set_active(true);
sampler1.set_should_record_sample();
manager->AddSampler(&sampler1);
......@@ -192,7 +185,7 @@ TEST(SamplerManager_DoesNotReAdd) {
sampler1.set_active(false);
}
TEST(AtomicGuard_GetNonBlockingSuccess) {
TEST_F(SamplerTest, AtomicGuard_GetNonBlockingSuccess) {
std::atomic_bool atomic{false};
{
AtomicGuard guard(&atomic, false);
......@@ -205,7 +198,7 @@ TEST(AtomicGuard_GetNonBlockingSuccess) {
CHECK(guard.is_success());
}
TEST(AtomicGuard_GetBlockingSuccess) {
TEST_F(SamplerTest, AtomicGuard_GetBlockingSuccess) {
std::atomic_bool atomic{false};
{
AtomicGuard guard(&atomic);
......
......@@ -9,9 +9,12 @@
#include "src/base/platform/time.h"
#include "src/base/utils/random-number-generator.h"
#include "src/libsampler/sampler.h" // for USE_SIGNALS
#include "test/cctest/cctest.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
using SignalAndMutexTest = TestWithContext;
namespace sampler {
// There seem to be problems with pthread_rwlock_t and signal handling on
......@@ -42,7 +45,7 @@ static void RestoreSignalHandler() {
sigaction(SIGPROF, &old_signal_handler, nullptr);
}
TEST(SignalsPlusSharedMutexes) {
TEST_F(SignalAndMutexTest, SignalsPlusSharedMutexes) {
static constexpr int kNumMutexes = 1024;
// 10us * 10000 = 100ms
static constexpr auto kSleepBetweenSamples =
......@@ -134,7 +137,7 @@ TEST(SignalsPlusSharedMutexes) {
InstallSignalHandler();
auto* rng = CcTest::i_isolate()->random_number_generator();
auto* rng = i_isolate()->random_number_generator();
// First start the mutex threads, then the sampling thread.
std::vector<std::unique_ptr<SharedMutexTestThread>> threads(4);
......
......@@ -3,6 +3,12 @@
# found in the LICENSE file.
[
[ALWAYS, {
# BUG(5193). The cpu profiler tests are notoriously flaky.
'SamplerTest.LibSamplerCollectSample': [SKIP],
}], # ALWAYS
##############################################################################
['system == macos and asan', {
# BUG(820416).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment