summaryrefslogtreecommitdiffstats
path: root/third_party/rust/libloading-0.5.2/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/libloading-0.5.2/tests
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/libloading-0.5.2/tests')
-rw-r--r--third_party/rust/libloading-0.5.2/tests/functions.rs151
-rw-r--r--third_party/rust/libloading-0.5.2/tests/markers.rs79
-rw-r--r--third_party/rust/libloading-0.5.2/tests/nagisa32.dllbin0 -> 3072 bytes
-rw-r--r--third_party/rust/libloading-0.5.2/tests/nagisa64.dllbin0 -> 2560 bytes
-rw-r--r--third_party/rust/libloading-0.5.2/tests/windows.rs56
5 files changed, 286 insertions, 0 deletions
diff --git a/third_party/rust/libloading-0.5.2/tests/functions.rs b/third_party/rust/libloading-0.5.2/tests/functions.rs
new file mode 100644
index 0000000000..c9bc067eac
--- /dev/null
+++ b/third_party/rust/libloading-0.5.2/tests/functions.rs
@@ -0,0 +1,151 @@
+extern crate libloading;
+use libloading::{Symbol, Library};
+
+const LIBPATH: &'static str = concat!(env!("OUT_DIR"), "/libtest_helpers.dll");
+
+fn make_helpers() {
+ static ONCE: ::std::sync::Once = ::std::sync::ONCE_INIT;
+ ONCE.call_once(|| {
+ let mut outpath = String::from(if let Some(od) = option_env!("OUT_DIR") { od } else { return });
+ let rustc = option_env!("RUSTC").unwrap_or_else(|| { "rustc".into() });
+ outpath.push_str(&"/libtest_helpers.dll"); // extension for windows required, POSIX does not care.
+ let _ = ::std::process::Command::new(rustc)
+ .arg("src/test_helpers.rs")
+ .arg("-o")
+ .arg(outpath)
+ .arg("-O")
+ .output()
+ .expect("could not compile the test helpers!");
+ });
+}
+
+#[test]
+fn test_id_u32() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ let f: Symbol<unsafe extern fn(u32) -> u32> = lib.get(b"test_identity_u32\0").unwrap();
+ assert_eq!(42, f(42));
+ }
+}
+
+#[repr(C)]
+#[derive(Clone,Copy,PartialEq,Debug)]
+struct S {
+ a: u64,
+ b: u32,
+ c: u16,
+ d: u8
+}
+
+#[test]
+fn test_id_struct() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ let f: Symbol<unsafe extern fn(S) -> S> = lib.get(b"test_identity_struct\0").unwrap();
+ assert_eq!(S { a: 1, b: 2, c: 3, d: 4 }, f(S { a: 1, b: 2, c: 3, d: 4 }));
+ }
+}
+
+#[test]
+fn test_0_no_0() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ let f: Symbol<unsafe extern fn(S) -> S> = lib.get(b"test_identity_struct\0").unwrap();
+ let f2: Symbol<unsafe extern fn(S) -> S> = lib.get(b"test_identity_struct").unwrap();
+ assert_eq!(*f, *f2);
+ }
+}
+
+#[test]
+fn wrong_name_fails() {
+ Library::new(concat!(env!("OUT_DIR"), "/libtest_help")).err().unwrap();
+}
+
+#[test]
+fn missing_symbol_fails() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ lib.get::<*mut ()>(b"test_does_not_exist").err().unwrap();
+ lib.get::<*mut ()>(b"test_does_not_exist\0").err().unwrap();
+ }
+}
+
+#[test]
+fn interior_null_fails() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ lib.get::<*mut ()>(b"test_does\0_not_exist").err().unwrap();
+ lib.get::<*mut ()>(b"test\0_does_not_exist\0").err().unwrap();
+ }
+}
+
+#[test]
+#[should_panic]
+fn test_incompatible_type() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ let _ = lib.get::<()>(b"test_identity_u32\0");
+ }
+}
+
+#[test]
+#[should_panic]
+fn test_incompatible_type_named_fn() {
+ make_helpers();
+ unsafe fn get<'a, T>(l: &'a Library, _: T) -> libloading::Result<Symbol<'a, T>> {
+ l.get::<T>(b"test_identity_u32\0")
+ }
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ let _ = get(&lib, test_incompatible_type_named_fn);
+ }
+}
+
+#[test]
+fn test_static_u32() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ let var: Symbol<*mut u32> = lib.get(b"TEST_STATIC_U32\0").unwrap();
+ **var = 42;
+ let help: Symbol<unsafe extern fn() -> u32> = lib.get(b"test_get_static_u32\0").unwrap();
+ assert_eq!(42, help());
+ }
+}
+
+#[test]
+fn test_static_ptr() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ let var: Symbol<*mut *mut ()> = lib.get(b"TEST_STATIC_PTR\0").unwrap();
+ **var = *var as *mut _;
+ let works: Symbol<unsafe extern fn() -> bool> =
+ lib.get(b"test_check_static_ptr\0").unwrap();
+ assert!(works());
+ }
+}
+
+#[cfg(any(windows, target_os="linux"))]
+#[cfg(test_nightly)]
+#[test]
+fn test_tls_static() {
+ make_helpers();
+ let lib = Library::new(LIBPATH).unwrap();
+ unsafe {
+ let var: Symbol<*mut u32> = lib.get(b"TEST_THREAD_LOCAL\0").unwrap();
+ **var = 84;
+ let help: Symbol<unsafe extern fn() -> u32> = lib.get(b"test_get_thread_local\0").unwrap();
+ assert_eq!(84, help());
+ }
+ ::std::thread::spawn(move || unsafe {
+ let help: Symbol<unsafe extern fn() -> u32> = lib.get(b"test_get_thread_local\0").unwrap();
+ assert_eq!(0, help());
+ }).join().unwrap();
+}
diff --git a/third_party/rust/libloading-0.5.2/tests/markers.rs b/third_party/rust/libloading-0.5.2/tests/markers.rs
new file mode 100644
index 0000000000..01da108c68
--- /dev/null
+++ b/third_party/rust/libloading-0.5.2/tests/markers.rs
@@ -0,0 +1,79 @@
+extern crate libloading;
+
+#[cfg(test)]
+fn assert_send<T: Send>() {}
+#[cfg(test)]
+fn assert_sync<T: Sync>() {}
+
+#[test]
+fn check_library_send() {
+ assert_send::<libloading::Library>();
+}
+
+#[cfg(unix)]
+#[test]
+fn check_unix_library_send() {
+ assert_send::<libloading::os::unix::Library>();
+}
+
+#[cfg(windows)]
+#[test]
+fn check_windows_library_send() {
+ assert_send::<libloading::os::windows::Library>();
+}
+
+#[test]
+fn check_library_sync() {
+ assert_sync::<libloading::Library>();
+}
+
+#[cfg(unix)]
+#[test]
+fn check_unix_library_sync() {
+ assert_sync::<libloading::os::unix::Library>();
+}
+
+#[cfg(windows)]
+#[test]
+fn check_windows_library_sync() {
+ assert_sync::<libloading::os::windows::Library>();
+}
+
+#[test]
+fn check_symbol_send() {
+ assert_send::<libloading::Symbol<fn() -> ()>>();
+ // assert_not_send::<libloading::Symbol<*const ()>>();
+}
+
+#[cfg(unix)]
+#[test]
+fn check_unix_symbol_send() {
+ assert_send::<libloading::os::unix::Symbol<fn() -> ()>>();
+ // assert_not_send::<libloading::os::unix::Symbol<*const ()>>();
+}
+
+#[cfg(windows)]
+#[test]
+fn check_windows_symbol_send() {
+ assert_send::<libloading::os::windows::Symbol<fn() -> ()>>();
+}
+
+#[test]
+fn check_symbol_sync() {
+ assert_sync::<libloading::Symbol<fn() -> ()>>();
+ // assert_not_sync::<libloading::Symbol<*const ()>>();
+}
+
+#[cfg(unix)]
+#[test]
+fn check_unix_symbol_sync() {
+ assert_sync::<libloading::os::unix::Symbol<fn() -> ()>>();
+ // assert_not_sync::<libloading::os::unix::Symbol<*const ()>>();
+}
+
+#[cfg(windows)]
+#[test]
+fn check_windows_symbol_sync() {
+ assert_sync::<libloading::os::windows::Symbol<fn() -> ()>>();
+ // assert_not_sync::<libloading::os::windows::Symbol<*const ()>>();
+}
diff --git a/third_party/rust/libloading-0.5.2/tests/nagisa32.dll b/third_party/rust/libloading-0.5.2/tests/nagisa32.dll
new file mode 100644
index 0000000000..0a6218ade9
--- /dev/null
+++ b/third_party/rust/libloading-0.5.2/tests/nagisa32.dll
Binary files differ
diff --git a/third_party/rust/libloading-0.5.2/tests/nagisa64.dll b/third_party/rust/libloading-0.5.2/tests/nagisa64.dll
new file mode 100644
index 0000000000..bacaa4b969
--- /dev/null
+++ b/third_party/rust/libloading-0.5.2/tests/nagisa64.dll
Binary files differ
diff --git a/third_party/rust/libloading-0.5.2/tests/windows.rs b/third_party/rust/libloading-0.5.2/tests/windows.rs
new file mode 100644
index 0000000000..343aaa1045
--- /dev/null
+++ b/third_party/rust/libloading-0.5.2/tests/windows.rs
@@ -0,0 +1,56 @@
+#![cfg(windows)]
+extern crate libloading;
+use libloading::os::windows::*;
+use std::ffi::CStr;
+
+// The ordinal DLL contains exactly one function (other than DllMain, that is) with ordinal number
+// 1. This function has the sugnature `fn() -> *const c_char` and returns a string "bunny\0" (in
+// reference to WindowsBunny).
+//
+// Both x86_64 and x86 versions of the .dll are functionally the same. Ideally we would compile the
+// dlls with well known ordinals from our own testing helpers library, but rustc does not allow
+// specifying a custom .def file (https://github.com/rust-lang/rust/issues/35089)
+//
+// The DLLs were kindly compiled by WindowsBunny (aka. @retep998).
+
+#[cfg(target_arch="x86")]
+fn load_ordinal_lib() -> Library {
+ Library::new("tests/nagisa32.dll").expect("nagisa32.dll")
+}
+
+#[cfg(target_arch="x86_64")]
+fn load_ordinal_lib() -> Library {
+ Library::new("tests/nagisa64.dll").expect("nagisa64.dll")
+}
+
+#[cfg(any(target_arch="x86", target_arch="x86_64"))]
+#[test]
+fn test_ordinal() {
+ let lib = load_ordinal_lib();
+ unsafe {
+ let windows: Symbol<unsafe fn() -> *const i8> = lib.get_ordinal(1).expect("function");
+ assert_eq!(CStr::from_ptr(windows()).to_bytes(), b"bunny");
+ }
+}
+
+#[cfg(any(target_arch="x86", target_arch="x86_64"))]
+#[test]
+fn test_ordinal_missing_fails() {
+ let lib = load_ordinal_lib();
+ unsafe {
+ let r: Result<Symbol<unsafe fn() -> *const i8>, _> = lib.get_ordinal(2);
+ r.err().unwrap();
+ let r: Result<Symbol<unsafe fn() -> *const i8>, _> = lib.get_ordinal(!0);
+ r.err().unwrap();
+ }
+}
+
+#[test]
+fn test_new_kernel23() {
+ Library::new("kernel23").err().unwrap();
+}
+
+#[test]
+fn test_new_kernel32_no_ext() {
+ Library::new("kernel32").unwrap();
+}