cleanup and fix miri & cross-compile
This commit is contained in:
committed by
Bennet Bleßmann
parent
9d8906da30
commit
7227e1d97c
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -591,6 +591,12 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "current_platform"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a74858bcfe44b22016cb49337d7b6f04618c58e5dbfdef61b06b8c434324a0bc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dashu"
|
name = "dashu"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
@@ -2689,6 +2695,7 @@ dependencies = [
|
|||||||
"crossterm",
|
"crossterm",
|
||||||
"crrl",
|
"crrl",
|
||||||
"ctrlc",
|
"ctrlc",
|
||||||
|
"current_platform",
|
||||||
"dashu",
|
"dashu",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ js-sys = "0.3"
|
|||||||
ouroboros = "0.18"
|
ouroboros = "0.18"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
current_platform = "0.2.0"
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
serial_test = "3.1.1"
|
serial_test = "3.1.1"
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env::consts::{DLL_PREFIX, DLL_SUFFIX},
|
env::consts::{DLL_PREFIX, DLL_SUFFIX},
|
||||||
io::Write,
|
io::Write,
|
||||||
path::Path,
|
path::{Path, PathBuf},
|
||||||
process::Stdio,
|
process::Stdio,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::helper::load_module_test;
|
use crate::helper::load_module_test;
|
||||||
|
|
||||||
#[test]
|
use current_platform::CURRENT_PLATFORM;
|
||||||
fn ffi_f64_nan() {
|
|
||||||
let tmp_dir: &Path = env!("CARGO_TARGET_TMPDIR").as_ref();
|
|
||||||
println!("CARGO_TARGET_TMPDIR: {tmp_dir:?}");
|
|
||||||
|
|
||||||
// technically UB as tests are by default multi-threaded,
|
const TMP_DIR: &'static str = env!("CARGO_TARGET_TMPDIR");
|
||||||
// but there is currently no other easy way to get the dynamic library file path as an input into a load_module_test test
|
|
||||||
std::env::set_var(
|
// each test is building its own library so that they can easier run in parallel,
|
||||||
"ffi_f64_nan_LIB",
|
// i.e. don't need to wait for a large dynamic library to compile,
|
||||||
tmp_dir.join(format!("{DLL_PREFIX}ffi_f64_nan{DLL_SUFFIX}")),
|
// also rusts test infra currently has no functionallity for a setup/befor step
|
||||||
);
|
fn build_dynamic_library(name: &str, src: &str) -> PathBuf {
|
||||||
|
let tmp_dir: &Path = TMP_DIR.as_ref();
|
||||||
|
|
||||||
let mut child = std::process::Command::new("rustc")
|
let mut child = std::process::Command::new("rustc")
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
|
.arg(format!("--target={CURRENT_PLATFORM}"))
|
||||||
.arg("--crate-type=dylib")
|
.arg("--crate-type=dylib")
|
||||||
.arg("--crate-name=ffi_f64_nan")
|
.arg(format!("--crate-name={name}"))
|
||||||
.arg("--out-dir")
|
.arg("--out-dir")
|
||||||
.arg(tmp_dir)
|
.arg(tmp_dir)
|
||||||
.arg("-")
|
.arg("-")
|
||||||
@@ -33,19 +32,31 @@ fn ffi_f64_nan() {
|
|||||||
.stdin
|
.stdin
|
||||||
.take()
|
.take()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.write_all(
|
.write_all(src.as_bytes())
|
||||||
r##"
|
|
||||||
#[no_mangle]
|
|
||||||
extern "C" fn ffi_f64_nan() -> f64 {
|
|
||||||
f64::NAN
|
|
||||||
}
|
|
||||||
"##
|
|
||||||
.as_bytes(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(child.wait().unwrap().success());
|
assert!(child.wait().unwrap().success());
|
||||||
|
|
||||||
|
tmp_dir.join(format!("{DLL_PREFIX}{name}{DLL_SUFFIX}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore = "ffi")]
|
||||||
|
fn ffi_f64_nan() {
|
||||||
|
let dynlib_path = build_dynamic_library(
|
||||||
|
"ffi_f64_nan",
|
||||||
|
r##"
|
||||||
|
#[no_mangle]
|
||||||
|
extern "C" fn ffi_f64_nan() -> f64 {
|
||||||
|
f64::NAN
|
||||||
|
}
|
||||||
|
"##,
|
||||||
|
);
|
||||||
|
|
||||||
|
// technically UB as tests are by default multi-threaded,
|
||||||
|
// but there is currently no other easy way to get the dynamic library file path as an input into a load_module_test test
|
||||||
|
std::env::set_var("ffi_f64_nan_LIB", dynlib_path);
|
||||||
|
|
||||||
load_module_test(
|
load_module_test(
|
||||||
"tests-pl/ffi_f64_nan.pl",
|
"tests-pl/ffi_f64_nan.pl",
|
||||||
" error(evaluation_error(undefined),round/1).\n",
|
" error(evaluation_error(undefined),round/1).\n",
|
||||||
@@ -53,48 +64,26 @@ fn ffi_f64_nan() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(miri, ignore = "ffi")]
|
||||||
fn ffi_f64_minus_zero() {
|
fn ffi_f64_minus_zero() {
|
||||||
let tmp_dir: &Path = env!("CARGO_TARGET_TMPDIR").as_ref();
|
let dynlib_path = build_dynamic_library(
|
||||||
println!("CARGO_TARGET_TMPDIR: {tmp_dir:?}");
|
"ffi_f64_minus_zero",
|
||||||
|
r##"
|
||||||
|
#[no_mangle]
|
||||||
|
extern "C" fn ffi_f64_minus_zero() -> f64 {
|
||||||
|
-0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
extern "C" fn signum(f: f64) -> f64 {
|
||||||
|
f.signum()
|
||||||
|
}
|
||||||
|
"##,
|
||||||
|
);
|
||||||
|
|
||||||
// technically UB as tests are by default multi-threaded,
|
// technically UB as tests are by default multi-threaded,
|
||||||
// but there is currently no other easy way to get the dynamic library file path as an input into a load_module_test test
|
// but there is currently no other easy way to get the dynamic library file path as an input into a load_module_test test
|
||||||
std::env::set_var(
|
std::env::set_var("ffi_f64_minus_zero_LIB", dynlib_path);
|
||||||
"ffi_f64_minus_zero_LIB",
|
|
||||||
tmp_dir.join(format!("{DLL_PREFIX}ffi_f64_minus_zero{DLL_SUFFIX}")),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut child = std::process::Command::new("rustc")
|
|
||||||
.stdin(Stdio::piped())
|
|
||||||
.arg("--crate-type=dylib")
|
|
||||||
.arg("--crate-name=ffi_f64_minus_zero")
|
|
||||||
.arg("--out-dir")
|
|
||||||
.arg(tmp_dir)
|
|
||||||
.arg("-")
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
child
|
|
||||||
.stdin
|
|
||||||
.take()
|
|
||||||
.unwrap()
|
|
||||||
.write_all(
|
|
||||||
r##"
|
|
||||||
#[no_mangle]
|
|
||||||
extern "C" fn ffi_f64_minus_zero() -> f64 {
|
|
||||||
-0.0
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
extern "C" fn signum(f: f64) -> f64 {
|
|
||||||
f.signum()
|
|
||||||
}
|
|
||||||
"##
|
|
||||||
.as_bytes(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert!(child.wait().unwrap().success());
|
|
||||||
|
|
||||||
// note: ouput is currently wrong correct would be 1.0,1.0
|
// note: ouput is currently wrong correct would be 1.0,1.0
|
||||||
load_module_test("tests-pl/ffi_f64_minus_zero.pl", "-1.0,1.0");
|
load_module_test("tests-pl/ffi_f64_minus_zero.pl", "-1.0,1.0");
|
||||||
|
|||||||
Reference in New Issue
Block a user