11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This test is to ensure that --diagnostic-dir does not change the directory 41cb0ef41Sopenharmony_ci// for --cpu-prof when --cpu-prof-dir is specified 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 81cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst assert = require('assert'); 111cb0ef41Sopenharmony_ciconst fs = require('fs'); 121cb0ef41Sopenharmony_ciconst path = require('path'); 131cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 161cb0ef41Sopenharmony_ciconst { 171cb0ef41Sopenharmony_ci getCpuProfiles, 181cb0ef41Sopenharmony_ci kCpuProfInterval, 191cb0ef41Sopenharmony_ci env, 201cb0ef41Sopenharmony_ci verifyFrames 211cb0ef41Sopenharmony_ci} = require('../common/cpu-prof'); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci// Test --diagnostic-dir changes the default for --cpu-prof 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci{ 261cb0ef41Sopenharmony_ci tmpdir.refresh(); 271cb0ef41Sopenharmony_ci const dir = path.join(tmpdir.path, 'prof'); 281cb0ef41Sopenharmony_ci const output = spawnSync(process.execPath, [ 291cb0ef41Sopenharmony_ci '--cpu-prof', 301cb0ef41Sopenharmony_ci '--cpu-prof-interval', 311cb0ef41Sopenharmony_ci kCpuProfInterval, 321cb0ef41Sopenharmony_ci '--diagnostic-dir', 331cb0ef41Sopenharmony_ci dir, 341cb0ef41Sopenharmony_ci fixtures.path('workload', 'fibonacci.js'), 351cb0ef41Sopenharmony_ci ], { 361cb0ef41Sopenharmony_ci cwd: tmpdir.path, 371cb0ef41Sopenharmony_ci env 381cb0ef41Sopenharmony_ci }); 391cb0ef41Sopenharmony_ci if (output.status !== 0) { 401cb0ef41Sopenharmony_ci console.log(output.stderr.toString()); 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci assert.strictEqual(output.status, 0); 431cb0ef41Sopenharmony_ci assert(fs.existsSync(dir)); 441cb0ef41Sopenharmony_ci const profiles = getCpuProfiles(dir); 451cb0ef41Sopenharmony_ci assert.strictEqual(profiles.length, 1); 461cb0ef41Sopenharmony_ci verifyFrames(output, profiles[0], 'fibonacci.js'); 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci// Test --cpu-prof-dir overwrites --diagnostic-dir 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci{ 521cb0ef41Sopenharmony_ci tmpdir.refresh(); 531cb0ef41Sopenharmony_ci const dir = path.join(tmpdir.path, 'diag'); 541cb0ef41Sopenharmony_ci const dir2 = path.join(tmpdir.path, 'prof'); 551cb0ef41Sopenharmony_ci const output = spawnSync(process.execPath, [ 561cb0ef41Sopenharmony_ci '--cpu-prof', 571cb0ef41Sopenharmony_ci '--cpu-prof-interval', 581cb0ef41Sopenharmony_ci kCpuProfInterval, 591cb0ef41Sopenharmony_ci '--diagnostic-dir', 601cb0ef41Sopenharmony_ci dir, 611cb0ef41Sopenharmony_ci '--cpu-prof-dir', 621cb0ef41Sopenharmony_ci dir2, 631cb0ef41Sopenharmony_ci fixtures.path('workload', 'fibonacci.js'), 641cb0ef41Sopenharmony_ci ], { 651cb0ef41Sopenharmony_ci cwd: tmpdir.path, 661cb0ef41Sopenharmony_ci env 671cb0ef41Sopenharmony_ci }); 681cb0ef41Sopenharmony_ci if (output.status !== 0) { 691cb0ef41Sopenharmony_ci console.log(output.stderr.toString()); 701cb0ef41Sopenharmony_ci } 711cb0ef41Sopenharmony_ci assert.strictEqual(output.status, 0); 721cb0ef41Sopenharmony_ci assert(fs.existsSync(dir2)); 731cb0ef41Sopenharmony_ci const profiles = getCpuProfiles(dir2); 741cb0ef41Sopenharmony_ci assert.strictEqual(profiles.length, 1); 751cb0ef41Sopenharmony_ci verifyFrames(output, profiles[0], 'fibonacci.js'); 761cb0ef41Sopenharmony_ci} 77