diff --git a/.travis.yml b/.travis.yml index 023da4ce..322a51b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,14 +4,14 @@ branches: os: - linux - - osx + # - osx language: rust rust: - stable - - beta - - nightly + # - beta + # - nightly # the earliest supported stable release; we depend upon # * >= 1.32 for uniform module paths @@ -38,7 +38,7 @@ env: - RUSTFLAGS="-A unknown-lints -D warnings" matrix: - CARGOFLAGS="" - - CARGOFLAGS="--release" + # - CARGOFLAGS="--release" before_script: - rustup update @@ -83,28 +83,23 @@ matrix: - name: coverage rust: stable os: linux - dist: xenial - sudo: required + dist: bionic addons: apt: packages: - - libcurl4-openssl-dev - - libdw-dev - - libelf-dev - - libiberty-dev - libsodium-dev - - binutils-dev - - cmake + - libssl-dev env: - COVERAGE=true before_script: - rustup update - - cargo install cargo-update || echo "cargo-update already installed" - - cargo install cargo-travis || echo "cargo-travis already installed" + - cargo install cargo-update || echo "cargo-update already installed" + - cargo install cargo-tarpaulin || echo "cargo-tarpaulin already installed" - cargo install-update -a script: - - cargo coveralls --exclude-pattern "_ctest.rs,_ctest.c" + - cargo build + - cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID --tests --no-fail-fast diff --git a/src/boxed.rs b/src/boxed.rs index 843f73ca..25bdb4ba 100644 --- a/src/boxed.rs +++ b/src/boxed.rs @@ -483,8 +483,6 @@ fn mprotect(ptr: *const T, prot: Prot) { } } -// LCOV_EXCL_START - #[cfg(test)] mod tests { use super::*; @@ -700,12 +698,14 @@ mod tests { #[cfg(test)] mod tests_sigsegv { use super::*; - use std::process; + #[cfg(not(tarpaulin))] fn assert_sigsegv(f: F) where F: FnOnce(), { + use std::process; + unsafe { let pid : libc::pid_t = libc::fork(); let mut stat : libc::c_int = 0; @@ -733,6 +733,10 @@ mod tests_sigsegv { } } + #[cfg(tarpaulin)] + fn assert_sigsegv(_f: F) where F: FnOnce() { + } + #[test] fn it_kills_attempts_to_read_while_locked() { assert_sigsegv(|| { @@ -864,5 +868,3 @@ mod tests_proven_statements { let _ = boxed.as_mut_slice(); } } - -// LCOV_EXCL_STOP diff --git a/src/ffi/sodium.rs b/src/ffi/sodium.rs index 52c53296..40266ff1 100644 --- a/src/ffi/sodium.rs +++ b/src/ffi/sodium.rs @@ -210,8 +210,6 @@ pub(crate) fn memrandom(bytes: &mut [u8]) { unsafe { randombytes_buf(bytes.as_mut_ptr() as *mut _, bytes.len()) } } -// LCOV_EXCL_START - #[cfg(test)] mod test { use super::*; @@ -236,5 +234,3 @@ mod test { assert!(!memcmp(&c, &a)); } } - -// LCOV_EXCL_STOP diff --git a/src/lib.rs b/src/lib.rs index f849b19d..576ac249 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -// LCOV_EXCL_LINE - //! Protected-access memory for cryptographic secrets. //! //! Provides a convenient way to allocate and access memory for diff --git a/src/secret.rs b/src/secret.rs index 05f8b27d..a3d48076 100644 --- a/src/secret.rs +++ b/src/secret.rs @@ -246,8 +246,6 @@ impl PartialEq for RefMut<'_, T> { impl Eq for RefMut<'_, T> {} -// LCOV_EXCL_START - #[cfg(test)] mod tests { use super::*; @@ -358,5 +356,3 @@ mod tests { Secret::::zero(|_| sodium::fail()); } } - -// LCOV_EXCL_STOP diff --git a/src/secret_box.rs b/src/secret_box.rs index 5ea1b2db..1915f7ac 100644 --- a/src/secret_box.rs +++ b/src/secret_box.rs @@ -406,8 +406,6 @@ impl PartialEq> for RefMut<'_, T> { impl Eq for RefMut<'_, T> {} -// LCOV_EXCL_START - #[cfg(test)] mod test { use super::*; @@ -558,5 +556,3 @@ mod tests_proven_statements { let _ = boxed.as_mut(); } } - -// LCOV_EXCL_STOP diff --git a/src/secret_vec.rs b/src/secret_vec.rs index 1ef9d12d..aea16554 100644 --- a/src/secret_vec.rs +++ b/src/secret_vec.rs @@ -413,8 +413,6 @@ impl PartialEq> for RefMut<'_, T> { impl Eq for RefMut<'_, T> {} -// LCOV_EXCL_START - #[cfg(test)] mod test { use super::*; @@ -550,5 +548,3 @@ mod test { assert_eq!(secret_2.borrow_mut(), secret_1.borrow()); } } - -// LCOV_EXCL_STOP diff --git a/src/traits/bytes.rs b/src/traits/bytes.rs index 3abbd9dd..79102198 100644 --- a/src/traits/bytes.rs +++ b/src/traits/bytes.rs @@ -109,3 +109,42 @@ unsafe impl AsContiguousBytes for [T] { self.as_ptr() as *mut _ } } + +#[cfg(test)] +mod tests { + use super::*; + + #[derive(Copy, Clone)] + struct Byte (u8); + + unsafe impl Bytes for Byte {} + + #[test] + fn it_uninitializes_to_a_garbage_value() { + let b = Byte::uninitialized(); + + assert_eq!(b.0, GARBAGE_VALUE); + } + + #[test] + fn it_reports_size_correctly() { + assert_eq!(::size(), 1); + } + + #[test] + fn it_provides_ptr_access() { + unsafe { + let b = Byte(255); + assert_eq!(*Bytes::as_u8_ptr(&b), 255); + } + } + + #[test] + fn it_provides_mut_ptr_access() { + unsafe { + let mut b = Byte(10); + *Bytes::as_mut_u8_ptr(&mut b) = 42; + assert_eq!(b.0, 42); + } + } +}