Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/kata-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ const (
kernelPropertyCorrect = "Kernel property value correct"

// these refer to fields in the procCPUINFO file
genericCPUFlagsTag = "flags"
genericCPUVendorField = "vendor_id"
genericCPUModelField = "model name"
genericCPUFlagsTag = "flags" // nolint: varcheck,unused
genericCPUVendorField = "vendor_id" // nolint: varcheck,unused
genericCPUModelField = "model name" // nolint: varcheck,unused
)

// variables rather than consts to allow tests to modify them
Expand Down
4 changes: 2 additions & 2 deletions cli/kata-check_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func TestKvmIsUsable(t *testing.T) {
assert.Error(err)
}

type TestDataa struct {
type TestData struct {
contents string
expectedVendor string
expectedModel string
Expand All @@ -505,7 +505,7 @@ foo : bar
%s
`, validVendor, validModel)

data := []TestDataa{
data := []TestData{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
Expand Down
10 changes: 5 additions & 5 deletions cli/kata-check_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ func normalizeArmModel(model string) string {
return model
}

func getCPUDetails() (vendor, model string, err error) {
if vendor, model, err := genericGetCPUDetails(); err == nil {
func getCPUDetails() (string, string, error) {
vendor, model, err := genericGetCPUDetails()
if err == nil {
vendor = normalizeArmVendor(vendor)
model = normalizeArmModel(model)
return vendor, model, err
} else {
return vendor, model, err
}

return vendor, model, err
}
48 changes: 33 additions & 15 deletions cli/kata-check_arm64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,27 @@ import (
"github.com/urfave/cli"
)

func setupCheckHostIsVMContainerCapable(assert *assert.Assertions, cpuInfoFile string, moduleData []testModuleData) {
//For now, Arm64 only deal with module check
func setupCheckHostIsVMContainerCapable(assert *assert.Assertions, cpuInfoFile string, cpuData []testCPUData, moduleData []testModuleData) {
createModules(assert, cpuInfoFile, moduleData)

err := makeCPUInfoFile(cpuInfoFile, "", "")
assert.NoError(err)
for _, d := range cpuData {
err := makeCPUInfoFile(cpuInfoFile, d.vendorID, d.flags)
assert.NoError(err)

details := vmContainerCapableDetails{
cpuInfoFile: cpuInfoFile,
requiredCPUFlags: archRequiredCPUFlags,
requiredCPUAttribs: archRequiredCPUAttribs,
requiredKernelModules: archRequiredKernelModules,
}

err = hostIsVMContainerCapable(details)
if d.expectError {
assert.Error(err)
} else {
assert.NoError(err)
}
}
}

func TestCCCheckCLIFunction(t *testing.T) {
Expand Down Expand Up @@ -55,6 +69,10 @@ func TestCCCheckCLIFunction(t *testing.T) {
t.Fatal(err)
}

cpuData := []testCPUData{
{"", "", false},
}

moduleData := []testModuleData{
{filepath.Join(sysModuleDir, "kvm"), true, ""},
{filepath.Join(sysModuleDir, "vhost"), true, ""},
Expand All @@ -74,7 +92,7 @@ func TestCCCheckCLIFunction(t *testing.T) {
kataLog.Logger.Out = savedLogOutput
}()

setupCheckHostIsVMContainerCapable(assert, cpuInfoFile, moduleData)
setupCheckHostIsVMContainerCapable(assert, cpuInfoFile, cpuData, moduleData)

ctx := createCLIContext(nil)
ctx.App.Name = "foo"
Expand Down Expand Up @@ -126,16 +144,16 @@ func TestKvmIsUsable(t *testing.T) {
assert.Error(err)
}

func TestGetCPUDetails(t *testing.T) {
type testData struct {
contents string
expectedVendor string
expectedModel string
expectedNormalizeVendor string
expectedNormalizeModel string
expectError bool
}
type TestData struct {
contents string
expectedVendor string
expectedModel string
expectedNormalizeVendor string
expectedNormalizeModel string
expectError bool
}

func TestGetCPUDetails(t *testing.T) {
const validVendorName = "0x41"
const validNormalizeVendorName = "ARM Limited"
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
Expand All @@ -151,7 +169,7 @@ foo : bar
%s
`, validVendor, validModel)

data := []testData{
data := []TestData{
{"", "", "", "", "", true},
{"invalid", "", "", "", "", true},
{archCPUVendorField, "", "", "", "", true},
Expand Down
4 changes: 2 additions & 2 deletions cli/kata-check_ppc64le_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestKvmIsUsable(t *testing.T) {
assert.Error(err)
}

type TestDataa struct {
type TestData struct {
contents string
expectedVendor string
expectedModel string
Expand All @@ -230,7 +230,7 @@ foo : bar
%s
`, validVendor, validModel)

data := []TestDataa{
data := []TestData{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
Expand Down
4 changes: 2 additions & 2 deletions cli/kata-check_s390x_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestKvmIsUsable(t *testing.T) {
assert.Error(err)
}

type TestDataa struct {
type TestData struct {
contents string
expectedVendor string
expectedModel string
Expand Down Expand Up @@ -235,7 +235,7 @@ foo : bar
%s
`, validVendor, validModel)

data := []TestDataa{
data := []TestData{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
Expand Down
3 changes: 2 additions & 1 deletion cli/kata-check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func makeCPUInfoFile(path, vendorID, flags string) error {
return ioutil.WriteFile(path, contents.Bytes(), testFileMode)
}

func genericTestGetCPUDetails(t *testing.T, validVendor string, validModel string, validContents string, data []TestDataa) {
// nolint: unused
func genericTestGetCPUDetails(t *testing.T, validVendor string, validModel string, validContents string, data []TestData) {
tmpdir, err := ioutil.TempDir("", "")
if err != nil {
panic(err)
Expand Down
1 change: 1 addition & 0 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func getExpectedAgentDetails(config oci.RuntimeConfig) (AgentInfo, error) {
}, nil
}

// nolint: unused
func genericGetExpectedHostDetails(tmpdir string, expectedVendor string, expectedModel string) (HostInfo, error) {
type filesToCreate struct {
file string
Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ func (q *qemu) resizeMemory(reqMemMB uint32, memoryBlockSizeMB uint32) (uint32,
}

// genericAppendBridges appends to devices the given bridges
// nolint: unused
func genericAppendBridges(devices []govmmQemu.Device, bridges []types.PCIBridge, machineType string) []govmmQemu.Device {
bus := defaultPCBridgeBus
switch machineType {
Expand Down Expand Up @@ -1437,6 +1438,7 @@ func genericAppendBridges(devices []govmmQemu.Device, bridges []types.PCIBridge,
return devices
}

// nolint: unused
func genericBridges(number uint32, machineType string) []types.PCIBridge {
var bridges []types.PCIBridge
var bt types.PCIType
Expand Down Expand Up @@ -1469,6 +1471,7 @@ func genericBridges(number uint32, machineType string) []types.PCIBridge {
return bridges
}

// nolint: unused
func genericMemoryTopology(memoryMb, hostMemoryMb uint64, slots uint8, memoryOffset uint32) govmmQemu.Memory {
// image NVDIMM device needs memory space 1024MB
// See https://github.com/clearcontainers/runtime/issues/380
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/qemu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const defaultQemuMachineType = QemuVirt
var defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=" + getGuestGICVersion()

// Not used
const defaultPCBridgeBus = ""
const defaultPCBridgeBus = "" // nolint: unused

var qemuPaths = map[string]string{
QemuVirt: defaultQemuPath,
Expand Down
9 changes: 5 additions & 4 deletions virtcontainers/qemu_arm64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newTestQemu(machineType string) qemuArch {

func TestQemuArm64CPUModel(t *testing.T) {
assert := assert.New(t)
arm64 := newTestQemu(virt)
arm64 := newTestQemu(QemuVirt)

expectedOut := defaultCPUModel
model := arm64.cpuModel()
Expand All @@ -40,18 +40,19 @@ func TestQemuArm64CPUModel(t *testing.T) {

func TestQemuArm64MemoryTopology(t *testing.T) {
assert := assert.New(t)
arm64 := newTestQemu(virt)
arm64 := newTestQemu(QemuVirt)
memoryOffset := 1024

hostMem := uint64(1024)
mem := uint64(120)
slots := uint8(10)
expectedMemory := govmmQemu.Memory{
Size: fmt.Sprintf("%dM", mem),
Slots: defaultMemSlots,
Slots: slots,
MaxMem: fmt.Sprintf("%dM", hostMem+uint64(memoryOffset)),
}

m := arm64.memoryTopology(mem, hostMem)
m := arm64.memoryTopology(mem, hostMem, slots)
assert.Equal(expectedMemory, m)
}

Expand Down