Skip to content

Commit

Permalink
Debug test
Browse files Browse the repository at this point in the history
  • Loading branch information
Drieger committed Jan 30, 2019
1 parent f3ab09e commit dbda298
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 92 deletions.
62 changes: 62 additions & 0 deletions test/fixtures/scan-scenario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

const common = require('../common');

const zlib = require('zlib');

let outerVar = 'outer variable';

exports.holder = {};

function makeThin(a, b) {
var str = a + b;
var obj = {};
obj[str]; // Turn the cons string into a thin string.
return str;
}

function closure() {

function Class() {
this.x = 1;
this.y = 123.456;

this.hashmap = {};
}


Class.prototype.method = function method() {
throw new Error('Uncaught');
};

const c = new Class();


let scopedVar = 'scoped value';
let scopedAPI = zlib.createDeflate()._handle;
let scopedArray = [ 0, scopedAPI ];

exports.holder = scopedAPI;

c.hashmap.scoped = function name() {
return scopedVar + outerVar + scopedAPI + scopedArray;
};

function Class_B() {
this.my_class_b = "Class B";
}

function Class_C(class_b_array) {
this.arr = class_b_array;
this.my_class_c = "My Class C";
}

const arr = new Array();
for(let i=0; i < 10; i++) arr.push(new Class_B());

let classC = new Class_C(arr);

c.method();
}

closure();
208 changes: 116 additions & 92 deletions test/plugin/scan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tape('v8 findrefs and friends', (t) => {
test(process.env.LLNODE_NODE_EXE, process.env.LLNODE_CORE, t);
} else {
common.saveCore({
scenario: 'inspect-scenario.js'
scenario: 'scan-scenario.js'
}, (err) => {
t.error(err);
t.ok(true, 'Saved core');
Expand All @@ -27,116 +27,140 @@ function test(executable, core, t) {
t.error(err);
t.ok(true, 'Loaded core');

sess.send('v8 findjsobjects');
// Just a separator
sess.send('version');
});

sess.linesUntil(versionMark, (err, lines) => {
t.error(err);
t.ok(/\d+ Class/.test(lines.join('\n')), 'Class should be in findjsobjects');

sess.send('v8 findjsobjects -d');
// Just a separator
sess.send('version');
});

sess.linesUntil(versionMark, (err, lines) => {
t.error(err);
t.ok(/3 +0 Class: x, y, hashmap/.test(lines.join('\n')),
'"Class: x, y, hashmap" should be in findjsobjects -d');

sess.send('v8 findjsinstances Class_B')
// sess.send('v8 findjsobjects');
sess.send('v8 findrefs -s "My Class C"');
// Just a separator
// sess.send('version');
sess.send('version');
});

// Test for findrefs -s
sess.linesUntil(versionMark, (err, lines) => {
t.error(err);

t.ok((lines.join('\n').match(/<Object: Class_B>/g)).length == 10, 'Should show 10 instances');
t.ok(/\(Showing 1 to 10 of 10 instances\)/.test(lines.join('\n')), 'Should show 1 to 10 ');

sess.send('v8 findjsinstances -n 5 Class_B');
sess.send('version');
});

sess.linesUntil(versionMark, (err, lines) => {
t.error(err);

t.ok((lines.join('\n').match(/<Object: Class_B>/g)).length == 5, 'Should show 5 instances');
t.ok(/\.\.\.\.\.\.\.\.\.\./.test(lines.join('\n')), 'Should show that more instances are available');
t.ok(/\(Showing 1 to 5 of 10 instances\)/.test(lines.join('\n')), 'Should show 1 to 5 ');

sess.send('v8 findjsinstances -n 5 Class_B');
t.ok(/(0x[0-9a-f]+): Class_C\.my_class_c=(0x[0-9a-f]+)/.test(lines.join('\n')), 'Should find class C with string');
sess.send('v8 findjsinstances Zlib');
sess.send('version');
});

sess.linesUntil(versionMark, (err, lines) => {
t.error(err);

t.ok((lines.join('\n').match(/<Object: Class_B>/g)).length == 5, 'Should show 5 instances');
t.notOk(/\.\.\.\.\.\.\.\.\.\./.test(lines.join('\n')), 'Should not show ellipses');
t.ok(/\(Showing 6 to 10 of 10 instances\)/.test(lines.join('\n')), 'Should show 6 to 10 ');

sess.send('v8 findjsinstances Class_B');
sess.send('version');
});
// Test for -r -s
/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
* t.ok(/Class_C\.arr/.test(lines.join('\n')), 'Should find parent reference with -r -s' );
* sess.send('v8 findjsinstances Zlib');
* sess.send('version');
* });
*/

/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
* t.ok(/\d+ Class/.test(lines.join('\n')), 'Class should be in findjsobjects');
*
* sess.send('v8 findjsobjects -d');
* // Just a separator
* sess.send('version');
* });
*/

