From 40e139bb96690e895bdad154038e86553f2bfdd8 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 24 Oct 2023 13:14:21 +0200 Subject: [PATCH] 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. --- link_test.go | 46 +++++++++++++++++++++++----------------------- netlink_test.go | 7 +++++++ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/link_test.go b/link_test.go index e70c254..c1d1255 100644 --- a/link_test.go +++ b/link_test.go @@ -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) { diff --git a/netlink_test.go b/netlink_test.go index 43a061c..d203301 100644 --- a/netlink_test.go +++ b/netlink_test.go @@ -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()) +}