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

Add travis ci #7

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: rust
rust: nightly
dist: trusty

script:
- ci/run.sh
6 changes: 5 additions & 1 deletion asan/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[package]
authors = ["Jorge Aparicio <japaricious@gmail.com>"]
name = "asan"
version = "0.1.0"
version = "0.1.0"

[features]
# Enables library tests that fail
fail = []
5 changes: 5 additions & 0 deletions asan/examples/out-of-bounds-fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
let xs = [0, 1, 2, 3];
let y = unsafe { *xs.as_ptr().offset(3) };
assert_eq!(y, 3);
}
7 changes: 7 additions & 0 deletions asan/examples/use-after-free-fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let xs = vec![0, 1, 2, 3];
let y = xs.as_ptr();
let z = unsafe { *y };
assert_eq!(z, 0);
drop(xs);
}
36 changes: 36 additions & 0 deletions asan/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#[cfg(test)]
mod tests {
#[test]
fn out_of_bounds_fixed() {
let xs = [0, 1, 2, 3];
let y = unsafe { *xs.as_ptr().offset(3) };
assert_eq!(y, 3);
}

#[test]
fn use_after_free_fixed() {
let xs = vec![0, 1, 2, 3];
let y = xs.as_ptr();
let z = unsafe { *y };
assert_eq!(z, 0);
drop(xs);
}

#[cfg(feature = "fail")]
#[test]
fn out_of_bounds() {
let xs = [0, 1, 2, 3];
let y = unsafe { *xs.as_ptr().offset(4) };
assert_eq!(y, 3);
}

#[cfg(feature = "fail")]
#[test]
fn use_after_free() {
let xs = vec![0, 1, 2, 3];
let y = xs.as_ptr();
drop(xs);
let z = unsafe { *y };
assert_eq!(z, 0);
}
}
90 changes: 90 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/sh

set -ex

# ASan tests
cd asan

# Without this ASan fails under travis although it works in my machine.
export ASAN_OPTIONS="detect_leaks=0"

# Broken tests: these should fail
! RUSTFLAGS="-Z sanitizer=address" cargo run --example out-of-bounds --target x86_64-unknown-linux-gnu
! RUSTFLAGS="-Z sanitizer=address" cargo run --example use-after-free --target x86_64-unknown-linux-gnu

# ASan release builds fail to compile:
# ! RUSTFLAGS="-Z sanitizer=address" cargo run --example out-of-bounds --target x86_64-unknown-linux-gnu --release
# ! RUSTFLAGS="-Z sanitizer=address" cargo run --example use-after-free --target x86_64-unknown-linux-gnu --release

# Fixed tests: these should pass
RUSTFLAGS="-Z sanitizer=address" cargo run --example out-of-bounds-fixed --target x86_64-unknown-linux-gnu
RUSTFLAGS="-Z sanitizer=address" cargo run --example use-after-free-fixed --target x86_64-unknown-linux-gnu

# Test harness (pass):
RUSTFLAGS="-Z sanitizer=address" cargo test --target x86_64-unknown-linux-gnu
# RUSTFLAGS="-Z sanitizer=address" cargo test --target x86_64-unknown-linux-gnu --release

# Test harness (fail):
! RUSTFLAGS="-Z sanitizer=address" cargo test --features fail --target x86_64-unknown-linux-gnu
# ! RUSTFLAGS="-Z sanitizer=address" cargo test --features fail --target x86_64-unknown-linux-gnu --release

# MSan tests
cd ../msan

# Broken tests: these should fail
! RUSTFLAGS="-Z sanitizer=memory" cargo run --example uninitialized-read --target x86_64-unknown-linux-gnu
# This fails because the compiler optimizes the undefined behavior out, might need a better test
# ! RUSTFLAGS="-Z sanitizer=memory" cargo run --example uninitialized-read --target x86_64-unknown-linux-gnu --release

# Fixed tests: these should pass
RUSTFLAGS="-Z sanitizer=memory" cargo run --example uninitialized-read-fixed --target x86_64-unknown-linux-gnu
RUSTFLAGS="-Z sanitizer=memory" cargo run --example uninitialized-read-fixed --target x86_64-unknown-linux-gnu --release

