-
Notifications
You must be signed in to change notification settings - Fork 2
KF-30 add tests for Semaphore #70
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
eb411d0 to
18d496b
Compare
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 kf::Semaphore class to validate its basic functionality including wait/release operations, timeout behavior, and limit enforcement. The changes also include a minor enhancement to the Semaphore implementation to prevent releasing beyond the maximum limit.
- Adds new test file
SemaphoreTest.cppwith comprehensive test scenarios covering various semaphore behaviors - Updates CMakeLists.txt to include the new test file in the build
- Enhances Semaphore implementation to check and enforce limit constraints during release operations
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/SemaphoreTest.cpp | New comprehensive test suite covering semaphore wait/release scenarios, timeout behavior, and limit enforcement |
| test/CMakeLists.txt | Adds SemaphoreTest.cpp to the test build configuration |
| include/kf/Semaphore.h | Adds limit enforcement logic and stores limit value for validation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| private: | ||
| LONG m_limit = 0; | ||
| KSEMAPHORE m_semaphore; |
Copilot
AI
Aug 15, 2025
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.
There's a race condition between reading the semaphore state and releasing it. Another thread could modify the semaphore count between these operations, potentially allowing the count to exceed the limit. Consider using atomic operations or proper synchronization.
| KSEMAPHORE m_semaphore; | |
| { | |
| KIRQL oldIrql; | |
| KeAcquireSpinLock(&m_lock, &oldIrql); | |
| LONG currentCount = KeReadStateSemaphore(&m_semaphore); | |
| if (currentCount + adjustment > m_limit) | |
| { | |
| KeReleaseSpinLock(&m_lock, oldIrql); | |
| return; | |
| } | |
| KeReleaseSemaphore(&m_semaphore, IO_NO_INCREMENT, adjustment, false); | |
| KeReleaseSpinLock(&m_lock, oldIrql); | |
| } | |
| private: | |
| LONG m_limit = 0; | |
| KSEMAPHORE m_semaphore; | |
| KSPIN_LOCK m_lock; |
Task: https://jira.dev.local/jira/browse/KF-30