Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/crates/aienos-kernel/tests/nvme_write_prp.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / crates / aienos-kernel / tests / nvme_write_prp.rs` 593 lines ยท 20384 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 //! D3 adversarial tests for the AIENOS P3 native NVMe **write + flush** lane. 17 //! 18 //! Target: `crates/aienos-kernel/tests/nvme_write_prp.rs`. Baseline: 19 //! aien-dev/aienux @ `ef359ec`. 20 //! 21 //! Pure PRP geometry is asserted against the real 22 //! `aienos_kernel::nvme::build_prps` with exact expected values. Transfer 23 //! behavior (one-block writes, page-crossing, MDTS chunk splitting, LBA range 24 //! rejection, flush) is driven through a self-contained fake controller built 25 //! only from the public `Registers`/`DmaMemory`/`Delay` traits, which records 26 //! every I/O command it is handed. No sleeps, no hardware, no repo internals. 27 28 use std::cell::RefCell; 29 use std::rc::Rc; 30 31 use aienos_kernel::block::{BlockDevice, BlockError}; 32 use aienos_kernel::nvme::driver::{ 33 Delay, DmaMemory, DmaRegion, NvmeController, NvmeError, ADMIN_DEPTH, PAGE_SIZE, 34 }; 35 use aienos_kernel::nvme::{ 36 build_prps, doorbell_offset, PrpError, Registers, CC_EN, CSTS_RDY, REG_ACQ, REG_ASQ, REG_CC, 37 REG_CSTS, 38 }; 39 40 const P4K: usize = 4096; 41 const P64K: usize = 65536; 42 /// CAP.TO = 1 (500 ms units), MQES = 1023, DSTRD = 0, MPSMIN = 0. 43 const CAP_LOW: u32 = 0x0100_03ff; 44 const STRIDE: u32 = 4; 45 const ADMIN_SQ_DB: u32 = doorbell_offset(0, false, STRIDE); 46 const IO_SQ_DB: u32 = doorbell_offset(1, false, STRIDE); 47 48 // --------------------------------------------------------------------------- 49 // Fake controller: an in-memory NVMe device answering admin and I/O commands. 50 // --------------------------------------------------------------------------- 51 52 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 53 struct IoCommand { 54 opcode: u8, 55 nsid: u32, 56 lba: u64, 57 blocks: u16, 58 prp1: u64, 59 prp2: u64, 60 } 61 62 struct Region { 63 base: u64, 64 len: usize, 65 bytes: Vec, 66 } 67 68 struct Device { 69 regions: Vec, 70 next_phys: u64, 71 cc: u32, 72 csts: u32, 73 namespace_size: u64, 74 mdts: u8, 75 command_error: u16, 76 admin_sq: u64, 77 admin_cq: u64, 78 admin_sq_tail: usize, 79 admin_cq_tail: usize, 80 admin_phase: bool, 81 io_sq: u64, 82 io_cq: u64, 83 io_sq_tail: usize, 84 io_cq_tail: usize, 85 io_phase: bool, 86 io_depth: usize, 87 io_commands: Vec, 88 } 89 90 impl Device { 91 fn new(namespace_size: u64, mdts: u8) -> Self { 92 Self { 93 regions: Vec::new(), 94 next_phys: 0x1000, 95 cc: 0, 96 csts: 0, 97 namespace_size, 98 mdts, 99 command_error: 0, 100 admin_sq: 0, 101 admin_cq: 0, 102 admin_sq_tail: 0, 103 admin_cq_tail: 0, 104 admin_phase: true, 105 io_sq: 0, 106 io_cq: 0, 107 io_sq_tail: 0, 108 io_cq_tail: 0, 109 io_phase: true, 110 io_depth: 0, 111 io_commands: Vec::new(), 112 } 113 } 114 115 fn alloc(&mut self, size: usize, alignment: usize) -> u64 { 116 let align = alignment.max(1) as u64; 117 let base = (self.next_phys + align - 1) & !(align - 1); 118 self.next_phys = base + size as u64; 119 self.regions.push(Region { 120 base, 121 len: size, 122 bytes: vec![0; size], 123 }); 124 base 125 } 126 127 fn region_index(&self, physical: u64, len: usize) -> Option { 128 self.regions 129 .iter() 130 .position(|r| physical >= r.base && physical + len as u64 <= r.base + r.len as u64) 131 } 132 133 fn read_mem(&mut self, physical: u64, output: &mut [u8]) -> Result<(), NvmeError> { 134 match self.region_index(physical, output.len()) { 135 Some(i) => { 136 output.copy_from_slice(&self.regions[i].bytes[..output.len()]); 137 Ok(()) 138 } 139 None => Err(NvmeError::Dma), 140 } 141 } 142 143 fn write_mem(&mut self, physical: u64, input: &[u8]) -> Result<(), NvmeError> { 144 match self.region_index(physical, input.len()) { 145 Some(i) => { 146 self.regions[i].bytes[..input.len()].copy_from_slice(input); 147 Ok(()) 148 } 149 None => Err(NvmeError::Dma), 150 } 151 } 152 153 fn poke(&mut self, physical: u64, bytes: &[u8]) { 154 if let Some(i) = self.region_index(physical, bytes.len()) { 155 self.regions[i].bytes[..bytes.len()].copy_from_slice(bytes); 156 } 157 } 158 159 fn peek_command(&self, base: u64, slot: usize) -> [u8; 64] { 160 let addr = base + (slot * 64) as u64; 161 let mut out = [0u8; 64]; 162 if let Some(i) = self.region_index(addr, 64) { 163 out.copy_from_slice(&self.regions[i].bytes[..64]); 164 } 165 out 166 } 167 168 fn fill_identify(&mut self, prp: u64, cns: u32) { 169 if let Some(i) = self.region_index(prp, PAGE_SIZE) { 170 let data = &mut self.regions[i].bytes; 171 data.fill(0); 172 if cns == 1 { 173 data[77] = self.mdts; 174 } else { 175 data[0..8].copy_from_slice(&self.namespace_size.to_le_bytes()); 176 data[26] = 0; // FLBAS -> format 0 177 data[130] = 9; // LBADS -> 512-byte blocks 178 } 179 } 180 } 181 182 fn run_admin(&mut self) { 183 let slot = self.admin_sq_tail; 184 let cmd = self.peek_command(self.admin_sq, slot); 185 let opcode = cmd[0]; 186 let cid = u16::from_le_bytes([cmd[2], cmd[3]]); 187 let prp = u64::from_le_bytes(cmd[24..32].try_into().unwrap()); 188 let cdw10 = u32::from_le_bytes(cmd[40..44].try_into().unwrap()); 189 let cdw11 = u32::from_le_bytes(cmd[44..48].try_into().unwrap()); 190 self.command_error = 0; 191 match opcode { 192 0x06 => self.fill_identify(prp, cdw10), 193 0x05 => { 194 self.io_cq = prp; 195 self.io_depth = ((cdw10 >> 16) & 0xffff) as usize + 1; 196 } 197 0x01 if cdw10 & 0xffff == 1 && cdw11 & 0xffff == 1 => self.io_sq = prp, 198 _ => {} 199 } 200 let at = self.admin_cq + (self.admin_cq_tail * 16) as u64; 201 let mut cqe = [0u8; 16]; 202 cqe[12..14].copy_from_slice(&cid.to_le_bytes()); 203 cqe[14..16] 204 .copy_from_slice(&((self.admin_phase as u16) | self.command_error).to_le_bytes()); 205 self.poke(at, &cqe); 206 self.admin_cq_tail = (self.admin_cq_tail + 1) % ADMIN_DEPTH; 207 if self.admin_cq_tail == 0 { 208 self.admin_phase = !self.admin_phase; 209 } 210 self.admin_sq_tail = (self.admin_sq_tail + 1) % ADMIN_DEPTH; 211 } 212 213 fn run_io(&mut self) { 214 let depth = self.io_depth; 215 if depth == 0 { 216 return; 217 } 218 let slot = self.io_sq_tail; 219 let cmd = self.peek_command(self.io_sq, slot); 220 let opcode = cmd[0]; 221 let cid = u16::from_le_bytes([cmd[2], cmd[3]]); 222 let nsid = u32::from_le_bytes(cmd[4..8].try_into().unwrap()); 223 let prp1 = u64::from_le_bytes(cmd[24..32].try_into().unwrap()); 224 let prp2 = u64::from_le_bytes(cmd[32..40].try_into().unwrap()); 225 let lba = u64::from(u32::from_le_bytes(cmd[40..44].try_into().unwrap())) 226 | (u64::from(u32::from_le_bytes(cmd[44..48].try_into().unwrap())) << 32); 227 let cdw12 = u32::from_le_bytes(cmd[48..52].try_into().unwrap()); 228 self.io_commands.push(IoCommand { 229 opcode, 230 nsid, 231 lba, 232 blocks: ((cdw12 & 0xffff) as u16).wrapping_add(1), 233 prp1, 234 prp2, 235 }); 236 let at = self.io_cq + (self.io_cq_tail * 16) as u64; 237 let mut cqe = [0u8; 16]; 238 cqe[12..14].copy_from_slice(&cid.to_le_bytes()); 239 cqe[14..16].copy_from_slice(&((self.io_phase as u16) | self.command_error).to_le_bytes()); 240 self.poke(at, &cqe); 241 self.io_cq_tail = (self.io_cq_tail + 1) % depth; 242 if self.io_cq_tail == 0 { 243 self.io_phase = !self.io_phase; 244 } 245 self.io_sq_tail = (self.io_sq_tail + 1) % depth; 246 } 247 } 248 249 // --------------------------------------------------------------------------- 250 // Public-trait fakes over the shared device. 251 // --------------------------------------------------------------------------- 252 253 type Shared = Rc>; 254 255 struct FakeRegs { 256 dev: Shared, 257 } 258 259 impl Registers for FakeRegs { 260 fn read32(&mut self, offset: u32) -> u32 { 261 let dev = self.dev.borrow(); 262 match offset { 263 0 => CAP_LOW, 264 4 => 0, 265 REG_CC => dev.cc, 266 REG_CSTS => dev.csts, 267 _ => 0, 268 } 269 } 270 271 fn write32(&mut self, offset: u32, value: u32) { 272 let mut dev = self.dev.borrow_mut(); 273 match offset { 274 REG_CC => { 275 dev.cc = value; 276 dev.csts = if value & CC_EN == 0 { 0 } else { CSTS_RDY }; 277 } 278 REG_ASQ => dev.admin_sq = (dev.admin_sq & !0xffff_ffff) | u64::from(value), 279 x if x == REG_ASQ + 4 => { 280 dev.admin_sq = (dev.admin_sq & 0xffff_ffff) | (u64::from(value) << 32) 281 } 282 REG_ACQ => dev.admin_cq = (dev.admin_cq & !0xffff_ffff) | u64::from(value), 283 x if x == REG_ACQ + 4 => { 284 dev.admin_cq = (dev.admin_cq & 0xffff_ffff) | (u64::from(value) << 32) 285 } 286 ADMIN_SQ_DB => dev.run_admin(), 287 IO_SQ_DB => dev.run_io(), 288 _ => {} 289 } 290 } 291 } 292 293 struct FakeDma { 294 dev: Shared, 295 } 296 297 impl DmaMemory for FakeDma { 298 fn allocate(&mut self, size: usize, alignment: usize) -> Result { 299 let physical = self.dev.borrow_mut().alloc(size, alignment); 300 Ok(DmaRegion { 301 physical, 302 bytes: vec![0; size], 303 }) 304 } 305 306 fn read(&self, physical: u64, output: &mut [u8]) -> Result<(), NvmeError> { 307 self.dev.borrow_mut().read_mem(physical, output) 308 } 309 310 fn write(&mut self, physical: u64, input: &[u8]) -> Result<(), NvmeError> { 311 self.dev.borrow_mut().write_mem(physical, input) 312 } 313 } 314 315 /// Host stand-in for a real-time delay: the fake device is always ready, so no 316 /// wait is ever needed. This keeps the tests free of sleeps. 317 struct NoDelay; 318 319 impl Delay for NoDelay { 320 fn delay_us(&mut self, _us: u32) {} 321 } 322 323 type Ctrl = NvmeController; 324 325 fn make(namespace_size: u64, mdts: u8) -> (Ctrl, Shared) { 326 let dev: Shared = Rc::new(RefCell::new(Device::new(namespace_size, mdts))); 327 let regs = FakeRegs { dev: dev.clone() }; 328 let dma = FakeDma { dev: dev.clone() }; 329 let controller = NvmeController::init(regs, dma, NoDelay).expect("init should succeed"); 330 (controller, dev) 331 } 332 333 fn io_commands(dev: &Shared) -> Vec { 334 dev.borrow().io_commands.clone() 335 } 336 337 // --------------------------------------------------------------------------- 338 // PRP geometry: one block, page crossings, PRP lists, chaining. 339 // --------------------------------------------------------------------------- 340 341 #[test] 342 fn one_block_aligned_write_is_single_prp1_page() { 343 // 512 bytes from a 4 KiB-aligned address live entirely in page one: 344 // PRP1 is the raw address, PRP2 unused, no list entries consumed. 345 let mut list = [0xDEAD_BEEFu64; 4]; 346 assert_eq!( 347 build_prps(0x1000, 512, P4K, 0x8000, &mut list).unwrap(), 348 (0x1000, 0, 0) 349 ); 350 assert_eq!(list, [0xDEAD_BEEF; 4], "list must be untouched"); 351 } 352 353 #[test] 354 fn write_crossing_page_boundary_uses_prp1_and_prp2() { 355 let mut list = [0u64; 0]; 356 assert_eq!( 357 build_prps(0x1000, 2 * P4K, P4K, 0, &mut list).unwrap(), 358 (0x1000, 0x2000, 0) 359 ); 360 // Unaligned start: PRP1 stays raw, PRP2 is the next page boundary. 361 assert_eq!( 362 build_prps(0x1080, P4K, P4K, 0, &mut list).unwrap(), 363 (0x1080, 0x2000, 0) 364 ); 365 } 366 367 #[test] 368 fn write_spanning_three_pages_uses_prp_list() { 369 let list_at = 0x80_0000u64; 370 let mut list = [0u64; 4]; 371 let (p1, p2, used) = build_prps(0x1000, 3 * P4K, P4K, list_at, &mut list).unwrap(); 372 assert_eq!((p1, p2, used), (0x1000, list_at, 2)); 373 assert_eq!(list[..2], [0x2000, 0x3000]); 374 } 375 376 #[test] 377 fn write_page_list_chains_at_4k_exact_entries() { 378 const PER: usize = P4K / 8; // 512 entries per 4 KiB list page 379 let list_at = 0x80_0000u64; 380 381 let mut full = vec![0u64; PER]; 382 let (p1, p2, used) = build_prps(0x1000, (1 + PER) * P4K, P4K, list_at, &mut full).unwrap(); 383 assert_eq!((p1, p2, used), (0x1000, list_at, PER)); 384 assert_eq!(full[PER - 1], 0x2000 + ((PER - 1) * P4K) as u64); 385 386 let mut chain = vec![0u64; PER + 2]; 387 let (p1, p2, used) = build_prps(0x1000, (2 + PER) * P4K, P4K, list_at, &mut chain).unwrap(); 388 assert_eq!((p1, p2, used), (0x1000, list_at, PER + 2)); 389 assert_eq!(chain[PER - 1], list_at + P4K as u64, "last slot chains"); 390 assert_eq!(chain[PER - 2], 0x2000 + ((PER - 2) * P4K) as u64); 391 assert_eq!(chain[PER], 0x2000 + ((PER - 1) * P4K) as u64); 392 assert_eq!(chain[PER + 1], 0x2000 + (PER * P4K) as u64); 393 } 394 395 #[test] 396 fn write_page_list_chains_at_64k_exact_entries() { 397 const PER: usize = P64K / 8; // 8192 entries per 64 KiB list page 398 let list_at = 0x200_0000u64; 399 400 let mut full = vec![0u64; PER]; 401 let (p1, p2, used) = build_prps(0x10000, (1 + PER) * P64K, P64K, list_at, &mut full).unwrap(); 402 assert_eq!((p1, p2, used), (0x10000, list_at, PER)); 403 assert_eq!(full[PER - 1], 0x20000 + ((PER - 1) * P64K) as u64); 404 405 let mut chain = vec![0u64; PER + 2]; 406 let (p1, p2, used) = build_prps(0x10000, (2 + PER) * P64K, P64K, list_at, &mut chain).unwrap(); 407 assert_eq!((p1, p2, used), (0x10000, list_at, PER + 2)); 408 assert_eq!(chain[PER - 1], list_at + P64K as u64, "last slot chains"); 409 assert_eq!(chain[PER - 2], 0x20000 + ((PER - 2) * P64K) as u64); 410 assert_eq!(chain[PER], 0x20000 + ((PER - 1) * P64K) as u64); 411 assert_eq!(chain[PER + 1], 0x20000 + (PER * P64K) as u64); 412 } 413 414 // --------------------------------------------------------------------------- 415 // Overflow and misalignment. 416 // --------------------------------------------------------------------------- 417 418 #[test] 419 fn address_near_u64_max_is_invalid_without_panic_or_wrap() { 420 let outcome = std::panic::catch_unwind(|| { 421 let mut list = [0u64; 0]; 422 build_prps(u64::MAX, 2, P4K, 0, &mut list) 423 }); 424 assert_eq!( 425 outcome.ok(), 426 Some(Err(PrpError::Invalid)), 427 "address=u64::MAX length=2 must be Invalid with no panic" 428 ); 429 430 // Page-aligned address whose second page would wrap past u64::MAX. 431 let outcome = std::panic::catch_unwind(|| { 432 let mut list = [0u64; 0]; 433 build_prps(u64::MAX - (P4K as u64 - 1), 2 * P4K, P4K, 0, &mut list) 434 }); 435 assert_eq!( 436 outcome.ok(), 437 Some(Err(PrpError::Invalid)), 438 "second-page wrap past u64::MAX must be Invalid with no panic" 439 ); 440 } 441 442 #[test] 443 fn offset_plus_length_overflow_is_invalid() { 444 let mut list = [0u64; 4]; 445 // Unaligned offset + enormous length overflows the covered span. 446 assert_eq!( 447 build_prps(0x1080, usize::MAX, P4K, 0x8000, &mut list), 448 Err(PrpError::Invalid) 449 ); 450 // Aligned start, length at usize::MAX: page rounding overflows. 451 assert_eq!( 452 build_prps(0, usize::MAX, P4K, 0x8000, &mut list), 453 Err(PrpError::Invalid) 454 ); 455 assert_eq!( 456 build_prps(u64::MAX, u64::MAX as usize, P4K, 0x8000, &mut list), 457 Err(PrpError::Invalid) 458 ); 459 } 460 461 #[test] 462 fn unaligned_prp1_spans_pages_correctly() { 463 let list_at = 0x80_0000u64; 464 let mut list = [0u64; 4]; 465 // 0x1080 + (2*P4K + 0x100) ends in the third page from an unaligned start. 466 // With 3+ pages the second return is the PRP list pointer, and the first 467 // list entry is the next page boundary after the raw PRP1. 468 let (p1, p2, used) = build_prps(0x1080, 2 * P4K + 0x100, P4K, list_at, &mut list).unwrap(); 469 assert_eq!((p1, p2, used), (0x1080, list_at, 2)); 470 assert_eq!(list[..2], [0x2000, 0x3000]); 471 } 472 473 #[test] 474 fn list_address_zero_or_unaligned_is_invalid_for_list_cases() { 475 let mut list = [0u64; 4]; 476 assert_eq!( 477 build_prps(0x1000, 3 * P4K, P4K, 0, &mut list), 478 Err(PrpError::Invalid), 479 "zero list address with a required list" 480 ); 481 assert_eq!( 482 build_prps(0x1000, 3 * P4K, P4K, 0x8001, &mut list), 483 Err(PrpError::Invalid), 484 "unaligned list address" 485 ); 486 assert_eq!( 487 build_prps(0x1000, 3 * P4K, P4K, 0xFFF, &mut list), 488 Err(PrpError::Invalid), 489 "list address at the top of a page" 490 ); 491 // A zero list address is fine when no list is needed (two pages -> PRP2). 492 assert_eq!( 493 build_prps(0x1000, 2 * P4K, P4K, 0, &mut list).unwrap(), 494 (0x1000, 0x2000, 0) 495 ); 496 } 497 498 // --------------------------------------------------------------------------- 499 // Transfer path through the fake controller. 500 // --------------------------------------------------------------------------- 501 502 #[test] 503 fn write_one_aligned_block_carries_single_prp1() { 504 let (mut c, dev) = make(4096, 0); 505 c.create_io_queues(8).unwrap(); 506 c.write_blocks(0, &[0xABu8; 512]).unwrap(); 507 508 let cmds = io_commands(&dev); 509 assert_eq!(cmds.len(), 1); 510 let cmd = cmds[0]; 511 assert_eq!(cmd.opcode, 0x01, "write opcode"); 512 assert_eq!(cmd.nsid, 1); 513 assert_eq!(cmd.lba, 0); 514 assert_eq!(cmd.blocks, 1); 515 assert_eq!( 516 cmd.prp1 & (PAGE_SIZE as u64 - 1), 517 0, 518 "PRP1 must be 4 KiB aligned" 519 ); 520 assert_eq!(cmd.prp2, 0, "single-page write must not use PRP2"); 521 } 522 523 #[test] 524 fn multi_block_write_crossing_page_emits_prp2() { 525 let (mut c, dev) = make(4096, 0); 526 c.create_io_queues(8).unwrap(); 527 // Nine 512-byte blocks = 4608 bytes: two pages, one command. 528 c.write_blocks(3, &vec![0u8; 9 * 512]).unwrap(); 529 530 let cmds = io_commands(&dev); 531 assert_eq!(cmds.len(), 1); 532 assert_eq!(cmds[0].blocks, 9); 533 assert_eq!(cmds[0].lba, 3); 534 assert_eq!(cmds[0].prp2, cmds[0].prp1 + PAGE_SIZE as u64); 535 } 536 537 #[test] 538 fn write_larger_than_mdts_is_split_into_commands() { 539 // MDTS = 1 -> PAGE_SIZE << 1 = 8 KiB per command. A 32 KiB write must be 540 // split into four sequential 16-block commands in a namespace big enough. 541 let (mut c, dev) = make(100_000, 1); 542 c.create_io_queues(8).unwrap(); 543 c.write_blocks(0, &vec![0u8; 32 * 1024]).unwrap(); 544 545 let cmds = io_commands(&dev); 546 assert_eq!(cmds.len(), 4, "32 KiB / 8 KiB = four commands"); 547 for (i, cmd) in cmds.iter().enumerate() { 548 assert_eq!(cmd.opcode, 0x01); 549 assert_eq!(cmd.blocks, 16, "8 KiB = 16 blocks of 512"); 550 assert_eq!(cmd.lba, (i as u64) * 16, "chunks advance by 16 LBAs"); 551 } 552 553 // MDTS = 0 -> 128 KiB cap; the same write fits in a single command. 554 let (mut c, dev) = make(100_000, 0); 555 c.create_io_queues(8).unwrap(); 556 c.write_blocks(0, &vec![0u8; 32 * 1024]).unwrap(); 557 assert_eq!(io_commands(&dev).len(), 1); 558 } 559 560 #[test] 561 fn write_past_namespace_end_is_rejected_before_any_command() { 562 let (mut c, dev) = make(100_000, 0); 563 c.create_io_queues(8).unwrap(); 564 565 // A write starting exactly at the last valid LBA. 566 assert_eq!( 567 c.write_blocks(100_000, &[0u8; 512]), 568 Err(BlockError::OutOfRange) 569 ); 570 // A write that starts in range but whose end exceeds block_count. 571 assert_eq!( 572 c.write_blocks(99_999, &[0u8; 1024]), 573 Err(BlockError::OutOfRange) 574 ); 575 576 let dev = dev.borrow(); 577 assert!(dev.io_commands.is_empty(), "no PRP/command may be built"); 578 assert_eq!(dev.io_sq_tail, 0, "no I/O doorbell may be rung"); 579 } 580 581 #[test] 582 fn flush_submits_opcode_zero_command() { 583 let (mut c, dev) = make(4096, 0); 584 c.create_io_queues(8).unwrap(); 585 assert_eq!(c.flush(), Ok(())); 586 587 let cmds = io_commands(&dev); 588 assert_eq!(cmds.len(), 1); 589 assert_eq!(cmds[0].opcode, 0x00, "flush opcode"); 590 assert_eq!(cmds[0].nsid, 1); 591 assert_eq!(cmds[0].prp1, 0); 592 assert_eq!(cmds[0].prp2, 0); 593 }