| 94 | ]; |
| 95 | |
| 96 | function runTest(test) { |
| 97 | const report = { |
| 98 | title: test.title, |
| 99 | perfMap: '[uninitialized]', |
| 100 | errors: [], |
| 101 | }; |
| 102 | |
| 103 | const args = test.nodeFlags.concat(fixtures.path('linux-perf-logger.js')); |
| 104 | const run = spawnSync(process.execPath, args, { cwd: tmpdir.path, encoding: 'utf8' }); |
| 105 | if (run.error) { |
| 106 | report.errors.push(run.error.stack); |
| 107 | return report; |
| 108 | } |
| 109 | if (run.status !== 0) { |
| 110 | report.errors.push(`running script:\n${run.stderr}`); |
| 111 | return report; |
| 112 | } |
| 113 | |
| 114 | try { |
| 115 | report.perfMap = readFileSync(`/tmp/perf-${run.pid}.map`, 'utf8'); |
| 116 | } catch (err) { |
| 117 | report.errors.push(`reading perf map: ${err.stack}`); |
| 118 | return report; |
| 119 | } |
| 120 | |
| 121 | const hexRegex = '[a-fA-F0-9]+'; |
| 122 | for (const testRegex of test.matches) { |
| 123 | const lineRegex = new RegExp(`${hexRegex} ${hexRegex}.* ${testRegex}`); |
| 124 | if (!lineRegex.test(report.perfMap)) { |
| 125 | report.errors.push(`Expected to match ${lineRegex}`); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | for (const regex of test.noMatches) { |
| 130 | const noMatch = new RegExp(regex); |
| 131 | if (noMatch.test(report.perfMap)) { |
| 132 | report.errors.push(`Expected not to match ${noMatch}`); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return report; |
| 137 | } |
| 138 | |
| 139 | function serializeError(report, index) { |
| 140 | return `[ERROR ${index + 1}] ${report.title} |