Skip to content

Commit

Permalink
PTX verification test step
Browse files Browse the repository at this point in the history
  • Loading branch information
denzp committed Sep 9, 2018
1 parent af6ed3b commit fff5f4b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ matrix:
include:
- os: linux
rust: nightly
addons:
apt:
packages:
- nvidia-cuda-toolkit

- os: osx
rust: nightly
Expand Down
42 changes: 38 additions & 4 deletions tests/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ 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", || {
let mut config = create_config(Mode::BuildSuccess, Profile::Debug);

config
.additional_steps
.push(Box::new(steps::assembly::StepFactory::new()));
.push(Box::new(AssemblyTestStepFactory::new()));

config
});
Expand All @@ -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
});
Expand All @@ -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
});
Expand All @@ -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
});
Expand Down
1 change: 1 addition & 0 deletions tests/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
56 changes: 56 additions & 0 deletions tests/steps/verification.rs
Original file line number Diff line number Diff line change
@@ -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<Box<TestStep>> {
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));
}
}
}

0 comments on commit fff5f4b

Please sign in to comment.