mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-26 10:34:24 +01:00
Fixes #50 This is done for decoupling device management part from other parts. It seperate device.go to several dirs and files: ``` virtcontainers/device ├── api │ └── interface.go ├── config │ └── config.go ├── drivers │ ├── block.go │ ├── generic.go │ ├── utils.go │ ├── vfio.go │ ├── vhost_user_blk.go │ ├── vhost_user.go │ ├── vhost_user_net.go │ └── vhost_user_scsi.go └── manager ├── manager.go └── utils.go ``` * `api` contains interface definition of device management, so upper level caller should import and use the interface, and lower level should implement the interface. it's bridge to device drivers and callers. * `config` contains structed exported data. * `drivers` contains specific device drivers including block, vfio and vhost user devices. * `manager` exposes an external management package with a `DeviceManager`. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
56 lines
988 B
Go
56 lines
988 B
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/runtime/virtcontainers/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)
|
|
}
|
|
}
|