fix(rust): match HUF tests to the forced decoder
The compression round-trip tests built an X1 decode table unconditionally. That violated the X2 decoder contract when the HUF force feature was enabled and triggered the production debug assertion instead of testing the selected configuration. Build the table with the selected X1/X2 reader and reserve the corresponding table capacity. Test Plan: - cargo test --manifest-path rust/Cargo.toml - cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression,decompression,dict-builder,huf-force-decompress-x1,legacy-v01,legacy-v02,legacy-v03,legacy-v04,legacy-v05,legacy-v06,legacy-v07 - cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression,decompression,dict-builder,huf-force-decompress-x2,legacy-v01,legacy-v02,legacy-v03,legacy-v04,legacy-v05,legacy-v06,legacy-v07 - cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings Refs: HUF force-mode build matrix
This commit is contained in:
+52
-14
@@ -1379,9 +1379,11 @@ pub unsafe extern "C" fn HUF_compress4X_repeat(
|
||||
#[cfg(all(test, feature = "decompression"))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::huf_decompress::{
|
||||
HUF_decompress1X_usingDTable, HUF_decompress4X_usingDTable, HUF_readDTableX1_wksp,
|
||||
};
|
||||
#[cfg(not(feature = "huf-force-decompress-x2"))]
|
||||
use crate::huf_decompress::HUF_readDTableX1_wksp;
|
||||
#[cfg(feature = "huf-force-decompress-x2")]
|
||||
use crate::huf_decompress::HUF_readDTableX2_wksp;
|
||||
use crate::huf_decompress::{HUF_decompress1X_usingDTable, HUF_decompress4X_usingDTable};
|
||||
|
||||
const WORKSPACE_SIZE: usize = HUF_WORKSPACE_SIZE;
|
||||
|
||||
@@ -1427,21 +1429,54 @@ mod tests {
|
||||
unsafe fn dtable_from_header(
|
||||
header: &[u8],
|
||||
workspace: &mut [u64; WORKSPACE_SIZE / size_of::<u64>()],
|
||||
) -> [u32; 1 + (1 << 11)] {
|
||||
let mut dtable = [0u32; 1 + (1 << 11)];
|
||||
) -> Vec<u32> {
|
||||
let dtable_size = if cfg!(feature = "huf-force-decompress-x2") {
|
||||
1 + (1 << 12)
|
||||
} else {
|
||||
1 + (1 << 11)
|
||||
};
|
||||
let mut dtable = vec![0u32; dtable_size];
|
||||
dtable[0] = 11 * 0x0100_0001;
|
||||
let read = HUF_readDTableX1_wksp(
|
||||
let read = read_dtable(
|
||||
dtable.as_mut_ptr(),
|
||||
header.as_ptr().cast::<c_void>(),
|
||||
header.len(),
|
||||
workspace.as_mut_ptr().cast::<c_void>(),
|
||||
std::mem::size_of_val(workspace),
|
||||
0,
|
||||
workspace,
|
||||
);
|
||||
assert!(!ERR_isError(read));
|
||||
dtable
|
||||
}
|
||||
|
||||
unsafe fn read_dtable(
|
||||
dtable: *mut u32,
|
||||
source: *const c_void,
|
||||
source_size: usize,
|
||||
workspace: &mut [u64; WORKSPACE_SIZE / size_of::<u64>()],
|
||||
) -> usize {
|
||||
#[cfg(feature = "huf-force-decompress-x2")]
|
||||
{
|
||||
HUF_readDTableX2_wksp(
|
||||
dtable,
|
||||
source,
|
||||
source_size,
|
||||
workspace.as_mut_ptr().cast::<c_void>(),
|
||||
std::mem::size_of_val(workspace),
|
||||
0,
|
||||
)
|
||||
}
|
||||
#[cfg(not(feature = "huf-force-decompress-x2"))]
|
||||
{
|
||||
HUF_readDTableX1_wksp(
|
||||
dtable,
|
||||
source,
|
||||
source_size,
|
||||
workspace.as_mut_ptr().cast::<c_void>(),
|
||||
std::mem::size_of_val(workspace),
|
||||
0,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tables_and_single_stream_round_trip() {
|
||||
let source = source();
|
||||
@@ -1516,16 +1551,19 @@ mod tests {
|
||||
)
|
||||
};
|
||||
assert!(c_size > 0);
|
||||
let mut dtable = [0u32; 1 + (1 << 11)];
|
||||
let dtable_size = if cfg!(feature = "huf-force-decompress-x2") {
|
||||
1 + (1 << 12)
|
||||
} else {
|
||||
1 + (1 << 11)
|
||||
};
|
||||
let mut dtable = vec![0u32; dtable_size];
|
||||
dtable[0] = 11 * 0x0100_0001;
|
||||
let header_size = unsafe {
|
||||
HUF_readDTableX1_wksp(
|
||||
read_dtable(
|
||||
dtable.as_mut_ptr(),
|
||||
compressed.as_ptr().cast::<c_void>(),
|
||||
c_size,
|
||||
workspace.as_mut_ptr().cast::<c_void>(),
|
||||
std::mem::size_of_val(&workspace),
|
||||
0,
|
||||
&mut workspace,
|
||||
)
|
||||
};
|
||||
assert!(!ERR_isError(header_size));
|
||||
|
||||
Reference in New Issue
Block a user