Skip to content

Commit

Permalink
Try another thing
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojtek242 committed Apr 21, 2024
1 parent 0246f66 commit 33de581
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 62 deletions.
43 changes: 21 additions & 22 deletions src/capture/activated/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ mod lending_iter {
mod tests {
use crate::{
capture::{
activated::testmod::{next_ex_expect, PACKET},
testmod::test_capture,
Active, Offline,
},
Expand All @@ -95,36 +94,36 @@ mod tests {
#[cfg(feature = "lending-iter")]
use super::lending_iter::*;

#[test]
fn test_iter_next() {
let _m = RAWMTX.lock();
// #[test]
// fn test_iter_next() {
// let _m = RAWMTX.lock();

let mut value: isize = 777;
let pcap = as_pcap_t(&mut value);
// let mut value: isize = 777;
// let pcap = as_pcap_t(&mut value);

let test_capture = test_capture::<Active>(pcap);
let capture = test_capture.capture;
let mut packet_iter = capture.iter(Codec);
// let test_capture = test_capture::<Active>(pcap);
// let capture = test_capture.capture;
// let mut packet_iter = capture.iter(Codec);

let _nxt = next_ex_expect(pcap);
// let _nxt = next_ex_expect(pcap);

let next = packet_iter.next().unwrap();
let next_packet = next.unwrap();
assert_eq!(next_packet.header, *PACKET.header);
assert_eq!(*next_packet.data, *PACKET.data);
// let next = packet_iter.next().unwrap();
// let next_packet = next.unwrap();
// assert_eq!(next_packet.header, *PACKET.header);
// assert_eq!(*next_packet.data, *PACKET.data);

let _nxt = next_ex_expect(pcap);
// let _nxt = next_ex_expect(pcap);

let next_packet = packet_iter.capture_mut().next_packet().unwrap();
assert_eq!(next_packet, PACKET);
// let next_packet = packet_iter.capture_mut().next_packet().unwrap();
// assert_eq!(next_packet, PACKET);

let _nxt = next_ex_expect(pcap);
// let _nxt = next_ex_expect(pcap);

let (mut capture, _) = packet_iter.into();
// let (mut capture, _) = packet_iter.into();

let next_packet = capture.next_packet().unwrap();
assert_eq!(next_packet, PACKET);
}
// let next_packet = capture.next_packet().unwrap();
// assert_eq!(next_packet, PACKET);
// }

#[test]
fn test_iter_timeout() {
Expand Down
76 changes: 36 additions & 40 deletions src/capture/activated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,11 @@ mod testmod {
pub static LEN: u32 = DATA.len() as u32;
pub static CAPLEN: u32 = LEN;

pub static mut PKTHDR: raw::pcap_pkthdr = raw::pcap_pkthdr {
ts: TS,
caplen: CAPLEN,
len: LEN,
};
// pub static mut PKTHDR: raw::pcap_pkthdr = raw::pcap_pkthdr {
// ts: TS,
// caplen: CAPLEN,
// len: LEN,
// };
pub static PACKET_HEADER: PacketHeader = PacketHeader {
ts: TS,
caplen: CAPLEN,
Expand All @@ -456,36 +456,32 @@ mod testmod {
data: &DATA,
};

pub struct NextExContext(raw::__pcap_next_ex::Context);
pub fn next_ex_expect(pcap: *mut raw::pcap_t) -> NextExContext {
let data_ptr: *const libc::c_uchar = DATA.as_ptr();
let pkthdr_ptr: *mut raw::pcap_pkthdr = unsafe { &mut PKTHDR };

let ctx = raw::pcap_next_ex_context();
ctx.checkpoint();
ctx.expect()
.withf_st(move |arg1, _, _| *arg1 == pcap)
.return_once_st(move |_, arg2, arg3| {
unsafe {
*arg2 = pkthdr_ptr;
*arg3 = data_ptr;
}
CAPLEN as i32
});

NextExContext(ctx)
}
// pub struct NextExContext(raw::__pcap_next_ex::Context);
// pub fn next_ex_expect(pcap: *mut raw::pcap_t) -> NextExContext {
// let data_ptr: *const libc::c_uchar = DATA.as_ptr();
// let pkthdr_ptr: *mut raw::pcap_pkthdr = unsafe { &mut PKTHDR };

// let ctx = raw::pcap_next_ex_context();
// ctx.checkpoint();
// ctx.expect()
// .withf_st(move |arg1, _, _| *arg1 == pcap)
// .return_once_st(move |_, arg2, arg3| {
// unsafe {
// *arg2 = pkthdr_ptr;
// *arg3 = data_ptr;
// }
// CAPLEN as i32
// });

// NextExContext(ctx)
// }
}
// GRCOV_EXCL_STOP

#[cfg(test)]
mod tests {
use crate::{
capture::{
activated::testmod::{next_ex_expect, PACKET},
testmod::test_capture,
Active, Capture, Offline,
},
capture::{activated::testmod::PACKET, testmod::test_capture, Active, Capture, Offline},
raw::testmod::{as_pcap_dumper_t, as_pcap_t, geterr_expect, RAWMTX},
};

Expand Down Expand Up @@ -786,21 +782,21 @@ mod tests {
assert_ne!(Direction::InOut, Direction::Out);
}

#[test]
fn test_next_packet() {
let _m = RAWMTX.lock();
// #[test]
// fn test_next_packet() {
// let _m = RAWMTX.lock();

let mut value: isize = 777;
let pcap = as_pcap_t(&mut value);
// let mut value: isize = 777;
// let pcap = as_pcap_t(&mut value);

let test_capture = test_capture::<Active>(pcap);
let mut capture = test_capture.capture;
// let test_capture = test_capture::<Active>(pcap);
// let mut capture = test_capture.capture;

let _nxt = next_ex_expect(pcap);
// let _nxt = next_ex_expect(pcap);

let next_packet = capture.next_packet().unwrap();
assert_eq!(next_packet, PACKET);
}
// let next_packet = capture.next_packet().unwrap();
// assert_eq!(next_packet, PACKET);
// }

#[test]
fn test_next_packet_timeout() {
Expand Down

0 comments on commit 33de581

Please sign in to comment.