2018-11-18 19:01:52 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
|
|
func TestDevLinkGetPortByIndex(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 {
|
|
|
|
p, err2 := DevLinkGetPortByIndex(port.BusName, port.DeviceName, port.PortIndex)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Log(*p)
|
2021-04-03 06:59:20 +00:00
|
|
|
if p.Fn != nil {
|
|
|
|
t.Log("function attributes = " , *p.Fn)
|
|
|
|
}
|
2020-06-15 09:32:49 +00:00
|
|
|
}
|
|
|
|
}
|