kata-containers/src/runtime/virtcontainers/qemu_ppc64le_test.go
Xynnn007 91bb6b7c34 runtime: add support for io.katacontainers.config.runtime.cc_init_data
io.katacontainers.config.runtime.cc_init_data specifies initdata used by
the pod in base64(gzip(initdata toml)) format. The initdata will be
encapsulated into an initdata image and mount it as a raw block device
to the guest.

The initdata image will be aligned with 512 bytes, which is chosen as a
usual sector size supported by different hypervisors like qemu, clh and
dragonball.

Note that this patch only adds support for qemu hypervisor.

Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
2025-04-15 16:35:59 +08:00

111 lines
2.7 KiB
Go

//go:build linux
// Copyright (c) 2018 IBM
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"fmt"
"testing"
govmmQemu "github.com/kata-containers/kata-containers/src/runtime/pkg/govmm/qemu"
"github.com/stretchr/testify/assert"
)
func newTestQemu(assert *assert.Assertions, machineType string) qemuArch {
config := HypervisorConfig{
HypervisorMachineType: machineType,
}
arch, err := newQemuArch(config)
assert.NoError(err)
return arch
}
func TestQemuPPC64leCPUModel(t *testing.T) {
assert := assert.New(t)
ppc64le := newTestQemu(assert, QemuPseries)
expectedOut := defaultCPUModel
model := ppc64le.cpuModel()
assert.Equal(expectedOut, model)
}
func TestQemuPPC64leMemoryTopology(t *testing.T) {
assert := assert.New(t)
ppc64le := newTestQemu(assert, QemuPseries)
memoryOffset := 1024
hostMem := uint64(1024)
mem := uint64(120)
slots := uint8(10)
m := ppc64le.memoryTopology(mem, hostMem, slots)
expectedMemory := govmmQemu.Memory{
Size: fmt.Sprintf("%dM", mem),
Slots: slots,
MaxMem: fmt.Sprintf("%dM", hostMem+uint64(memoryOffset)),
}
assert.Equal(expectedMemory, m)
}
func TestQemuPPC64leAppendProtectionDevice(t *testing.T) {
assert := assert.New(t)
ppc64le := newTestQemu(assert, QemuPseries)
var devices []govmmQemu.Device
var bios, firmware string
var err error
devices, bios, err = ppc64le.appendProtectionDevice(devices, firmware, "", []byte(nil))
assert.NoError(err)
//no protection
assert.Empty(bios)
//Secure Execution protection
ppc64le.(*qemuPPC64le).protection = seProtection
devices, bios, err = ppc64le.appendProtectionDevice(devices, firmware, "", []byte(nil))
assert.Error(err)
assert.Empty(bios)
//SEV protection
ppc64le.(*qemuPPC64le).protection = sevProtection
devices, bios, err = ppc64le.appendProtectionDevice(devices, firmware, "", []byte(nil))
assert.Error(err)
assert.Empty(bios)
//SNP protection
ppc64le.(*qemuPPC64le).protection = snpProtection
devices, bios, err = ppc64le.appendProtectionDevice(devices, firmware, "", []byte(nil))
assert.Error(err)
assert.Empty(bios)
//TDX protection
ppc64le.(*qemuPPC64le).protection = tdxProtection
devices, bios, err = ppc64le.appendProtectionDevice(devices, firmware, "", []byte(nil))
assert.Error(err)
assert.Empty(bios)
//PEF protection
ppc64le.(*qemuPPC64le).protection = pefProtection
devices, bios, err = ppc64le.appendProtectionDevice(devices, firmware, "", []byte(nil))
assert.NoError(err)
assert.Empty(bios)
expectedOut := []govmmQemu.Device{
govmmQemu.Object{
Driver: govmmQemu.SpaprTPMProxy,
Type: govmmQemu.PEFGuest,
ID: pefID,
DeviceID: tpmID,
File: tpmHostPath,
},
}
assert.Equal(expectedOut, devices)
}