1'use strict';
2const common = require('../common');
3if (common.isWindows)
4  common.skip('No signals on Window');
5
6const assert = require('assert');
7const { spawnSync } = require('child_process');
8
9// Test that a hard crash does not cause an endless loop.
10
11if (process.argv[2] === 'child') {
12  const { internalBinding } = require('internal/test/binding');
13  const { causeSegfault } = internalBinding('process_methods');
14
15  causeSegfault();
16} else {
17  const child = spawnSync(process.execPath,
18                          ['--expose-internals', __filename, 'child'],
19                          { stdio: 'inherit' });
20  // FreeBSD uses SIGILL (v12.2) or SIGBUS (v12.4 and greater) for this kind of crash.
21  // macOS uses SIGILL or SIGTRAP (arm64) for this kind of crash.
22  const allowedSignals = ['SIGSEGV', 'SIGILL', 'SIGTRAP', 'SIGBUS'];
23  assert(
24    allowedSignals.includes(child.signal),
25    `child.signal = ${child.signal}`,
26  );
27}
28