diff --git a/.travis.yml b/.travis.yml index 136fc5b..d5680f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,10 @@ matrix: include: - os: linux rust: nightly + addons: + apt: + packages: + - nvidia-cuda-toolkit - os: osx rust: nightly diff --git a/tests/linker.rs b/tests/linker.rs index a25d3fa..47d7884 100644 --- a/tests/linker.rs +++ b/tests/linker.rs @@ -9,6 +9,10 @@ use std::env::{current_dir, current_exe}; use std::path::Path; mod steps; +use steps::{ + assembly::StepFactory as AssemblyTestStepFactory, ir::StepFactory as IRTestStepFactory, + verification::StepFactory as VerificationTestStepFactory, +}; fn ptx_assembly_tests(tester: &mut TestRunner) { tester.add("Debug PTX Assembly", || { @@ -16,7 +20,7 @@ fn ptx_assembly_tests(tester: &mut TestRunner) { config .additional_steps - .push(Box::new(steps::assembly::StepFactory::new())); + .push(Box::new(AssemblyTestStepFactory::new())); config }); @@ -26,7 +30,37 @@ fn ptx_assembly_tests(tester: &mut TestRunner) { config .additional_steps - .push(Box::new(steps::assembly::StepFactory::new())); + .push(Box::new(AssemblyTestStepFactory::new())); + + config + }); + + tester.add("Debug PTX Assembly Verification", || { + let mut config = create_config(Mode::BuildSuccess, Profile::Debug); + + config.crates_filter = Box::new(|path| { + VerificationTestStepFactory::is_runnable() + && path != Path::new("examples/undefined-ref") + }); + + config + .additional_steps + .push(Box::new(VerificationTestStepFactory::new())); + + config + }); + + tester.add("Release PTX Assembly Verification", || { + let mut config = create_config(Mode::BuildSuccess, Profile::Release); + + config.crates_filter = Box::new(|path| { + VerificationTestStepFactory::is_runnable() + && path != Path::new("examples/undefined-ref") + }); + + config + .additional_steps + .push(Box::new(VerificationTestStepFactory::new())); config }); @@ -38,7 +72,7 @@ fn ir_tests(tester: &mut TestRunner) { config .additional_steps - .push(Box::new(steps::ir::StepFactory::new())); + .push(Box::new(IRTestStepFactory::new())); config }); @@ -48,7 +82,7 @@ fn ir_tests(tester: &mut TestRunner) { config .additional_steps - .push(Box::new(steps::ir::StepFactory::new())); + .push(Box::new(IRTestStepFactory::new())); config }); diff --git a/tests/steps/mod.rs b/tests/steps/mod.rs index 0d78095..8eb3d0b 100644 --- a/tests/steps/mod.rs +++ b/tests/steps/mod.rs @@ -6,6 +6,7 @@ use crate_compile_test::prelude::*; pub mod assembly; pub mod ir; +pub mod verification; trait LinkOutputCheckStep { fn get_crate_name(&self) -> String; diff --git a/tests/steps/verification.rs b/tests/steps/verification.rs new file mode 100644 index 0000000..2555536 --- /dev/null +++ b/tests/steps/verification.rs @@ -0,0 +1,56 @@ +use std::path::Path; +use std::process::Command; + +use crate_compile_test::prelude::*; +use crate_compile_test::steps::{TestStep, TestStepFactory}; + +pub struct StepFactory; +pub struct Step; + +impl StepFactory { + pub fn new() -> Self { + StepFactory {} + } + + pub fn is_runnable() -> bool { + if let Ok(output) = Command::new("ptxas").args(&["-V"]).output() { + output.status.success() + } else { + false + } + } +} + +impl TestStepFactory for StepFactory { + fn initialize(&self, _config: &Config, _crate_path: &Path) -> Result> { + Ok(Box::new(Step {})) + } +} + +impl TestStep for Step { + fn execute(&self, config: &Config, build_path: &Path) -> Result<()> { + let assembly_path = match config.profile { + Profile::Release => build_path + .join("nvptx64-nvidia-cuda") + .join("release") + .join("example.ptx"), + + Profile::Debug => build_path + .join("nvptx64-nvidia-cuda") + .join("debug") + .join("example.ptx"), + }; + + let output = Command::new("ptxas") + .arg("--compile-only") + .arg(assembly_path) + .current_dir(build_path) + .output()?; + + if output.status.success() { + Ok(()) + } else { + bail!("{}", String::from_utf8_lossy(&output.stderr)); + } + } +}