Skip to content

parity: add LCOW document permutation tests#2631

Open
shreyanshjain7174 wants to merge 2 commits intomicrosoft:mainfrom
shreyanshjain7174:parity/lcow-permutations
Open

parity: add LCOW document permutation tests#2631
shreyanshjain7174 wants to merge 2 commits intomicrosoft:mainfrom
shreyanshjain7174:parity/lcow-permutations

Conversation

@shreyanshjain7174
Copy link
Contributor

This PR extends the LCOW parity test infrastructure from #2629 with permutation tests that exercise annotation and option combinations triggering different document construction branches in the legacy and v2 pipelines.

Note: This PR is stacked on #2629. The diff will clean up once that PR merges.

Changes

Permutation tests (TestLCOWDocumentParityPermutations)

19 test cases covering:

  • CPU partial combinations — count-only, limit-only, weight-only
  • Memory — overcommit disabled, cold discard hint
  • Boot mode — kernel direct + VHD rootfs
  • Feature flags — scratch encryption + disabled writable shares, writable overlay dirs
  • Device interactions — VPMem disabled (triggers 4 SCSI controllers)
  • Cross-group — physically backed + VPMem disabled + scratch encryption, full CPU + memory + MMIO + QoS + cold discard + VHD boot
  • Shim option overrides — annotation CPU/memory overriding shim option values
  • Kernel args — VPCIEnabled + custom boot options, time sync + process dump + writable overlay, initrd boot whitespace quirk

Gap tests

3 tests documenting known v2 builder differences using inverted assertions (they expect a diff and only fail if the documents unexpectedly match):

Gap Legacy V2
No CPUGroupID set CpuGroup = nil CpuGroup = &{Id:""}
No StorageQoS set StorageQoS = nil StorageQoS = &{}
Initrd boot VPMem controller allocated VirtualPMem = nil

These are tracked for fixes in the v2 builder (see #2630).

Kernel cmdline whitespace handling

Added normalizeKernelCmdLine and isOnlyKernelCmdLineWhitespaceDiff helpers. The legacy builder produces a leading space in kernel command lines for initrd+KernelDirect boot that the v2 builder correctly omits. Since HCS trims whitespace, this difference is harmless and we warn instead of failing.

Testing

Requires admin PowerShell + Hyper-V enabled (tests call processorinfo.HostProcessorInfo via HCS).

cd test && go test -v -run TestLCOWDocumentParityPermutations ./parity/vm/

Depends on

Address review feedback from PR microsoft#2629. Major changes:

Source changes (internal/uvm/):
- Export VerifyOptions, MakeLCOWDoc, MakeLCOWSecurityDoc as public functions
  so they can be called directly from the test package.
- Remove MakeLCOWDocument composite wrapper — test assembles the pipeline
  itself using the exported primitives.
- Add NewUtilityVMForDoc constructor in types.go. This is needed because
  MakeLCOWDoc takes a *UtilityVM parameter and reads its unexported fields
  (scsiControllerCount, vpmemMaxCount, etc). The test cannot set these
  fields directly from outside the package, so NewUtilityVMForDoc creates
  a minimal UtilityVM with only the fields needed for document generation.
- Original source code comments preserved — only function names changed
  from lowercase to uppercase.

Test changes (test/parity/vm/):
- Moved from test/parity/ to test/parity/vm/ for future WCOW support.
- Removed functional build tag — these are not functional tests.
- Removed all normalization (nil-vs-empty, map sorting, owner zeroing).
  cmp.Diff handles maps natively. Real differences are not masked.
- Merged pipeline helpers into hcs_document_creator_test.go.
- Removed helpers_test.go — setupBootFiles and jsonToString moved inline.
- Generic doc.go that covers both LCOW and future WCOW.
- All test cases explicitly populate every field (CPU, memory, MMIO, QoS,
  CPUGroupID) so comparison always checks populated values, not defaults.
- Use maps.Clone for annotation copying.
- Use testing.Verbose() to gate debug logging.
- Descriptive error messages throughout.

All 8 tests pass (3 document parity + 5 field parity).

Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
Add TestLCOWDocumentParityPermutations to exercise annotation and option
combinations that trigger different document construction branches in the
legacy and v2 LCOW pipelines. Each test sets all required fields so
comparisons check real values rather than defaults.

Permutation categories:
- CPU partial combinations (count, limit, weight)
- Memory (overcommit disabled, cold discard hint)
- Boot mode (kernel direct + VHD rootfs)
- Feature flags (scratch encryption, writable overlay)
- Device interactions (VPMem disabled → 4 SCSI controllers)
- Cross-group (physically backed + VPMem + encryption)
- Shim option overrides (annotation CPU/memory priority)
- Kernel args (VPCIEnabled, time sync, process dump, initrd boot)

Gap tests document three known v2 builder differences:
- No CPUGroupID: legacy nil vs v2 empty CpuGroup struct
- No StorageQoS: legacy nil vs v2 empty StorageQoS struct
- Initrd boot: legacy VPMem controller vs v2 nil VirtualPMem

Gap tests use inverted assertions — they expect a diff and only fail if
documents unexpectedly match, signaling the v2 bug was fixed.

Also adds normalizeKernelCmdLine and isOnlyKernelCmdLineWhitespaceDiff
helpers to handle a known legacy quirk where initrd+KernelDirect boot
produces a leading space in kernel command lines that v2 correctly omits.

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.

1 participant