rustc_codegen_cranelift icon indicating copy to clipboard operation
rustc_codegen_cranelift copied to clipboard

Fix libcore tests

Open bjorn3 opened this issue 5 years ago • 6 comments

When removing the tests requiring rand and adding a Cargo.toml to src/libcore/tests, running cargo test in that directory gives the following failures:

---- checked_mul stdout ----
---- checked_mul stderr ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some(18446744073709551612s)`,
 right: `None`', lib.rs:83:5
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- f32::max stdout ----
---- f32::max stderr ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `NaN`,
 right: `9.0`', lib.rs:142:1
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- f32::min stdout ----
---- f32::min stderr ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `NaN`,
 right: `9.0`', lib.rs:142:1
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- f64::max stdout ----
---- f64::max stderr ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `NaN`,
 right: `9.0`', lib.rs:143:1
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- f64::min stdout ----
---- f64::min stderr ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `NaN`,
 right: `9.0`', lib.rs:143:1
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- from_str_issue7588 stdout ----
---- from_str_issue7588 stderr ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some(232)`,
 right: `None`', lib.rs:89:5
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- iterator_len stdout ----
---- iterator_len stderr ----
thread 'main' panicked at 'attempt to copy from unaligned or null pointer', /Users/bjorn/Documents/rustc_codegen_cranelift/build_sysroot/sysroot_src/src/libcore/macros/mod.rs:15:40
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- test_is_sorted stdout ----
---- test_is_sorted stderr ----
thread 'main' panicked at 'attempt to create unaligned or null slice', /Users/bjorn/Documents/rustc_codegen_cranelift/build_sysroot/sysroot_src/src/libcore/macros/mod.rs:15:40
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- test_iterator_step_by_nth_overflow stdout ----
---- test_iterator_step_by_nth_overflow stderr ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `163208757609`,
 right: `18446744236918309225`', lib.rs:39:5
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---- test_range_inclusive_size_hint stdout ----
---- test_range_inclusive_size_hint stderr ----
Unexpected error: child process exited with signal 4
---- test_range_size_hint stdout ----
---- test_range_size_hint stderr ----
Unexpected error: child process exited with signal 4

failures:
    checked_mul
    f32::max
    f32::min
    f64::max
    f64::min
    from_str_issue7588
    iterator_len
    test_is_sorted
    test_iterator_step_by_nth_overflow
    test_range_inclusive_size_hint
    test_range_size_hint

test result: FAILED. 0 passed; 11 failed; 0 ignored; 0 measured; 0 filtered out

iter::test_successors even hangs. You have to manually kill the process executing it to be able to continue the testing.

Edit: some failures were due to panic catching not being implemented. Ignoring them.

bjorn3 avatar Nov 24 '19 10:11 bjorn3

Source
#![feature(core_private_bignum)]
#![feature(is_sorted)]
#![feature(array_value_iter)]

use core::array::IntoIter;
use core::convert::TryFrom;
use core::iter::*;
use core::usize;
use core::time::Duration;
use core::num::bignum::tests::Big8x3 as Big;

#[test]
fn iterator_len() {
    IntoIter::new([] as [String; 0]);
}

#[test]
fn test_iterator_step_by_nth_overflow() {
    #[cfg(target_pointer_width = "32")]
    type Bigger = u64;
    #[cfg(target_pointer_width = "64")]
    type Bigger = u128;

    #[derive(Clone)]
    struct Test(Bigger);
    impl Iterator for &mut Test {
        type Item = i32;
        fn next(&mut self) -> Option<Self::Item> { Some(21) }
        fn nth(&mut self, n: usize) -> Option<Self::Item> {
            self.0 += n as Bigger + 1;
            Some(42)
        }
    }

    let mut it = Test(0);
    let root = usize::MAX >> (::std::mem::size_of::<usize>() * 8 / 2);
    let n = root + 20;
    (&mut it).step_by(n).nth(n);
    assert_eq!(it.0, n as Bigger * n as Bigger);
}

#[test]
fn test_range_size_hint() {
    use core::usize::MAX as UMAX;
    use core::isize::{MAX as IMAX, MIN as IMIN};

    let imin = i128::try_from(IMIN).unwrap();
    let imax = i128::try_from(IMAX).unwrap();
    assert_eq!((imin..imax + 1).size_hint(), (UMAX, None));
}

#[test]
fn test_range_inclusive_size_hint() {
    use core::usize::MAX as UMAX;
    use core::isize::{MAX as IMAX, MIN as IMIN};

    let imin = i128::try_from(IMIN).unwrap();
    let imax = i128::try_from(IMAX).unwrap();
    assert_eq!((imin..=imax + 1).size_hint(), (UMAX, None));
}

#[test]
fn test_successors() {
    let mut powers_of_10 = successors(Some(1_u16), |n| n.checked_mul(10));
    assert_eq!(powers_of_10.by_ref().collect::<Vec<_>>(), &[1, 10, 100, 1_000, 10_000]);
    assert_eq!(powers_of_10.next(), None);

    let mut empty = successors(None::<u32>, |_| unimplemented!());
    assert_eq!(empty.next(), None);
    assert_eq!(empty.next(), None);
}

#[test]
fn test_is_sorted() {
    let empty: [i32; 0] = [];
    assert!(empty.is_sorted());
}

#[test]
fn checked_mul() {
    assert_eq!(Duration::new(::core::u64::MAX - 1, 0).checked_mul(2), None);
}

#[test]
fn from_str_issue7588() {
    let u : Option<u8> = u8::from_str_radix("1000", 10).ok();
    assert_eq!(u, None);
}

