summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/tests/thread/clocks.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/rustix/tests/thread/clocks.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/tests/thread/clocks.rs')
-rw-r--r--vendor/rustix/tests/thread/clocks.rs212
1 files changed, 212 insertions, 0 deletions
diff --git a/vendor/rustix/tests/thread/clocks.rs b/vendor/rustix/tests/thread/clocks.rs
new file mode 100644
index 000000000..cf14df777
--- /dev/null
+++ b/vendor/rustix/tests/thread/clocks.rs
@@ -0,0 +1,212 @@
+#[cfg(not(any(
+ target_os = "emscripten",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "openbsd",
+ target_os = "redox",
+ target_os = "wasi",
+)))]
+use rustix::thread::{clock_nanosleep_absolute, clock_nanosleep_relative, ClockId};
+#[cfg(not(target_os = "redox"))]
+use {
+ rustix::io,
+ rustix::thread::{nanosleep, NanosleepRelativeResult, Timespec},
+};
+
+#[cfg(not(target_os = "redox"))]
+#[test]
+fn test_invalid_nanosleep() {
+ match nanosleep(&Timespec {
+ tv_sec: 0,
+ tv_nsec: 1_000_000_000,
+ }) {
+ NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match nanosleep(&Timespec {
+ tv_sec: 0,
+ tv_nsec: !0,
+ }) {
+ NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match nanosleep(&Timespec {
+ tv_sec: !0,
+ tv_nsec: 1_000_000_000,
+ }) {
+ NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match nanosleep(&Timespec {
+ tv_sec: !0,
+ tv_nsec: !0,
+ }) {
+ NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+}
+
+#[cfg(not(any(
+ target_os = "emscripten",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "openbsd",
+ target_os = "redox",
+ target_os = "wasi",
+)))]
+#[test]
+fn test_invalid_nanosleep_absolute() {
+ match clock_nanosleep_absolute(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: 0,
+ tv_nsec: 1000000000,
+ },
+ ) {
+ Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match clock_nanosleep_absolute(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: 0,
+ tv_nsec: !0,
+ },
+ ) {
+ Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match clock_nanosleep_absolute(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: !0,
+ tv_nsec: 1_000_000_000,
+ },
+ ) {
+ Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match clock_nanosleep_absolute(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: !0,
+ tv_nsec: !0,
+ },
+ ) {
+ Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+}
+
+#[cfg(not(any(
+ target_os = "emscripten",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "openbsd",
+ target_os = "redox",
+ target_os = "wasi",
+)))]
+#[test]
+fn test_invalid_nanosleep_relative() {
+ match clock_nanosleep_relative(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: 0,
+ tv_nsec: 1_000_000_000,
+ },
+ ) {
+ NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match clock_nanosleep_relative(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: 0,
+ tv_nsec: !0,
+ },
+ ) {
+ NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match clock_nanosleep_relative(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: !0,
+ tv_nsec: 1_000_000_000,
+ },
+ ) {
+ NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+ match clock_nanosleep_relative(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: !0,
+ tv_nsec: !0,
+ },
+ ) {
+ NanosleepRelativeResult::Err(io::Errno::INVAL) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+}
+
+#[cfg(not(target_os = "redox"))]
+#[test]
+fn test_zero_nanosleep() {
+ match nanosleep(&Timespec {
+ tv_sec: 0,
+ tv_nsec: 0,
+ }) {
+ NanosleepRelativeResult::Ok => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+}
+
+#[cfg(not(any(
+ target_os = "emscripten",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "openbsd",
+ target_os = "redox",
+ target_os = "wasi",
+)))]
+#[test]
+fn test_zero_nanosleep_absolute() {
+ match clock_nanosleep_absolute(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: 0,
+ tv_nsec: 0,
+ },
+ ) {
+ Ok(()) => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+}
+
+#[cfg(not(any(
+ target_os = "emscripten",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "openbsd",
+ target_os = "redox",
+ target_os = "wasi",
+)))]
+#[test]
+fn test_zero_nanosleep_relative() {
+ match clock_nanosleep_relative(
+ ClockId::Monotonic,
+ &Timespec {
+ tv_sec: 0,
+ tv_nsec: 0,
+ },
+ ) {
+ NanosleepRelativeResult::Ok => (),
+ otherwise => panic!("unexpected resut: {:?}", otherwise),
+ }
+}