Skip to content

Commit 917d728

Browse files
author
Shreyansh Sancheti
committed
parity: add LCOW document permutation tests
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>
1 parent b6a131c commit 917d728

2 files changed

Lines changed: 414 additions & 3 deletions

File tree

test/parity/vm/hcs_document_creator_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import (
88
"fmt"
99
"os"
1010
"path/filepath"
11+
"strings"
1112
"testing"
1213

1314
"github.com/opencontainers/runtime-spec/specs-go"
1415

16+
"github.com/google/go-cmp/cmp"
17+
1518
runhcsopts "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
1619
lcowbuilder "github.com/Microsoft/hcsshim/internal/builder/vm/lcow"
1720
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
@@ -111,3 +114,74 @@ func jsonToString(v interface{}) string {
111114
}
112115
return string(b)
113116
}
117+
118+
// normalizeKernelCmdLine trims leading/trailing whitespace from the kernel
119+
// command line in the document. The legacy builder has a minor quirk that
120+
// produces a leading space for initrd+KernelDirect boot. The v2 builder
121+
// does not. Since HCS trims whitespace from kernel args, this difference
122+
// is harmless and we normalize it away.
123+
func normalizeKernelCmdLine(doc *hcsschema.ComputeSystem) {
124+
if doc == nil || doc.VirtualMachine == nil || doc.VirtualMachine.Chipset == nil {
125+
return
126+
}
127+
if kd := doc.VirtualMachine.Chipset.LinuxKernelDirect; kd != nil {
128+
kd.KernelCmdLine = strings.TrimSpace(kd.KernelCmdLine)
129+
}
130+
if uefi := doc.VirtualMachine.Chipset.Uefi; uefi != nil && uefi.BootThis != nil {
131+
uefi.BootThis.OptionalData = strings.TrimSpace(uefi.BootThis.OptionalData)
132+
}
133+
}
134+
135+
// isOnlyKernelCmdLineWhitespaceDiff returns true if the only difference between
136+
// two documents is leading/trailing whitespace in the kernel command line.
137+
// This is a known legacy quirk where initrd+KernelDirect boot produces a
138+
// leading space that v2 correctly omits.
139+
func isOnlyKernelCmdLineWhitespaceDiff(legacy, v2 *hcsschema.ComputeSystem) bool {
140+
// Deep copy and normalize, then re-compare.
141+
legacyCopy := *legacy
142+
v2Copy := *v2
143+
// Shallow copy the VM and chipset to avoid mutating originals.
144+
if legacyCopy.VirtualMachine != nil {
145+
vmCopy := *legacyCopy.VirtualMachine
146+
legacyCopy.VirtualMachine = &vmCopy
147+
if vmCopy.Chipset != nil {
148+
chipCopy := *vmCopy.Chipset
149+
legacyCopy.VirtualMachine.Chipset = &chipCopy
150+
if chipCopy.LinuxKernelDirect != nil {
151+
lkdCopy := *chipCopy.LinuxKernelDirect
152+
legacyCopy.VirtualMachine.Chipset.LinuxKernelDirect = &lkdCopy
153+
}
154+
if chipCopy.Uefi != nil {
155+
uefiCopy := *chipCopy.Uefi
156+
legacyCopy.VirtualMachine.Chipset.Uefi = &uefiCopy
157+
if uefiCopy.BootThis != nil {
158+
btCopy := *uefiCopy.BootThis
159+
legacyCopy.VirtualMachine.Chipset.Uefi.BootThis = &btCopy
160+
}
161+
}
162+
}
163+
}
164+
if v2Copy.VirtualMachine != nil {
165+
vmCopy := *v2Copy.VirtualMachine
166+
v2Copy.VirtualMachine = &vmCopy
167+
if vmCopy.Chipset != nil {
168+
chipCopy := *vmCopy.Chipset
169+
v2Copy.VirtualMachine.Chipset = &chipCopy
170+
if chipCopy.LinuxKernelDirect != nil {
171+
lkdCopy := *chipCopy.LinuxKernelDirect
172+
v2Copy.VirtualMachine.Chipset.LinuxKernelDirect = &lkdCopy
173+
}
174+
if chipCopy.Uefi != nil {
175+
uefiCopy := *chipCopy.Uefi
176+
v2Copy.VirtualMachine.Chipset.Uefi = &uefiCopy
177+
if uefiCopy.BootThis != nil {
178+
btCopy := *uefiCopy.BootThis
179+
v2Copy.VirtualMachine.Chipset.Uefi.BootThis = &btCopy
180+
}
181+
}
182+
}
183+
}
184+
normalizeKernelCmdLine(&legacyCopy)
185+
normalizeKernelCmdLine(&v2Copy)
186+
return cmp.Diff(&legacyCopy, &v2Copy) == ""
187+
}

0 commit comments

Comments
 (0)