aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2020-04-03 11:05:08 -0400
committerJack O'Connor <[email protected]>2020-04-03 18:51:35 -0400
commiteaef2698cf0f9c18ee97d9b5f3743e99d07dc90b (patch)
tree94afc369d6bd1b3db981a7827132d1b738bb5627
parente3069da68e58d280e54c5bfc36a8182117d34b41 (diff)
move the long set of CI steps into Rust codeci
-rw-r--r--tests/ci/Cargo.toml7
-rw-r--r--tests/ci/src/main.rs141
2 files changed, 148 insertions, 0 deletions
diff --git a/tests/ci/Cargo.toml b/tests/ci/Cargo.toml
new file mode 100644
index 0000000..d423363
--- /dev/null
+++ b/tests/ci/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "ci"
+version = "0.0.0"
+edition = "2018"
+
+[dependencies]
+anyhow = "1.0.28"
diff --git a/tests/ci/src/main.rs b/tests/ci/src/main.rs
new file mode 100644
index 0000000..df58037
--- /dev/null
+++ b/tests/ci/src/main.rs
@@ -0,0 +1,141 @@
+use anyhow::bail;
+use std::path::Path;
+use std::process::Command;
+
+struct TestCommand {
+ command: Command,
+ repr: String,
+}
+
+impl TestCommand {
+ fn new(args: impl IntoIterator<Item = impl AsRef<str>>) -> Self {
+ Self::new_inner(args, None)
+ }
+
+ fn new_with_dir(args: impl IntoIterator<Item = impl AsRef<str>>, dir: &str) -> Self {
+ Self::new_inner(args, Some(dir))
+ }
+
+ fn new_inner(args: impl IntoIterator<Item = impl AsRef<str>>, dir: Option<&str>) -> Self {
+ let mut args = args.into_iter();
+ let prog = args.next().unwrap().as_ref().to_string();
+ let mut command = Command::new(&prog);
+ let mut repr = prog;
+ if let Some(dir) = dir {
+ command.current_dir(dir);
+ repr = format!("cd {} && {}", dir, repr);
+ }
+ for arg in args {
+ let arg_str: &str = arg.as_ref();
+ command.arg(arg_str);
+ repr.push_str(" ");
+ repr.push_str(arg_str);
+ }
+ Self { command, repr }
+ }
+
+ fn run(&mut self) -> anyhow::Result<()> {
+ println!("====================================================");
+ println!("Command: {}", &self.repr);
+ println!("====================================================");
+ let status = self.command.status()?;
+ if !status.success() {
+ bail!("command failed: {}", &self.repr);
+ }
+ Ok(())
+ }
+}
+
+fn main() -> anyhow::Result<()> {
+ let show = matches!(std::env::args().nth(1), Some(s) if s == "--show");
+
+ #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+ {
+ let mark = |b| if b { "YES ✔" } else { "no" };
+ println!("x86 CPU features detected:");
+ println!(" SSE4.1: {}", mark(is_x86_feature_detected!("sse4.1")));
+ println!(" AVX2: {}", mark(is_x86_feature_detected!("avx2")));
+ println!(" AVX512F: {}", mark(is_x86_feature_detected!("avx512f")));
+ println!("AVX512VL: {}", mark(is_x86_feature_detected!("avx512vl")));
+ println!("");
+ }
+
+ let project_root_dir = Path::new(env!("CARGO_MANIFEST_DIR"))
+ .parent()
+ .unwrap()
+ .parent()
+ .unwrap();
+ std::env::set_current_dir(project_root_dir)?;
+
+ let mut commands = Vec::new();
+ commands.push(TestCommand::new(&["cargo", "test"]));
+ commands.push(TestCommand::new(&[
+ "cargo",
+ "test",
+ "--no-default-features",
+ ]));
+
+ for purity in &[&[][..], &["prefer_intrinsics"][..], &["pure"][..]] {
+ for support in &[
+ &[][..],
+ &["no_avx512"][..],
+ &["no_avx512", "no_avx2"][..],
+ &["no_avx512", "no_avx2", "no_sse41"][..],
+ ] {
+ for &release in &[false, true] {
+ let mut command = vec!["cargo", "test"];
+ let mut features_vec: Vec<&str> = purity.to_vec();
+ features_vec.extend_from_slice(support);
+ let features = format!("--features={}", features_vec.join(","));
+ command.push(&features);
+ if release {
+ command.push("--release");
+ }
+ commands.push(TestCommand::new(command));
+ }
+ }
+ }
+
+ commands.push(TestCommand::new_with_dir(&["cargo", "test"], "b3sum"));
+ commands.push(TestCommand::new_with_dir(
+ &["cargo", "test", "--no-default-features"],
+ "b3sum",
+ ));
+
+ commands.push(TestCommand::new_with_dir(
+ &["cargo", "test"],
+ "test_vectors",
+ ));
+ commands.push(TestCommand::new_with_dir(
+ &["cargo", "test", "--features=prefer_intrinsics"],
+ "test_vectors",
+ ));
+ commands.push(TestCommand::new_with_dir(
+ &["cargo", "test", "--features=pure"],
+ "test_vectors",
+ ));
+
+ commands.push(TestCommand::new_with_dir(
+ &["cargo", "test"],
+ "c/blake3_c_rust_bindings",
+ ));
+ commands.push(TestCommand::new_with_dir(
+ &["cargo", "test", "--features=prefer_intrinsics"],
+ "c/blake3_c_rust_bindings",
+ ));
+
+ commands.push(TestCommand::new_with_dir(
+ &["cargo", "test"],
+ "reference_impl",
+ ));
+
+ for command in &mut commands {
+ if show {
+ println!("{}", &command.repr);
+ } else {
+ command.run()?;
+ }
+ }
+
+ Ok(())
+}