]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
frames(rust): don't call into C if running Rust unit tests
authorJason Ish <jason.ish@oisf.net>
Tue, 26 Apr 2022 20:59:18 +0000 (14:59 -0600)
committerVictor Julien <vjulien@oisf.net>
Sat, 30 Apr 2022 06:01:49 +0000 (08:01 +0200)
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

rust/src/frames.rs

index a9079d0dc179d05b409ecf2e93f462978340bc71..14d7ff8e45556883f467036604a0db443541cfae 100644 (file)
@@ -52,19 +52,25 @@ impl Frame {
     ) -> Option<Self> {
         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());
-        let frame = unsafe {
-            AppLayerFrameNewByRelativeOffset(
-                flow,
-                stream_slice,
-                offset as u32,
-                frame_len,
-                dir,
-                frame_type,
-            )
-        };
-        let id = unsafe { AppLayerFrameGetId(frame) };
-        if id > 0 {
-            Some(Self { id })
+        // If running Rust unit tests this won't be compiled and None will be returned, as we don't
+        // have the Suricata C code available for linkage.
+        if cfg!(not(test)) {
+            let frame = unsafe {
+                AppLayerFrameNewByRelativeOffset(
+                    flow,
+                    stream_slice,
+                    offset as u32,
+                    frame_len,
+                    dir,
+                    frame_type,
+                )
+            };
+            let id = unsafe { AppLayerFrameGetId(frame) };
+            if id > 0 {
+                Some(Self { id })
+            } else {
+                None
+            }
         } else {
             None
         }