tast-tests: Check histogram counts in crostini.FsCorruption

This is what we actually want to check for, and not doing so concealed
that the DBus signal wasn't being received by chrome.

BUG=chromium:1018093
TEST=Ran test

Cq-Depend: 2072198, 2071442
Change-Id: Ib1f1768707eb7d8efc6473d98fb6c0ecd218c87e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/tast-tests/+/2072197
Reviewed-by: Nic Hollingum <hollingum@google.com>
Reviewed-by: Miriam Zimmerman <mutexlox@chromium.org>
Reviewed-by: Shuhei Takahashi <nya@chromium.org>
Commit-Queue: Fergus Dall <sidereal@google.com>
Tested-by: Fergus Dall <sidereal@google.com>
(cherry picked from commit 599543ac978ffc4bfc84a87d76297a07fd3b4841)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/tast-tests/+/2081554
Reviewed-by: Fergus Dall <sidereal@google.com>
diff --git a/src/chromiumos/tast/local/bundles/cros/crostini/fs_corruption.go b/src/chromiumos/tast/local/bundles/cros/crostini/fs_corruption.go
index 001b4f3..64bae16 100644
--- a/src/chromiumos/tast/local/bundles/cros/crostini/fs_corruption.go
+++ b/src/chromiumos/tast/local/bundles/cros/crostini/fs_corruption.go
@@ -15,6 +15,8 @@
 	"github.com/godbus/dbus"
 
 	"chromiumos/tast/errors"
+	"chromiumos/tast/local/chrome"
+	"chromiumos/tast/local/chrome/metrics"
 	"chromiumos/tast/local/crash"
 	"chromiumos/tast/local/crostini"
 	"chromiumos/tast/local/dbusutil"
@@ -36,6 +38,7 @@
 	anomalyEventServicePath              = dbus.ObjectPath("/org/chromium/AnomalyEventService")
 	anomalyEventServiceInterface         = "org.chromium.AnomalyEventServiceInterface"
 	anomalyGuestFileCorruptionSignalName = "GuestFileCorruption"
+	fsCorruptionHistogram                = "Crostini.FilesystemCorruption"
 )
 
 func init() {
@@ -125,6 +128,17 @@
 	}
 }
 
+func checkHistogram(ctx context.Context, cr *chrome.Chrome, baseline int64) (int64, error) {
+	hist, err := metrics.GetHistogram(ctx, cr, fsCorruptionHistogram)
+	if err != nil {
+		return 0, err
+	}
+	if hist.Sum <= baseline {
+		return hist.Sum, errors.Errorf("expected total of more then %v histogram values, got %v", baseline, hist.Sum)
+	}
+	return hist.Sum, nil
+}
+
 // testOverwriteAtOffsets overwrites the VM disk that stores
 // |container| at the locations in |offsets| with uuidReplacement. It
 // then restarts the VM and container and checks that the filesystem
@@ -179,8 +193,9 @@
 // FsCorruption sets up the VM and then introduces corruption into its disk to check that this is detected correctly.
 func FsCorruption(ctx context.Context, s *testing.State) {
 	data := s.PreValue().(crostini.PreData)
+	cr := data.Chrome
 
-	if err := crash.SetUpCrashTest(ctx, crash.WithConsent(data.Chrome)); err != nil {
+	if err := crash.SetUpCrashTest(ctx, crash.WithConsent(cr)); err != nil {
 		s.Fatal("Failed to set up crash test: ", err)
 	}
 	defer crash.TearDownCrashTest()
@@ -222,10 +237,23 @@
 	cmd = testexec.CommandContext(ctx, "mv", "--force", backupPath, data.Container.VM.DiskPath)
 	defer cmd.Run(testexec.DumpLogOnError)
 
+	histogramCount, err := checkHistogram(ctx, cr, -1)
+	if err != nil {
+		s.Fatal("Failed to get baseline for histogram: ", err)
+	}
+
 	if err := testOverwriteAtOffsets(ctx, bigOffsets, data.Container, backupPath, s.OutDir()); err != nil {
 		s.Fatal("Didn't get an error signal for big file: ", err)
 	}
+	histogramCount, err = checkHistogram(ctx, cr, histogramCount)
+	if err != nil {
+		s.Fatal("Failed to check histogram: ", err)
+	}
+
 	if err := testOverwriteAtOffsets(ctx, smallOffsets, data.Container, backupPath, s.OutDir()); err != nil {
 		s.Fatal("Didn't get an error signal for small file: ", err)
 	}
+	if _, err := checkHistogram(ctx, cr, histogramCount); err != nil {
+		s.Fatal("Failed to check histogram: ", err)
+	}
 }