Skip to content

Commit dfd2bab

Browse files
committed
fix: resolve test compilation errors and add SharedUtilities to all test targets
- Add SharedUtilities sources to all test targets in Package.swift - Fix USBIPUnlinkRequest parameter order in USBRequestProcessorTests - Fix USBSpeed enum case from .highSpeed to .high - Resolve duplicate responseData variable declaration - Add MockDeviceClaimManager to RequestProcessor constructors - Fix USBIPCommand references to USBIPProtocol.Command - Add type annotation for USBSubmitProcessor initialization
1 parent f211b49 commit dfd2bab

5 files changed

Lines changed: 32 additions & 22 deletions

File tree

.spec-workflow/specs/automated-production-release/tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ The implementation follows a systematic approach to build the automated producti
213213
- _Requirements: Code quality standards_
214214
- _Leverage: existing build and test infrastructure_
215215

216-
- [-] 27. Create pull request and monitor CI validation
216+
- [x] 27. Create pull request and monitor CI validation
217217
- Push feature branch and create comprehensive pull request
218218
- Monitor CI pipeline execution and resolve any integration issues
219219
- Ensure all GitHub Actions workflows pass validation

Package.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,20 @@ let package = Package(
6363
]),
6464
.testTarget(
6565
name: "USBIPDCoreTests",
66-
dependencies: ["USBIPDCore"]),
66+
dependencies: ["USBIPDCore"],
67+
sources: [".", "../SharedUtilities"]),
6768
.testTarget(
6869
name: "USBIPDCLITests",
69-
dependencies: ["USBIPDCLI"]),
70+
dependencies: ["USBIPDCLI"],
71+
sources: [".", "../SharedUtilities"]),
7072
.testTarget(
7173
name: "IntegrationTests",
72-
dependencies: ["USBIPDCore", "QEMUTestServer", "USBIPDCLI", "SystemExtension", "Common"]),
74+
dependencies: ["USBIPDCore", "QEMUTestServer", "USBIPDCLI", "SystemExtension", "Common"],
75+
sources: [".", "../SharedUtilities"]),
7376
.testTarget(
7477
name: "SystemExtensionTests",
75-
dependencies: ["SystemExtension", "Common"]),
78+
dependencies: ["SystemExtension", "Common"],
79+
sources: [".", "../SharedUtilities"]),
7680
.testTarget(
7781
name: "QEMUIntegrationTests",
7882
dependencies: ["QEMUTestServer", "USBIPDCore", "Common"],

Tests/IntegrationTests/QEMUUSBIPProtocolTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ extension QEMUUSBIPProtocolTests {
686686
}
687687

688688
/// Helper to validate USB/IP header structure
689-
private func validateUSBIPHeader(_ header: USBIPHeader, expectedCommand: USBIPCommand) {
689+
private func validateUSBIPHeader(_ header: USBIPHeader, expectedCommand: USBIPProtocol.Command) {
690690
XCTAssertEqual(header.version, USBIPProtocol.version, "Header version should match protocol")
691691
XCTAssertEqual(header.command, expectedCommand, "Header command should match expected")
692692
XCTAssertEqual(header.status, 0, "Header status should be success for normal operations")

Tests/USBIPDCoreTests/Protocol/USBRequestProcessorTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class USBRequestProcessorTests: XCTestCase {
2424
mockDeviceCommunicator = MockUSBDeviceCommunicator()
2525
urbTracker = URBTracker()
2626

27-
submitProcessor = USBSubmitProcessor(deviceCommunicator: mockDeviceCommunicator)
27+
submitProcessor = USBSubmitProcessor(deviceCommunicator: mockDeviceCommunicator as USBDeviceCommunicator)
2828
unlinkProcessor = USBUnlinkProcessor(submitProcessor: submitProcessor)
2929

3030
testDevice = createTestDevice()
@@ -54,7 +54,7 @@ final class USBRequestProcessorTests: XCTestCase {
5454
deviceClass: 0x09,
5555
deviceSubClass: 0x00,
5656
deviceProtocol: 0x00,
57-
speed: .highSpeed,
57+
speed: .high,
5858
manufacturerString: "Test Manufacturer",
5959
productString: "Test Device",
6060
serialNumberString: "TEST001"
@@ -100,10 +100,10 @@ final class USBRequestProcessorTests: XCTestCase {
100100
) throws -> Data {
101101
let request = USBIPUnlinkRequest(
102102
seqnum: seqnum,
103+
unlinkSeqnum: unlinkSeqnum,
103104
devid: devid,
104105
direction: direction,
105-
ep: endpoint,
106-
unlinkSeqnum: unlinkSeqnum
106+
ep: endpoint
107107
)
108108

109109
return try request.encode()
@@ -113,8 +113,8 @@ final class USBRequestProcessorTests: XCTestCase {
113113

114114
func testProcessSubmitRequestControlTransferSuccess() async throws {
115115
// Configure mock for control transfer success
116-
let responseData = Data([0x12, 0x01, 0x00, 0x02, 0x09, 0x00, 0x00, 0x40]) // Device descriptor
117-
mockDeviceCommunicator.setControlTransferResponse(responseData)
116+
let mockResponseData = Data([0x12, 0x01, 0x00, 0x02, 0x09, 0x00, 0x00, 0x40]) // Device descriptor
117+
mockDeviceCommunicator.setControlTransferResponse(mockResponseData)
118118

119119
// Create control transfer request (GET_DESCRIPTOR)
120120
let setupPacket = Data([0x80, 0x06, 0x00, 0x01, 0x00, 0x00, 0x12, 0x00])

Tests/USBIPDCoreTests/RequestProcessorTests.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class RequestProcessorTests: XCTestCase {
7979
let device = createSampleDevice()
8080
deviceDiscovery.devices = [device]
8181

82-
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery)
82+
let mockDeviceClaimManager = MockDeviceClaimManager()
83+
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery, deviceClaimManager: mockDeviceClaimManager)
8384
let requestData = createDeviceListRequest()
8485

8586
// Act
@@ -90,7 +91,7 @@ class RequestProcessorTests: XCTestCase {
9091

9192
// Decode the response to verify it
9293
let response = try USBIPMessageDecoder.decodeDeviceListResponse(from: responseData)
93-
XCTAssertEqual(response.header.command, .replyDeviceList, "Response should be a device list reply")
94+
XCTAssertEqual(response.header.command, USBIPProtocol.Command.replyDeviceList, "Response should be a device list reply")
9495
XCTAssertEqual(response.header.status, 0, "Status should be success (0)")
9596
XCTAssertEqual(response.deviceCount, 1, "Response should contain 1 device")
9697
XCTAssertEqual(response.devices.count, 1, "Response should contain 1 device")
@@ -108,7 +109,8 @@ class RequestProcessorTests: XCTestCase {
108109
let deviceDiscovery = MockDeviceDiscovery()
109110
deviceDiscovery.devices = []
110111

111-
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery)
112+
let mockDeviceClaimManager = MockDeviceClaimManager()
113+
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery, deviceClaimManager: mockDeviceClaimManager)
112114
let requestData = createDeviceListRequest()
113115

114116
// Act
@@ -119,7 +121,7 @@ class RequestProcessorTests: XCTestCase {
119121

120122
// Decode the response to verify it
121123
let response = try USBIPMessageDecoder.decodeDeviceListResponse(from: responseData)
122-
XCTAssertEqual(response.header.command, .replyDeviceList, "Response should be a device list reply")
124+
XCTAssertEqual(response.header.command, USBIPProtocol.Command.replyDeviceList, "Response should be a device list reply")
123125
XCTAssertEqual(response.header.status, 0, "Status should be success (0)")
124126
XCTAssertEqual(response.deviceCount, 0, "Response should contain 0 devices")
125127
XCTAssertEqual(response.devices.count, 0, "Response should contain 0 devices")
@@ -131,7 +133,8 @@ class RequestProcessorTests: XCTestCase {
131133
let device = createSampleDevice()
132134
deviceDiscovery.devices = [device]
133135

134-
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery)
136+
let mockDeviceClaimManager = MockDeviceClaimManager()
137+
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery, deviceClaimManager: mockDeviceClaimManager)
135138
let requestData = createDeviceImportRequest(busID: "1-1:1.0")
136139

137140
// Act
@@ -144,7 +147,7 @@ class RequestProcessorTests: XCTestCase {
144147

145148
// Decode the response to verify it
146149
let response = try USBIPMessageDecoder.decodeDeviceImportResponse(from: responseData)
147-
XCTAssertEqual(response.header.command, .replyDeviceImport, "Response should be a device import reply")
150+
XCTAssertEqual(response.header.command, USBIPProtocol.Command.replyDeviceImport, "Response should be a device import reply")
148151
XCTAssertEqual(response.header.status, 0, "Status should be success (0)")
149152
XCTAssertEqual(response.status, 0, "Status should be success (0)")
150153
XCTAssertNotNil(response.deviceInfo, "Device info should be present")
@@ -162,7 +165,8 @@ class RequestProcessorTests: XCTestCase {
162165
let deviceDiscovery = MockDeviceDiscovery()
163166
deviceDiscovery.devices = [] // No devices available
164167

165-
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery)
168+
let mockDeviceClaimManager = MockDeviceClaimManager()
169+
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery, deviceClaimManager: mockDeviceClaimManager)
166170
let requestData = createDeviceImportRequest(busID: "1-1:1.0")
167171

168172
// Act
@@ -173,15 +177,16 @@ class RequestProcessorTests: XCTestCase {
173177

174178
// Decode the response to verify it
175179
let response = try USBIPMessageDecoder.decodeDeviceImportResponse(from: responseData)
176-
XCTAssertEqual(response.header.command, .replyDeviceImport, "Response should be a device import reply")
180+
XCTAssertEqual(response.header.command, USBIPProtocol.Command.replyDeviceImport, "Response should be a device import reply")
177181
XCTAssertEqual(response.status, 1, "Status should be error (1)")
178182
XCTAssertNil(response.deviceInfo, "Device info should not be present for error response")
179183
}
180184

181185
func testProcessInvalidRequest() throws {
182186
// Arrange
183187
let deviceDiscovery = MockDeviceDiscovery()
184-
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery)
188+
let mockDeviceClaimManager = MockDeviceClaimManager()
189+
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery, deviceClaimManager: mockDeviceClaimManager)
185190

186191
// Create an invalid request with incorrect data
187192
let invalidData = Data([0x01, 0x02, 0x03, 0x04])
@@ -193,7 +198,8 @@ class RequestProcessorTests: XCTestCase {
193198
func testProcessUnsupportedCommand() throws {
194199
// Arrange
195200
let deviceDiscovery = MockDeviceDiscovery()
196-
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery)
201+
let mockDeviceClaimManager = MockDeviceClaimManager()
202+
let processor = RequestProcessor(deviceDiscovery: deviceDiscovery, deviceClaimManager: mockDeviceClaimManager)
197203

198204
// Create a reply message (which should not be processed as a request)
199205
let header = USBIPHeader(command: .replyDeviceList)

0 commit comments

Comments
 (0)