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

Commit

Permalink
test: add unit test for func MaxQemuVCPUs
Browse files Browse the repository at this point in the history
we should add unit test for func MaxQemuVCPUS in qemu_amd64_test.go

Signed-off-by: Penny Zheng <[email protected]>
Signed-off-by: Wei Chen <[email protected]>
  • Loading branch information
Pennyzct committed Aug 27, 2018
1 parent a14cf06 commit d145535
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions virtcontainers/qemu_arm64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ package virtcontainers

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

govmmQemu "github.com/intel/govmm/qemu"
Expand Down Expand Up @@ -50,3 +54,53 @@ func TestQemuArm64MemoryTopology(t *testing.T) {
m := arm64.memoryTopology(mem, hostMem)
assert.Equal(expectedMemory, m)
}

func TestMaxQemuVCPUs(t *testing.T) {
assert := assert.New(t)

type testData struct {
contents string
expectedResult uint32
}

data := []testData{
{"", uint32(runtime.NumCPU())},
{" 1: 0 0 GICv2 25 Level vgic \n", uint32(8)},
{" 1: 0 0 GICv3 25 Level vgic \n", uint32(123)},
{" 1: 0 0 GICv4 25 Level vgic \n", uint32(123)},
}

tmpdir, err := ioutil.TempDir("", "")
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpdir)

savedGicProfile := gicProfile

testGicProfile := filepath.Join(tmpdir, "interrupts")

// override
gicProfile = testGicProfile

defer func() {
gicProfile = savedGicProfile
}()

savedHostGICVersion := hostGICVersion

defer func() {
hostGICVersion = savedHostGICVersion
}()

for _, d := range data {
err := ioutil.WriteFile(gicProfile, []byte(d.contents), os.FileMode(0640))
assert.NoError(err)

hostGICVersion = getHostGICVersion()
vCPUs := MaxQemuVCPUs()

assert.Equal(d.expectedResult, vCPUs)
}

}

0 comments on commit d145535

Please sign in to comment.