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