/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
* t.ok(/3 +0 Class: x, y, hashmap/.test(lines.join('\n')),
* '"Class: x, y, hashmap" should be in findjsobjects -d');
*
* sess.send('v8 findjsinstances Class_B')
* // Just a separator
* sess.send('version');
* });
*/

/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
*
* t.ok((lines.join('\n').match(/<Object: Class_B>/g)).length == 10, 'Should show 10 instances');
* t.ok(/\(Showing 1 to 10 of 10 instances\)/.test(lines.join('\n')), 'Should show 1 to 10 ');
*
* sess.send('v8 findjsinstances -n 5 Class_B');
* sess.send('version');
* });
*/

/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
*
* t.ok((lines.join('\n').match(/<Object: Class_B>/g)).length == 5, 'Should show 5 instances');
* t.ok(/\.\.\.\.\.\.\.\.\.\./.test(lines.join('\n')), 'Should show that more instances are available');
* t.ok(/\(Showing 1 to 5 of 10 instances\)/.test(lines.join('\n')), 'Should show 1 to 5 ');
*
* sess.send('v8 findjsinstances -n 5 Class_B');
* sess.send('version');
* });
*/

/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
*
* t.ok((lines.join('\n').match(/<Object: Class_B>/g)).length == 5, 'Should show 5 instances');
* t.notOk(/\.\.\.\.\.\.\.\.\.\./.test(lines.join('\n')), 'Should not show ellipses');
* t.ok(/\(Showing 6 to 10 of 10 instances\)/.test(lines.join('\n')), 'Should show 6 to 10 ');
*
* sess.send('v8 findjsinstances Class_B');
* sess.send('version');
* });
*/

// Test for recursive findrefs, a new `Class_C` was introduced in `inspect-scenario.js`
sess.linesUntil(versionMark, (err, lines) => {
t.error(err);

for (let i=0; i < lines.length; i++) {
const match = lines[i].match(/(0x[0-9a-f]+):<Object: Class_B>/i);
if (match) {
sess.send(`v8 findrefs -r ${match[1]}`);
break;
}
}
sess.send('version');
});
/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
*
* for (let i=0; i < lines.length; i++) {
* const match = lines[i].match(/(0x[0-9a-f]+):<Object: Class_B>/i);
* if (match) {
* sess.send(`v8 findrefs -r ${match[1]}`);
* break;
* }
* }
* sess.send('version');
* });
*/

// Test if parent `Class_C` is present on tree generated by previous command
// This means that we successfully transversed the reference tree
sess.linesUntil(versionMark, (err, lines) => {
t.error(err);
t.ok(/Class_C\.arr/.test(lines.join('\n')), 'Should find parent reference' );
sess.send('v8 findrefs -n my_class_c');
sess.send('version');
});
/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
* t.ok(/Class_C\.arr/.test(lines.join('\n')), 'Should find parent reference' );
* sess.send('v8 findrefs -n my_class_c');
* sess.send('version');
* });
*/

// Test for findrefs -n
sess.linesUntil(versionMark, (err, lines) => {
t.error(err);
t.ok(/(0x[0-9a-f]+): Class_C\.my_class_c=(0x[0-9a-f]+)/.test(lines.join('\n')), 'Should find class C with property');
sess.send('v8 findrefs -s "My Class C"');
sess.send('version');
});
/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
* t.ok(/(0x[0-9a-f]+): Class_C\.my_class_c=(0x[0-9a-f]+)/.test(lines.join('\n')), 'Should find class C with property');
* sess.send('v8 findrefs -r -n my_class_b');
* sess.send('version');
* });
*/

// Test for findrefs -s
sess.linesUntil(versionMark, (err, lines) => {
t.error(err);
t.ok(/(0x[0-9a-f]+): Class_C\.my_class_c=(0x[0-9a-f]+)/.test(lines.join('\n')), 'Should find class C with string');
sess.send('v8 findrefs -r -s "Class B"');
sess.send('version');
});
// Test for -r -n
/*
* sess.linesUntil(versionMark, (err, lines) => {
* t.error(err);
* t.ok(/Class_C\.arr/.test(lines.join('\n')), 'Should find parent reference with -r -n' );
* sess.send('v8 findrefs -s "My Class C"');
* sess.send('version');
* });
*/

// Test for -r -s
sess.linesUntil(versionMark, (err, lines) => {
t.error(err);
t.ok(/Class_C\.arr/.test(lines.join('\n')), 'Should find parent reference with -r -s' );
sess.send('v8 findrefs -r -n "name"');
sess.send('version');
});

// Test for -r -n
sess.linesUntil(versionMark, (err, lines) => {
t.error(err);
t.ok(/Class_C\.arr/.test(lines.join('\n')), 'Should find parent reference with -r -n' );
sess.send('v8 findjsinstances Zlib');
sess.send('version');
});

sess.linesUntil(versionMark, (err, lines) => {
t.error(err);
Expand Down

0 comments on commit dbda298

Please sign in to comment.