Skip to content

Commit 6a8dbbe

Browse files
committed
Create tests for rav1e binary
1 parent 7656089 commit 6a8dbbe

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.y4m binary

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ features = ["parallel"]
108108
signal-hook = { version = "0.1.9", optional = true }
109109

110110
[dev-dependencies]
111+
assert_cmd = "0.12"
111112
criterion = "0.3"
112113
pretty_assertions = "0.6"
113114
interpolate_name = "0.2.2"

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!small_input.y4m

tests/binary.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#[cfg(feature = "binaries")]
2+
mod binary {
3+
use assert_cmd::Command;
4+
use rand::distributions::Alphanumeric;
5+
use rand::{thread_rng, Rng};
6+
use std::env::temp_dir;
7+
use std::fs::File;
8+
use std::io::Read;
9+
use std::path::PathBuf;
10+
11+
fn get_y4m_input() -> Vec<u8> {
12+
let mut input = File::open(&format!(
13+
"{}/tests/small_input.y4m",
14+
env!("CARGO_MANIFEST_DIR")
15+
))
16+
.unwrap();
17+
let mut data = Vec::new();
18+
input.read_to_end(&mut data).unwrap();
19+
data
20+
}
21+
22+
fn get_tempfile_path(extension: &str) -> PathBuf {
23+
let mut path = temp_dir();
24+
let filename =
25+
thread_rng().sample_iter(&Alphanumeric).take(12).collect::<String>();
26+
path.push(format!("{}.{}", filename, extension));
27+
path
28+
}
29+
30+
#[test]
31+
fn one_pass_qp_based() {
32+
let mut cmd = Command::cargo_bin("rav1e").unwrap();
33+
let outfile = get_tempfile_path("ivf");
34+
35+
cmd
36+
.arg("--quantizer")
37+
.arg("100")
38+
.arg("-o")
39+
.arg(&outfile)
40+
.arg("-")
41+
.write_stdin(get_y4m_input())
42+
.assert()
43+
.success();
44+
}
45+
46+
#[test]
47+
fn one_pass_bitrate_based() {
48+
let mut cmd = Command::cargo_bin("rav1e").unwrap();
49+
let outfile = get_tempfile_path("ivf");
50+
51+
cmd
52+
.arg("--bitrate")
53+
.arg("1000")
54+
.arg("-o")
55+
.arg(&outfile)
56+
.arg("-")
57+
.write_stdin(get_y4m_input())
58+
.assert()
59+
.success();
60+
}
61+
62+
#[test]
63+
fn two_pass_bitrate_based() {
64+
let outfile = get_tempfile_path("ivf");
65+
let passfile = get_tempfile_path("pass");
66+
67+
let mut cmd1 = Command::cargo_bin("rav1e").unwrap();
68+
cmd1
69+
.arg("--bitrate")
70+
.arg("1000")
71+
.arg("-o")
72+
.arg(&outfile)
73+
.arg("--first-pass")
74+
.arg(&passfile)
75+
.arg("-")
76+
.write_stdin(get_y4m_input())
77+
.assert()
78+
.success();
79+
80+
let mut cmd2 = Command::cargo_bin("rav1e").unwrap();
81+
cmd2
82+
.arg("--bitrate")
83+
.arg("1000")
84+
.arg("-o")
85+
.arg(&outfile)
86+
.arg("--second-pass")
87+
.arg(&passfile)
88+
.arg("-")
89+
.write_stdin(get_y4m_input())
90+
.assert()
91+
.success();
92+
}
93+
}

0 commit comments

Comments
 (0)