summaryrefslogtreecommitdiffstats
path: root/vendor/nix/test/test_sched.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
commit10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch)
treebdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/nix/test/test_sched.rs
parentReleasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff)
downloadrustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz
rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/nix/test/test_sched.rs')
-rw-r--r--vendor/nix/test/test_sched.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/nix/test/test_sched.rs b/vendor/nix/test/test_sched.rs
new file mode 100644
index 000000000..c52616b8b
--- /dev/null
+++ b/vendor/nix/test/test_sched.rs
@@ -0,0 +1,39 @@
+use nix::sched::{sched_getaffinity, sched_getcpu, sched_setaffinity, CpuSet};
+use nix::unistd::Pid;
+
+#[test]
+fn test_sched_affinity() {
+ // If pid is zero, then the mask of the calling process is returned.
+ let initial_affinity = sched_getaffinity(Pid::from_raw(0)).unwrap();
+ let mut at_least_one_cpu = false;
+ let mut last_valid_cpu = 0;
+ for field in 0..CpuSet::count() {
+ if initial_affinity.is_set(field).unwrap() {
+ at_least_one_cpu = true;
+ last_valid_cpu = field;
+ }
+ }
+ assert!(at_least_one_cpu);
+
+ // Now restrict the running CPU
+ let mut new_affinity = CpuSet::new();
+ new_affinity.set(last_valid_cpu).unwrap();
+ sched_setaffinity(Pid::from_raw(0), &new_affinity).unwrap();
+
+ // And now re-check the affinity which should be only the one we set.
+ let updated_affinity = sched_getaffinity(Pid::from_raw(0)).unwrap();
+ for field in 0..CpuSet::count() {
+ // Should be set only for the CPU we set previously
+ assert_eq!(
+ updated_affinity.is_set(field).unwrap(),
+ field == last_valid_cpu
+ )
+ }
+
+ // Now check that we're also currently running on the CPU in question.
+ let cur_cpu = sched_getcpu().unwrap();
+ assert_eq!(cur_cpu, last_valid_cpu);
+
+ // Finally, reset the initial CPU set
+ sched_setaffinity(Pid::from_raw(0), &initial_affinity).unwrap();
+}