Skip to content

Commit

Permalink
tests: Use nix signals when needed in tests
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Apr 25, 2024
1 parent 14e225a commit 32e66cd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
66 changes: 33 additions & 33 deletions src/sources/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macro_rules! define_signal_enum {
pub enum Signal {
$(
$(#[$inner:meta])*
$name:ident = $value:ident,
$value:ident,
)*
}
) => {
Expand All @@ -37,7 +37,7 @@ macro_rules! define_signal_enum {
pub enum Signal {
$(
$(#[$inner])*
$name = nix::sys::signal::Signal::$value as i32,
$value = nix::sys::signal::Signal::$value as i32,
)*
}

Expand All @@ -46,7 +46,7 @@ macro_rules! define_signal_enum {
fn as_nix(self) -> nix::sys::signal::Signal {
match self {
$(
Signal::$name => nix::sys::signal::Signal::$value,
Signal::$value => nix::sys::signal::Signal::$value,
)*
}
}
Expand All @@ -55,7 +55,7 @@ macro_rules! define_signal_enum {
fn from_num(id: i32) -> Self {
match nix::sys::signal::Signal::try_from(id) {
$(
Ok(nix::sys::signal::Signal::$value) => Self::$name,
Ok(nix::sys::signal::Signal::$value) => Self::$value,
)*

Ok(sig) => panic!("unknown signal: {:?}", sig),
Expand All @@ -72,70 +72,70 @@ define_signal_enum! {
/// The signal types that we are able to listen for.
pub enum Signal {
/// `SIGHUP`
Hup = SIGHUP,
SIGHUP,
/// `SIGINT`
Int = SIGINT,
SIGINT,
/// `SIGQUIT`
Quit = SIGQUIT,
SIGQUIT,
/// `SIGILL`
Ill = SIGILL,
SIGILL,
/// `SIGTRAP`
Trap = SIGTRAP,
SIGTRAP,
/// `SIGABRT`, aka `SIGIOT`
#[doc(alias = "Iot")]
#[doc(alias = "Abrt")]
Abort = SIGABRT,
SIGABRT,
/// `SIGBUS`
Bus = SIGBUS,
SIGBUS,
/// `SIGFPE`
Fpe = SIGFPE,
SIGFPE,
/// `SIGKILL`
Kill = SIGKILL,
SIGKILL,
/// `SIGUSR1`
Usr1 = SIGUSR1,
SIGUSR1,
/// `SIGSEGV`
Segv = SIGSEGV,
SIGSEGV,
/// `SIGUSR2`
Usr2 = SIGUSR2,
SIGUSR2,
/// `SIGPIPE`
Pipe = SIGPIPE,
SIGPIPE,
/// `SIGALRM`
#[doc(alias = "Alrm")]
Alarm = SIGALRM,
SIGALRM,
/// `SIGTERM`
Term = SIGTERM,
SIGTERM,
/// `SIGCHLD`
#[doc(alias = "Chld")]
Child = SIGCHLD,
SIGCHLD,
/// `SIGCONT`
Cont = SIGCONT,
SIGCONT,
/// `SIGSTOP`
Stop = SIGSTOP,
SIGSTOP,
/// `SIGTSTP`
Tstp = SIGTSTP,
SIGTSTP,
/// `SIGTTIN`
Ttin = SIGTTIN,
SIGTTIN,
/// `SIGTTOU`
Ttou = SIGTTOU,
SIGTTOU,
/// `SIGURG`
Urg = SIGURG,
SIGURG,
/// `SIGXCPU`
Xcpu = SIGXCPU,
SIGXCPU,
/// `SIGXFSZ`
Xfsz = SIGXFSZ,
SIGXFSZ,
/// `SIGVTALRM`
#[doc(alias = "Vtalrm")]
Vtalarm = SIGVTALRM,
SIGVTALRM,
/// `SIGPROF`
Prof = SIGPROF,
SIGPROF,
/// `SIGWINCH`
Winch = SIGWINCH,
SIGWINCH,
/// `SIGIO`, aka `SIGPOLL`
#[doc(alias = "Poll")]
Io = SIGIO,
SIGIO,
/// `SIGSYS`, aka `SIGUNUSED`
#[doc(alias = "Unused")]
Sys = SIGSYS,
SIGSYS,
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod test {
.unwrap();

// send ourselves a SIGUSR1
kill(Pid::this(), Signal::SIGUSR1).unwrap();
kill(Pid::this(), nix::sys::signal::Signal::SIGUSR1).unwrap();

event_loop
.dispatch(Some(Duration::from_millis(10)), &mut signal_received)
Expand Down Expand Up @@ -79,7 +79,7 @@ mod test {
.unwrap();

// send ourselves a SIGUSR2
kill(Pid::this(), Signal::SIGUSR2).unwrap();
kill(Pid::this(), nix::sys::signal::Signal::SIGUSR2).unwrap();

event_loop
.dispatch(Some(Duration::from_millis(10)), &mut signal_received)
Expand Down Expand Up @@ -110,11 +110,11 @@ mod test {

// block sigusr2 anyway, to not be killed by it
let mut set = SigSet::empty();
set.add(Signal::SIGUSR2);
set.add(nix::sys::signal::Signal::SIGUSR2);
set.thread_block().unwrap();

// send ourselves a SIGUSR2
kill(Pid::this(), Signal::SIGUSR2).unwrap();
kill(Pid::this(), nix::sys::signal::Signal::SIGUSR2).unwrap();

event_loop
.dispatch(Some(Duration::from_millis(10)), &mut signal_received)
Expand Down

0 comments on commit 32e66cd

Please sign in to comment.