Skip to content

Commit bb5159a

Browse files
authored
[nextest-runner] handle SIGINFO and SIGUSR1 to dump info to screen (#1938)
Part 1 of work to perform interactive queries. With this change, if nextest receives either SIGINFO (where available) or SIGUSR1, it will print a list of all currently running tests with their states. The full test state machine is modeled in the event responses, along with possible sources of errors. I tried making Ctrl-Break on Windows do the same thing, but unfortunately that doesn't quite work in practice. That's because Ctrl-Break is received by all processes connected to the console, not just by the equivalent of the "foreground process group". The printing out of info works, but running tests are immediately aborted as well. So remove this. (In interactive terminals we'll support an alternative -- pressing `i` -- which should work for most use cases on Windows.) There is also an undocumented environment variable `__NEXTEST_SIGQUIT_AS_INFO` which allows `SIGQUIT` (`Ctrl-\`) to perform an info query. Quite useful for testing on Linux, where SIGINFO is sadly unavailable. Note: illumos does support SIGINFO, but that is blocked on an upstream issue: tokio-rs/tokio#6995
1 parent e2af307 commit bb5159a

File tree

13 files changed

+2098
-219
lines changed

13 files changed

+2098
-219
lines changed

nextest-runner/src/errors.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
use crate::{
77
cargo_config::{TargetTriple, TargetTripleSource},
88
config::{ConfigExperimental, CustomTestGroup, ScriptId, TestGroup},
9-
helpers::{dylib_path_envvar, extract_abort_status},
9+
helpers::{display_exit_status, dylib_path_envvar},
1010
redact::Redactor,
1111
reuse_build::{ArchiveFormat, ArchiveStep},
12-
runner::AbortStatus,
1312
target_runner::PlatformRunnerSource,
1413
};
1514
use camino::{FromPathBufError, Utf8Path, Utf8PathBuf};
@@ -974,30 +973,6 @@ impl CreateTestListError {
974973
}
975974
}
976975

977-
fn display_exit_status(exit_status: ExitStatus) -> String {
978-
match extract_abort_status(exit_status) {
979-
#[cfg(unix)]
980-
Some(AbortStatus::UnixSignal(sig)) => match crate::helpers::signal_str(sig) {
981-
Some(s) => {
982-
format!("signal {sig} (SIG{s})")
983-
}
984-
None => {
985-
format!("signal {sig}")
986-
}
987-
},
988-
#[cfg(windows)]
989-
Some(AbortStatus::WindowsNtStatus(nt_status)) => {
990-
format!("code {}", crate::helpers::display_nt_status(nt_status))
991-
}
992-
None => match exit_status.code() {
993-
Some(code) => {
994-
format!("code {code}")
995-
}
996-
None => "an unknown error".to_owned(),
997-
},
998-
}
999-
}
1000-
1001976
/// An error that occurs while writing list output.
1002977
#[derive(Debug, Error)]
1003978
#[non_exhaustive]

nextest-runner/src/helpers.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,35 @@ pub(crate) fn extract_abort_status(exit_status: ExitStatus) -> Option<AbortStatu
313313
}
314314
}
315315

316+
pub(crate) fn display_exit_status(exit_status: ExitStatus) -> String {
317+
match extract_abort_status(exit_status) {
318+
Some(abort_status) => display_abort_status(abort_status),
319+
None => match exit_status.code() {
320+
Some(code) => format!("exit code {}", code),
321+
None => "an unknown error".to_owned(),
322+
},
323+
}
324+
}
325+
326+
/// Display the abort status.
327+
pub(crate) fn display_abort_status(abort_status: AbortStatus) -> String {
328+
match abort_status {
329+
#[cfg(unix)]
330+
AbortStatus::UnixSignal(sig) => match crate::helpers::signal_str(sig) {
331+
Some(s) => {
332+
format!("signal {sig} (SIG{s})")
333+
}
334+
None => {
335+
format!("signal {sig}")
336+
}
337+
},
338+
#[cfg(windows)]
339+
AbortStatus::WindowsNtStatus(nt_status) => {
340+
format!("code {}", crate::helpers::display_nt_status(nt_status))
341+
}
342+
}
343+
}
344+
316345
#[cfg(unix)]
317346
pub(crate) fn signal_str(signal: i32) -> Option<&'static str> {
318347
// These signal numbers are the same on at least Linux, macOS, FreeBSD and illumos.

nextest-runner/src/list/test_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ impl<'a> TestInstance<'a> {
990990
/// Return an identifier for test instances, including being able to sort
991991
/// them.
992992
#[inline]
993-
pub(crate) fn id(&self) -> TestInstanceId<'a> {
993+
pub fn id(&self) -> TestInstanceId<'a> {
994994
TestInstanceId {
995995
binary_id: &self.suite_info.binary_id,
996996
test_name: self.name,
@@ -1060,7 +1060,7 @@ impl<'a> TestInstance<'a> {
10601060
///
10611061
/// Returned by [`TestInstance::id`].
10621062
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
1063-
pub(crate) struct TestInstanceId<'a> {
1063+
pub struct TestInstanceId<'a> {
10641064
/// The binary ID.
10651065
pub binary_id: &'a RustBinaryId,
10661066

nextest-runner/src/reporter/aggregator.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ impl<'cfg> MetadataJunit<'cfg> {
6565
| TestEventKind::RunContinued { .. } => {}
6666
TestEventKind::SetupScriptStarted { .. }
6767
| TestEventKind::SetupScriptSlow { .. }
68-
| TestEventKind::SetupScriptFinished { .. } => {}
68+
| TestEventKind::SetupScriptFinished { .. }
69+
| TestEventKind::InfoStarted { .. }
70+
| TestEventKind::InfoResponse { .. }
71+
| TestEventKind::InfoFinished { .. } => {}
6972
TestEventKind::TestStarted { .. } => {}
7073
TestEventKind::TestSlow { .. } => {}
7174
TestEventKind::TestAttemptFailedWillRetry { .. }

0 commit comments

Comments
 (0)