Skip to content

Commit

Permalink
Rollup merge of rust-lang#68291 - tmiasko:sanitizer-tests, r=nikomats…
Browse files Browse the repository at this point in the history
…akis

Update sanitizer tests

* Move tests from src/test/run-make-fulldeps to src/test/ui.
* Fix memory sanitizer test to detect the intended issue rather than
  an unrelated one caused by the use of an uninstrumented std.
  • Loading branch information
tmandry authored Jan 18, 2020
2 parents 2a1ab29 + ea64a33 commit 87293cd
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 75 deletions.
30 changes: 0 additions & 30 deletions src/test/run-make-fulldeps/sanitizer-address/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions src/test/run-make-fulldeps/sanitizer-address/overflow.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/run-make-fulldeps/sanitizer-invalid-target/Makefile

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/run-make-fulldeps/sanitizer-invalid-target/hello.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/test/run-make-fulldeps/sanitizer-leak/Makefile

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/run-make-fulldeps/sanitizer-memory/Makefile

This file was deleted.

8 changes: 0 additions & 8 deletions src/test/run-make-fulldeps/sanitizer-memory/maybeuninit.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/test/run-make-fulldeps/sanitizer-memory/uninit.rs

This file was deleted.

21 changes: 21 additions & 0 deletions src/test/ui/sanitizer-address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// needs-sanitizer-support
// only-x86_64
//
// compile-flags: -Z sanitizer=address -O
//
// run-fail
// error-pattern: AddressSanitizer: stack-buffer-overflow
// error-pattern: 'xs' <== Memory access at offset

#![feature(test)]

use std::hint::black_box;
use std::mem;

fn main() {
let xs = [0, 1, 2, 3];
// Avoid optimizing everything out.
let xs = black_box(xs.as_ptr());
let code = unsafe { *xs.offset(4) };
std::process::exit(code);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// needs-sanitizer-support
// only-x86_64
//
// compile-flags: -Z sanitizer=leak -O
//
// run-fail
// error-pattern: LeakSanitizer: detected memory leaks

#![feature(test)]

use std::hint::black_box;
Expand Down
44 changes: 44 additions & 0 deletions src/test/ui/sanitizer-memory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// needs-sanitizer-support
// only-linux
// only-x86_64
//
// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
//
// run-fail
// error-pattern: MemorySanitizer: use-of-uninitialized-value
// error-pattern: Uninitialized value was created by an allocation
// error-pattern: in the stack frame of function 'random'
//
// This test case intentionally limits the usage of the std,
// since it will be linked with an uninstrumented version of it.

#![feature(core_intrinsics)]
#![feature(start)]
#![feature(test)]

use std::hint::black_box;
use std::mem::MaybeUninit;

#[inline(never)]
#[no_mangle]
fn random() -> [isize; 32] {
let r = unsafe { MaybeUninit::uninit().assume_init() };
// Avoid optimizing everything out.
black_box(r)
}

#[inline(never)]
#[no_mangle]
fn xor(a: &[isize]) -> isize {
let mut s = 0;
for i in 0..a.len() {
s = s ^ a[i];
}
s
}

#[start]
fn main(_: isize, _: *const *const u8) -> isize {
let r = random();
xor(&r)
}
7 changes: 7 additions & 0 deletions src/test/ui/sanitizer-unsupported-target.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// ignore-tidy-linelength
// compile-flags: -Z sanitizer=leak --target i686-unknown-linux-gnu
// error-pattern: error: LeakSanitizer only works with the `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin` target

#![feature(no_core)]
#![no_core]
#![no_main]
4 changes: 4 additions & 0 deletions src/test/ui/sanitizer-unsupported-target.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: LeakSanitizer only works with the `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin` target

error: aborting due to previous error

0 comments on commit 87293cd

Please sign in to comment.