Skip to content

Add usb device integation test#44

Draft
superstian wants to merge 6 commits intomainfrom
add_usb_device_integation_test
Draft

Add usb device integation test#44
superstian wants to merge 6 commits intomainfrom
add_usb_device_integation_test

Conversation

@superstian
Copy link
Copy Markdown
Collaborator

@superstian superstian commented Aug 25, 2025

Adds a new test class for serialized integration testing. Currently WIP

@superstian superstian force-pushed the add_usb_device_integation_test branch 3 times, most recently from cbfab50 to 9ca036f Compare August 25, 2025 11:52
@superstian superstian marked this pull request as ready for review August 25, 2025 11:54
Comment on lines +66 to +67
// Should this fail?
using var _libUsb2 = new LibUsb(_loggerFactory);
Copy link
Copy Markdown
Owner

@tmittet tmittet Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say no maybe, but calling _libUsb2.Initialize() on the second instance should. It's a .NET convention that constructors don't throw. Normally constructors should not throw, but in this case I'm not entirely sure. Maybe it's better if we treat the LibUsb type as a singleton?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested fix here: #45

}
}

using var _libUsb = new LibUsb(_loggerFactory);
Copy link
Copy Markdown
Owner

@tmittet tmittet Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I committed some changes to TestDeviceSource.cs, see 2c50c2c

Maybe we could use the TestDeviceSource and do something like this to skip the test if device not found:
_deviceSource.OpenUsbDeviceOrSkip().Dispose();?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could implement a using var token = _deviceSource.ClaimDeviceOrSkip() that would find a suitable USB device and reserve for the test, without opening it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of skipping tests like this. It can lead to tests getting skipped in CI without us knowing it. We have seen this in the past with other similar projects

It would be nice to have additional logic with some sort of configuration where we can define what devices to test and what tests to run on a specific system.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of skipping tests like this. It can lead to tests getting skipped in CI without us knowing it. We have seen this in the past with other similar projects

It would be nice to have additional logic with some sort of configuration where we can define what devices to test and what tests to run on a specific system.

The point of the skip tests design is:

  • convenience for integrators/contributors that don't have access to all supported devices
  • easily prototype and add tests for new devices in a dev environment, while still running as many tests as possible
  • make it apparent what the problem is: skip=DUT not available, fail=Something is wrong

I don't see the downside: In a CI environment with access to a devices with e.g. vendor class interface, we can easily run all tests for category "UsbVendorClassDevice" and fail on skip. Or if we had a CI environment will all supported devices on one host, we could run all tests and fail on skip.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will help a bit in enforcing how test skip is used in this project: deb247c

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be named WindowsHandles or similar. I guess we have no plan of making this work on any other OS?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make another test project for tests that are Windows platform specific. IMO this makes it easier to organize platform specific code/dependencies and choose what projects to run on what node in CI.

We can make the TestInfrastructure types public and share them between all the test projects. The cleanest is likely to extract the shared TestInfrastructure to a separate project.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good plan.

@tmittet tmittet marked this pull request as draft August 27, 2025 06:47
@tmittet tmittet force-pushed the add_usb_device_integation_test branch from 2c50c2c to ab16816 Compare August 27, 2025 13:01
@tmittet
Copy link
Copy Markdown
Owner

tmittet commented Aug 27, 2025

Rebased on main and extracted Windows specific tests to separate project

@tmittet tmittet force-pushed the add_usb_device_integation_test branch 2 times, most recently from df8c248 to f184711 Compare August 29, 2025 13:43
@tmittet tmittet force-pushed the main branch 3 times, most recently from 2b3dd7b to f967b1c Compare March 7, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants