Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: run abort tests #14013

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ test-all-valgrind: test-build
$(PYTHON) tools/test.py --mode=debug,release --valgrind

CI_NATIVE_SUITES := addons addons-napi
CI_JS_SUITES := async-hooks doctool inspector known_issues message parallel pseudo-tty sequential
CI_JS_SUITES := abort async-hooks doctool inspector known_issues message parallel pseudo-tty sequential

# Build and test addons without building anything else
test-ci-native: LOGLEVEL := info
Expand Down
20 changes: 13 additions & 7 deletions test/abort/test-abort-backtrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ if (process.argv[2] === 'child') {
process.abort();
} else {
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
const frames =
child.stderr.toString().trimRight().split('\n').map((s) => s.trim());
const stderr = child.stderr.toString();

assert.strictEqual(child.stdout.toString(), '');
assert.ok(frames.length > 0);
// All frames should start with a frame number.
assert.ok(frames.every((frame, index) => frame.startsWith(`${index + 1}:`)));
// At least some of the frames should include the binary name.
assert.ok(frames.some((frame) => frame.includes(`[${process.execPath}]`)));
// stderr will be empty for systems that don't support backtraces.
if (stderr !== '') {
const frames = stderr.trimRight().split('\n').map((s) => s.trim());

if (!frames.every((frame, index) => frame.startsWith(`${index + 1}:`))) {
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
}

if (!frames.some((frame) => frame.includes(`[${process.execPath}]`))) {
assert.fail(`Some frames should include the binary name:\n${stderr}`);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the number of frames is lesser than or equal to zero, wouldn't it be better to log it as ignored?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean call common.skip()? Or something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we want to assert that that behavior is consistent.

P.S. Need to open an issue for documenting this behavior in:

node/doc/api/process.md

Lines 406 to 413 in 99c478e

## process.abort()
<!-- YAML
added: v0.7.0
-->
The `process.abort()` method causes the Node.js process to exit immediately and
generate a core file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we want to assert that that behavior is consistent.

Assert that what behavior is consistent?

IIUC, there's no way to guarantee strictly from JS-land that a backtrace will be printed. It depends on which libc is used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott Yes, I meant common.skip only, because the test is actually not successful but we are skipping.

Copy link
Member Author

@Trott Trott Aug 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott Yes, I meant common.skip only, because the test is actually not successful but we are skipping.

Perhaps. I was thinking that we're still testing that we aren't getting a malformed backtrace. A well-formed backtrace is fine. No backtrace is fine. Malformed backtrace is a problem. But I could go either way. If you (or anyone) feels strongly that common.skip() should be used here, I'll do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above the if block says few systems don't support backtraces. We have a common.skip at the top of the file, for Windows. They both are the same?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows and AIX don't support it ever, but for everything else, it depends on which libc is used. See

#if defined(__linux__) && !defined(__GLIBC__) || \
defined(__UCLIBC__) || \
defined(_AIX)
#define HAVE_EXECINFO_H 0
#else
#define HAVE_EXECINFO_H 1
#endif

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Okay. Perhaps, we can set the skip message to Node.js is not compiled with GLIBC or something, like we do for OpenSSL.

Or lets not worry too much about it. The changes are good the way they are anyway. 👍

}
4 changes: 2 additions & 2 deletions test/abort/test-abort-uncaught-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (process.argv[2] === 'child') {
throw new Error('child error');
} else {
run('', null);
run('--abort-on-uncaught-exception', ['SIGABRT', 'SIGILL']);
run('--abort-on-uncaught-exception', ['SIGABRT', 'SIGTRAP', 'SIGILL']);
}

function run(flags, signals) {
Expand All @@ -26,7 +26,7 @@ function run(flags, signals) {
assert.strictEqual(code, 1);
} else {
if (signals)
assert.strictEqual(signals.includes(sig), true);
assert(signals.includes(sig), `Unexpected signal ${sig}`);
else
assert.strictEqual(sig, null);
}
Expand Down
2 changes: 1 addition & 1 deletion test/abort/testcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
import testpy

def GetConfiguration(context, root):
return testpy.SimpleTestConfiguration(context, root, 'abort')
return testpy.AbortTestConfiguration(context, root, 'abort')
12 changes: 12 additions & 0 deletions test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,15 @@ def ListTests(self, current_path, path, arch, mode):
for test in result:
test.parallel = True
return result

class AbortTestConfiguration(SimpleTestConfiguration):
def __init__(self, context, root, section, additional=None):
super(AbortTestConfiguration, self).__init__(context, root, section,
additional)

def ListTests(self, current_path, path, arch, mode):
result = super(AbortTestConfiguration, self).ListTests(
current_path, path, arch, mode)
for test in result:
test.disable_core_files = True
return result
18 changes: 15 additions & 3 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def __init__(self, context, path, arch, mode):
self.arch = arch
self.mode = mode
self.parallel = False
self.disable_core_files = False
self.thread_id = 0

def IsNegative(self):
Expand All @@ -516,7 +517,8 @@ def RunCommand(self, command, env):
output = Execute(full_command,
self.context,
self.context.GetTimeout(self.mode),
env)
env,
disable_core_files = self.disable_core_files)
self.Cleanup()
return TestOutput(self,
full_command,
Expand Down Expand Up @@ -718,7 +720,7 @@ def CheckedUnlink(name):
PrintError("os.unlink() " + str(e))
break

def Execute(args, context, timeout=None, env={}, faketty=False):
def Execute(args, context, timeout=None, env={}, faketty=False, disable_core_files=False):
if faketty:
import pty
(out_master, fd_out) = pty.openpty()
Expand All @@ -740,6 +742,14 @@ def Execute(args, context, timeout=None, env={}, faketty=False):
for key, value in env.iteritems():
env_copy[key] = value

preexec_fn = None

if disable_core_files and not utils.IsWindows():
def disableCoreFiles():
import resource
resource.setrlimit(resource.RLIMIT_CORE, (0,0))
preexec_fn = disableCoreFiles

(process, exit_code, timed_out, output) = RunProcess(
context,
timeout,
Expand All @@ -749,7 +759,8 @@ def Execute(args, context, timeout=None, env={}, faketty=False):
stderr = fd_err,
env = env_copy,
faketty = faketty,
pty_out = pty_out
pty_out = pty_out,
preexec_fn = preexec_fn
)
if faketty:
os.close(out_master)
Expand Down Expand Up @@ -1237,6 +1248,7 @@ def __init__(self, case, outcomes):
self.case = case
self.outcomes = outcomes
self.parallel = self.case.parallel
self.disable_core_files = self.case.disable_core_files


class Configuration(object):
Expand Down