Add code coverage and ioctl unit testing#52
Merged
Conversation
colemancda
force-pushed
the
feature/code-coverage
branch
from
July 18, 2026 02:59
860a46e to
631397f
Compare
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
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.
Summary
Adds code coverage measurement/enforcement and unit-testing scaffolding for the package's
ioctl()calls, plus value-type tests — and fixes three real bugs the new tests exposed.Coverage: 1.53% → 41.23% (949/2302 lines), 40 tests, all passing. Rebased on latest
master.Code coverage
Scripts/coverage.shruns the suite with coverage, exports LCOV + Cobertura reports scoped to the package's ownSources/, and enforces a minimum line-coverage threshold (currently 1%, to be ratcheted up as the suite grows).swift.yml) runs the gate and publishes to GitHub Code Quality; replaces the retiredmaxep/spm-lcov-actionstep and refreshes the deprecatedubuntu-20.04runner andupload-artifact@v3action.ioctl unit testing
Syscall mocking modeled on swift-system's
MockingDriver:Internal/Mocking.swift— thread-localMockingDriverthat records a trace of syscalls, can force errnos (.always/.countedfor error-path andEINTR-retry tests), and exposes anioctlHandlerclosure to fake the kernel's out-parameter reply.Internal/Syscalls.swift—system_ioctlshims that divert to the mock underENABLE_MOCKING(debug only) and compile to the plainioctlin release.Internal/IOControl.swift— in-moduleSocketDescriptor.inputOutputoverloads that route all existing ioctl call sites through the mockable seam without touching them.ENABLE_MOCKINGis defined for debug builds only, mirroring swift-system.Bugs found and fixed by the new tests
HCIScaninquiry parsing used the wrong buffer offset — results were read at SwiftMemoryLayout.size(9) instead of the Csizeof(struct hci_inquiry_req)(10) the kernel writes at, and the misaligned typed rebind traps at runtime. Rewritten with a properly aligned raw buffer, stride-based offsets, andloadUnaligned.RFCOMMIO.GetDeviceListhad the same ABI bug —dev_info[]was read at offset 2 instead of the C flexible-array offset 4 (count padded to element alignment), with the same misalignment trap.RFCOMMDevicecopied the source address intodestination(destination = cValue.source).Tests
IOControlTests.swift— ioctl paths through the mock seam: request tracing, faked kernel replies forHCIGETDEVLIST,HCIGETDEVINFO,HCIINQUIRY(verifies marshalled request fields incl. GIAC lap), RFCOMM create/release/list/get-info, forced-errno, and interrupt-retry paths.ValueTests.swift— pure value-type logic:AddressType, the fullHCIError → Errnomapping,HostControllerIO/RFCOMMIOround trips + descriptions +Codable,HCIDeviceOptions,LinkMode,RFCOMMState,HCIBusType/HCIControllerTypedescriptions,HCIPacketType,BluetoothSocketProtocol, and socket-option encode/decode round trips (Security, RFCOMMLinkMode,ConnectionInfo).All run without Bluetooth hardware, on Linux and Darwin.
Progress log
Now fully covered:
Error,AddressType,HCIBusType,HCIControllerType,HCIDeviceFlag,HCIDeviceOptions,RFCOMMFlag,RFCOMMLinkMode,RFCOMMGetDeviceInformation. Remaining gaps are the asyncHostControlleroperations and L2CAP/socket plumbing that need a live HCI socket.The toolchain is pinned to Swift 6.3.3 via
.swift-version.Includes the BitMaskOptionSet → native
OptionSetmigration (#53, merged into this branch).