|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | #![cfg(test)] |
| 5 | +// UNSAFETY: This test module contains unsafe code to set some environment variables |
| 6 | +// for getting code coverage. |
| 7 | +#![expect(unsafe_code)] |
5 | 8 |
|
6 | 9 | use crate::GuestDmaMode; |
7 | 10 | use crate::ManaEndpoint; |
@@ -99,7 +102,7 @@ async fn test_lso_partial_bytes(driver: DefaultDriver) { |
99 | 102 | metadata.l3_protocol = net_backend::L3Protocol::Ipv4; |
100 | 103 | let header_length = |
101 | 104 | (metadata.l2_len as u16 + metadata.l3_len + metadata.l4_len as u16) as usize; |
102 | | - // Add a few bytes to header to mimick the head segment being larger than the header length. |
| 105 | + // Add a few bytes to header to mimic the head segment being larger than the header length. |
103 | 106 | let packet_len: usize = num_segments * (header_length + 2); |
104 | 107 | let stats = test_endpoint_lso(driver, packet_len, num_segments, metadata, 1).await; |
105 | 108 |
|
@@ -154,7 +157,7 @@ async fn test_lso_segment_coalescing_partial_bytes_in_header(driver: DefaultDriv |
154 | 157 | metadata.l3_protocol = net_backend::L3Protocol::Ipv4; |
155 | 158 | let header_length = |
156 | 159 | (metadata.l2_len as u16 + metadata.l3_len + metadata.l4_len as u16) as usize; |
157 | | - // Add a few bytes to header to mimick the head segment being larger than the header length. |
| 160 | + // Add a few bytes to header to mimic the head segment being larger than the header length. |
158 | 161 | let packet_len: usize = num_segments * (header_length + 2); |
159 | 162 | let stats = test_endpoint_lso(driver, packet_len, num_segments, metadata, 1).await; |
160 | 163 |
|
@@ -184,12 +187,43 @@ async fn test_lso_segment_coalescing_only_header(driver: DefaultDriver) { |
184 | 187 | let packet_len: usize = num_segments * header_length; |
185 | 188 |
|
186 | 189 | // An LSO packet without any payload is considered bad packet and should be dropped. |
187 | | - let stats = test_endpoint_lso(driver, packet_len, num_segments, metadata, 0).await; |
| 190 | + let stats = test_endpoint_lso( |
| 191 | + driver.clone(), |
| 192 | + packet_len, |
| 193 | + num_segments, |
| 194 | + metadata.clone(), |
| 195 | + 0, |
| 196 | + ) |
| 197 | + .await; |
188 | 198 |
|
189 | 199 | assert_eq!(stats.tx_packets.get(), 0, "tx_packets increase"); |
190 | 200 | assert_eq!(stats.rx_packets.get(), 0, "rx_packets increase"); |
191 | 201 | assert_eq!(stats.tx_errors.get(), 0, "tx_errors remain the same"); |
192 | 202 | assert_eq!(stats.rx_errors.get(), 0, "rx_errors remain the same"); |
| 203 | + |
| 204 | + // Set the environment variable to allow LSO packet with only 1 SGE, for testing purposes. |
| 205 | + // SAFETY: Setting environment variable for test purposes, to get code coverage. |
| 206 | + unsafe { |
| 207 | + std::env::set_var("ALLOW_LSO_PKT_WITH_ONE_SGE", "1"); |
| 208 | + } |
| 209 | + |
| 210 | + let stats = test_endpoint_lso( |
| 211 | + driver.clone(), |
| 212 | + packet_len, |
| 213 | + num_segments, |
| 214 | + metadata.clone(), |
| 215 | + 0, |
| 216 | + ) |
| 217 | + .await; |
| 218 | + |
| 219 | + unsafe { |
| 220 | + std::env::remove_var("ALLOW_LSO_PKT_WITH_ONE_SGE"); |
| 221 | + } |
| 222 | + |
| 223 | + assert_eq!(stats.tx_packets.get(), 0, "tx_packets increase"); |
| 224 | + assert_eq!(stats.rx_packets.get(), 0, "rx_packets increase"); |
| 225 | + assert_eq!(stats.tx_errors.get(), 1, "tx_errors remain the same"); |
| 226 | + assert_eq!(stats.rx_errors.get(), 0, "rx_errors remain the same"); |
193 | 227 | } |
194 | 228 |
|
195 | 229 | macro_rules! lso_split_headers { |
|
0 commit comments