mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-03 10:37:10 +00:00
runtime: Enable kata-check test on riscv64
Provide according tests to cover `kata-runtime` package, test `kata-runtime`'s `check` functionality on riscv64 platforms. Signed-off-by: Yuting Nie <nieyuting@iscas.ac.cn>
This commit is contained in:
parent
b6924ef5e5
commit
1f52f83309
@ -60,6 +60,9 @@ func kvmIsUsable() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func archHostCanCreateVMContainer(hypervisorType vc.HypervisorType) error {
|
func archHostCanCreateVMContainer(hypervisorType vc.HypervisorType) error {
|
||||||
|
if hypervisorType == "remote" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return kvmIsUsable()
|
return kvmIsUsable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
102
src/runtime/cmd/kata-runtime/kata-check_riscv64_test.go
Normal file
102
src/runtime/cmd/kata-runtime/kata-check_riscv64_test.go
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// Copyright (c) 2025 Institute of Software, CAS.
|
||||||
|
// Copyright (c) 2018 ARM Limited
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupCheckHostIsVMContainerCapable(assert *assert.Assertions, cpuInfoFile string, cpuData []testCPUData, moduleData []testModuleData) {
|
||||||
|
createModules(assert, cpuInfoFile, moduleData)
|
||||||
|
err := makeCPUInfoFile(cpuInfoFile, "", "")
|
||||||
|
assert.NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCCCheckCLIFunction(t *testing.T) {
|
||||||
|
var cpuData []testCPUData
|
||||||
|
moduleData := []testModuleData{
|
||||||
|
{filepath.Join(sysModuleDir, "kvm"), "", true},
|
||||||
|
{filepath.Join(sysModuleDir, "vhost"), "", true},
|
||||||
|
{filepath.Join(sysModuleDir, "vhost_net"), "", true},
|
||||||
|
}
|
||||||
|
|
||||||
|
genericCheckCLIFunction(t, cpuData, moduleData)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCPUDetails(t *testing.T) {
|
||||||
|
type testData struct {
|
||||||
|
contents string
|
||||||
|
expectedNormalizeVendor string
|
||||||
|
expectedNormalizeModel string
|
||||||
|
expectError bool
|
||||||
|
}
|
||||||
|
|
||||||
|
validVendorName := "0x0"
|
||||||
|
validModelName := "0x0"
|
||||||
|
validVendor := fmt.Sprintf(`%s : %s`, archCPUVendorField, validVendorName)
|
||||||
|
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},
|
||||||
|
{archCPUModelField, "", "", true},
|
||||||
|
{"", validVendorName, "", true},
|
||||||
|
{"", "", validModelName, true},
|
||||||
|
{validContents, validVendorName, validModelName, false},
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpdir := t.TempDir()
|
||||||
|
|
||||||
|
savedProcCPUInfo := procCPUInfo
|
||||||
|
|
||||||
|
testProcCPUInfo := filepath.Join(tmpdir, "cpuinfo")
|
||||||
|
|
||||||
|
// override
|
||||||
|
procCPUInfo = testProcCPUInfo
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
procCPUInfo = savedProcCPUInfo
|
||||||
|
}()
|
||||||
|
|
||||||
|
_, _, err := getCPUDetails()
|
||||||
|
// ENOENT
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.True(t, os.IsNotExist(err))
|
||||||
|
|
||||||
|
for _, d := range data {
|
||||||
|
err := createFile(procCPUInfo, d.contents)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
vendor, model, err := getCPUDetails()
|
||||||
|
|
||||||
|
if d.expectError {
|
||||||
|
assert.Error(t, err, fmt.Sprintf("%+v", d))
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
assert.NoError(t, err, fmt.Sprintf("%+v", d))
|
||||||
|
assert.Equal(t, d.expectedNormalizeVendor, vendor)
|
||||||
|
assert.Equal(t, d.expectedNormalizeModel, model)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetCPUtype(t *testing.T) {
|
||||||
|
testSetCPUTypeGeneric(t)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user