Files
gex/test/gexcc/trapstack.test.js
velzieandClaude Opus 5.5 8e6a09ad2d GEX_TRAP_STACK: a guest's trap's engine stack too
The switch kept stack traces and printed them for the runtime's own
crashes; a wasm32 program's trap (the process killed by its signal) now
says its stack once, on one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_e0aa53aa95eb4b86910519b4d14812a5
2026-11-10 06:17:33 -05:00

31 lines
1.7 KiB
JavaScript

// GEX_TRAP_STACK=1: a guest trap's engine stack on stderr, in the page's
// runtime under Node, and nothing of it without the switch. The program is
// fixtures/gexcc/programs/faultsig.c's `trap` case (__builtin_trap, SIGILL).
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { FIXTURES, gexcc } from '../lib/gexcc.mjs';
export const meta = { hosts: ['node'], timeout: 600 };
const ROOT = join(import.meta.dirname, '..', '..');
export default async function (t) {
const c = gexcc(t);
const x86 = t.arch === 'x86';
const seed = join(ROOT, 'page/public/gex', `seed${x86 ? '.x86' : ''}.shared.wasm`);
if (!existsSync(seed)) t.skip(`no ${seed} (make assets)`);
const d = c.dir('trapstack');
await c.build(['-O1', '-w', '-o', `${d}/faultsig`, join(FIXTURES, 'programs', 'faultsig.c')]);
const run = (on) => c.run([process.execPath, join(ROOT, 'hosts/browser/js/run-node.mjs'),
'--file', `/t/faultsig=${d}/faultsig`, '--cwd', '/t', '--argv0', './faultsig', seed, `${d}/faultsig`, 'trap'],
{ cwd: d, env: { GEX_ARCH: x86 ? 'x86' : 'aarch64', GEX_SHARED: '1', ...(on ? { GEX_TRAP_STACK: '1' } : {}) } });
const on = await run(true);
const line = on.out.split('\n').find((l) => l.includes('[trapstack]')) ?? '';
t.check('trapstack: the trap and its stack', /unreachable/i.test(line) && /wasm-function|wasm:\/\//.test(line), on.out.split('\n').slice(-6).join(' / '));
t.check('trapstack: the process died of SIGILL', on.code === 128 + 4 || on.code === -4 || on.code === 4, `exit ${on.code}`);
const off = await run(false);
t.check('off: no stack', !off.out.includes('[trapstack]'), off.out.split('\n').slice(-3).join(' / '));
c.clean();
}