# Test harness (pass):
# Fails because of: https://github.com/rust-lang/rust/issues/39610
# RUSTFLAGS="-Z sanitizer=memory" cargo test --target x86_64-unknown-linux-gnu
# RUSTFLAGS="-Z sanitizer=memory" cargo test --target x86_64-unknown-linux-gnu --release

# Test harness (fail):
# Fails for the wrong reason: https://github.com/rust-lang/rust/issues/39610
! RUSTFLAGS="-Z sanitizer=memory" cargo test --features fail --target x86_64-unknown-linux-gnu
! RUSTFLAGS="-Z sanitizer=memory" cargo test --features fail --target x86_64-unknown-linux-gnu --release

# LSan tests
cd ../lsan

# Broken tests: these should fail
# These tests don't fail but they should:
# ! RUSTFLAGS="-Z sanitizer=leak" cargo run --example memory-leak --target x86_64-unknown-linux-gnu
# ! RUSTFLAGS="-Z sanitizer=leak" cargo run --example rc-cycle --target x86_64-unknown-linux-gnu
# ! RUSTFLAGS="-Z sanitizer=leak" cargo run --example memory-leak --target x86_64-unknown-linux-gnu --release
# ! RUSTFLAGS="-Z sanitizer=leak" cargo run --example rc-cycle --target x86_64-unknown-linux-gnu -- release

# Fixed tests: these should pass (they do pass on my machine, but fail on travis due to: https://github.com/travis-ci/travis-ci/issues/9033)
# RUSTFLAGS="-Z sanitizer=leak" cargo run --example memory-leak-fixed --target x86_64-unknown-linux-gnu
# RUSTFLAGS="-Z sanitizer=leak" cargo run --example memory-leak-fixed --target x86_64-unknown-linux-gnu --release
# RUSTFLAGS="-Z sanitizer=leak" cargo run --example rc-cycle-fixed --target x86_64-unknown-linux-gnu
# RUSTFLAGS="-Z sanitizer=leak" cargo run --example rc-cycle-fixed --target x86_64-unknown-linux-gnu --release

# TSan tests
cd ../tsan

# Broken tests: these should fail
! RUSTFLAGS="-Z sanitizer=thread" cargo run --example data-race --target x86_64-unknown-linux-gnu
! RUSTFLAGS="-Z sanitizer=thread" cargo run --example data-race --target x86_64-unknown-linux-gnu --release

# Fixed tests: these should pass
RUSTFLAGS="-Z sanitizer=thread" cargo run --example data-race-fixed --target x86_64-unknown-linux-gnu
RUSTFLAGS="-Z sanitizer=thread" cargo run --example data-race-fixed --target x86_64-unknown-linux-gnu --release

# Test harness (pass):
# Fails because of https://github.com/rust-lang/rust/issues/39608
# RUSTFLAGS="-Z sanitizer=thread" cargo test --target x86_64-unknown-linux-gnu
# RUSTFLAGS="-Z sanitizer=thread" cargo test --target x86_64-unknown-linux-gnu --release
# setting RUST_TEST_THREADS=1 fixes it:
RUST_TEST_THREADS=1 RUSTFLAGS="-Z sanitizer=thread" cargo test --target x86_64-unknown-linux-gnu
RUST_TEST_THREADS=1 RUSTFLAGS="-Z sanitizer=thread" cargo test --target x86_64-unknown-linux-gnu --release

# Test harness (fail):
! RUSTFLAGS="-Z sanitizer=thread" cargo test --features fail --target x86_64-unknown-linux-gnu
! RUSTFLAGS="-Z sanitizer=thread" cargo test --features fail --target x86_64-unknown-linux-gnu --release
5 changes: 5 additions & 0 deletions lsan/examples/memory-leak-fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use std::mem;

fn main() {
let xs = vec![0, 1, 2, 3];
}
19 changes: 19 additions & 0 deletions lsan/examples/rc-cycle-fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::cell::RefCell;
use std::rc::Rc;

