From 5e953e7df688d6ca833e319a859cd1b7f9a013cb Mon Sep 17 00:00:00 2001
From: Andrew Stoycos <astoycos@redhat.com>
Date: Wed, 26 Jul 2023 12:53:02 -0400
Subject: [PATCH] add smoke test for loaded_programs()

Add a smoke test for the loaded_programs() API as well as
all the relevant methods on the ProgramInfo type.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
---
 test/integration-test/src/tests/smoke.rs | 30 +++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/test/integration-test/src/tests/smoke.rs b/test/integration-test/src/tests/smoke.rs
index 8b09ac92..c1298114 100644
--- a/test/integration-test/src/tests/smoke.rs
+++ b/test/integration-test/src/tests/smoke.rs
@@ -1,5 +1,5 @@
 use aya::{
-    programs::{Extension, Xdp, XdpFlags},
+    programs::{loaded_programs, Extension, Xdp, XdpFlags},
     util::KernelVersion,
     Bpf, BpfLoader,
 };
@@ -34,3 +34,31 @@ fn extension() {
     let drop_: &mut Extension = bpf.program_mut("drop").unwrap().try_into().unwrap();
     drop_.load(pass.fd().unwrap(), "xdp_pass").unwrap();
 }
+
+#[test]
+fn list_loaded_programs() {
+    if loaded_programs().count() == 0 {
+        eprintln!("No programs to list");
+        return;
+    }
+    // Ensure the loaded_programs() api doesn't panic.
+    loaded_programs().for_each(|p| {
+        let prog = p.unwrap();
+
+        // Ensure all relevant helper functions don't panic
+        prog.name();
+        prog.name_as_str();
+        prog.id();
+        prog.tag();
+        prog.program_type();
+        prog.gpl_compatible();
+        prog.map_ids().unwrap();
+        prog.btf_id();
+        prog.size_translated();
+        prog.size_translated();
+        prog.memory_locked().unwrap();
+        prog.verified_instruction_count();
+        prog.loaded_at();
+        prog.fd().unwrap();
+    })
+}