2018-11-18 19:01:52 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-04-03 09:27:23 +00:00
|
|
|
"flag"
|
2018-11-18 19:01:52 +00:00
|
|
|
)
|
|
|
|
|
2019-03-24 00:25:57 +00:00
|
|
|
func TestDevLinkGetDeviceList(t *testing.T) {
|
|
|
|
minKernelRequired(t, 4, 12)
|
|
|
|
setUpNetlinkTestWithKModule(t, "devlink")
|
|
|
|
_, err := DevLinkGetDeviceList()
|
2018-11-18 19:01:52 +00:00
|
|
|
if err != nil {
|
2019-03-24 00:25:57 +00:00
|
|
|
t.Fatal(err)
|
2018-11-18 19:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:25:57 +00:00
|
|
|
func TestDevLinkGetDeviceByName(t *testing.T) {
|
2018-11-18 19:01:52 +00:00
|
|
|
minKernelRequired(t, 4, 12)
|
|
|
|
setUpNetlinkTestWithKModule(t, "devlink")
|
2019-03-24 00:25:57 +00:00
|
|
|
_, err := DevLinkGetDeviceByName("foo", "bar")
|
2018-11-18 19:01:52 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2019-03-24 01:41:55 +00:00
|
|
|
|
|
|
|
func TestDevLinkSetEswitchMode(t *testing.T) {
|
|
|
|
minKernelRequired(t, 4, 12)
|
|
|
|
setUpNetlinkTestWithKModule(t, "devlink")
|
|
|
|
dev, err := DevLinkGetDeviceByName("foo", "bar")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = DevLinkSetEswitchMode(dev, "switchdev")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = DevLinkSetEswitchMode(dev, "legacy")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 09:05:23 +00:00
|
|
|
|
|
|
|
func TestDevLinkGetAllPortList(t *testing.T) {
|
|
|
|
minKernelRequired(t, 5, 4)
|
|
|
|
ports, err := DevLinkGetAllPortList()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Log("devlink port count = ", len(ports))
|
|
|
|
for _, port := range ports {
|
|
|
|
t.Log(*port)
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 09:32:49 +00:00
|
|
|
|
2021-04-03 09:27:23 +00:00
|
|
|
func TestDevLinkAddDelSfPort(t *testing.T) {
|
|
|
|
var addAttrs DevLinkPortAddAttrs
|
|
|
|
minKernelRequired(t, 5, 13)
|
|
|
|
if bus == "" || device == "" {
|
|
|
|
t.Log("devlink bus and device are empty, skipping test")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
dev, err := DevLinkGetDeviceByName(bus, device)
|
2020-06-15 09:32:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2021-04-03 09:27:23 +00:00
|
|
|
return
|
2020-06-15 09:32:49 +00:00
|
|
|
}
|
2021-04-03 09:27:23 +00:00
|
|
|
addAttrs.SfNumberValid = true
|
|
|
|
addAttrs.SfNumber = uint32(sfnum)
|
|
|
|
addAttrs.PfNumber = 0
|
|
|
|
port, err2 := DevLinkPortAdd(dev.BusName, dev.DeviceName, 7, addAttrs)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Fatal(err2)
|
|
|
|
return
|
2020-06-15 09:32:49 +00:00
|
|
|
}
|
2021-04-03 09:27:23 +00:00
|
|
|
t.Log(*port)
|
|
|
|
if port.Fn != nil {
|
|
|
|
t.Log("function attributes = " , *port.Fn)
|
|
|
|
}
|
|
|
|
err2 = DevLinkPortDel(dev.BusName, dev.DeviceName, port.PortIndex)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Fatal(err2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var bus string
|
|
|
|
var device string
|
|
|
|
var sfnum uint
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&bus, "bus", "", "devlink device bus name")
|
|
|
|
flag.StringVar(&device, "device", "", "devlink device devicename")
|
|
|
|
flag.UintVar(&sfnum, "sfnum", 0, "devlink port sfnumber")
|
2020-06-15 09:32:49 +00:00
|
|
|
}
|