-
Notifications
You must be signed in to change notification settings - Fork 138
test: add unit tests for IDE DMA engine PRD exhaustion handling #1904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: eric135 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive unit tests for the IDE DMA engine's PRD (Physical Region Descriptor) exhaustion handling, specifically testing the bug fix from PR #633 where sectors_remaining wasn't being set to 0 when PRD became exhausted during write operations.
- Adds 10 new unit tests covering normal operation, PRD exhaustion scenarios, and edge cases
- Tests both read and write DMA completion functions to ensure proper handling of PRD exhaustion
- Includes helper function to create minimal HardDrive instances for isolated testing
// Write some minimal data to make it a valid disk | ||
let disk = Disk::new(disk_file::FileDisk::open(handle, false).unwrap()).unwrap(); | ||
let path = IdePath::default(); | ||
HardDrive::new(disk, path).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple unwrap()
calls in test helper function could cause unclear test failures. Consider using expect()
with descriptive messages to make test failures easier to debug.
HardDrive::new(disk, path).unwrap() | |
let temp_file = NamedTempFile::new().expect("Failed to create temporary file for test hard drive"); | |
let handle = temp_file.reopen().expect("Failed to reopen temporary file for test hard drive"); | |
// Write some minimal data to make it a valid disk | |
let file_disk = disk_file::FileDisk::open(handle, false).expect("Failed to open FileDisk for test hard drive"); | |
let disk = Disk::new(file_disk).expect("Failed to create Disk for test hard drive"); | |
let path = IdePath::default(); | |
HardDrive::new(disk, path).expect("Failed to create HardDrive for test") |
Copilot uses AI. Check for mistakes.
let temp_file = NamedTempFile::new().unwrap(); | ||
let handle = temp_file.reopen().unwrap(); | ||
|
||
// Write some minimal data to make it a valid disk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment mentions "Write some minimal data to make it a valid disk" but no data is actually written to the temporary file. This could cause issues if the Disk constructor expects valid disk content.
// Write some minimal data to make it a valid disk | |
let mut temp_file = NamedTempFile::new().unwrap(); | |
// Write 512 bytes of zeroes to make it a valid disk | |
temp_file.write_all(&[0u8; 512]).unwrap(); | |
let handle = temp_file.reopen().unwrap(); |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about the IDE protocol bits being tested here, but the code looks reasonable enough.
Fixes #1587
This PR adds comprehensive unit tests for the IDE DMA engine, specifically focusing on the PRD (Physical Region Descriptor) exhaustion handling that was fixed in PR #633. The IDE DMA engine is a complex area that has been tricky to get right, and these tests will make it easier to reason through future changes.
Background
PR #633 fixed a bug where the PRD table could become exhausted early during write operations without the exhaustion flag being set properly. This left the disk waiting for remaining data that would never come. The fix was to set
sectors_remaining = 0
when the PRD becomes exhausted, rather than continuing to decrement it normally.Tests Added
The new unit tests cover the following scenarios:
Core DMA Completion Logic
sectors_remaining
is decremented correctly when PRD is not exhaustedsectors_remaining
is set to 0 when PRD is exhausted (the key bug fix)sectors_remaining
reaches 0Read vs Write Operations
write_media_sectors_complete()
andread_media_sectors_complete()
functionsEdge Cases
sectors_before_interrupt
equalssectors_remaining
Bug Demonstration
test_prd_exhausted_behavior_difference
: Explicitly demonstrates the difference between normal and PRD exhausted scenarios to highlight the bug fixImplementation Details
The tests use a minimal
HardDrive
instance created with a temporary file-backed disk to avoid the complexity of full integration testing while still exercising the real code paths. Each test focuses on a specific aspect of the DMA engine behavior to ensure good coverage and maintainability.Verification
These unit tests complement the existing integration test
enlightened_cmd_test_incomplete_prd
by providing focused, fast-running tests that can be easily debugged and extended as the DMA engine evolves.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.