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

Commit

Permalink
ppc64le: kata-env fails due to missing vendor field
Browse files Browse the repository at this point in the history
There is no vendor field in /proc/cpuinfo contents
on ppc64le. Make sure to return "" for vendor field
for ppc64le and fix all the corresponding testcases
as well.

Fixes: #864

Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com
  • Loading branch information
nitkon committed Nov 27, 2018
1 parent 6d17e27 commit ca58bb4
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 41 deletions.
31 changes: 30 additions & 1 deletion cli/kata-check_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -488,8 +489,36 @@ func TestKvmIsUsable(t *testing.T) {
assert.Error(err)
}

type TestDataa struct {
contents string
expectedVendor string
expectedModel string
expectError bool
}

func TestGetCPUDetails(t *testing.T) {
genericTestGetCPUDetails(t)
const validVendorName = "a vendor"
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)

const validModelName = "some CPU model"
validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName)

validContents := fmt.Sprintf(`
a : b
%s
foo : bar
%s
`, validVendor, validModel)

data := []TestDataa{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
{validVendor, "", "", true},
{validModel, "", "", true},
{validContents, validVendorName, validModelName, false},
}
genericTestGetCPUDetails(t, validVendor, validModel, validContents, data)
}

func TestSetCPUtype(t *testing.T) {
Expand Down
12 changes: 9 additions & 3 deletions cli/kata-check_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (

const (
cpuFlagsTag = genericCPUFlagsTag
archCPUVendorField = genericCPUVendorField
archCPUModelField = genericCPUModelField
archCPUVendorField = ""
archCPUModelField = "model"
)

var (
ppc64CpuCmd = "ppc64_cpu"
smtStatusOption = "--smt"
_ = genericCPUVendorField
_ = genericCPUModelField
)

// archRequiredCPUFlags maps a CPU flag value to search for and a
Expand Down Expand Up @@ -94,7 +96,11 @@ func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
}

func getCPUDetails() (vendor, model string, err error) {
return genericGetCPUDetails()
vendor, model, err = genericGetCPUDetails()
if err == nil {
model = "POWER8"
}
return vendor, model, err
}

func isSMTOff() bool {
Expand Down
33 changes: 32 additions & 1 deletion cli/kata-check_ppc64le_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -207,8 +208,38 @@ func TestKvmIsUsable(t *testing.T) {
assert.Error(err)
}

type TestDataa struct {
contents string
expectedVendor string
expectedModel string
expectError bool
}

func TestGetCPUDetails(t *testing.T) {
genericTestGetCPUDetails(t)

const validVendorName = ""
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)

const validModelName = "POWER8"
validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName)

validContents := fmt.Sprintf(`
a : b
%s
foo : bar
%s
`, validVendor, validModel)

data := []TestDataa{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
{validVendor, "", "", true},
{validModel, "", validModelName, false},
{validContents, validVendorName, validModelName, false},
}

genericTestGetCPUDetails(t, validVendor, validModel, validContents, data)
}

func TestSetCPUtype(t *testing.T) {
Expand Down
31 changes: 1 addition & 30 deletions cli/kata-check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,36 +137,7 @@ func makeCPUInfoFile(path, vendorID, flags string) error {
return ioutil.WriteFile(path, contents.Bytes(), testFileMode)
}

func genericTestGetCPUDetails(t *testing.T) {
type testData struct {
contents string
expectedVendor string
expectedModel string
expectError bool
}

const validVendorName = "a vendor"
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)

const validModelName = "some CPU model"
validModel := fmt.Sprintf(`%s : %s`, archCPUModelField, validModelName)

validContents := fmt.Sprintf(`
a : b
%s
foo : bar
%s
`, validVendor, validModel)

data := []testData{
{"", "", "", true},
{"invalid", "", "", true},
{archCPUVendorField, "", "", true},
{validVendor, "", "", true},
{validModel, "", "", true},
{validContents, validVendorName, validModelName, false},
}

func genericTestGetCPUDetails(t *testing.T, validVendor string, validModel string, validContents string, data []TestDataa) {
tmpdir, err := ioutil.TempDir("", "")
if err != nil {
panic(err)
Expand Down
4 changes: 3 additions & 1 deletion cli/kata-env_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
)

func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
return genericGetExpectedHostDetails(tmpdir)
expectedVendor := "moi"
expectedModel := "awesome XI"
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel)
}

func TestEnvGetEnvInfoSetsCPUType(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion cli/kata-env_ppc64le_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ package main
import "testing"

func getExpectedHostDetails(tmpdir string) (HostInfo, error) {
return genericGetExpectedHostDetails(tmpdir)
expectedVendor := ""
expectedModel := "POWER8"
return genericGetExpectedHostDetails(tmpdir, expectedVendor, expectedModel)
}

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

func genericGetExpectedHostDetails(tmpdir string) (HostInfo, error) {
func genericGetExpectedHostDetails(tmpdir string, expectedVendor string, expectedModel string) (HostInfo, error) {
type filesToCreate struct {
file string
contents string
Expand All @@ -194,8 +194,8 @@ func genericGetExpectedHostDetails(tmpdir string) (HostInfo, error) {
}

expectedCPU := CPUInfo{
Vendor: "moi",
Model: "awesome XI",
Vendor: expectedVendor,
Model: expectedModel,
}

expectedHostDetails := HostInfo{
Expand Down
2 changes: 1 addition & 1 deletion cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func genericGetCPUDetails() (vendor, model string, err error) {
}
}

if vendor == "" {
if archCPUVendorField != "" && vendor == "" {
return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo)
}

Expand Down

0 comments on commit ca58bb4

Please sign in to comment.