schedtest/rwsem.c:test rwsemaphore api #3399
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
use cmocka framework to write unit tests for rwsem api
Summary
Add unit tests for rwsemaphore API using cmocka framework to improve code coverage and ensure correctness of reader-writer semaphore functionality. The tests verify basic synchronization primitives including initialization, lock acquisition (blocking/non-blocking), and lock release for both readers and writers.
Impact
Build: Minimal impact, only adds new test files
Testing: Adds new test case rwsemtest for schedtest (enabled with CONFIG_TESTING_SCHEDTEST=y)
Compatibility: No breaking changes, purely additive
Testing
Test Scenarios
Single Writer: Writer thread acquires write lock, updates shared resource (0 → 10), verifies exclusive access
Multiple Readers: Three reader threads with different behaviors:
Reader 1: Basic read lock/unlock with data verification
Reader 2: Tests down_read_trylock() non-blocking behavior
Reader 3: Tests recursive read lock acquisition (same thread acquires twice)
Reader-Writer Exclusion: Verifies readers are blocked while writer holds the lock
Tested on QEMU simultiaon
Config:CONFIG_TESTING_SCHEDTEST=y