diff --git a/test/integration-test/src/tests/log.rs b/test/integration-test/src/tests/log.rs index e59ddea7..9c1b1ac9 100644 --- a/test/integration-test/src/tests/log.rs +++ b/test/integration-test/src/tests/log.rs @@ -1,7 +1,6 @@ use std::{ borrow::Cow, sync::{Arc, Mutex}, - time::Instant, }; use aya::{programs::UProbe, Ebpf}; @@ -15,8 +14,8 @@ pub extern "C" fn trigger_ebpf_program() { core::hint::black_box(trigger_ebpf_program); } -pub(crate) struct TestingLogger { - pub(crate) log: F, +struct TestingLogger { + log: F, } impl Log for TestingLogger { @@ -33,11 +32,10 @@ impl Log for TestingLogger { } #[derive(Debug, PartialEq)] -pub(crate) struct CapturedLog<'a> { - pub(crate) body: Cow<'a, str>, - pub(crate) level: Level, - pub(crate) target: Cow<'a, str>, - pub(crate) timestamp: Option, +struct CapturedLog<'a> { + pub body: Cow<'a, str>, + pub level: Level, + pub target: Cow<'a, str>, } #[test(tokio::test)] @@ -56,7 +54,6 @@ async fn log() { body: format!("{}", record.args()).into(), level: record.level(), target: record.target().to_string().into(), - timestamp: None, }); }, }, @@ -94,7 +91,6 @@ async fn log() { body: "Hello from eBPF!".into(), level: Level::Debug, target: "log".into(), - timestamp: None, }), ); @@ -104,7 +100,6 @@ async fn log() { body: "69, 420, wao, 77616f".into(), level: Level::Error, target: "log".into(), - timestamp: None, }) ); @@ -114,7 +109,6 @@ async fn log() { body: "ip structs, without format hint: ipv4: 10.0.0.1, ipv6: 2001:db8::1".into(), level: Level::Info, target: "log".into(), - timestamp: None, }) ); @@ -124,7 +118,6 @@ async fn log() { body: "ip structs, with format hint: ipv4: 10.0.0.1, ipv6: 2001:db8::1".into(), level: Level::Info, target: "log".into(), - timestamp: None, }) ); @@ -134,7 +127,6 @@ async fn log() { body: "ip enums, without format hint: ipv4: 10.0.0.1, ipv6: 2001:db8::1".into(), level: Level::Info, target: "log".into(), - timestamp: None, }) ); @@ -144,7 +136,6 @@ async fn log() { body: "ip enums, with format hint: ipv4: 10.0.0.1, ipv6: 2001:db8::1".into(), level: Level::Info, target: "log".into(), - timestamp: None, }) ); @@ -154,7 +145,6 @@ async fn log() { body: "ip as bits: ipv4: 10.0.0.1".into(), level: Level::Info, target: "log".into(), - timestamp: None, }) ); @@ -164,7 +154,6 @@ async fn log() { body: "ip as octets: ipv4: 10.0.0.1, ipv6: 2001:db8::1".into(), level: Level::Info, target: "log".into(), - timestamp: None, }) ); @@ -174,7 +163,6 @@ async fn log() { body: "mac lc: 04:20:06:09:00:40, mac uc: 04:20:06:09:00:40".into(), level: Level::Trace, target: "log".into(), - timestamp: None, }) ); @@ -184,7 +172,6 @@ async fn log() { body: "hex lc: 2f, hex uc: 2F".into(), level: Level::Warn, target: "log".into(), - timestamp: None, }) ); @@ -194,7 +181,6 @@ async fn log() { body: "hex lc: deadbeef, hex uc: DEADBEEF".into(), level: Level::Debug, target: "log".into(), - timestamp: None, }) ); @@ -204,7 +190,6 @@ async fn log() { body: "42 43 44 45".into(), level: Level::Debug, target: "log".into(), - timestamp: None, }) ); diff --git a/test/integration-test/src/tests/tcx.rs b/test/integration-test/src/tests/tcx.rs index 6042c5c8..ad21d2e9 100644 --- a/test/integration-test/src/tests/tcx.rs +++ b/test/integration-test/src/tests/tcx.rs @@ -1,47 +1,17 @@ -use std::{ - net::UdpSocket, - sync::{Arc, Mutex}, - time::{Duration, Instant}, -}; - use aya::{ programs::{tc::TcAttachOptions, LinkOrder, SchedClassifier, TcAttachType}, util::KernelVersion, - Ebpf, EbpfLoader, + EbpfLoader, }; -use aya_log::EbpfLogger; -use log::{debug, Record}; use test_log::test; -use crate::{ - tests::log::{CapturedLog, TestingLogger}, - utils::NetNsGuard, -}; - -fn setup_logs(loader: &mut Ebpf, logs: &Arc>>>) { - let captured_logs = logs.clone(); - EbpfLogger::init_with_logger( - loader, - TestingLogger { - log: move |record: &Record| { - let mut logs = captured_logs.lock().unwrap(); - logs.push(CapturedLog { - body: format!("{}", record.args()).into(), - level: record.level(), - target: record.target().to_string().into(), - timestamp: Some(Instant::now()), - }); - }, - }, - ) - .unwrap(); -} +use crate::utils::NetNsGuard; #[test(tokio::test)] -async fn tcx_ordering() { +async fn tcx_attach() { let kernel_version = KernelVersion::current().unwrap(); if kernel_version < KernelVersion::new(6, 6, 0) { - eprintln!("skipping tcx_ordering test on kernel {kernel_version:?}"); + eprintln!("skipping tcx_attach test on kernel {kernel_version:?}"); return; } @@ -64,18 +34,6 @@ async fn tcx_ordering() { .load(crate::TCX) .unwrap(); - let logs0: Arc>> = Arc::new(Mutex::new(Vec::new())); - setup_logs(&mut program0, &logs0); - - let logs1 = Arc::new(Mutex::new(Vec::new())); - setup_logs(&mut program1, &logs1); - - let logs2 = Arc::new(Mutex::new(Vec::new())); - setup_logs(&mut program2, &logs2); - - let logs3 = Arc::new(Mutex::new(Vec::new())); - setup_logs(&mut program3, &logs3); - let prog0: &mut SchedClassifier = program0 .program_mut("tcx_order") .unwrap() @@ -132,43 +90,4 @@ async fn tcx_ordering() { prog3 .attach_with_options("lo", TcAttachType::Ingress, options) .unwrap(); - - // Wait for system to stabilize - tokio::time::sleep(std::time::Duration::from_millis(100)).await; - - const PAYLOAD: &str = "hello tcx"; - - let sock = UdpSocket::bind("127.0.0.1:1778").unwrap(); - let addr = sock.local_addr().unwrap(); - sock.set_read_timeout(Some(Duration::from_secs(60))) - .unwrap(); - // We only need to send data since we're attaching tcx programs to the ingress hook - sock.send_to(PAYLOAD.as_bytes(), addr).unwrap(); - - // Allow logs to populate - tokio::time::sleep(std::time::Duration::from_millis(100)).await; - - let log0 = logs0.lock().unwrap(); - let log1 = logs1.lock().unwrap(); - let log2 = logs2.lock().unwrap(); - let log3 = logs3.lock().unwrap(); - - debug!("log0: {:?}", log0.first()); - debug!("log1: {:?}", log1.first()); - debug!("log2: {:?}", log2.first()); - debug!("log3: {:?}", log3.first()); - - // sort logs by timestamp - let mut sorted_logs = [ - log0.first().unwrap(), - log1.first().unwrap(), - log2.first().unwrap(), - log3.first().unwrap(), - ]; - sorted_logs.sort_by(|a, b| a.timestamp.cmp(&b.timestamp)); - - assert!(sorted_logs[0].body.contains("order: 0")); - assert!(sorted_logs[1].body.contains("order: 1")); - assert!(sorted_logs[2].body.contains("order: 2")); - assert!(sorted_logs[3].body.contains("order: 3")); }