1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-16 11:46:17 +00:00

nproc: Improve the support of OMP_NUM_THREADS

This commit is contained in:
Sylvestre Ledru 2022-03-13 18:13:48 +01:00
parent 2c6bbcf716
commit 24b4af768c
2 changed files with 32 additions and 12 deletions

View file

@ -1,3 +1,4 @@
// spell-checker:ignore incorrectnumber
use crate::common::util::*;
#[test]
@ -15,11 +16,11 @@ fn test_nproc_all_omp() {
let result = TestScenario::new(util_name!())
.ucmd_keepenv()
.env("OMP_NUM_THREADS", "1")
.env("OMP_NUM_THREADS", "60")
.succeeds();
let nproc_omp: u8 = result.stdout_str().trim().parse().unwrap();
assert!(nproc - 1 == nproc_omp);
assert!(nproc_omp == 60);
let result = TestScenario::new(util_name!())
.ucmd_keepenv()
@ -28,6 +29,14 @@ fn test_nproc_all_omp() {
.succeeds();
let nproc_omp: u8 = result.stdout_str().trim().parse().unwrap();
assert!(nproc == nproc_omp);
// If the parsing fails, returns the number of CPU
let result = TestScenario::new(util_name!())
.ucmd_keepenv()
.env("OMP_NUM_THREADS", "incorrectnumber") // returns the number CPU
.succeeds();
let nproc_omp: u8 = result.stdout_str().trim().parse().unwrap();
assert!(nproc == nproc_omp);
}
#[test]
@ -52,3 +61,14 @@ fn test_nproc_ignore() {
assert!(nproc_total - 1 == nproc);
}
}
#[test]
fn test_nproc_ignore_all_omp() {
let result = TestScenario::new(util_name!())
.ucmd_keepenv()
.env("OMP_NUM_THREADS", "42")
.arg("--ignore=40")
.succeeds();
let nproc: u8 = result.stdout_str().trim().parse().unwrap();
assert!(nproc == 2);
}