Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Fix version reporting in NodeReport section
Browse files Browse the repository at this point in the history
Report the versions of Node.js and its components based on the runtime
and not compile time constants.

Extend the tests to validate the versions reported in the report.

Fixes: #29
  • Loading branch information
richardlau committed Nov 24, 2016
1 parent 95a046e commit 4788811
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
31 changes: 22 additions & 9 deletions src/node_report.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "node_report.h"
#include "node_version.h"
#include "v8.h"
#include "time.h"
#include "zlib.h"
#include "ares.h"

#include <fcntl.h>
#include <string.h>
Expand Down Expand Up @@ -52,7 +49,7 @@ using v8::String;
using v8::V8;

// Internal/static function declarations
static void PrintVersionInformation(FILE* fp);
static void PrintVersionInformation(FILE* fp, Isolate* isolate);
static void PrintJavaScriptStack(FILE* fp, Isolate* isolate, DumpEvent event, const char* location);
static void PrintStackFromStackTrace(FILE* fp, Isolate* isolate, DumpEvent event);
static void PrintStackFrame(FILE* fp, Isolate* isolate, Local<StackFrame> frame, int index, void* pc);
Expand Down Expand Up @@ -317,7 +314,7 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c
fflush(fp);

// Print Node.js and OS version information
PrintVersionInformation(fp);
PrintVersionInformation(fp, isolate);
fflush(fp);

// Print summary JavaScript stack backtrace
Expand Down Expand Up @@ -369,12 +366,28 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c
* Function to print Node.js version, OS version and machine information
*
******************************************************************************/
static void PrintVersionInformation(FILE* fp) {
static void PrintVersionInformation(FILE* fp, Isolate* isolate) {

// Print Node.js and deps component versions
fprintf(fp, "\nNode.js version: %s\n", NODE_VERSION);
fprintf(fp, "(v8: %s, libuv: %s, zlib: %s, ares: %s)\n",
V8::GetVersion(), uv_version_string(), ZLIB_VERSION, ARES_VERSION_STR);
fprintf(fp, "\nprocess.versions = {\n");
{
Nan::MaybeLocal<Value> process = Nan::Get(
isolate->GetCurrentContext()->Global(),
Nan::New<String>("process").ToLocalChecked());
Local<Value> versions = Nan::Get(process.ToLocalChecked().As<Object>(),
Nan::New<String>("versions").ToLocalChecked()).ToLocalChecked();
Local<Object> versionsObj = versions.As<Object>();
Local<v8::Array> keys = Nan::GetOwnPropertyNames(versionsObj)
.ToLocalChecked();
for (uint32_t i = 0, nKeys = (*keys)->Length(); i < nKeys; i++) {
Local<Value> keyVal = Nan::Get(keys.As<Object>(), i).ToLocalChecked();
Local<Value> valVal = Nan::Get(versionsObj, keyVal).ToLocalChecked();
Nan::Utf8String name(keyVal);
Nan::Utf8String version(valVal);
fprintf(fp, " %s: %s\n", *name, *version);
}
}
fprintf(fp, "}\n");

// Print operating system and machine information (Windows)
#ifdef _WIN32
Expand Down
26 changes: 21 additions & 5 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const REPORT_SECTIONS = [
'System Information'
];

const reNewline = '(?:\\r*\\n)'

exports.findReports = (pid) => {
// Default filenames are of the form NodeReport.<date>.<time>.<pid>.<seq>.txt
const format = '^NodeReport\\.\\d+\\.\\d+\\.' + pid + '\\.\\d+\\.txt$';
Expand All @@ -29,16 +31,30 @@ exports.validate = (t, report, pid) => {
t.test('Validating ' + report, (t) => {
fs.readFile(report, (err, data) => {
const reportContents = data.toString();
const plan = REPORT_SECTIONS.length + (pid ? 1 : 0);
const nodeComponents = Object.keys(process.versions);
const plan = REPORT_SECTIONS.length + (pid ? 1 : 0)
+ nodeComponents.length;
t.plan(plan);
if (pid) {
t.match(reportContents, new RegExp('Process ID: ' + pid),
'Checking report contains expected process ID ' + pid);
}
REPORT_SECTIONS.forEach((section) => {
t.match(reportContents, new RegExp('==== ' + section),
'Checking report contains ' + section + ' section');
});
const nodeReportSection = getSection(reportContents, 'NodeReport');
if (pid) {
t.match(nodeReportSection, new RegExp('Process ID: ' + pid),
'NodeReport section contains expected process ID');
}
nodeComponents.forEach((c) => {
t.match(nodeReportSection, new RegExp(c + ': ' + process.versions[c]),
'NodeReport section contains expected ' + c + ' version');
});
});
});
};

const getSection = (report, section) => {
const re = new RegExp('==== ' + section + ' =+' + reNewline + '+([\\S\\s]+?)'
+ reNewline + '+={80}' + reNewline);
const match = re.exec(report);
return match ? match[1] : '';
};

0 comments on commit 4788811

Please sign in to comment.