Reorganize driver host tests, fix bugs around pointer host code#492
Reorganize driver host tests, fix bugs around pointer host code#492
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR reorganizes driver host tests by removing the separate cuda_tests crate and integrating test infrastructure directly into zluda. Additionally, it fixes bugs in pointer host code related to error handling and attribute retrieval.
- Consolidates test infrastructure by removing the cuda_tests crate and moving functionality into zluda/src/tests.rs
- Improves error handling in pointer attribute functions by using unwrap_or for graceful degradation
- Adds comprehensive test coverage for pointer attribute edge cases
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| zluda/src/tests/mod.rs | Removes old test module (file deleted) |
| zluda/src/tests.rs | Adds new consolidated test infrastructure with CudaApi trait and implementations |
| zluda/src/impl/pointer.rs | Refactors pointer attribute handling with better error handling and adds extensive tests |
| zluda/src/impl/driver.rs | Adds simple initialization test using new test infrastructure |
| zluda/Cargo.toml | Updates dependencies, removes cuda_tests and adds libloading as dev dependency |
| cuda_tests/ files | Removes entire cuda_tests crate (files deleted) |
| cuda_macros/src/lib.rs | Replaces generate_api_macro with test_cuda attribute macro for simpler test generation |
| Cargo.toml | Removes cuda_tests from workspace members |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (*(data_ptr.cast::<hipDeviceptr_t>())).0.is_null() { | ||
| *(data_ptr.cast::<hipDeviceptr_t>()) = ptr; | ||
| } |
There was a problem hiding this comment.
This code has undefined behavior. It reads from an uninitialized pointer at line 68, then conditionally writes to it at line 69. The read operation accesses potentially garbage memory. Consider initializing the target memory or using a different approach to check if initialization is needed.
| if (*(data_ptr.cast::<hipDeviceptr_t>())).0.is_null() { | |
| *(data_ptr.cast::<hipDeviceptr_t>()) = ptr; | |
| } | |
| *(data_ptr.cast::<hipDeviceptr_t>()) = ptr; |
| *(data_ptr.cast::<CUmemorytype>()) = | ||
| to_cu_memory_type(*data_ptr.cast::<hipMemoryType>())?; | ||
| to_cu_memory_type(*data_ptr.cast::<hipMemoryType>()).unwrap_or(CUmemorytype(0)); |
There was a problem hiding this comment.
This code reads from uninitialized memory at line 78. The *data_ptr.cast::<hipMemoryType>() dereferences a pointer that may contain garbage data, passing undefined values to to_cu_memory_type. This could lead to unpredictable behavior.
No description provided.