Skip to content

Commit

Permalink
Create tests for rav1e binary
Browse files Browse the repository at this point in the history
  • Loading branch information
shssoichiro committed Mar 24, 2020
1 parent 7656089 commit 6a8dbbe
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.y4m binary
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ features = ["parallel"]
signal-hook = { version = "0.1.9", optional = true }

[dev-dependencies]
assert_cmd = "0.12"
criterion = "0.3"
pretty_assertions = "0.6"
interpolate_name = "0.2.2"
Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!small_input.y4m
93 changes: 93 additions & 0 deletions tests/binary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#[cfg(feature = "binaries")]
mod binary {
use assert_cmd::Command;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use std::env::temp_dir;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;

fn get_y4m_input() -> Vec<u8> {
let mut input = File::open(&format!(
"{}/tests/small_input.y4m",
env!("CARGO_MANIFEST_DIR")
))
.unwrap();
let mut data = Vec::new();
input.read_to_end(&mut data).unwrap();
data
}

fn get_tempfile_path(extension: &str) -> PathBuf {
let mut path = temp_dir();
let filename =
thread_rng().sample_iter(&Alphanumeric).take(12).collect::<String>();
path.push(format!("{}.{}", filename, extension));
path
}

#[test]
fn one_pass_qp_based() {
let mut cmd = Command::cargo_bin("rav1e").unwrap();
let outfile = get_tempfile_path("ivf");

cmd
.arg("--quantizer")
.arg("100")
.arg("-o")
.arg(&outfile)
.arg("-")
.write_stdin(get_y4m_input())
.assert()
.success();
}

#[test]
fn one_pass_bitrate_based() {
let mut cmd = Command::cargo_bin("rav1e").unwrap();
let outfile = get_tempfile_path("ivf");

cmd
.arg("--bitrate")
.arg("1000")
.arg("-o")
.arg(&outfile)
.arg("-")
.write_stdin(get_y4m_input())
.assert()
.success();
}

#[test]
fn two_pass_bitrate_based() {
let outfile = get_tempfile_path("ivf");
let passfile = get_tempfile_path("pass");

let mut cmd1 = Command::cargo_bin("rav1e").unwrap();
cmd1
.arg("--bitrate")
.arg("1000")
.arg("-o")
.arg(&outfile)
.arg("--first-pass")
.arg(&passfile)
.arg("-")
.write_stdin(get_y4m_input())
.assert()
.success();

let mut cmd2 = Command::cargo_bin("rav1e").unwrap();
cmd2
.arg("--bitrate")
.arg("1000")
.arg("-o")
.arg(&outfile)
.arg("--second-pass")
.arg(&passfile)
.arg("-")
.write_stdin(get_y4m_input())
.assert()
.success();
}
}
Loading

0 comments on commit 6a8dbbe

Please sign in to comment.