Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -413,6 +413,7 @@ mod imp {
use {Error, ErrorKind};

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

#[derive(Debug)]
pub struct OsRng;
Expand All @@ -423,10 +424,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());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// 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
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is/should this list be the same as in .travis.yml?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why that's required; e.g. I don't see much point testing docs on multiple platforms.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I did not check the list completely. And you are right, not everything is interesting to test on all platforms. The --all flag is mostly there for workspaces, which we don't use yet, right? But I see no problem in keeping it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I revised the tests for non-cross builds and combined the two nightly targets we've had for ages, as well as a bit more clean-up. Yes, --all does nothing helpful now. But I'm not sure it will do quite the right thing in the future either because I don't believe passed --features apply to sub-targets.

fi
}

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