-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue-105, Brro Compressor E2E Tests and test workflow imrpovement #117
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f3c05f9
build_and_test workflow updated to allow clippy process all crate tar…
worryg0d 09acfa4
brro-compressor e2e tests
worryg0d 4307832
Merge branch 'main' into issue-105
cjrolo ec2829f
Merge branch 'main' into issue-105
cjrolo b55a6f2
Merge branch 'main' into issue-105
cjrolo 5d553e3
CI clippy lint improvement
worryg0d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
use brro_compressor::utils::error::calculate_error; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
use wavbrro::wavbrro::WavBrro; | ||
|
||
const TEST_FILE_NAME: &str = "go_gc_heap_goal_bytes.wbro"; | ||
const TEST_COMPRESSED_FILE_NAME: &str = "go_gc_heap_goal_bytes.bro"; | ||
const TEST_WBRO_PATH: &str = "tests/wbros/go_gc_heap_goal_bytes.wbro"; | ||
|
||
#[test] | ||
fn test_compressor_idw_lossless() { | ||
test_lossless_compression("idw") | ||
} | ||
|
||
#[test] | ||
fn test_compressor_idw_lossy() { | ||
test_lossy_compression("fft") | ||
} | ||
|
||
#[test] | ||
fn test_compressor_polynomial_lossless() { | ||
test_lossless_compression("polynomial") | ||
} | ||
|
||
#[test] | ||
fn test_compressor_polynomial_lossy() { | ||
test_lossy_compression("fft") | ||
} | ||
|
||
#[test] | ||
fn test_compressor_noop() { | ||
test_lossless_compression("noop") | ||
} | ||
|
||
#[test] | ||
fn test_compressor_fft_lossy() { | ||
test_lossy_compression("fft") | ||
} | ||
|
||
#[test] | ||
fn test_compressor_auto_lossless() { | ||
test_lossless_compression("auto") | ||
} | ||
|
||
#[test] | ||
fn test_compressor_auto_lossy() { | ||
test_lossy_compression("auto") | ||
} | ||
|
||
fn test_lossless_compression(compressor: &str) { | ||
test_compression_decompression_flow(compressor, 0, compare_samples_lossless) | ||
} | ||
|
||
fn test_lossy_compression(compressor: &str) { | ||
test_compression_decompression_flow(compressor, 5, compare_samples_with_allowed_error) | ||
} | ||
|
||
#[test] | ||
fn test_compressor_constant() { | ||
// tests/wbros/uptime.wbro constant data which can be compressed by constant compressor | ||
let test_dir = tempfile::tempdir().unwrap().into_path(); | ||
fs::copy("tests/wbros/uptime.wbro", test_dir.join("uptime.wbro")).unwrap(); | ||
|
||
run_compressor(&[ | ||
"--compressor", | ||
"noop", | ||
test_dir.join("uptime.wbro").to_str().unwrap(), | ||
]); | ||
|
||
run_compressor(&["-u", test_dir.join("uptime.bro").to_str().unwrap()]); | ||
|
||
compare_samples_lossless( | ||
&PathBuf::from("tests/wbros/uptime.wbro"), | ||
&test_dir.join("uptime.wbro"), | ||
) | ||
} | ||
|
||
/// Runs compression and decompression test for a specified compressor. | ||
/// max_error is an error level, compression speed is set as the lowest (0). | ||
/// | ||
/// It compresses tests/wbros/go_gc_duration_count.wbro file, decompresses | ||
/// got .bro file, and compares the original .wbro and the decompressed one. | ||
fn test_compression_decompression_flow( | ||
compressor: &str, | ||
allowed_error: u8, | ||
compare_fn: fn(original: &Path, processed: &Path), | ||
) { | ||
let test_dir = prepare_test_dir(); | ||
|
||
// Running data compression | ||
run_compressor(&[ | ||
"--compressor", | ||
compressor, | ||
"--error", | ||
allowed_error.to_string().as_str(), | ||
test_dir.join(TEST_FILE_NAME).to_str().unwrap(), | ||
]); | ||
|
||
// Running data decompression | ||
run_compressor(&[ | ||
"-u", | ||
test_dir.join(TEST_COMPRESSED_FILE_NAME).to_str().unwrap(), | ||
]); | ||
|
||
compare_fn( | ||
&PathBuf::from(TEST_WBRO_PATH), | ||
&test_dir.join(TEST_FILE_NAME), | ||
) | ||
} | ||
|
||
/// Prepares test directory and copies test wbro file there. | ||
fn prepare_test_dir() -> PathBuf { | ||
let test_dir = tempfile::tempdir().unwrap().into_path(); | ||
fs::copy(TEST_WBRO_PATH, test_dir.join(TEST_FILE_NAME)).unwrap(); | ||
test_dir | ||
} | ||
|
||
/// Runs compressor binary with provided arguments. | ||
fn run_compressor(args: &[&str]) { | ||
let compressor_bin = env!("CARGO_BIN_EXE_brro-compressor"); | ||
let exit_status = std::process::Command::new(compressor_bin) | ||
.args(args) | ||
.status() | ||
.unwrap(); | ||
|
||
assert!(exit_status.success()); | ||
} | ||
|
||
fn compare_samples_lossless(original: &Path, uncompressed: &Path) { | ||
let original_samples = WavBrro::from_file(original).unwrap(); | ||
let uncompressed_samples = WavBrro::from_file(uncompressed).unwrap(); | ||
assert_eq!(original_samples, uncompressed_samples); | ||
} | ||
|
||
fn compare_samples_with_allowed_error(original: &Path, uncompressed: &Path) { | ||
const MAX_ALLOWED_ERROR: f64 = 0.05; | ||
|
||
let original_samples = WavBrro::from_file(original).unwrap(); | ||
let uncompressed_samples = WavBrro::from_file(uncompressed).unwrap(); | ||
let err = calculate_error(&original_samples, &uncompressed_samples); | ||
|
||
assert!( | ||
err <= MAX_ALLOWED_ERROR, | ||
"Error: {}\nOriginal : {:?}\nUncompressed: {:?}", | ||
err, | ||
original_samples, | ||
uncompressed_samples | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could achieve this more simply as:
Its the
-D warnings
that causes clippy to abort and not continue on to other crates.But we also need the
-D warnings
to actually return non-zero exit code and fail CI.Its also worth noting that clippy is easy to run locally, it is automatically installed already and you can just
cargo clippy
to see most of the failures locally. (I think it skips tests and benches) Since we dont use any features in fft-compressor yet:cargo clippy --all-targets
will test everything including tests/benchesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! I like this approach much more. I added this one to the CI job.