windows-drivers-rs icon indicating copy to clipboard operation
windows-drivers-rs copied to clipboard

refactor: make cargo wdk integration tests faster

Open gurry opened this issue 2 months ago • 0 comments

This PR improves the performance of cargo-wdk integration tests by making the locks they take more fine grained. On my laptop the test execution time has reduced from ~13 minutes to ~5 minutes.

We need locks here for two reasons:

  1. To prevent a race while generating the cert from the cert store
  2. To avoid concurrently running multiple cargo build commands on the same driver project

Earlier we used a single lock to fulfil these requirements. That serialized all the tests with respect to each other and hurt performance. In this PR we still use locks but we do it differently.

To address requirement 1. we have made cargo-wdk itself take a lock on the cert store instead of relying on the test for synchronization. This lock is super fine-grained compared to before. For 2. we take a separate lock per driver project instead of having every test block on the same lock. Together these changes allow parallelism that improves performance.

Another thing: we now use a named mutex as the locking primitive instead of a file lock because mutexes are cleaner as they create no files. This also fixes #489.

While the performance wins here are significant, more can be done in this area. For example we could copy test projects out into their own isolated directories and run tests on those copies. That will eliminate requirement 2 entirely and remove all locks from the cargo-wdk test code giving us even bigger wins. Something to look into in the future.

gurry avatar Oct 21 '25 06:10 gurry