Skip to content

Commit

Permalink
unit-test: fix undefined struct field SupportVSocks on arm64
Browse files Browse the repository at this point in the history
Since arch-specific func getExpectedHostDetails holds undefined struct
field SupportVSocks on arm64, unit test TestEnvGetEnvInfoSetsCPUType,
TestEnvGetHostInfo and so on failed.
I'm trying to use generic func genericgetExpectedHostDetails on arm64
to avoid similar issues.

Fixes: kata-containers#1287

Signed-off-by: Penny Zheng <[email protected]>
  • Loading branch information
Pennyzct committed Mar 1, 2019
1 parent 6f2597e commit cc66ada
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 86 deletions.
3 changes: 2 additions & 1 deletion cli/kata-env_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
expectedVendor := "moi"
expectedModel := "awesome XI"
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel)
expectedVMContainerCapable := false
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel, expectedVMContainerCapable)
}

func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {
Expand Down
86 changes: 4 additions & 82 deletions cli/kata-env_arm64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,14 @@
package main

import (
"fmt"
"path/filepath"
goruntime "runtime"
"testing"
)

func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
type filesToCreate struct {
file string
contents string
}

const expectedKernelVersion = "99.1"
const expectedArch = goruntime.GOARCH

expectedDistro := DistroInfo{
Name: "Foo",
Version: "42",
}

expectedCPU := CPUInfo{
Vendor: "0x41",
Model: "8",
}

expectedNormalizeCPU := CPUInfo{
Vendor: "ARM Limited",
Model: "v8",
}

expectedHostDetails := HostInfo{
Kernel: expectedKernelVersion,
Architecture: expectedArch,
Distro: expectedDistro,
CPU: expectedNormalizeCPU,
VMContainerCapable: true,
}

testProcCPUInfo := filepath.Join(tmpdir, "cpuinfo")
testOSRelease := filepath.Join(tmpdir, "os-release")

// XXX: This file is *NOT* created by this function on purpose
// (to ensure the only file checked by the tests is
// testOSRelease). osReleaseClr handling is tested in
// utils_test.go.
testOSReleaseClr := filepath.Join(tmpdir, "os-release-clr")

testProcVersion := filepath.Join(tmpdir, "proc-version")

// override
procVersion = testProcVersion
osRelease = testOSRelease
osReleaseClr = testOSReleaseClr
procCPUInfo = testProcCPUInfo

procVersionContents := fmt.Sprintf("Linux version %s a b c",
expectedKernelVersion)

osReleaseContents := fmt.Sprintf(`
NAME="%s"
VERSION_ID="%s"
`, expectedDistro.Name, expectedDistro.Version)

procCPUInfoContents := fmt.Sprintf(`
%s : %s
%s : %s
`,
archCPUVendorField,
expectedCPU.Vendor,
archCPUModelField,
expectedCPU.Model)

data := []filesToCreate{
{procVersion, procVersionContents},
{osRelease, osReleaseContents},
{procCPUInfo, procCPUInfoContents},
}

for _, d := range data {
err := createFile(d.file, d.contents)
if err != nil {
return HostInfo{}, err
}
}

return expectedHostDetails, nil
expectedVendor := "0x41"
expectedModel := "8"
expectedVMContainerCapable := true
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel, expectedVMContainerCapable)
}

func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion cli/kata-env_ppc64le_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import "testing"
func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
expectedVendor := ""
expectedModel := "POWER8"
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel)
expectedVMContainerCapable := false
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel, expectedVMContainerCapable)
}

func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {
Expand Down
9 changes: 7 additions & 2 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func getExpectedAgentDetails(config oci.RuntimeConfig) (AgentInfo, error) {
}

// nolint: unused
func genericGetExpectedHostDetails(tmpdir string, expectedVendor string, expectedModel string) (HostInfo, error) {
func genericGetExpectedHostDetails(tmpdir string, expectedVendor string, expectedModel string, expectedVMContainerCapable bool) (HostInfo, error) {
type filesToCreate struct {
file string
contents string
Expand All @@ -269,7 +269,7 @@ func genericGetExpectedHostDetails(tmpdir string, expectedVendor string, expecte
Architecture: expectedArch,
Distro: expectedDistro,
CPU: expectedCPU,
VMContainerCapable: false,
VMContainerCapable: expectedVMContainerCapable,
SupportVSocks: vcUtils.SupportsVsocks(),
}

Expand Down Expand Up @@ -320,6 +320,11 @@ VERSION_ID="%s"
}
}

if goruntime.GOARCH == "arm64" {
expectedHostDetails.CPU.Vendor = normalizeArmVendor(expectedVendor)
expectedHostDetails.CPU.Model = normalizeArmModel(expectedModel)
}

return expectedHostDetails, nil
}

Expand Down

0 comments on commit cc66ada

Please sign in to comment.