Commit 2ab2e484 authored by yurys@chromium.org's avatar yurys@chromium.org

Introduce THREADED_PROFILED_TEST macro

A bunch of tests in test-api.cc need to be executed two times: with CPU profiler on and off to check different code paths. There are only two such tests at the moment but I'm going to add more and having this logic duplicated in all these tests look awkward. The tests are executed as part of Threading* tests and there is no much sense in running CPU profiler in that case. This change addresses both problems by introducing THREADED_PROFILED_TEST macro which mosly resembles THREADED_TEST except that when such test is executed as a standalone test (not part of a test-api/Threading*) it will first run the test normally and the start CPU profiler and run the test again.

BUG=244580
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/17072002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15220 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3b53f7dc
...@@ -73,6 +73,25 @@ using ::v8::V8; ...@@ -73,6 +73,25 @@ using ::v8::V8;
using ::v8::Value; using ::v8::Value;
#define THREADED_PROFILED_TEST(Name) \
static void Test##Name(); \
TEST(Name##WithProfiler) { \
RunWithProfiler(&Test##Name); \
} \
THREADED_TEST(Name)
void RunWithProfiler(void (*test)()) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::Local<v8::String> profile_name = v8::String::New("my_profile1");
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
cpu_profiler->StartCpuProfiling(profile_name);
(*test)();
cpu_profiler->DeleteAllCpuProfiles();
}
static void ExpectString(const char* code, const char* expected) { static void ExpectString(const char* code, const char* expected) {
Local<Value> result = CompileRun(code); Local<Value> result = CompileRun(code);
CHECK(result->IsString()); CHECK(result->IsString());
...@@ -938,19 +957,11 @@ static void Return239Callback( ...@@ -938,19 +957,11 @@ static void Return239Callback(
template<typename Handler> template<typename Handler>
static void TestFunctionTemplateInitializer(Handler handler, static void TestFunctionTemplateInitializer(Handler handler,
Handler handler_2) { Handler handler_2) {
for (int i = 0; i < 2; i++) {
bool is_profiling = (i > 0);
// Test constructor calls. // Test constructor calls.
{ {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::Local<v8::String> profile_name = v8::String::New("my_profile1");
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
if (is_profiling) {
cpu_profiler->StartCpuProfiling(profile_name);
}
Local<v8::FunctionTemplate> fun_templ = Local<v8::FunctionTemplate> fun_templ =
v8::FunctionTemplate::New(handler); v8::FunctionTemplate::New(handler);
Local<Function> fun = fun_templ->GetFunction(); Local<Function> fun = fun_templ->GetFunction();
...@@ -959,10 +970,6 @@ static void TestFunctionTemplateInitializer(Handler handler, ...@@ -959,10 +970,6 @@ static void TestFunctionTemplateInitializer(Handler handler,
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
CHECK_EQ(102, script->Run()->Int32Value()); CHECK_EQ(102, script->Run()->Int32Value());
} }
if (is_profiling) {
cpu_profiler->StopCpuProfiling(profile_name);
}
} }
// Use SetCallHandler to initialize a function template, should work like // Use SetCallHandler to initialize a function template, should work like
// the previous one. // the previous one.
...@@ -970,12 +977,6 @@ static void TestFunctionTemplateInitializer(Handler handler, ...@@ -970,12 +977,6 @@ static void TestFunctionTemplateInitializer(Handler handler,
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::Local<v8::String> profile_name = v8::String::New("my_profile2");
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
if (is_profiling) {
cpu_profiler->StartCpuProfiling(profile_name);
}
Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
fun_templ->SetCallHandler(handler_2); fun_templ->SetCallHandler(handler_2);
Local<Function> fun = fun_templ->GetFunction(); Local<Function> fun = fun_templ->GetFunction();
...@@ -984,11 +985,6 @@ static void TestFunctionTemplateInitializer(Handler handler, ...@@ -984,11 +985,6 @@ static void TestFunctionTemplateInitializer(Handler handler,
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
CHECK_EQ(102, script->Run()->Int32Value()); CHECK_EQ(102, script->Run()->Int32Value());
} }
if (is_profiling) {
cpu_profiler->DeleteAllCpuProfiles();
}
}
} }
} }
...@@ -996,17 +992,9 @@ static void TestFunctionTemplateInitializer(Handler handler, ...@@ -996,17 +992,9 @@ static void TestFunctionTemplateInitializer(Handler handler,
template<typename Constructor, typename Accessor> template<typename Constructor, typename Accessor>
static void TestFunctionTemplateAccessor(Constructor constructor, static void TestFunctionTemplateAccessor(Constructor constructor,
Accessor accessor) { Accessor accessor) {
for (int i = 0; i < 2; i++) {
bool is_profiling = (i > 0);
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
if (is_profiling) {
v8::Local<v8::String> profile_name = v8::String::New("my_profile1");
cpu_profiler->StartCpuProfiling(profile_name);
}
Local<v8::FunctionTemplate> fun_templ = Local<v8::FunctionTemplate> fun_templ =
v8::FunctionTemplate::New(constructor); v8::FunctionTemplate::New(constructor);
fun_templ->SetClassName(v8_str("funky")); fun_templ->SetClassName(v8_str("funky"));
...@@ -1025,15 +1013,10 @@ static void TestFunctionTemplateAccessor(Constructor constructor, ...@@ -1025,15 +1013,10 @@ static void TestFunctionTemplateAccessor(Constructor constructor,
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
CHECK_EQ(239, script->Run()->Int32Value()); CHECK_EQ(239, script->Run()->Int32Value());
} }
if (is_profiling) {
cpu_profiler->DeleteAllCpuProfiles();
}
}
} }
THREADED_TEST(FunctionTemplate) { THREADED_PROFILED_TEST(FunctionTemplate) {
TestFunctionTemplateInitializer(handle_call, handle_call_2); TestFunctionTemplateInitializer(handle_call, handle_call_2);
TestFunctionTemplateInitializer(handle_call_indirect, handle_call_indirect_2); TestFunctionTemplateInitializer(handle_call_indirect, handle_call_indirect_2);
TestFunctionTemplateInitializer(handle_callback, handle_callback_2); TestFunctionTemplateInitializer(handle_callback, handle_callback_2);
...@@ -1067,17 +1050,9 @@ static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { ...@@ -1067,17 +1050,9 @@ static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
template<typename Callback> template<typename Callback>
static void TestSimpleCallback(Callback callback) { static void TestSimpleCallback(Callback callback) {
for (int i = 0; i < 2; i++) {
bool is_profiling = i;
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
if (is_profiling) {
v8::Local<v8::String> profile_name = v8::String::New("my_profile1");
cpu_profiler->StartCpuProfiling(profile_name);
}
v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
object_template->Set("callback", v8::FunctionTemplate::New(callback)); object_template->Set("callback", v8::FunctionTemplate::New(callback));
v8::Local<v8::Object> object = object_template->NewInstance(); v8::Local<v8::Object> object = object_template->NewInstance();
...@@ -1091,15 +1066,10 @@ static void TestSimpleCallback(Callback callback) { ...@@ -1091,15 +1066,10 @@ static void TestSimpleCallback(Callback callback) {
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
CHECK_EQ(51425, script->Run()->Int32Value()); CHECK_EQ(51425, script->Run()->Int32Value());
} }
if (is_profiling) {
cpu_profiler->DeleteAllCpuProfiles();
}
}
} }
THREADED_TEST(SimpleCallback) { THREADED_PROFILED_TEST(SimpleCallback) {
TestSimpleCallback(SimpleDirectCallback); TestSimpleCallback(SimpleDirectCallback);
TestSimpleCallback(SimpleIndirectCallback); TestSimpleCallback(SimpleIndirectCallback);
TestSimpleCallback(SimpleCallback); TestSimpleCallback(SimpleCallback);
......
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