Skip to content

Commit 7bb61d8

Browse files
committed
testing: Remove #[cfg(not(test))] attributes
The vast majority of these are not needed. This also makes it easier to: - Add code - Tell which sections actually are testing-dependent
1 parent 158a56a commit 7bb61d8

File tree

13 files changed

+3
-206
lines changed

13 files changed

+3
-206
lines changed

src/block.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@
1414

1515
use core::cell::RefCell;
1616

17-
#[cfg(not(test))]
1817
use crate::virtio::Error as VirtioError;
19-
#[cfg(not(test))]
2018
use crate::virtio::VirtioTransport;
2119

22-
#[cfg(not(test))]
2320
const QUEUE_SIZE: usize = 16;
2421

2522
#[repr(C)]
2623
#[repr(align(16))]
2724
#[derive(Default)]
28-
#[cfg(not(test))]
2925
/// A virtio qeueue entry descriptor
3026
struct Desc {
3127
addr: u64,
@@ -37,7 +33,6 @@ struct Desc {
3733
#[repr(C)]
3834
#[repr(align(2))]
3935
#[derive(Default)]
40-
#[cfg(not(test))]
4136
/// The virtio available ring
4237
struct AvailRing {
4338
flags: u16,
@@ -48,7 +43,6 @@ struct AvailRing {
4843
#[repr(C)]
4944
#[repr(align(4))]
5045
#[derive(Default)]
51-
#[cfg(not(test))]
5246
/// The virtio used ring
5347
struct UsedRing {
5448
flags: u16,
@@ -58,7 +52,6 @@ struct UsedRing {
5852

5953
#[repr(C)]
6054
#[derive(Default)]
61-
#[cfg(not(test))]
6255
/// A single element in the used ring
6356
struct UsedElem {
6457
id: u32,
@@ -67,7 +60,6 @@ struct UsedElem {
6760

6861
#[repr(C)]
6962
#[repr(align(64))]
70-
#[cfg(not(test))]
7163
/// Device driver for virtio block over any transport
7264
pub struct VirtioBlockDevice<'a> {
7365
transport: &'a mut dyn VirtioTransport,
@@ -77,7 +69,6 @@ pub struct VirtioBlockDevice<'a> {
7769
#[repr(C)]
7870
#[repr(align(64))]
7971
#[derive(Default)]
80-
#[cfg(not(test))]
8172
struct DriverState {
8273
descriptors: [Desc; QUEUE_SIZE],
8374
avail: AvailRing,
@@ -88,12 +79,10 @@ struct DriverState {
8879
pub enum Error {
8980
BlockIOError,
9081

91-
#[cfg(not(test))]
9282
BlockNotSupported,
9383
}
9484

9585
#[repr(C)]
96-
#[cfg(not(test))]
9786
/// Header used for virtio block requests
9887
struct BlockRequestHeader {
9988
request: u32,
@@ -102,7 +91,6 @@ struct BlockRequestHeader {
10291
}
10392

10493
#[repr(C)]
105-
#[cfg(not(test))]
10694
/// Footer used for virtio block requests
10795
struct BlockRequestFooter {
10896
status: u8,
@@ -121,15 +109,13 @@ pub trait SectorWrite {
121109
fn flush(&self) -> Result<(), Error>;
122110
}
123111

124-
#[cfg(not(test))]
125112
#[derive(PartialEq, Copy, Clone)]
126113
enum RequestType {
127114
Read = 0,
128115
Write = 1,
129116
Flush = 4,
130117
}
131118

132-
#[cfg(not(test))]
133119
impl<'a> VirtioBlockDevice<'a> {
134120
pub fn new(transport: &'a mut dyn VirtioTransport) -> VirtioBlockDevice<'a> {
135121
VirtioBlockDevice {
@@ -307,14 +293,12 @@ impl<'a> VirtioBlockDevice<'a> {
307293
}
308294
}
309295

310-
#[cfg(not(test))]
311296
impl<'a> SectorRead for VirtioBlockDevice<'a> {
312297
fn read(&self, sector: u64, data: &mut [u8]) -> Result<(), Error> {
313298
self.request(sector, Some(data), RequestType::Read)
314299
}
315300
}
316301

317-
#[cfg(not(test))]
318302
impl<'a> SectorWrite for VirtioBlockDevice<'a> {
319303
fn write(&self, sector: u64, data: &mut [u8]) -> Result<(), Error> {
320304
self.request(sector, Some(data), RequestType::Write)

src/bzimage.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,38 @@
1515
use crate::fat;
1616
use fat::Read;
1717

18-
#[cfg(not(test))]
1918
pub enum Error {
2019
FileError,
2120
KernelOld,
2221
MagicMissing,
2322
NotRelocatable,
2423
}
2524

26-
#[cfg(not(test))]
2725
impl From<fat::Error> for Error {
2826
fn from(_: fat::Error) -> Error {
2927
Error::FileError
3028
}
3129
}
3230

3331
// From firecracker
34-
#[cfg(not(test))]
3532
/// Kernel command line start address.
3633
const CMDLINE_START: usize = 0x4b000;
37-
#[cfg(not(test))]
3834
/// Kernel command line start address maximum size.
3935
const CMDLINE_MAX_SIZE: usize = 0x10000;
40-
#[cfg(not(test))]
4136
/// The 'zero page', a.k.a linux kernel bootparams.
4237
pub const ZERO_PAGE_START: usize = 0x7000;
4338

44-
#[cfg(not(test))]
4539
const KERNEL_LOCATION: u32 = 0x20_0000;
4640

47-
#[cfg(not(test))]
4841
const E820_RAM: u32 = 1;
4942

50-
#[cfg(not(test))]
5143
#[repr(C, packed)]
5244
struct E820Entry {
5345
addr: u64,
5446
size: u64,
5547
entry_type: u32,
5648
}
5749

58-
#[cfg(not(test))]
5950
pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> {
6051
let mut zero_page = crate::mem::MemoryRegion::new(ZERO_PAGE_START as u64, 4096);
6152

@@ -119,7 +110,6 @@ pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> {
119110
Ok(())
120111
}
121112

122-
#[cfg(not(test))]
123113
pub fn append_commandline(addition: &str) -> Result<(), Error> {
124114
let mut cmdline_region =
125115
crate::mem::MemoryRegion::new(CMDLINE_START as u64, CMDLINE_MAX_SIZE as u64);
@@ -146,7 +136,6 @@ pub fn append_commandline(addition: &str) -> Result<(), Error> {
146136
Ok(())
147137
}
148138

149-
#[cfg(not(test))]
150139
pub fn load_kernel(f: &mut dyn Read) -> Result<u64, Error> {
151140
f.seek(0)?;
152141

src/common.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,27 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#[cfg(not(test))]
1615
#[macro_export]
1716
macro_rules! offset_of {
1817
($container:ty, $field:ident) => {
1918
unsafe { &(*(core::ptr::null() as *const $container)).$field as *const _ as usize }
2019
};
2120
}
2221

23-
#[cfg(not(test))]
2422
#[macro_export]
2523
macro_rules! container_of {
2624
($ptr:ident, $container:ty, $field:ident) => {{
2725
(($ptr as usize) - offset_of!($container, $field)) as *const $container
2826
}};
2927
}
3028

31-
#[cfg(not(test))]
3229
#[macro_export]
3330
macro_rules! container_of_mut {
3431
($ptr:ident, $container:ty, $field:ident) => {{
3532
(($ptr as usize) - offset_of!($container, $field)) as *mut $container
3633
}};
3734
}
3835

39-
#[cfg(not(test))]
4036
pub fn ucs2_as_ascii_length(input: *const u16) -> usize {
4137
let mut len = 0;
4238
loop {
@@ -50,7 +46,6 @@ pub fn ucs2_as_ascii_length(input: *const u16) -> usize {
5046
len
5147
}
5248

53-
#[cfg(not(test))]
5449
pub fn ucs2_to_ascii(input: *const u16, output: &mut [u8]) {
5550
let mut i: usize = 0;
5651
assert!(output.len() >= ucs2_as_ascii_length(input));
@@ -65,7 +60,6 @@ pub fn ucs2_to_ascii(input: *const u16, output: &mut [u8]) {
6560
}
6661
}
6762

68-
#[cfg(not(test))]
6963
pub fn ascii_to_ucs2(input: &str, output: &mut [u16]) {
7064
assert!(output.len() >= input.len() * 2);
7165

src/efi/alloc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ impl Allocator {
349349
count
350350
}
351351

352-
#[cfg(not(test))]
353352
pub fn update_virtual_addresses(&mut self, descriptors: &[MemoryDescriptor]) -> Status {
354353
let mut i = 0;
355354

@@ -374,7 +373,6 @@ impl Allocator {
374373
Status::SUCCESS
375374
}
376375

377-
#[cfg(not(test))]
378376
pub fn get_map_key(&self) -> usize {
379377
self.key
380378
}

src/efi/block.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use r_efi::efi::{AllocateType, Guid, MemoryType, Status};
1818
use r_efi::protocols::device_path::Protocol as DevicePathProtocol;
1919
use r_efi::{eficall, eficall_abi};
2020

21-
#[cfg(not(test))]
2221
pub const PROTOCOL_GUID: Guid = Guid::from_fields(
2322
0x964e_5b21,
2423
0x6459,
@@ -28,7 +27,6 @@ pub const PROTOCOL_GUID: Guid = Guid::from_fields(
2827
&[0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b],
2928
);
3029

31-
#[cfg(not(test))]
3230
#[repr(packed)]
3331
pub struct HardDiskDevicePathProtocol {
3432
pub device_path: DevicePathProtocol,
@@ -40,14 +38,12 @@ pub struct HardDiskDevicePathProtocol {
4038
pub signature_type: u8,
4139
}
4240

43-
#[cfg(not(test))]
4441
#[repr(packed)]
4542
pub struct ControllerDevicePathProtocol {
4643
pub device_path: DevicePathProtocol,
4744
pub controller: u32,
4845
}
4946

50-
#[cfg(not(test))]
5147
#[repr(C)]
5248
struct BlockIoMedia {
5349
media_id: u32,
@@ -61,7 +57,6 @@ struct BlockIoMedia {
6157
last_block: u64,
6258
}
6359

64-
#[cfg(not(test))]
6560
#[repr(C)]
6661
pub struct BlockIoProtocol {
6762
revision: u64,
@@ -89,7 +84,6 @@ pub struct BlockIoProtocol {
8984
) -> Status},
9085
}
9186

92-
#[cfg(not(test))]
9387
#[repr(C)]
9488
pub struct BlockWrapper<'a> {
9589
hw: super::HandleWrapper,
@@ -103,18 +97,15 @@ pub struct BlockWrapper<'a> {
10397
start_lba: u64,
10498
}
10599

106-
#[cfg(not(test))]
107100
pub struct BlockWrappers<'a> {
108101
pub wrappers: [*mut BlockWrapper<'a>; 16],
109102
pub count: usize,
110103
}
111104

112-
#[cfg(not(test))]
113105
pub extern "win64" fn reset(_: *mut BlockIoProtocol, _: bool) -> Status {
114106
Status::UNSUPPORTED
115107
}
116108

117-
#[cfg(not(test))]
118109
pub extern "win64" fn read_blocks(
119110
proto: *mut BlockIoProtocol,
120111
_: u32,
@@ -143,7 +134,6 @@ pub extern "win64" fn read_blocks(
143134
Status::SUCCESS
144135
}
145136

146-
#[cfg(not(test))]
147137
pub extern "win64" fn write_blocks(
148138
proto: *mut BlockIoProtocol,
149139
_: u32,
@@ -172,7 +162,6 @@ pub extern "win64" fn write_blocks(
172162
Status::SUCCESS
173163
}
174164

175-
#[cfg(not(test))]
176165
pub extern "win64" fn flush_blocks(proto: *mut BlockIoProtocol) -> Status {
177166
let wrapper = container_of!(proto, BlockWrapper, proto);
178167
let wrapper = unsafe { &*wrapper };
@@ -184,7 +173,6 @@ pub extern "win64" fn flush_blocks(proto: *mut BlockIoProtocol) -> Status {
184173
}
185174
}
186175

187-
#[cfg(not(test))]
188176
impl<'a> BlockWrapper<'a> {
189177
pub fn new(
190178
block: *const crate::block::VirtioBlockDevice,
@@ -307,7 +295,6 @@ impl<'a> BlockWrapper<'a> {
307295
}
308296
}
309297

310-
#[cfg(not(test))]
311298
#[allow(clippy::transmute_ptr_to_ptr)]
312299
pub fn populate_block_wrappers(
313300
wrappers: &mut BlockWrappers,

0 commit comments

Comments
 (0)