11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst cp = require('child_process');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst CODE = `
71cb0ef41Sopenharmony_ci  const { internalBinding } = require('internal/test/binding');
81cb0ef41Sopenharmony_ci  const { isTraceCategoryEnabled } = internalBinding('trace_events');
91cb0ef41Sopenharmony_ci  console.log(
101cb0ef41Sopenharmony_ci    isTraceCategoryEnabled("custom")
111cb0ef41Sopenharmony_ci  );
121cb0ef41Sopenharmony_ci`;
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
151cb0ef41Sopenharmony_citmpdir.refresh();
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciconst procEnabled = cp.spawn(
181cb0ef41Sopenharmony_ci  process.execPath,
191cb0ef41Sopenharmony_ci  [ '--trace-event-categories', 'custom',
201cb0ef41Sopenharmony_ci    // Make test less noisy since internal/test/binding
211cb0ef41Sopenharmony_ci    // emits a warning.
221cb0ef41Sopenharmony_ci    '--no-warnings',
231cb0ef41Sopenharmony_ci    '--expose-internals',
241cb0ef41Sopenharmony_ci    '-e', CODE ],
251cb0ef41Sopenharmony_ci  { cwd: tmpdir.path }
261cb0ef41Sopenharmony_ci);
271cb0ef41Sopenharmony_cilet procEnabledOutput = '';
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciprocEnabled.stdout.on('data', (data) => procEnabledOutput += data);
301cb0ef41Sopenharmony_ciprocEnabled.stderr.pipe(process.stderr);
311cb0ef41Sopenharmony_ciprocEnabled.once('close', common.mustCall(() => {
321cb0ef41Sopenharmony_ci  assert.strictEqual(procEnabledOutput, 'true\n');
331cb0ef41Sopenharmony_ci}));
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciconst procDisabled = cp.spawn(
361cb0ef41Sopenharmony_ci  process.execPath,
371cb0ef41Sopenharmony_ci  [ '--trace-event-categories', 'other',
381cb0ef41Sopenharmony_ci    // Make test less noisy since internal/test/binding
391cb0ef41Sopenharmony_ci    // emits a warning.
401cb0ef41Sopenharmony_ci    '--no-warnings',
411cb0ef41Sopenharmony_ci    '--expose-internals',
421cb0ef41Sopenharmony_ci    '-e', CODE ],
431cb0ef41Sopenharmony_ci  { cwd: tmpdir.path }
441cb0ef41Sopenharmony_ci);
451cb0ef41Sopenharmony_cilet procDisabledOutput = '';
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ciprocDisabled.stdout.on('data', (data) => procDisabledOutput += data);
481cb0ef41Sopenharmony_ciprocDisabled.stderr.pipe(process.stderr);
491cb0ef41Sopenharmony_ciprocDisabled.once('close', common.mustCall(() => {
501cb0ef41Sopenharmony_ci  assert.strictEqual(procDisabledOutput, 'false\n');
511cb0ef41Sopenharmony_ci}));
52