diff options
| author | Cesar Eduardo Barros <[email protected]> | 2020-01-20 11:09:37 -0300 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2020-01-20 11:58:07 -0500 |
| commit | 273a679ddcad272796c09be678d161d278d9316e (patch) | |
| tree | b8450078f59c4ae904147207f79477020c054467 /b3sum/tests | |
| parent | b8c33e11ef4a85a0d88743cb7f00b66c2c9fc538 (diff) | |
b3sum: add no-mmap option
Using mmap is not always the best option. For instance, if the file is
truncated while being read, b3sum will receive a SIGBUS and abort.
Follow ripgrep's lead and add a --no-mmap option to disable mmap. This
can also help benchmark the mmap versus the read path, and help debug
performance issues potentially caused by mmap access patterns (like
issue #32).
Diffstat (limited to 'b3sum/tests')
| -rw-r--r-- | b3sum/tests/test.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/b3sum/tests/test.rs b/b3sum/tests/test.rs index 5837bac..bb2f4e0 100644 --- a/b3sum/tests/test.rs +++ b/b3sum/tests/test.rs @@ -98,6 +98,19 @@ fn test_derive_key() { } #[test] +fn test_no_mmap() { + let f = tempfile::NamedTempFile::new().unwrap(); + f.as_file().write_all(b"foo").unwrap(); + f.as_file().flush().unwrap(); + + let expected = blake3::hash(b"foo").to_hex(); + let output = cmd!(b3sum_exe(), "--no-mmap", "--no-names", f.path()) + .read() + .unwrap(); + assert_eq!(&*expected, &*output); +} + +#[test] fn test_length_without_value_is_an_error() { let result = cmd!(b3sum_exe(), "--length") .stdin_bytes("foo") |
