mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-26 18:44:47 +01:00
Enable GPU device support in kata runtime, including GVT-g and GVT-d. GVT-g: graphic virtualization technology with mediated pass through GVT-d: graphic virtualization technology with direct pass through BDF of device eg "0000:00:1c.0" is used to distinguish GPU device in GVT-d, while sysfsdev of device eg "f79944e4-5a3d-11e8-99ce-479cbab002e4" is used in GVT-g. Fixes #542 Signed-off-by: Zhao Xinda <xinda.zhao@intel.com>
50 lines
1007 B
Go
50 lines
1007 B
Go
// Copyright (c) 2017-2018 Intel Corporation
|
|
// Copyright (c) 2018 Huawei Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package drivers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetVFIODetails(t *testing.T) {
|
|
type testData struct {
|
|
deviceStr string
|
|
expectedStr string
|
|
}
|
|
|
|
data := []testData{
|
|
{"0000:02:10.0", "02:10.0"},
|
|
{"0000:0210.0", ""},
|
|
{"f79944e4-5a3d-11e8-99ce-", ""},
|
|
{"f79944e4-5a3d-11e8-99ce", ""},
|
|
{"test", ""},
|
|
{"", ""},
|
|
}
|
|
|
|
for _, d := range data {
|
|
deviceBDF, deviceSysfsDev, vfioDeviceType, err := getVFIODetails(d.deviceStr, "")
|
|
|
|
switch vfioDeviceType {
|
|
case config.VFIODeviceNormalType:
|
|
assert.Equal(t, d.expectedStr, deviceBDF)
|
|
case config.VFIODeviceMediatedType:
|
|
assert.Equal(t, d.expectedStr, deviceSysfsDev)
|
|
default:
|
|
assert.NotNil(t, err)
|
|
}
|
|
|
|
if d.expectedStr == "" {
|
|
assert.NotNil(t, err)
|
|
} else {
|
|
assert.Nil(t, err)
|
|
}
|
|
}
|
|
}
|