Skip to content

Reorganize driver host tests, fix bugs around pointer host code#492

Merged
vosen merged 3 commits intomasterfrom
host_tests
Sep 3, 2025
Merged

Reorganize driver host tests, fix bugs around pointer host code#492
vosen merged 3 commits intomasterfrom
host_tests

Conversation

@vosen
Copy link
Copy Markdown
Owner

@vosen vosen commented Sep 3, 2025

No description provided.

@vosen vosen requested a review from Copilot September 3, 2025 18:07
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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.

Comment thread zluda/src/impl/pointer.rs
Comment on lines +68 to +70
if (*(data_ptr.cast::<hipDeviceptr_t>())).0.is_null() {
*(data_ptr.cast::<hipDeviceptr_t>()) = ptr;
}
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if (*(data_ptr.cast::<hipDeviceptr_t>())).0.is_null() {
*(data_ptr.cast::<hipDeviceptr_t>()) = ptr;
}
*(data_ptr.cast::<hipDeviceptr_t>()) = ptr;
Copilot uses AI. Check for mistakes.
Comment thread zluda/src/impl/pointer.rs
Comment on lines 77 to +78
*(data_ptr.cast::<CUmemorytype>()) =
to_cu_memory_type(*data_ptr.cast::<hipMemoryType>())?;
to_cu_memory_type(*data_ptr.cast::<hipMemoryType>()).unwrap_or(CUmemorytype(0));
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@vosen vosen merged commit 8a7a5b4 into master Sep 3, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants