mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Add compilation tests with optimization enabled
Introduces a new variant of `tests/lib.rs` that compiles the source files in `tests/run` with `-Copt-level=3`.
This commit is contained in:
parent
5d25b8fc45
commit
63ffdfdd17
@ -9,8 +9,12 @@ license = "MIT OR Apache-2.0"
|
||||
crate-type = ["dylib"]
|
||||
|
||||
[[test]]
|
||||
name = "lang_tests"
|
||||
path = "tests/lib.rs"
|
||||
name = "lang_tests_debug"
|
||||
path = "tests/lang_tests_debug.rs"
|
||||
harness = false
|
||||
[[test]]
|
||||
name = "lang_tests_release"
|
||||
path = "tests/lang_tests_release.rs"
|
||||
harness = false
|
||||
|
||||
[features]
|
||||
|
@ -1,3 +1,4 @@
|
||||
//! The common code for `tests/lang_tests_*.rs`
|
||||
use std::{
|
||||
env::{self, current_dir},
|
||||
path::PathBuf,
|
||||
@ -7,7 +8,15 @@ use std::{
|
||||
use lang_tester::LangTester;
|
||||
use tempfile::TempDir;
|
||||
|
||||
fn main() {
|
||||
/// Controls the compile options (e.g., optimization level) used to compile
|
||||
/// test code.
|
||||
#[allow(dead_code)] // Each test crate picks one variant
|
||||
pub enum Profile {
|
||||
Debug,
|
||||
Release,
|
||||
}
|
||||
|
||||
pub fn main_inner(profile: Profile) {
|
||||
let tempdir = TempDir::new().expect("temp dir");
|
||||
let current_dir = current_dir().expect("current dir");
|
||||
let current_dir = current_dir.to_str().expect("current dir").to_string();
|
||||
@ -42,6 +51,15 @@ fn main() {
|
||||
"-o", exe.to_str().expect("to_str"),
|
||||
path.to_str().expect("to_str"),
|
||||
]);
|
||||
match profile {
|
||||
Profile::Debug => {}
|
||||
Profile::Release => {
|
||||
compiler.args(&[
|
||||
"-C", "opt-level=3",
|
||||
"-C", "lto=no",
|
||||
]);
|
||||
}
|
||||
}
|
||||
// Test command 2: run `tempdir/x`.
|
||||
let runtime = Command::new(exe);
|
||||
vec![("Compiler", compiler), ("Run-time", runtime)]
|
5
tests/lang_tests_debug.rs
Normal file
5
tests/lang_tests_debug.rs
Normal file
@ -0,0 +1,5 @@
|
||||
mod lang_tests_common;
|
||||
|
||||
fn main() {
|
||||
lang_tests_common::main_inner(lang_tests_common::Profile::Debug);
|
||||
}
|
5
tests/lang_tests_release.rs
Normal file
5
tests/lang_tests_release.rs
Normal file
@ -0,0 +1,5 @@
|
||||
mod lang_tests_common;
|
||||
|
||||
fn main() {
|
||||
lang_tests_common::main_inner(lang_tests_common::Profile::Release);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// Compiler:
|
||||
//
|
||||
// Run-time:
|
||||
// stdout: Panicking
|
||||
// stdout: Success
|
||||
// status: signal
|
||||
|
||||
#![allow(unused_attributes)]
|
||||
@ -64,7 +64,9 @@ mod intrinsics {
|
||||
#[no_mangle]
|
||||
pub fn panic(_msg: &str) -> ! {
|
||||
unsafe {
|
||||
libc::puts("Panicking\0" as *const str as *const u8);
|
||||
// Panicking is expected iff overflow checking is enabled.
|
||||
#[cfg(debug_assertions)]
|
||||
libc::puts("Success\0" as *const str as *const u8);
|
||||
libc::fflush(libc::stdout);
|
||||
intrinsics::abort();
|
||||
}
|
||||
@ -124,6 +126,15 @@ impl Add for isize {
|
||||
#[start]
|
||||
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
|
||||
let int = 9223372036854775807isize;
|
||||
let int = int + argc;
|
||||
let int = int + argc; // overflow
|
||||
|
||||
// If overflow checking is disabled, we should reach here.
|
||||
#[cfg(not(debug_assertions))]
|
||||
unsafe {
|
||||
libc::puts("Success\0" as *const str as *const u8);
|
||||
libc::fflush(libc::stdout);
|
||||
intrinsics::abort();
|
||||
}
|
||||
|
||||
int
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user