Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions test/parity/vm/doc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
//go:build windows

// Package vmparity validates that the v2 modular VM document builders produce
// HCS ComputeSystem documents equivalent to the legacy shim pipelines.
// Package vmparity validates that the v2 VM document builders produce HCS
// ComputeSystem documents equivalent to the legacy shim pipelines.
//
// Currently covers LCOW; WCOW parity will be added in a future PR.
// Currently covers LCOW parity between:
// - Legacy: OCI spec → oci.UpdateSpecFromOptions → oci.ProcessAnnotations →
// oci.SpecToUVMCreateOpts → uvm.MakeLCOWDoc → *hcsschema.ComputeSystem
// - V2: vm.Spec + runhcsopts.Options → lcow.BuildSandboxConfig →
// *hcsschema.ComputeSystem + *SandboxOptions
//
// WCOW parity will be added in a future PR.
package vmparity
44 changes: 44 additions & 0 deletions test/parity/vm/hcs_lcow_document_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/opencontainers/runtime-spec/specs-go"

runhcsopts "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
Expand Down Expand Up @@ -111,3 +113,45 @@ func jsonToString(v interface{}) string {
}
return string(b)
}

// normalizeKernelCmdLine trims leading/trailing whitespace from the kernel
// command line in the document. The legacy builder has a minor quirk that
// produces a leading space for initrd+KernelDirect boot. The v2 builder
// does not. Since HCS trims whitespace from kernel args, this difference
// is harmless and we normalize it away.
func normalizeKernelCmdLine(doc *hcsschema.ComputeSystem) {
if doc == nil || doc.VirtualMachine == nil || doc.VirtualMachine.Chipset == nil {
return
}
if kd := doc.VirtualMachine.Chipset.LinuxKernelDirect; kd != nil {
kd.KernelCmdLine = strings.TrimSpace(kd.KernelCmdLine)
}
if uefi := doc.VirtualMachine.Chipset.Uefi; uefi != nil && uefi.BootThis != nil {
uefi.BootThis.OptionalData = strings.TrimSpace(uefi.BootThis.OptionalData)
}
}

// deepCopyDoc returns a deep copy of a ComputeSystem via JSON round-trip.
func deepCopyDoc(doc *hcsschema.ComputeSystem) *hcsschema.ComputeSystem {
b, err := json.Marshal(doc)
if err != nil {
panic(fmt.Sprintf("failed to marshal ComputeSystem for deep copy: %v", err))
}
var copy hcsschema.ComputeSystem
if err := json.Unmarshal(b, &copy); err != nil {
panic(fmt.Sprintf("failed to unmarshal ComputeSystem for deep copy: %v", err))
}
return &copy
}

// isOnlyKernelCmdLineWhitespaceDiff returns true if the only difference between
// two documents is leading/trailing whitespace in the kernel command line.
// This is a known legacy quirk where initrd+KernelDirect boot produces a
// leading space that v2 correctly omits.
func isOnlyKernelCmdLineWhitespaceDiff(legacy, v2 *hcsschema.ComputeSystem) bool {
legacyCopy := deepCopyDoc(legacy)
v2Copy := deepCopyDoc(v2)
normalizeKernelCmdLine(legacyCopy)
normalizeKernelCmdLine(v2Copy)
return cmp.Diff(legacyCopy, v2Copy) == ""
}
Loading
Loading