rust-vmm / vmm-sys-util

Helpers and utilities used by multiple rust-vmm components and VMMs
BSD 3-Clause "New" or "Revised" License
78 stars 64 forks source link

rand selftest issues on s390x: wrong byte order? #192

Open mjt0k opened 1 year ago

mjt0k commented 1 year ago

Here's an example selftest failure on s390x:

---- rand::tests::test_rand_alphanumerics_impl stdout ----
thread 'rand::tests::test_rand_alphanumerics_impl' panicked at 'assertion failed: `(left == right)`
  left: `"67676"`,
 right: `"76767"`', src/rand.rs:133:9

    fn test_rand_alphanumerics_impl() {
        let s = rand_alphanumerics_impl(&|| 14134, 5);
        assert_eq!("67676", s);
    }

---- rand::tests::test_rand_bytes_impl stdout ----
thread 'rand::tests::test_rand_bytes_impl' panicked at 'assertion failed: `(left == right)`
  left: `[135, 214, 18, 0]`,
 right: `[0, 18, 214, 135]`', src/rand.rs:154:9

    fn test_rand_bytes_impl() {
        let s = rand_bytes_impl(&|| 1234567, 4);
        assert_eq!(vec![135, 214, 18, 0], s);
    }

---- rand::tests::test_xor_pseudo_rng_u8_alphas stdout ----
thread 'rand::tests::test_xor_pseudo_rng_u8_alphas' panicked at 'assertion failed: `(left == right)`
  left: `[54, 55]`,
 right: `[55, 54]`', src/rand.rs:127:9

    fn test_xor_pseudo_rng_u8_alphas() {
        let i = 3612982; // 55 (shifted 16 places), 33 (shifted 8 places), 54...
                         // The 33 will be discarded as it is not a valid letter
                         // (upper or lower) or number.
        let s = xor_pseudo_rng_u8_alphanumerics(&|| i);
        assert_eq!(vec![54, 55], s);
    }

---- rand::tests::test_xor_pseudo_rng_u8_bytes stdout ----
thread 'rand::tests::test_xor_pseudo_rng_u8_bytes' panicked at 'assertion failed: `(left == right)`
  left: `[54, 33, 55, 0]`,
 right: `[0, 55, 33, 54]`', src/rand.rs:148:9

    fn test_xor_pseudo_rng_u8_bytes() {
        let i = 3612982; // 55 (shifted 16 places), 33 (shifted 8 places), 54...
                         // The 33 will be discarded as it is not a valid letter
                         // (upper or lower) or number.
        let s = xor_pseudo_rng_u8_bytes(&|| i);
        assert_eq!(vec![54, 33, 55, 0], s);
    }

It looks like some byte swapping is occurring here?

https://ci.debian.net/data/autopkgtest/testing/s390x/r/rust-vmm-sys-util/32901017/log.gz

plugwash commented 1 year ago

This appears to be fixed by https://github.com/rust-vmm/vmm-sys-util/commit/64e447579cc3355b21c50c63ef8c87341f5e80f4 ?