Skip to content

hcs: add function variables for compute API calls and unit tests#2644

Open
shreyanshjain7174 wants to merge 1 commit intomicrosoft:mainfrom
shreyanshjain7174:hcs/system-driver-interface
Open

hcs: add function variables for compute API calls and unit tests#2644
shreyanshjain7174 wants to merge 1 commit intomicrosoft:mainfrom
shreyanshjain7174:hcs/system-driver-interface

Conversation

@shreyanshjain7174
Copy link
Copy Markdown
Contributor

@shreyanshjain7174 shreyanshjain7174 commented Mar 23, 2026

The HCS layer (internal/hcs/system.go, process.go) calls vmcompute.dll directly today — testing the System/Process lifecycle logic requires admin privileges and a running HCS service.

This replaces the direct vmcompute.HcsXxx() calls with package-level function variables (hcsXxx) defined in zsyscall_compute.go. The variables default to the vmcompute functions. Tests swap individual variables to intercept specific operations — no interface, no mock framework, no passthrough struct.

Tests are in package hcs (internal) so they access the function vars directly — no wrapper layer.

No behavioral change. The function variables delegate to the exact same vmcompute functions.

9 tests covering: synchronous and async Start completion, system exit during pending Start (VM crash at boot), HCS service disconnect during pending Start, system exit during pending Pause, waitBackground exit classification (normal vs unexpected), multi-goroutine Wait fan-out, and late callback arrival after unregistration.

@shreyanshjain7174 shreyanshjain7174 requested a review from a team as a code owner March 23, 2026 11:06
@shreyanshjain7174 shreyanshjain7174 force-pushed the hcs/system-driver-interface branch 2 times, most recently from 3a910f6 to 11ebebd Compare March 24, 2026 14:34
@shreyanshjain7174 shreyanshjain7174 requested review from helsaawy and removed request for helsaawy March 26, 2026 14:03
@shreyanshjain7174 shreyanshjain7174 force-pushed the hcs/system-driver-interface branch 2 times, most recently from c35f103 to c65d060 Compare April 1, 2026 12:51
@shreyanshjain7174 shreyanshjain7174 changed the title hcs: add driver interface for HCS system and process operations hcs: add function variables for compute API calls and unit tests Apr 1, 2026
Copy link
Copy Markdown
Contributor

@rawahars rawahars left a comment

Choose a reason for hiding this comment

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

Please add some comments on what we are trying to test in each case.
Some comments within the test case itself and method doc too.

Copy link
Copy Markdown
Contributor

@helsaawy helsaawy left a comment

Choose a reason for hiding this comment

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

I am not sure the benefit we get from this: the double indirection of function variables in both zsyscall_compute.go and export_test.go (as well as having system_test.go be in a dedicated testing module) feels very overcomplicated.
it honestly might be simpler/easier to start and manage actual HCS compute systems, since we would need to test that functionality isolated from the uvm package anyways

@shreyanshjain7174
Copy link
Copy Markdown
Contributor Author

shreyanshjain7174 commented Apr 1, 2026

Thanks for the feedback, both.

@helsaawy — fair point on the double indirection. The export_test.go Set* wrappers exist only because system_test.go is in package hcs_test (external). If I move the tests into package hcs (internal), they can swap the function vars directly — no setter wrappers, no export_test.go bloat. That cuts the indirection to one layer: zsyscall_compute.go vars swapped inline in each test.

On whether real HCS functional tests would be simpler — for the trivial guard tests (closed handle, swallowed errors), yes. But the async notification tests (system exit during pending Start, service disconnect during Start, waitBackground exit classification, late callback after unregister) exercise race-sensitive paths that are hard to reproduce reliably against a live system. Those are the ones I want to keep — the rest I can trim.

@rawahars — will add test comments explaining what each case exercises.

Plan: move tests to package hcs, drop the Set* helpers, add test documentation, and trim the obvious guard tests. I'll push an update.

Can I get an Ack @helsaawy ?

@shreyanshjain7174 shreyanshjain7174 force-pushed the hcs/system-driver-interface branch from c65d060 to c80927a Compare April 6, 2026 06:04
@shreyanshjain7174
Copy link
Copy Markdown
Contributor Author

Pushed the update addressing both reviews:

@helsaawy — moved tests into package hcs (internal). The Set* wrapper functions and exported notification constants are gone. Tests swap function vars directly via a generic swapFunc helper. export_test.go is down to ~40 lines (just newTestSystem, setupCallback, fireNotification — things that access unexported fields). No more double indirection.

Trimmed the trivial guard tests (closed-handle checks, shutdown/terminate swallowing) — those are 3-line if blocks that don't need unit tests. Kept only the async notification tests that exercise race-sensitive paths hard to reproduce against a live system.

@rawahars — added doc comments on every test explaining what scenario it exercises and why it matters (VM crash during boot, HCS service disconnect, unexpected exit classification, fan-out, late callback safety).

Replace direct vmcompute.HcsXxx() calls in system.go and process.go with
package-level function variables (hcsXxx) defined in zsyscall_compute.go.
The variables default to the vmcompute functions. Tests swap individual
variables to intercept specific operations.

Tests are in package hcs (internal) so they access the function vars
directly — no wrapper layer needed.

9 tests covering: synchronous and async Start completion, system exit
during pending Start (VM crash at boot), HCS service disconnect during
pending Start, system exit during pending Pause, waitBackground exit
classification (normal vs unexpected), multi-goroutine Wait fan-out,
and late callback arrival after unregistration.

Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
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.

4 participants