@@ -270,7 +270,7 @@ func snapshotNet(t *testing.T) string {
270270 }
271271 section ("ip rule" , cmdOut (t , "ip" , "rule" , "show" ))
272272 section ("route main" , cmdOut (t , "ip" , "-4" , "route" , "show" ))
273- section ("route awl-table" , cmdOut (t , "ip" , "-4" , "route" , "show" , "table" , strconv . Itoa ( tableID ) ))
273+ section ("route awl-table" , routeTableDump (t , tableID ))
274274 section ("iptables filter" , cmdOut (t , "iptables" , "-S" ))
275275 section ("iptables nat" , cmdOut (t , "iptables" , "-t" , "nat" , "-S" ))
276276 return b .String ()
@@ -340,8 +340,28 @@ func mustCmd(t *testing.T, name string, args ...string) {
340340
341341func cmdOut (t * testing.T , name string , args ... string ) string {
342342 t .Helper ()
343- out , err := exec .Command (name , args ... ).Output ()
344- require .NoErrorf (t , err , "%s %s" , name , strings .Join (args , " " ))
343+ // CombinedOutput (not Output) so a failing command surfaces its stderr
344+ // diagnostic in the test log instead of a bare "exit status N". On success
345+ // these commands print nothing to stderr, so the captured value is unchanged.
346+ out , err := exec .Command (name , args ... ).CombinedOutput ()
347+ require .NoErrorf (t , err , "%s %s: %s" , name , strings .Join (args , " " ), out )
348+ return string (out )
349+ }
350+
351+ // routeTableDump returns the routes in the given table, tolerating the
352+ // "table does not exist" case. Newer iproute2/kernels (e.g. Ubuntu 24.04) make
353+ // `ip route show table <id>` fail with exit 2 ("FIB table does not exist") when
354+ // the table has never held a route, whereas older versions returned empty with
355+ // exit 0. Both mean the same thing here — an empty table — so normalise to "".
356+ func routeTableDump (t * testing.T , table int ) string {
357+ t .Helper ()
358+ out , err := exec .Command ("ip" , "-4" , "route" , "show" , "table" , strconv .Itoa (table )).CombinedOutput ()
359+ if err != nil {
360+ if strings .Contains (string (out ), "does not exist" ) {
361+ return ""
362+ }
363+ require .NoErrorf (t , err , "ip -4 route show table %d: %s" , table , out )
364+ }
345365 return string (out )
346366}
347367
0 commit comments