| // Copyright 2020 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package crash |
| |
| import ( |
| "context" |
| "os" |
| "time" |
| |
| "github.com/google/go-cmp/cmp" |
| "github.com/google/go-cmp/cmp/cmpopts" |
| |
| "chromiumos/tast/local/crash" |
| "chromiumos/tast/testing" |
| ) |
| |
| func init() { |
| testing.AddTest(&testing.Test{ |
| Func: SenderOld, |
| Desc: "Check that old minidump crashes are uploaded", |
| Contacts: []string{ |
| "mutexlox@chromium.org", |
| "iby@chromium.org", |
| "cros-telemetry@google.com", |
| "nya@chromium.org", // ported to Tast |
| }, |
| Attr: []string{"group:mainline"}, |
| // We only care about crash_sender on internal builds. |
| SoftwareDeps: []string{"cros_internal"}, |
| }) |
| } |
| |
| func SenderOld(ctx context.Context, s *testing.State) { |
| if err := crash.SetUpCrashTest(ctx, crash.FilterCrashes(crash.FilterInIgnoreAllCrashes), crash.WithMockConsent()); err != nil { |
| s.Fatal("Setup failed: ", err) |
| } |
| defer crash.TearDownCrashTest(ctx) |
| |
| const basename = "some_program.1.2.3.4" |
| exp, err := crash.AddFakeMinidumpCrash(ctx, basename) |
| if err != nil { |
| s.Fatal("Failed to add a fake minidump crash: ", err) |
| } |
| |
| // Change timestamps to pretend that crash dumps were generated 25 hours ago. |
| ts := time.Now().Add(-25 * time.Hour) |
| for _, fp := range []string{exp.MetadataPath, exp.PayloadPath} { |
| if err := os.Chtimes(fp, ts, ts); err != nil { |
| s.Fatal("Failed to change file timestamp: ", err) |
| } |
| } |
| |
| got, err := crash.RunSender(ctx) |
| if err != nil { |
| s.Fatal("Failed to run crash_sender: ", err) |
| } |
| want := []*crash.SendResult{{ |
| Success: true, |
| Data: *exp, |
| }} |
| if diff := cmp.Diff(got, want, cmpopts.IgnoreFields(crash.SendResult{}, "Schedule")); diff != "" { |
| s.Log("Results mismatch (-got +want): ", diff) |
| s.Errorf("crash_sender sent unexpected %d results; see logs for diff", len(got)) |
| } |
| } |