11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst cp = require('child_process'); 51cb0ef41Sopenharmony_ciconst fs = require('fs'); 61cb0ef41Sopenharmony_ciconst path = require('path'); 71cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst names = [ 101cb0ef41Sopenharmony_ci 'ContextifyScript::New', 111cb0ef41Sopenharmony_ci 'RunInContext', 121cb0ef41Sopenharmony_ci]; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') { 151cb0ef41Sopenharmony_ci const vm = require('vm'); 161cb0ef41Sopenharmony_ci vm.runInNewContext('1 + 1'); 171cb0ef41Sopenharmony_ci} else { 181cb0ef41Sopenharmony_ci tmpdir.refresh(); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci const proc = cp.fork(__filename, 211cb0ef41Sopenharmony_ci [ 'child' ], { 221cb0ef41Sopenharmony_ci cwd: tmpdir.path, 231cb0ef41Sopenharmony_ci execArgv: [ 241cb0ef41Sopenharmony_ci '--trace-event-categories', 251cb0ef41Sopenharmony_ci 'node.vm.script', 261cb0ef41Sopenharmony_ci ] 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci proc.once('exit', common.mustCall(() => { 301cb0ef41Sopenharmony_ci const file = path.join(tmpdir.path, 'node_trace.1.log'); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci assert(fs.existsSync(file)); 331cb0ef41Sopenharmony_ci fs.readFile(file, common.mustCall((err, data) => { 341cb0ef41Sopenharmony_ci const traces = JSON.parse(data.toString()).traceEvents 351cb0ef41Sopenharmony_ci .filter((trace) => trace.cat !== '__metadata'); 361cb0ef41Sopenharmony_ci traces.forEach((trace) => { 371cb0ef41Sopenharmony_ci assert.strictEqual(trace.pid, proc.pid); 381cb0ef41Sopenharmony_ci assert(names.includes(trace.name)); 391cb0ef41Sopenharmony_ci }); 401cb0ef41Sopenharmony_ci })); 411cb0ef41Sopenharmony_ci })); 421cb0ef41Sopenharmony_ci} 43