summaryrefslogtreecommitdiff
path: root/test/sys
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2017-07-19 22:59:47 -0600
committerMarcin Mielniczuk <marmistrz.dev@zoho.eu>2017-07-25 09:09:52 +0200
commit085f47c1afa6fbde6ee484767b892666a2cbb567 (patch)
treed1e55122ae1e7e1fce2e272f8a2e8261b1fc13d3 /test/sys
parent93b29290e8adf2181c012bd9b76aa05b99212682 (diff)
downloadnix-085f47c1afa6fbde6ee484767b892666a2cbb567.zip
Fix thread safety issues in pty and termios tests
ptsname(3) returns a pointer to a global variable, so it isn't thread-safe. Protect it with a mutex.
Diffstat (limited to 'test/sys')
-rw-r--r--test/sys/test_termios.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs
index c6572052..2455a4e5 100644
--- a/test/sys/test_termios.rs
+++ b/test/sys/test_termios.rs
@@ -18,10 +18,14 @@ fn write_all(f: RawFd, buf: &[u8]) {
// Test tcgetattr on a terminal
#[test]
fn test_tcgetattr_pty() {
- let pty = openpty(None, None).unwrap();
+ // openpty uses ptname(3) internally
+ #[allow(unused_variables)]
+ let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+
+ let pty = openpty(None, None).expect("openpty failed");
assert!(termios::tcgetattr(pty.master).is_ok());
- close(pty.master).unwrap();
- close(pty.slave).unwrap();
+ close(pty.master).expect("closing the master failed");
+ close(pty.slave).expect("closing the slave failed");
}
// Test tcgetattr on something that isn't a terminal
#[test]
@@ -41,12 +45,16 @@ fn test_tcgetattr_ebadf() {
// Test modifying output flags
#[test]
fn test_output_flags() {
+ // openpty uses ptname(3) internally
+ #[allow(unused_variables)]
+ let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+
// Open one pty to get attributes for the second one
let mut termios = {
- let pty = openpty(None, None).unwrap();
+ let pty = openpty(None, None).expect("openpty failed");
assert!(pty.master > 0);
assert!(pty.slave > 0);
- let termios = tcgetattr(pty.master).unwrap();
+ let termios = tcgetattr(pty.master).expect("tcgetattr failed");
close(pty.master).unwrap();
close(pty.slave).unwrap();
termios
@@ -80,6 +88,10 @@ fn test_output_flags() {
// Test modifying local flags
#[test]
fn test_local_flags() {
+ // openpty uses ptname(3) internally
+ #[allow(unused_variables)]
+ let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
+
// Open one pty to get attributes for the second one
let mut termios = {
let pty = openpty(None, None).unwrap();