This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 374
/
qemu_ppc64le_test.go
85 lines (66 loc) · 1.84 KB
/
qemu_ppc64le_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2018 IBM
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"fmt"
"os/exec"
"regexp"
"strconv"
"testing"
govmmQemu "github.com/kata-containers/govmm/qemu"
"github.com/stretchr/testify/assert"
)
var qemuVersionArgs = "--version"
func newTestQemu(machineType string) qemuArch {
config := HypervisorConfig{
HypervisorMachineType: machineType,
}
return newQemuArch(config)
}
func TestQemuPPC64leCPUModel(t *testing.T) {
assert := assert.New(t)
ppc64le := newTestQemu(QemuPseries)
expectedOut := defaultCPUModel
model := ppc64le.cpuModel()
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)
memoryOffset := 1024
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)),
}
assert.Equal(expectedMemory, m)
}