Permalink
Browse files

core, bugfix: ensure the coverage report could be generated successfu…

…lly. (#369)
  • Loading branch information...
ngot committed Nov 1, 2017
1 parent 95cf94c commit 5c42bd478ac07b4f462f5ddaa9ffad4dc27a90aa
Showing with 25 additions and 26 deletions.
  1. +1 −2 fibjs/include/options.h
  2. +1 −1 fibjs/include/v8_api.h
  3. +15 −5 fibjs/src/base/options.cpp
  4. +6 −10 fibjs/src/base/v8_api.cpp
  5. +2 −8 fibjs/src/process/process.cpp
View
@@ -17,8 +17,7 @@ extern int32_t stack_size;
extern bool g_prof;
extern int32_t g_prof_interval;
extern bool g_cov;
extern exlib::string g_cov_filename;
extern FILE* g_cov;
extern bool g_tracetcp;
}
View
@@ -23,7 +23,7 @@ exlib::string traceInfo(v8::Isolate* isolate, int32_t deep, void* entry_fp, void
exlib::string traceInfo(v8::Isolate* isolate, int32_t deep);
void beginCoverage(v8::Isolate* isolate);
void WriteLcovData(v8::Isolate* isolate, const char* file);
void WriteLcovData(v8::Isolate* isolate, FILE* file);
} /* namespace fibjs */
View
@@ -24,8 +24,7 @@ int32_t stack_size = 256;
bool g_prof = false;
int32_t g_prof_interval = 1000;
bool g_cov = false;
exlib::string g_cov_filename;
FILE* g_cov = nullptr;
bool g_tracetcp = false;
@@ -94,11 +93,22 @@ void options(int32_t& pos, char* argv[])
g_prof_interval = 50;
df++;
} else if (!qstrcmp(arg, "--cov=", 6)) {
g_cov = true;
g_cov_filename = arg + 6;
g_cov = fopen(arg + 6, "a");
if (g_cov == nullptr) {
printf("Invalid filename: %s\n", arg + 6);
_exit(0);
}
df++;
} else if (!qstrcmp(arg, "--cov")) {
g_cov = true;
char name[22];
date_t d;
d.now();
sprintf(name, "fibjs-%d.lcov", (int32_t)d.date());
g_cov = fopen(name, "a");
if (g_cov == nullptr) {
printf("Can't open file: %s, please try again", name);
_exit(0);
}
df++;
} else if (!qstrcmp(arg, "--v8-options")) {
v8::internal::FlagList::PrintHelp();
View
@@ -150,12 +150,8 @@ inline void WriteLcovDataForNamedRange(FILE* sink,
fprintf(sink, "FNDA:%d,%s\n", count, name.c_str());
}
void WriteLcovData(v8::Isolate* isolate, const char* file)
void WriteLcovData(v8::Isolate* isolate, FILE* file)
{
FILE* sink = fopen(file, "a");
if (sink == NULL)
return;
v8::HandleScope handle_scope(isolate);
v8::debug::Coverage coverage = v8::debug::Coverage::CollectPrecise(isolate);
@@ -167,7 +163,7 @@ void WriteLcovData(v8::Isolate* isolate, const char* file)
if (!script->Name().ToLocal(&name))
continue;
std::string file_name = ToSTLString(isolate, name);
fprintf(sink, "SF:%s\n", file_name.c_str());
fprintf(file, "SF:%s\n", file_name.c_str());
std::vector<uint32_t> lines;
for (size_t j = 0; j < script_data.FunctionCount(); j++) {
v8::debug::Coverage::FunctionData function_data = script_data.GetFunctionData(j);
@@ -189,7 +185,7 @@ void WriteLcovData(v8::Isolate* isolate, const char* file)
name_stream << start.GetColumnNumber() << ">";
}
WriteLcovDataForNamedRange(sink, lines, name_stream.str(), start_line,
WriteLcovDataForNamedRange(file, lines, name_stream.str(), start_line,
end_line, count);
}
@@ -204,11 +200,11 @@ void WriteLcovData(v8::Isolate* isolate, const char* file)
}
// Write per-line coverage. LCOV uses 1-based line numbers.
for (size_t i = 0; i < lines.size(); i++)
fprintf(sink, "DA:%d,%d\n", (int32_t)(i + 1), lines[i]);
fprintf(file, "DA:%d,%d\n", (int32_t)(i + 1), lines[i]);
fprintf(sink, "end_of_record\n");
fprintf(file, "end_of_record\n");
}
fclose(sink);
fclose(file);
}
}
@@ -267,14 +267,8 @@ result_t process_base::exit()
flushLog();
if (g_cov && isolate->m_id == 1) {
if (g_cov_filename.length() > 0) {
WriteLcovData(isolate->m_isolate, g_cov_filename.c_str());
} else {
char name[32];
sprintf(name, "fibjs-%08x.lcov", (uint32_t)(intptr_t)isolate);
WriteLcovData(isolate->m_isolate, name);
}
if (g_cov != nullptr && isolate->m_id == 1) {
WriteLcovData(isolate->m_isolate, g_cov);
}
#ifdef _WIN32

0 comments on commit 5c42bd4

Please sign in to comment.