Skip to content

Commit

Permalink
Merge branch 'trust'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Feb 27, 2018
2 parents 7069151 + 1a32adf commit ca3282a
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 19 deletions.
76 changes: 64 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,86 @@
language: rust
sudo: false

# We aim to test all the following in any combination:
# - standard tests, benches, documentation, all available features
# - pinned stable, latest stable, beta and nightly Rust releases
# - Linux, OS X, Android, iOS, bare metal (i.e. no_std)
# - x86_64, ARMv7, a Big-Endian arch (MIPS)
matrix:
include:
- rust: 1.22.0
install:
script:
- cargo test
- cargo build --no-default-features # we cannot exclude doc tests
- rust: stable
- cargo test --all --tests --no-default-features
- cargo test --all --features serde-1,log
- rust: stable
os: osx
install:
script:
- cargo test --all --tests --no-default-features
- cargo test --all --features serde-1,log
- rust: beta
install:
script:
- cargo test --all --tests --no-default-features
- rust: nightly

- rust: nightly
install:
before_script:
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
script:
- cargo doc --no-deps --all-features
- cargo test --benches
- cargo test --features nightly
- cargo test --tests --no-default-features --features=alloc
- cargo test --all --features serde-1,log,nightly
- cargo test --benches
- cargo doc --no-deps --all-features
after_success:
- travis-cargo --only nightly doc-upload

# Trust cross-built/emulated targets. We must repeat all non-default values.
- rust: stable
sudo: required
dist: trusty
services: docker
env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1
- rust: stable
sudo: required
dist: trusty
services: docker
env: TARGET=mips-unknown-linux-gnu
- rust: stable
sudo: required
dist: trusty
services: docker
env: TARGET=armv7-linux-androideabi DISABLE_TESTS=1
- rust: stable
os: osx
sudo: required
dist: trusty
services: docker
env: TARGET=armv7-apple-ios DISABLE_TESTS=1
- rust: nightly
sudo: required
dist: trusty
services: docker
# Bare metal target; no std; only works on nightly
env: TARGET=thumbv6m-none-eabi DISABLE_TESTS=1 DISABLE_STD=1

before_install:
- set -e
- rustup self update

# Used by all Trust targets; others must override:
install:
- sh utils/ci/install.sh
- source ~/.cargo/env || true
script:
- cargo test
- cargo test --tests --no-default-features
- cargo test --features serde-1,log
- cargo test --tests --no-default-features --features=serde-1
- bash utils/ci/script.sh

after_script: set +e

cache: cargo
before_cache:
# Travis can't cache files that are not readable by "others"
- chmod -R a+r $HOME/.cargo

env:
global:
Expand Down
3 changes: 2 additions & 1 deletion src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ mod imp {
use {Error, ErrorKind};

use std::ptr;
use std::io;

#[derive(Debug)]
pub struct OsRng;
Expand All @@ -430,10 +431,10 @@ mod imp {
}
pub fn try_fill_bytes(&mut self, v: &mut [u8]) -> Result<(), Error> {
let mib = [libc::CTL_KERN, libc::KERN_ARND];
trace!("OsRng: reading {} bytes via kern.arandom", v.len());
// kern.arandom permits a maximum buffer size of 256 bytes
for s in v.chunks_mut(256) {
let mut s_len = s.len();
trace!("OsRng: reading {} bytes via kern.arandom", v.len());
let ret = unsafe {
libc::sysctl(mib.as_ptr(), mib.len() as libc::c_uint,
s.as_mut_ptr() as *mut _, &mut s_len,
Expand Down
9 changes: 5 additions & 4 deletions src/prng/hc128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The HC-128 random number generator.

use core::{fmt, slice};
use core::fmt;
use {RngCore, SeedableRng};
use {impls, le};

Expand Down Expand Up @@ -337,6 +337,7 @@ impl RngCore for Hc128Rng {
// This improves performance by about 12%.
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn fill_bytes(&mut self, dest: &mut [u8]) {
use core::slice::from_raw_parts_mut;
let mut filled = 0;

// Continue filling from the current set of results
Expand All @@ -354,9 +355,9 @@ impl RngCore for Hc128Rng {

while filled < len_direct {
let dest_u32: &mut [u32] = unsafe {
slice::from_raw_parts_mut(
dest[filled..].as_mut_ptr() as *mut u8 as *mut u32,
16)
from_raw_parts_mut(
dest[filled..].as_mut_ptr() as *mut u8 as *mut u32,
16)
};
self.state.update(dest_u32);
filled += 16 * 4;
Expand Down
5 changes: 3 additions & 2 deletions src/prng/xorshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ mod tests {
let mut rng1 = XorShiftRng::from_seed(seed);
assert_eq!(rng1.next_u64(), 4325440999699518727);

let mut rng2 = XorShiftRng::from_rng(&mut rng1).unwrap();
assert_eq!(rng2.next_u64(), 15614385950550801700);
let _rng2 = XorShiftRng::from_rng(&mut rng1).unwrap();
// Note: we cannot test the state of _rng2 because from_rng does not
// fix Endianness. This is allowed in the trait specification.
}

#[test]
Expand Down
49 changes: 49 additions & 0 deletions utils/ci/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# From https://github.com/japaric/trust

set -ex

main() {
local target=
if [ $TRAVIS_OS_NAME = linux ]; then
target=x86_64-unknown-linux-musl
sort=sort
else
target=x86_64-apple-darwin
sort=gsort # for `sort --sort-version`, from brew's coreutils.
fi

# Builds for iOS are done on OSX, but require the specific target to be
# installed.
case $TARGET in
aarch64-apple-ios)
rustup target install aarch64-apple-ios
;;
armv7-apple-ios)
rustup target install armv7-apple-ios
;;
armv7s-apple-ios)
rustup target install armv7s-apple-ios
;;
i386-apple-ios)
rustup target install i386-apple-ios
;;
x86_64-apple-ios)
rustup target install x86_64-apple-ios
;;
esac

# This fetches latest stable release
local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \
| cut -d/ -f3 \
| grep -E '^v[0.1.0-9.]+$' \
| $sort --version-sort \
| tail -n1)
curl -LSfs https://japaric.github.io/trust/install.sh | \
sh -s -- \
--force \
--git japaric/cross \
--tag $tag \
--target $target
}

main
28 changes: 28 additions & 0 deletions utils/ci/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Derived from https://github.com/japaric/trust

set -ex

main() {
if [ ! -z $DISABLE_TESTS ]; then
if [ ! -z $DISABLE_STD ]; then
cross build --all --no-default-features --target $TARGET --release
else
cross build --all --features log,serde-1 --target $TARGET
fi
return
fi

if [ ! -z $NIGHTLY ]; then
cross test --all --tests --no-default-features --features alloc --target $TARGET
cross test --all --features serde-1,log,nightly --target $TARGET
cross test --all --benches --target $TARGET
else
cross test --all --tests --no-default-features --target $TARGET
cross test --all --features serde-1,log --target $TARGET
fi
}

# we don't run the "test phase" when doing deploys
if [ -z $TRAVIS_TAG ]; then
main
fi

0 comments on commit ca3282a

Please sign in to comment.