Skip to content

Commit ffba451

Browse files
d-sonuganicholasbishop
authored andcommitted
gave network statistics a better interface; refactored a little
1 parent 1058fc2 commit ffba451

File tree

4 files changed

+342
-53
lines changed

4 files changed

+342
-53
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use uefi::prelude::*;
2+
3+
pub fn test(bt: &BootServices) {
4+
info!("Testing Network protocols");
5+
6+
pxe::test(bt);
7+
snp::test(bt);
8+
}
9+
10+
mod pxe;
11+
mod snp;

uefi-test-runner/src/proto/network.rs renamed to uefi-test-runner/src/proto/network/pxe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use uefi::{
88
};
99

1010
pub fn test(bt: &BootServices) {
11-
info!("Testing Network protocols");
11+
info!("Testing The PXE base code protocol");
1212

1313
if let Ok(handles) = bt.find_handles::<BaseCode>() {
1414
for handle in handles {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use uefi::prelude::BootServices;
2+
use uefi::proto::network::snp::SimpleNetwork;
3+
use uefi::proto::network::MacAddress;
4+
5+
6+
pub fn test(bt: &BootServices) {
7+
info!("Testing the simple network protocol");
8+
9+
let handles = bt
10+
.find_handles::<SimpleNetwork>()
11+
.expect("Failed to get handles for `SimpleNetwork` protocol");
12+
13+
for handle in handles {
14+
15+
let simple_network = bt.open_protocol_exclusive::<SimpleNetwork>(handle);
16+
if simple_network.is_err() { continue; }
17+
let simple_network = simple_network.unwrap();
18+
19+
// Check shutdown
20+
simple_network.shutdown().expect("Failed to shutdown Simple Network");
21+
22+
// Check stop
23+
simple_network.stop().expect("Failed to stop Simple Network");
24+
25+
// Check start
26+
simple_network.start().expect("Failed to start Simple Network");
27+
28+
// Check initialize
29+
simple_network.initialize(None, None)
30+
.expect("Failed to initialize Simple Network");
31+
32+
simple_network.reset_statistics().unwrap();
33+
34+
// Reading the interrupt status clears it
35+
simple_network.get_interrupt_status().unwrap();
36+
37+
// Set receive filters
38+
simple_network.receive_filters(0x01 | 0x02 | 0x04 | 0x08 | 0x10, 0, false, None, None)
39+
.expect("Failed to set receive filters");
40+
41+
// Check media
42+
if !simple_network.mode().media_present_supported || !simple_network.mode().media_present {
43+
continue;
44+
}
45+
46+
let payload = &[0u8; 46];
47+
48+
let dest_addr = MacAddress([0xffu8;32]);
49+
assert!(!simple_network.get_interrupt_status().unwrap().transmit_interrupt());
50+
// Send the frame
51+
simple_network.transmit(
52+
simple_network.mode().media_header_size as usize,
53+
payload,
54+
None,
55+
Some(&dest_addr),
56+
Some(&0x0800),
57+
)
58+
.expect("Failed to transmit frame");
59+
60+
info!("Waiting for the transmit");
61+
while !simple_network.get_interrupt_status().unwrap().transmit_interrupt() {}
62+
63+
// Attempt to receive a frame
64+
let mut buffer = [0u8; 1500];
65+
66+
let mut count = 0;
67+
68+
info!("Waiting for the reception");
69+
while count < 1_000 {
70+
let result = simple_network.receive(
71+
&mut buffer,
72+
None,
73+
None,
74+
None,
75+
None
76+
);
77+
if result.is_ok() { break; }
78+
count += 1;
79+
}
80+
81+
// Get stats
82+
let stats = simple_network.collect_statistics().expect("Failed to collect statistics");
83+
info!("Stats: {:?}", stats);
84+
85+
// One frame should have been transmitted and one received
86+
assert_eq!(stats.tx_total_frames().unwrap(), 1);
87+
assert_eq!(stats.rx_total_frames().unwrap(), 1);
88+
}
89+
}

0 commit comments

Comments
 (0)