From 6f404f5edb6de80a6ce11b57cc68ddc283a1ad64 Mon Sep 17 00:00:00 2001
From: Ryan Alameddine <rhalameddine@gmail.com>
Date: Fri, 14 Mar 2025 22:42:45 -0700
Subject: [PATCH] Added integration test which fails on zero-length read

---
 test/integration-ebpf/Cargo.toml              |  4 ++++
 test/integration-ebpf/src/socket_filter.rs    | 20 +++++++++++++++++++
 test/integration-test/src/lib.rs              |  1 +
 test/integration-test/src/tests.rs            |  1 +
 .../src/tests/socket_filter.rs                | 13 ++++++++++++
 5 files changed, 39 insertions(+)
 create mode 100644 test/integration-ebpf/src/socket_filter.rs
 create mode 100644 test/integration-test/src/tests/socket_filter.rs

diff --git a/test/integration-ebpf/Cargo.toml b/test/integration-ebpf/Cargo.toml
index c99e2cef..082e86ba 100644
--- a/test/integration-ebpf/Cargo.toml
+++ b/test/integration-ebpf/Cargo.toml
@@ -89,3 +89,7 @@ path = "src/xdp_sec.rs"
 [[bin]]
 name = "uprobe_cookie"
 path = "src/uprobe_cookie.rs"
+
+[[bin]]
+name = "socket_filter"
+path = "src/socket_filter.rs"
diff --git a/test/integration-ebpf/src/socket_filter.rs b/test/integration-ebpf/src/socket_filter.rs
new file mode 100644
index 00000000..b9cf4cd8
--- /dev/null
+++ b/test/integration-ebpf/src/socket_filter.rs
@@ -0,0 +1,20 @@
+#![no_std]
+#![no_main]
+
+use aya_ebpf::{macros::socket_filter, programs::SkBuffContext};
+
+
+#[socket_filter]
+pub fn read_one(ctx: SkBuffContext) -> i64 {
+    // Read 1 byte
+    let mut dst = [0; 1];
+    let _ = ctx.load_bytes(0, &mut dst);
+
+    0
+}
+
+#[cfg(not(test))]
+#[panic_handler]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+    loop {}
+}
diff --git a/test/integration-test/src/lib.rs b/test/integration-test/src/lib.rs
index 5dcef22a..50012891 100644
--- a/test/integration-test/src/lib.rs
+++ b/test/integration-test/src/lib.rs
@@ -32,6 +32,7 @@ pub const TEST: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/test")
 pub const TWO_PROGS: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/two_progs"));
 pub const XDP_SEC: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/xdp_sec"));
 pub const UPROBE_COOKIE: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/uprobe_cookie"));
+pub const SOCKET_FILTER: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/socket_filter"));
 
 #[cfg(test)]
 mod tests;
diff --git a/test/integration-test/src/tests.rs b/test/integration-test/src/tests.rs
index 9ca83669..49cdc8ae 100644
--- a/test/integration-test/src/tests.rs
+++ b/test/integration-test/src/tests.rs
@@ -14,3 +14,4 @@ mod strncmp;
 mod tcx;
 mod uprobe_cookie;
 mod xdp;
+mod socket_filter;
\ No newline at end of file
diff --git a/test/integration-test/src/tests/socket_filter.rs b/test/integration-test/src/tests/socket_filter.rs
new file mode 100644
index 00000000..add7f98d
--- /dev/null
+++ b/test/integration-test/src/tests/socket_filter.rs
@@ -0,0 +1,13 @@
+use aya::{programs::SocketFilter, Ebpf};
+
+#[test]
+fn socket_filter_load() {
+    let mut bpf = Ebpf::load(crate::SOCKET_FILTER).unwrap();
+    let prog: &mut SocketFilter = bpf
+        .program_mut("read_one")
+        .unwrap()
+        .try_into()
+        .unwrap();
+    prog.load().unwrap();
+
+}
\ No newline at end of file