Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
vc:Execute TestQemuPPC64leMemoryTopology depending on qemu version
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nitkon committed May 20, 2019
1 parent 3d4729d commit f7cc028
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion virtcontainers/qemu_ppc64le_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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)
}

0 comments on commit f7cc028

Please sign in to comment.