From 35672b58960b54e27222468c7116f6e98c4f14ca Mon Sep 17 00:00:00 2001 From: Penny Zheng Date: Fri, 1 Mar 2019 10:32:34 +0800 Subject: [PATCH] unit-test: fix undefined struct field SupportVSocks on arm64 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: #1287 Signed-off-by: Penny Zheng --- cli/kata-env_amd64_test.go | 3 +- cli/kata-env_arm64_test.go | 86 ++---------------------------------- cli/kata-env_ppc64le_test.go | 3 +- cli/kata-env_test.go | 9 +++- 4 files changed, 15 insertions(+), 86 deletions(-) diff --git a/cli/kata-env_amd64_test.go b/cli/kata-env_amd64_test.go index 7d359ee2a..e58763be6 100644 --- a/cli/kata-env_amd64_test.go +++ b/cli/kata-env_amd64_test.go @@ -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) { diff --git a/cli/kata-env_arm64_test.go b/cli/kata-env_arm64_test.go index 0b0827f52..c2dcbb7be 100644 --- a/cli/kata-env_arm64_test.go +++ b/cli/kata-env_arm64_test.go @@ -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) { diff --git a/cli/kata-env_ppc64le_test.go b/cli/kata-env_ppc64le_test.go index fb0f28dca..81666f716 100644 --- a/cli/kata-env_ppc64le_test.go +++ b/cli/kata-env_ppc64le_test.go @@ -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) { diff --git a/cli/kata-env_test.go b/cli/kata-env_test.go index 4efdf51c6..cf4b0e889 100644 --- a/cli/kata-env_test.go +++ b/cli/kata-env_test.go @@ -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 @@ -269,7 +269,7 @@ func genericGetExpectedHostDetails(tmpdir string, expectedVendor string, expecte Architecture: expectedArch, Distro: expectedDistro, CPU: expectedCPU, - VMContainerCapable: false, + VMContainerCapable: expectedVMContainerCapable, SupportVSocks: vcUtils.SupportsVsocks(), } @@ -320,6 +320,11 @@ VERSION_ID="%s" } } + if goruntime.GOARCH == "arm64" { + expectedHostDetails.CPU.Vendor = "ARM Limited" + expectedHostDetails.CPU.Model = "v8" + } + return expectedHostDetails, nil }