frames(rust): don't call into C if running Rust unit tests

Wrap the calls behind frames to C code if a `cfg!(not(test))` so they
don't get compiled when running Rust unit tests.  Linkage to C functions
is not yet available for Rust unit tests, and this will keep the check
out of individual parsers.

Ticket: 4984
pull/7349/head
Jason Ish 4 years ago committed by Victor Julien
parent c74ea3840d
commit 8d1840f595

@ -52,19 +52,25 @@ impl Frame {
) -> Option<Self> { ) -> Option<Self> {
let offset = frame_start.as_ptr() as usize - stream_slice.as_slice().as_ptr() as usize; let offset = frame_start.as_ptr() as usize - stream_slice.as_slice().as_ptr() as usize;
SCLogDebug!("offset {} stream_slice.len() {} frame_start.len() {}", offset, stream_slice.len(), frame_start.len()); SCLogDebug!("offset {} stream_slice.len() {} frame_start.len() {}", offset, stream_slice.len(), frame_start.len());
let frame = unsafe { // If running Rust unit tests this won't be compiled and None will be returned, as we don't
AppLayerFrameNewByRelativeOffset( // have the Suricata C code available for linkage.
flow, if cfg!(not(test)) {
stream_slice, let frame = unsafe {
offset as u32, AppLayerFrameNewByRelativeOffset(
frame_len, flow,
dir, stream_slice,
frame_type, offset as u32,
) frame_len,
}; dir,
let id = unsafe { AppLayerFrameGetId(frame) }; frame_type,
if id > 0 { )
Some(Self { id }) };
let id = unsafe { AppLayerFrameGetId(frame) };
if id > 0 {
Some(Self { id })
} else {
None
}
} else { } else {
None None
} }

Loading…
Cancel
Save