Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libcore tests #806

Closed
bjorn3 opened this issue Nov 24, 2019 · 7 comments
Closed

Fix libcore tests #806

bjorn3 opened this issue Nov 24, 2019 · 7 comments
Labels
C-bug Category: This is a bug.

Comments

@bjorn3
Copy link
Member

bjorn3 commented Nov 24, 2019

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 bjorn3 added the C-bug Category: This is a bug. label Nov 24, 2019
@bjorn3
Copy link
Member Author

bjorn3 commented Nov 24, 2019

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
Copy link
Member Author

bjorn3 commented Nov 24, 2019

@bjorn3 bjorn3 added this to the MVP milestone Dec 24, 2019
@jyn514
Copy link
Member

jyn514 commented Jun 21, 2020

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

@bjorn3
Copy link
Member Author

bjorn3 commented Jun 21, 2020

I actually fixed #6 as part of revisiting this :) ef4186a, 177348f, 5f54cc7 The new broken test list is:

@bjorn3 bjorn3 removed this from the MVP milestone Jul 17, 2020
bjorn3 added a commit that referenced this issue Feb 21, 2021
@bjorn3
Copy link
Member Author

bjorn3 commented Jul 29, 2021

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

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 18, 2022

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

Dylan-DPC referenced this issue in Dylan-DPC/rust Mar 19, 2022
…tolnay

Don't declare test_variadic_fnptr with two conflicting signatures

It is UB for LLVM and results in a compile error for Cranelift.

cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/806
Fixes rust-lang#66690
matthiaskrgr referenced this issue in matthiaskrgr/rust Mar 19, 2022
…tolnay

Don't declare test_variadic_fnptr with two conflicting signatures

It is UB for LLVM and results in a compile error for Cranelift.

cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/806
Fixes rust-lang#66690
bors referenced this issue in rust-lang-ci/rust Mar 23, 2022
…lnay

Don't declare test_variadic_fnptr with two conflicting signatures

It is UB for LLVM and results in a compile error for Cranelift.

cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/806
Fixes rust-lang#66690
@bjorn3
Copy link
Member Author

bjorn3 commented Oct 22, 2023

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 bjorn3 closed this as completed Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants