mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-07 08:24:23 +01:00
In Virt the vhost-user-block is an PCIe device so we need to make sure to consider it as well. We're keeping track of vhost-user-block devices and deduce the correct amount of PCIe root ports. Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
106 lines
2.0 KiB
Go
106 lines
2.0 KiB
Go
// Copyright (c) 2017 Intel Corporation
|
|
// Copyright (c) 2018 Huawei Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package manager
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kata-containers/kata-containers/src/runtime/pkg/device/config"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIsVFIO(t *testing.T) {
|
|
type testData struct {
|
|
path string
|
|
expected bool
|
|
}
|
|
|
|
data := []testData{
|
|
{"/dev/vfio/16", true},
|
|
{"/dev/vfio/1", true},
|
|
{"/dev/vfio/", false},
|
|
{"/dev/vfio", false},
|
|
{"/dev/vf", false},
|
|
{"/dev", false},
|
|
{"/dev/vfio/vfio", false},
|
|
{"/dev/vfio/vfio/12", false},
|
|
}
|
|
|
|
for _, d := range data {
|
|
isVFIO := IsVFIO(d.path)
|
|
assert.Equal(t, d.expected, isVFIO)
|
|
}
|
|
}
|
|
|
|
func TestIsBlock(t *testing.T) {
|
|
type testData struct {
|
|
devType string
|
|
expected bool
|
|
}
|
|
|
|
data := []testData{
|
|
{"b", true},
|
|
{"c", false},
|
|
{"u", false},
|
|
}
|
|
|
|
for _, d := range data {
|
|
isBlock := isBlock(config.DeviceInfo{DevType: d.devType})
|
|
assert.Equal(t, d.expected, isBlock)
|
|
}
|
|
}
|
|
|
|
func TestIsVhostUserBlk(t *testing.T) {
|
|
type testData struct {
|
|
devType string
|
|
major int64
|
|
expected bool
|
|
}
|
|
|
|
data := []testData{
|
|
{"b", config.VhostUserBlkMajor, true},
|
|
{"c", config.VhostUserBlkMajor, false},
|
|
{"b", config.VhostUserSCSIMajor, false},
|
|
{"c", config.VhostUserSCSIMajor, false},
|
|
{"b", 240, false},
|
|
}
|
|
|
|
for _, d := range data {
|
|
isVhostUserBlk := IsVhostUserBlk(
|
|
config.DeviceInfo{
|
|
DevType: d.devType,
|
|
Major: d.major,
|
|
})
|
|
assert.Equal(t, d.expected, isVhostUserBlk)
|
|
}
|
|
}
|
|
|
|
func TestIsVhostUserSCSI(t *testing.T) {
|
|
type testData struct {
|
|
devType string
|
|
major int64
|
|
expected bool
|
|
}
|
|
|
|
data := []testData{
|
|
{"b", config.VhostUserBlkMajor, false},
|
|
{"c", config.VhostUserBlkMajor, false},
|
|
{"b", config.VhostUserSCSIMajor, true},
|
|
{"c", config.VhostUserSCSIMajor, false},
|
|
{"b", 240, false},
|
|
}
|
|
|
|
for _, d := range data {
|
|
isVhostUserSCSI := isVhostUserSCSI(
|
|
config.DeviceInfo{
|
|
DevType: d.devType,
|
|
Major: d.major,
|
|
})
|
|
assert.Equal(t, d.expected, isVhostUserSCSI)
|
|
}
|
|
}
|