macro_rules! test_float {
    ($modname: ident, $fty: ty, $inf: expr, $neginf: expr, $nan: expr) => { mod $modname {
        // FIXME(nagisa): these tests should test for sign of -0.0
        #[test]
        fn min() {
            assert_eq!((0.0 as $fty).min(0.0), 0.0);
            assert_eq!((-0.0 as $fty).min(-0.0), -0.0);
            assert_eq!((9.0 as $fty).min(9.0), 9.0);
            assert_eq!((-9.0 as $fty).min(0.0), -9.0);
            assert_eq!((0.0 as $fty).min(9.0), 0.0);
            assert_eq!((-0.0 as $fty).min(-9.0), -9.0);
            assert_eq!(($inf as $fty).min(9.0), 9.0);
            assert_eq!((9.0 as $fty).min($inf), 9.0);
            assert_eq!(($inf as $fty).min(-9.0), -9.0);
            assert_eq!((-9.0 as $fty).min($inf), -9.0);
            assert_eq!(($neginf as $fty).min(9.0), $neginf);
            assert_eq!((9.0 as $fty).min($neginf), $neginf);
            assert_eq!(($neginf as $fty).min(-9.0), $neginf);
            assert_eq!((-9.0 as $fty).min($neginf), $neginf);
            assert_eq!(($nan as $fty).min(9.0), 9.0);
            assert_eq!(($nan as $fty).min(-9.0), -9.0);
            assert_eq!((9.0 as $fty).min($nan), 9.0);
            assert_eq!((-9.0 as $fty).min($nan), -9.0);
            assert!(($nan as $fty).min($nan).is_nan());
        }
        #[test]
        fn max() {
            assert_eq!((0.0 as $fty).max(0.0), 0.0);
            assert_eq!((-0.0 as $fty).max(-0.0), -0.0);
            assert_eq!((9.0 as $fty).max(9.0), 9.0);
            assert_eq!((-9.0 as $fty).max(0.0), 0.0);
            assert_eq!((0.0 as $fty).max(9.0), 9.0);
            assert_eq!((-0.0 as $fty).max(-9.0), -0.0);
            assert_eq!(($inf as $fty).max(9.0), $inf);
            assert_eq!((9.0 as $fty).max($inf), $inf);
            assert_eq!(($inf as $fty).max(-9.0), $inf);
            assert_eq!((-9.0 as $fty).max($inf), $inf);
            assert_eq!(($neginf as $fty).max(9.0), 9.0);
            assert_eq!((9.0 as $fty).max($neginf), 9.0);
            assert_eq!(($neginf as $fty).max(-9.0), -9.0);
            assert_eq!((-9.0 as $fty).max($neginf), -9.0);
            assert_eq!(($nan as $fty).max(9.0), 9.0);
            assert_eq!(($nan as $fty).max(-9.0), -9.0);
            assert_eq!((9.0 as $fty).max($nan), 9.0);
            assert_eq!((-9.0 as $fty).max($nan), -9.0);
            assert!(($nan as $fty).max($nan).is_nan());
        }
    } }
}

test_float!(f32, f32, ::core::f32::INFINITY, ::core::f32::NEG_INFINITY, ::core::f32::NAN);
test_float!(f64, f64, ::core::f64::INFINITY, ::core::f64::NEG_INFINITY, ::core::f64::NAN);

bjorn3 avatar Nov 24 '19 11:11 bjorn3

  • [ ] checked_mul (no checked mul, #6)
  • [ ] {f32, f64}::{min, max}
  • [ ] from_str_issue7588 (no checked mul, #6)
  • [x] iterator_len (fixed in 4a8b0ca2748509d7a5156a5ac30ccccab7cdd906)
  • [x] test_is_sorted (fixed in 4a8b0ca2748509d7a5156a5ac30ccccab7cdd906)
  • [ ] test_iterator_step_by_nth_overflow
  • [ ] test_range_inclusive_size_hint
  • [ ] test_range_size_hint
  • [ ] test_successors (no checked mul, #6)

bjorn3 avatar Nov 24 '19 11:11 bjorn3

Might be worth revisiting this now that https://github.com/bjorn3/rustc_codegen_cranelift/issues/6 is fixed :)

jyn514 avatar Jun 21 '20 19:06 jyn514

I actually fixed #6 as part of revisiting this :) ef4186a85b4c9bd94d258e3280cb239f26b8436e, 177348fbb49631c9ea6ec974c709e9a6530820aa, 5f54cc7658ffb538fa9ad06727ca0bedd009beaf The new broken test list is:

  • [x] test_rotate (missing rotl/rotr for int < 32bit, https://github.com/bytecodealliance/wasmtime/issues/1045)
  • [x] test_variadic_fnptr (declares same function with two different signatures, fixed in https://github.com/rust-lang/rust/pull/95088)
  • [x] sort_unstable (depends on rand, which doesn't have a fallback for missing sse support)
  • [ ] array_default_impl_avoids_leaks_on_panic (depends on unwinding)
  • [x] a few float tests (depend on NaN not propagating for fmin and fmax #1049)
  • [ ] various tests requiring optimizations to finish in reasonable time

bjorn3 avatar Jun 21 '20 19:06 bjorn3

Fixed the float tests. I forgot to tick the checkbox for the rotate test previously it seems.

bjorn3 avatar Jul 29 '21 13:07 bjorn3

Enabled sort_unstable in 31329f98412b70f034e41420dba28cb8d14ec4a9 and disabled sort_nth_unstable due to being too slow.

bjorn3 avatar Mar 18 '22 20:03 bjorn3

With the exception of an s390x failure due to stack value alignment, and the AtomicU128/AtomicI128 tests due to missing 128bit atomic support in Cranelift, everything passes now. A couple of tests are disabled due to being way too slow when not being fully optimized though.

bjorn3 avatar Oct 22 '23 17:10 bjorn3