mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 17:22:33 +00:00
vc:Execute TestQemuPPC64leMemoryTopology depending on qemu version
Set qemu major/minor version when running unit test TestQemuPPC64leMemoryTopology on ppc64le & execute the unit test accordingly. Fixes: #1308 Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com
This commit is contained in:
parent
3d4729d6b2
commit
f7cc028891
@ -7,12 +7,17 @@ package virtcontainers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
govmmQemu "github.com/intel/govmm/qemu"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var qemuVersionArgs = "--version"
|
||||
|
||||
func newTestQemu(machineType string) qemuArch {
|
||||
config := HypervisorConfig{
|
||||
HypervisorMachineType: machineType,
|
||||
@ -34,6 +39,31 @@ func TestQemuPPC64leCPUModel(t *testing.T) {
|
||||
assert.Equal(expectedOut, model)
|
||||
}
|
||||
|
||||
func getQemuVersion() (qemuMajorVersion int, qemuMinorVersion int) {
|
||||
|
||||
cmd := exec.Command(defaultQemuPath, qemuVersionArgs)
|
||||
additionalEnv := "LANG=C"
|
||||
cmd.Env = append(cmd.Env, additionalEnv)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Could not execute command %s %s", defaultQemuPath, qemuVersionArgs)
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
re := regexp.MustCompile("[0-9]+")
|
||||
qVer := re.FindAllString(string(out), -1)
|
||||
|
||||
qMajor, err := strconv.Atoi(qVer[0])
|
||||
qMinor, err1 := strconv.Atoi(qVer[1])
|
||||
|
||||
if err != nil || err1 != nil {
|
||||
err = fmt.Errorf("Could not convert string to int")
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
return qMajor, qMinor
|
||||
}
|
||||
|
||||
func TestQemuPPC64leMemoryTopology(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
ppc64le := newTestQemu(QemuPseries)
|
||||
@ -42,12 +72,19 @@ func TestQemuPPC64leMemoryTopology(t *testing.T) {
|
||||
hostMem := uint64(1024)
|
||||
mem := uint64(120)
|
||||
slots := uint8(10)
|
||||
|
||||
qemuMajorVersion, qemuMinorVersion = getQemuVersion()
|
||||
m := ppc64le.memoryTopology(mem, hostMem, slots)
|
||||
|
||||
if qemuMajorVersion <= 2 && qemuMinorVersion < 10 {
|
||||
hostMem = uint64(defaultMemMaxPPC64le)
|
||||
}
|
||||
|
||||
expectedMemory := govmmQemu.Memory{
|
||||
Size: fmt.Sprintf("%dM", mem),
|
||||
Slots: slots,
|
||||
MaxMem: fmt.Sprintf("%dM", hostMem+uint64(memoryOffset)),
|
||||
}
|
||||
|
||||
m := ppc64le.memoryTopology(mem, hostMem, slots)
|
||||
assert.Equal(expectedMemory, m)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user