Skip to content

Commit

Permalink
Fix test_ptymaster_drop after PR #1098
Browse files Browse the repository at this point in the history
This test cannot be compiled under Redox.  PR #1098 attempted to disable
it for Redox, but actually disabled it everywhere.  AFAICT, Cargo has no
syntax to conditionally enable a target, except based on features.
Instead, use conditional compilation within the test.
  • Loading branch information
asomers committed Jun 1, 2020
1 parent 1ae5dd8 commit fb76c21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ name = "test-mount"
path = "test/test_mount.rs"
harness = false

[[target.'cfg(not(target_os = "redox"))'.test]]
[[test]]
name = "test-ptymaster-drop"
path = "test/test_ptymaster_drop.rs"
39 changes: 22 additions & 17 deletions test/test_ptymaster_drop.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use nix::fcntl::OFlag;
use nix::pty::*;
use nix::unistd::close;
use std::os::unix::io::AsRawFd;
#[cfg(not(target_os = "redox"))]
mod t {
use nix::fcntl::OFlag;
use nix::pty::*;
use nix::unistd::close;
use std::os::unix::io::AsRawFd;

/// Regression test for Issue #659
/// `PtyMaster` should panic rather than double close the file descriptor
/// This must run in its own test process because it deliberately creates a race
/// condition.
#[test]
#[should_panic(expected = "Closing an invalid file descriptor!")]
// In Travis on i686-unknown-linux-musl, this test gets SIGABRT. I don't know
// why. It doesn't happen on any other target, and it doesn't happen on my PC.
#[cfg_attr(all(target_env = "musl", target_arch = "x86"), ignore)]
fn test_double_close() {
let m = posix_openpt(OFlag::O_RDWR).unwrap();
close(m.as_raw_fd()).unwrap();
drop(m); // should panic here
/// Regression test for Issue #659
///
/// `PtyMaster` should panic rather than double close the file descriptor
/// This must run in its own test process because it deliberately creates a
/// race condition.
#[test]
#[should_panic(expected = "Closing an invalid file descriptor!")]
// In Travis on i686-unknown-linux-musl, this test gets SIGABRT. I don't
// know why. It doesn't happen on any other target, and it doesn't happen
// on my PC.
#[cfg_attr(all(target_env = "musl", target_arch = "x86"), ignore)]
fn test_double_close() {
let m = posix_openpt(OFlag::O_RDWR).unwrap();
close(m.as_raw_fd()).unwrap();
drop(m); // should panic here
}
}

0 comments on commit fb76c21

Please sign in to comment.