#[derive(Clone)]
struct Cycle {
cell: RefCell<Option<Rc<Cycle>>>,
}

impl Drop for Cycle {
fn drop(&mut self) {
println!("freed");
}
}

fn main() {
let cycle = Rc::new(Cycle { cell: RefCell::new(None)});
*cycle.cell.borrow_mut() = Some(cycle.clone());
*cycle.cell.borrow_mut() = None;
}
6 changes: 5 additions & 1 deletion msan/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[package]
authors = ["Jorge Aparicio <japaricious@gmail.com>"]
name = "msan"
version = "0.1.0"
version = "0.1.0"

[features]
# Enables tests that fail.
fail = []
4 changes: 4 additions & 0 deletions msan/examples/uninitialized-read-fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let xs: [u8; 4] = [0; 4];
let y = xs[0] + xs[1];
}
16 changes: 16 additions & 0 deletions msan/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[cfg(test)]
mod tests {
#[test]
fn uninitialized_read_fixed() {
let xs: [u8; 4] = [0; 4];
let y = xs[0] + xs[1];
}

#[cfg(feature = "fail")]
#[test]
fn uninitialized_read() {
use std::mem;
let xs: [u8; 4] = unsafe { mem::uninitialized() };
let y = xs[0] + xs[1];
}
}
6 changes: 5 additions & 1 deletion tsan/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[package]
authors = ["Jorge Aparicio <japaricious@gmail.com>"]
name = "tsan"
version = "0.1.0"
version = "0.1.0"

[features]
# Enable tests that fail
fail = []
15 changes: 15 additions & 0 deletions tsan/examples/data-race-fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(integer_atomics)]

use std::thread;
use std::sync::atomic::{AtomicI32, Ordering};


static ANSWER: AtomicI32 = AtomicI32::new(0);

fn main() {
let t1 = thread::spawn(|| ANSWER.store(42, Ordering::SeqCst) );
ANSWER.store(24, Ordering::SeqCst);
t1.join().ok();
let v = ANSWER.load(Ordering::SeqCst);
assert!(v == 42 || v == 24);
}
71 changes: 71 additions & 0 deletions tsan/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#![cfg_attr(test, feature(integer_atomics))]

#[cfg(test)]
mod tests {

#[test]
fn data_race_fixed() {
use std::thread;
use std::sync::atomic::{AtomicI32, Ordering};

static ANSWER: AtomicI32 = AtomicI32::new(0);

fn foo() {
let t1 = thread::spawn(|| ANSWER.store(42, Ordering::SeqCst) );
ANSWER.store(24, Ordering::SeqCst);
t1.join().ok();
let v = ANSWER.load(Ordering::SeqCst);
assert!(v == 42 || v == 24);
}
foo();
}

#[test]
fn data_race_fixed1() {
use std::thread;
use std::sync::atomic::{AtomicI32, Ordering};

static ANSWER: AtomicI32 = AtomicI32::new(0);

fn foo() {
let t1 = thread::spawn(|| ANSWER.store(42, Ordering::SeqCst) );
ANSWER.store(24, Ordering::SeqCst);
t1.join().ok();
let v = ANSWER.load(Ordering::SeqCst);
assert!(v == 42 || v == 24);
}
foo();
}

#[test]
fn data_race_fixed2() {
use std::thread;
use std::sync::atomic::{AtomicI32, Ordering};

static ANSWER: AtomicI32 = AtomicI32::new(0);

fn foo() {
let t1 = thread::spawn(|| ANSWER.store(42, Ordering::SeqCst) );
ANSWER.store(24, Ordering::SeqCst);
t1.join().ok();
let v = ANSWER.load(Ordering::SeqCst);
assert!(v == 42 || v == 24);
}
foo();
}

#[cfg(feature = "fail")]
#[test]
fn data_race() {
use std::thread;
static mut ANSWER: i32 = 0;
fn foo() {
let t1 = thread::spawn(|| unsafe { ANSWER = 42 });
unsafe {
ANSWER = 24;
}
t1.join().ok();
}
foo();
}
}