From 40826b0557fc3af642236c427863d25239e7c620 Mon Sep 17 00:00:00 2001 From: Jay Zhuang Date: Fri, 17 Jul 2020 11:17:20 -0700 Subject: DUT logs in test failure messages in packetimpact DUT logs will include logs from the posix server and gVisor, which provides a way to instrument the DUT during test failures. PiperOrigin-RevId: 321816647 --- test/packetimpact/runner/packetimpact_test.go | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/packetimpact/runner/packetimpact_test.go b/test/packetimpact/runner/packetimpact_test.go index 1a99719c2..ff5f5c7f1 100644 --- a/test/packetimpact/runner/packetimpact_test.go +++ b/test/packetimpact/runner/packetimpact_test.go @@ -308,12 +308,29 @@ func TestOne(t *testing.T) { "--device", testNetDev, "--dut_type", *dutPlatform, ) - logs, err := testbench.Exec(ctx, dockerutil.ExecOpts{}, testArgs...) - if !*expectFailure && err != nil { - t.Fatalf("test failed: %v, logs from testbench:\n%s", err, logs) - } - if *expectFailure && err == nil { - t.Fatalf("test failure expected but the test succeeded, enable the test and mark the corresponding bug as fixed, logs from testbench:\n%s", logs) + testbenchLogs, err := testbench.Exec(ctx, dockerutil.ExecOpts{}, testArgs...) + if (err != nil) != *expectFailure { + var dutLogs string + if logs, err := dut.Logs(ctx); err != nil { + dutLogs = fmt.Sprintf("failed to fetch DUT logs: %s", err) + } else { + dutLogs = logs + } + + t.Errorf(`test error: %v, expect failure: %t + +====== Begin of DUT Logs ====== + +%s + +====== End of DUT Logs ====== + +====== Begin of Testbench Logs ====== + +%s + +====== End of Testbench Logs ======`, + err, *expectFailure, dutLogs, testbenchLogs) } } -- cgit v1.2.3