mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
tests/chmod: protect umask with a mutex
`test_chmod_ugoa` and `test_chmod_many_options` both change umask, which is global state. Since tests run concurrently, this might lead to a situation where one of the tests changes umask to a value that screws another test's checks. To prevent this, we introduce a mutex that should be held by any test that changes umask. Unfortunately, there's no way to hide umask behind this mutex and enforce its usage: programmers will have to maintain the discipline themselves.
This commit is contained in:
parent
60f6f61ac9
commit
655804cff4
4 changed files with 13 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -35,6 +35,7 @@ dependencies = [
|
||||||
"id 0.0.1",
|
"id 0.0.1",
|
||||||
"install 0.0.1",
|
"install 0.0.1",
|
||||||
"kill 0.0.1",
|
"kill 0.0.1",
|
||||||
|
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"link 0.0.1",
|
"link 0.0.1",
|
||||||
"ln 0.0.1",
|
"ln 0.0.1",
|
||||||
|
|
|
@ -233,6 +233,7 @@ regex="*"
|
||||||
rand="*"
|
rand="*"
|
||||||
tempdir="*"
|
tempdir="*"
|
||||||
unindent="*"
|
unindent="*"
|
||||||
|
lazy_static = "*"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "uutils"
|
name = "uutils"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use common::util::*;
|
use common::util::*;
|
||||||
use std::fs::{metadata, OpenOptions, set_permissions};
|
use std::fs::{metadata, OpenOptions, set_permissions};
|
||||||
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
use self::libc::umask;
|
use self::libc::umask;
|
||||||
|
@ -9,6 +10,9 @@ use self::libc::umask;
|
||||||
static TEST_FILE: &'static str = "file";
|
static TEST_FILE: &'static str = "file";
|
||||||
static REFERENCE_FILE: &'static str = "reference";
|
static REFERENCE_FILE: &'static str = "reference";
|
||||||
static REFERENCE_PERMS: u32 = 0o247;
|
static REFERENCE_PERMS: u32 = 0o247;
|
||||||
|
lazy_static! {
|
||||||
|
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
|
||||||
|
}
|
||||||
|
|
||||||
struct TestCase {
|
struct TestCase {
|
||||||
args: Vec<&'static str>,
|
args: Vec<&'static str>,
|
||||||
|
@ -70,6 +74,8 @@ fn test_chmod_octal() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chmod_ugoa() {
|
fn test_chmod_ugoa() {
|
||||||
|
let _guard = UMASK_MUTEX.lock();
|
||||||
|
|
||||||
let last = unsafe {
|
let last = unsafe {
|
||||||
umask(0)
|
umask(0)
|
||||||
};
|
};
|
||||||
|
@ -117,6 +123,8 @@ fn test_chmod_ugo_copy() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chmod_many_options() {
|
fn test_chmod_many_options() {
|
||||||
|
let _guard = UMASK_MUTEX.lock();
|
||||||
|
|
||||||
let original_umask = unsafe {
|
let original_umask = unsafe {
|
||||||
umask(0)
|
umask(0)
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
|
||||||
// For conditional compilation
|
// For conditional compilation
|
||||||
macro_rules! unix_only {
|
macro_rules! unix_only {
|
||||||
($($fea:expr, $m:ident);+) => {
|
($($fea:expr, $m:ident);+) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue