MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / test_parse_malloc_event

Function test_parse_malloc_event

crates/memtrack/src/ebpf/events.rs:132–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

130
131 #[test]
132 fn test_parse_malloc_event() {
133 // Create a mock event with malloc data
134 let mut event: bindings::event = unsafe { std::mem::zeroed() };
135 event.header.event_type = bindings::EVENT_TYPE_MALLOC as u8;
136 event.header.timestamp = 12345678;
137 event.header.pid = 1000;
138 event.header.tid = 2000;
139 event.data.alloc.addr = 0x1000;
140 event.data.alloc.size = 128;
141
142 let bytes = unsafe {
143 std::slice::from_raw_parts(
144 &event as *const _ as *const u8,
145 std::mem::size_of_val(&event),
146 )
147 };
148
149 // Parse and validate:
150 let parsed = parse_event(bytes).unwrap();
151 assert_eq!(parsed.pid, 1000);
152 assert_eq!(parsed.tid, 2000);
153 assert_eq!(parsed.timestamp, 12345678);
154 assert_eq!(parsed.addr, 0x1000);
155
156 match parsed.kind {
157 MemtrackEventKind::Malloc { size } => {
158 assert_eq!(size, 128);
159 }
160 _ => panic!("Expected Malloc event kind"),
161 }
162 }
163}

Callers

nothing calls this directly

Calls 1

parse_eventFunction · 0.85

Tested by

no test coverage detected