From 6241f89f49820c193213b2d395bb09030409166d Mon Sep 17 00:00:00 2001 From: Zeling Feng Date: Fri, 16 Apr 2021 16:22:09 -0700 Subject: Include logs for packetimpact tests that are expected to fail PiperOrigin-RevId: 368938936 --- test/packetimpact/runner/dut.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'test/packetimpact/runner/dut.go') diff --git a/test/packetimpact/runner/dut.go b/test/packetimpact/runner/dut.go index b271bd47e..4fb2f5c4b 100644 --- a/test/packetimpact/runner/dut.go +++ b/test/packetimpact/runner/dut.go @@ -369,30 +369,32 @@ func TestWithDUT(ctx context.Context, t *testing.T, mkDevice func(*dockerutil.Co "--dut_infos_json", string(dutInfosBytes), ) testbenchLogs, err := testbenchContainer.Exec(ctx, dockerutil.ExecOpts{}, testArgs...) - if (err != nil) != expectFailure { - var dutLogs string - for i, dut := range duts { - logs, err := dut.Logs(ctx) - if err != nil { - logs = fmt.Sprintf("failed to fetch DUT logs: %s", err) - } - dutLogs = fmt.Sprintf(`%s====== Begin of DUT-%d Logs ====== + var dutLogs string + for i, dut := range duts { + logs, err := dut.Logs(ctx) + if err != nil { + logs = fmt.Sprintf("failed to fetch DUT logs: %s", err) + } + dutLogs = fmt.Sprintf(`%s====== Begin of DUT-%d Logs ====== %s ====== End of DUT-%d Logs ====== `, dutLogs, i, logs, i) - } - - t.Errorf(`test error: %v, expect failure: %t - + } + testLogs := fmt.Sprintf(` %s====== Begin of Testbench Logs ====== %s -====== End of Testbench Logs ======`, - err, expectFailure, dutLogs, testbenchLogs) +====== End of Testbench Logs ======`, dutLogs, testbenchLogs) + if (err != nil) != expectFailure { + t.Errorf(`test error: %v, expect failure: %t +%s`, err, expectFailure, testLogs) + } else if expectFailure { + t.Logf(`test failed as expected: %v +%s`, err, testLogs) } } -- cgit v1.2.3