Enable extended error message reporting in tests

This causes the NETLINK_EXT_ACK socket option to be set and extended
error messages to be reported in errors. This should help debug test
failures.

Also use errors.Is to check for errors because using extended error
reporting, the errors no longer match exactly.
This commit is contained in:
Tobias Klauser 2023-10-24 13:14:21 +02:00 committed by Alessandro Boch
parent a4fcbb7aeb
commit 40e139bb96
2 changed files with 30 additions and 23 deletions

View File

@ -2048,7 +2048,7 @@ func TestLinkXdp(t *testing.T) {
if err := LinkSetXdpFd(testXdpLink, fd); err != nil {
t.Fatal(err)
}
if err := LinkSetXdpFdWithFlags(testXdpLink, fd, nl.XDP_FLAGS_UPDATE_IF_NOEXIST); err != unix.EBUSY {
if err := LinkSetXdpFdWithFlags(testXdpLink, fd, nl.XDP_FLAGS_UPDATE_IF_NOEXIST); !errors.Is(err, unix.EBUSY) {
t.Fatal(err)
}
if err := LinkSetXdpFd(testXdpLink, -1); err != nil {
@ -2161,33 +2161,33 @@ func TestLinkSetGSOMaxSize(t *testing.T) {
}
func TestLinkSetGSOMaxSegs(t *testing.T) {
minKernelRequired(t, 5, 19)
tearDown := setUpNetlinkTest(t)
defer tearDown()
minKernelRequired(t, 5, 19)
tearDown := setUpNetlinkTest(t)
defer tearDown()
iface := &Veth{LinkAttrs: LinkAttrs{Name: "foo", TxQLen: testTxQLen, MTU: 1500}, PeerName: "bar"}
if err := LinkAdd(iface); err != nil {
t.Fatal(err)
}
iface := &Veth{LinkAttrs: LinkAttrs{Name: "foo", TxQLen: testTxQLen, MTU: 1500}, PeerName: "bar"}
if err := LinkAdd(iface); err != nil {
t.Fatal(err)
}
link, err := LinkByName("foo")
if err != nil {
t.Fatal(err)
}
link, err := LinkByName("foo")
if err != nil {
t.Fatal(err)
}
err = LinkSetGSOMaxSegs(link, 16)
if err != nil {
t.Fatal(err)
}
err = LinkSetGSOMaxSegs(link, 16)
if err != nil {
t.Fatal(err)
}
link, err = LinkByName("foo")
if err != nil {
t.Fatal(err)
}
link, err = LinkByName("foo")
if err != nil {
t.Fatal(err)
}
if link.Attrs().GSOMaxSegs != 16 {
t.Fatalf("GSO max segments was not modified")
}
if link.Attrs().GSOMaxSegs != 16 {
t.Fatalf("GSO max segments was not modified")
}
}
func TestLinkSetGROMaxSize(t *testing.T) {

View File

@ -1,3 +1,4 @@
//go:build linux
// +build linux
package netlink
@ -15,6 +16,7 @@ import (
"strings"
"testing"
"github.com/vishvananda/netlink/nl"
"github.com/vishvananda/netns"
"golang.org/x/sys/unix"
)
@ -214,3 +216,8 @@ func KernelVersion() (kernel, major int, err error) {
}
return
}
func TestMain(m *testing.M) {
nl.EnableErrorMessageReporting = true
os.Exit(m.Run())
}