-
Notifications
You must be signed in to change notification settings - Fork 17
Add testing machinery to libcxlmk #51
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... instead of hardcoding values, avoiding potential truncation issues. Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Removed the unused static struct cxlmi_ctx *ctx; declaration and its dead-code reference (if (!c) c = ctx;) from log.c. Since ctx was never assigned a value, the fallback was ineffective. Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
1. In cxlmi_cmd_get_log() in->length already specifies the number of bytes to read from the log, not the number of struct cxlmi_cmd_get_log_rsp entries. Multiplying by sizeof(*rsp_pl) (which is 4 bytes) may cause a buffer overflow. According to the CXL spec, the Get Log command's length field specifies the number of bytes to transfer, and the response is raw log data of that length. The fix is to simply copy in->length bytes. 2. Fix conflicting names for Sanitize operations. Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
The arm_cci_request() function sets the pl_length field in the CCI
message header, which must contain only the payload size (data in the
payload[] flexible array), not including the CCI message header itself.
Several commands were passing incorrect payload sizes:
1. Commands passing req_sz instead of payload size:
- get_feature: was passing req_sz (header + payload) instead of
just sizeof(*req_pl)
- set_feature: same issue, now correctly includes feature_data_sz
2. Commands not accounting for variable-length data:
- clear_event_records: now includes handles array size
- transfer_fw: now includes firmware data size
- set_lsa: now includes LSA data size
- media_operations_sanitize: now includes DPA range list size
- add_dc_response: now includes extent list size
- release_dc: now includes extent list size
- send_ld_cxlio_mem_request: now includes data length
- set_ld_allocations: now includes allocation list size
- set_qos_allocated_bw: now includes QoS fraction array size
- set_qos_bw_limit: now includes QoS limit fraction array size
... and some other fixes:
3. Logic error:
- vendor_specific: condition was inverted (in ? 0 : in_size should
be in ? in_size : 0)
4. Export cxlmi_cmd_fmapi_get_head_info() which was not in the main
header file.
5. Add the extra data size parameters for transfer fw, set lsa and
security send.
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Generic-Component-Commands.md
1. Fixed syntax error (extra semicolon) in cxlmi_cmd_get_event_records signature
2. Fixed wrong function name for Get FW Info - was cxlmi_cmd_request_bg_op_abort,
now cxlmi_cmd_get_fw_info
3. Fixed num_supported_feature_entries type from uint32_t to uint16_t in
cxlmi_cmd_get_supported_features_rsp
4. Fixed feature_data from pointer to array in cxlmi_cmd_get_feature_rsp
Memory-Device-Commands.md
1. Added _rsp suffix to all response struct names
2. Added _req suffix to all request struct names
3. Fixed Get LSA - was labeled "Return payload" but is actually "Input payload",
added missing void *ret parameter
4. Fixed Set LSA - added missing size_t data_sz parameter
5. Fixed Set SLD QoS Control - removed return payload (function doesn't have one)
6. Fixed Security Send - added missing size_t data_sz parameter
7. Fixed Release Dynamic Capacity - wrong struct name cxlmi_cmd_memdev_release_dyn_cap
changed to cxlmi_cmd_memdev_release_dc_req
FM-API.md
1. Added _rsp suffix to all response struct names
2. Added _req suffix to all request struct names
3. Fixed Get DCD Info - changed supported_block_sizes[8] array to individual
region_X_supported_blk_sz_mask fields
4. Fixed DC List Tags - wrong field names start_ind/max_tags changed to start_idx/tags_count
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Add a comprehensive mock transport layer and test suite for unit testing the libcxlmi command API without requiring real CXL hardware. The mock transport allows tests to: - Set expected responses for specific command set/opcode combinations - Queue multiple responses for sequential command testing - Verify request payloads sent by the library - Test error code handling and retry scenarios - Validate endianness conversions Test coverage includes 325 tests across: - All 76 CXL-MI commands (generic, events, firmware, timestamps, logs, features, memory device, health/alerts, media/poison, sanitize, security, SLD QoS, DCD config, and FM-API commands) - Error code handling for all defined CXL return codes - Request payload verification (correct encoding and field values) - Response payload verification (correct decoding and field extraction) - Endianness verification for multi-byte fields - Edge cases for variable-length responses (empty arrays, multiple entries) - Boundary value tests (max counts, zero values, overflow conditions) Also adds GitHub CI workflow with: - Build matrix (GCC/Clang on x86-64 and ARM64) - AddressSanitizer and UndefinedBehaviorSanitizer - Valgrind memory checking - Code coverage with Codecov integration - Clang static analyzer Generated-by: Claude AI Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Fix typos throughout the code base found by codespell CI. Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
The response length varies based on command success/failure. Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Miscellaneous fixlets to silence the tool in the CI. ... also for mock device tests. Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Add unit tests for CXL command sets that can run against real hardware or QEMU-emulated devices: - cxl-test-generic: Tests 27 generic CXL commands (identify, events, firmware, logs, features, timestamp) - cxl-test-memdev: Tests 35 memory device commands (health, LSA, poison, sanitize, DCD, security) - cxl-test-fmapi: Tests 34 FM-API commands (physical/virtual switch, MLD port, multi-headed device, DCD) All tests support both ioctl (/dev/cxl/memX) and MCTP transports. Common test infrastructure is shared via tests/test-common.h. Add QEMU test scripts for automated testing: - scripts/qemu-cxl-test.sh: Builds libcxlmi and runs tests in QEMU with emulated CXL Type3 devices (volatile + persistent) - scripts/qemu-mctp-test.sh: Builds libcxlmi and runs tests in QEMU with emulated CXL Type3 device under a switch (FM-owned LD). - scripts/qemu-init.c: Minimal init that discovers CXL devices and runs the test suite Update docs/Testing.md with comprehensive documentation covering bare metal testing, QEMU testing, and both transport options. Generated-by: Claude AI Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This adds both a mock test framework as well as unit tests that can be used in bare metal or via qemu along with the respective automation.