coreutils/tests/by-util/test_nproc.rs

48 lines
1.3 KiB
Rust
Raw Normal View History

2020-06-02 21:20:29 +00:00
use crate::common::util::*;
#[test]
fn test_nproc() {
2021-04-17 23:28:06 +00:00
let nproc: u8 = new_ucmd!().succeeds().stdout_str().trim().parse().unwrap();
2020-06-02 21:20:29 +00:00
assert!(nproc > 0);
}
#[test]
fn test_nproc_all_omp() {
2021-04-17 23:28:06 +00:00
let result = new_ucmd!().arg("--all").succeeds();
let nproc: u8 = result.stdout_str().trim().parse().unwrap();
2020-06-02 21:20:29 +00:00
assert!(nproc > 0);
let result = TestScenario::new(util_name!())
2020-06-09 11:37:59 +00:00
.ucmd_keepenv()
.env("OMP_NUM_THREADS", "1")
2021-04-17 23:28:06 +00:00
.succeeds();
let nproc_omp: u8 = result.stdout_str().trim().parse().unwrap();
2020-06-09 11:37:59 +00:00
assert!(nproc - 1 == nproc_omp);
2020-06-02 21:20:29 +00:00
let result = TestScenario::new(util_name!())
2020-06-09 11:37:59 +00:00
.ucmd_keepenv()
.env("OMP_NUM_THREADS", "1") // Has no effect
.arg("--all")
2021-04-17 23:28:06 +00:00
.succeeds();
let nproc_omp: u8 = result.stdout_str().trim().parse().unwrap();
2020-06-02 21:20:29 +00:00
assert!(nproc == nproc_omp);
}
#[test]
fn test_nproc_ignore() {
2021-04-17 23:28:06 +00:00
let result = new_ucmd!().succeeds();
let nproc: u8 = result.stdout_str().trim().parse().unwrap();
2020-06-02 21:20:29 +00:00
if nproc > 1 {
// Ignore all CPU but one
let result = TestScenario::new(util_name!())
.ucmd_keepenv()
.arg("--ignore")
.arg((nproc - 1).to_string())
2021-04-17 23:28:06 +00:00
.succeeds();
let nproc: u8 = result.stdout_str().trim().parse().unwrap();
2020-06-02 21:20:29 +00:00
assert!(nproc == 1);
}
}