Unit tests: Use Md5sum to decide whether to discard MMAPs

Previously, we used the array index of the test files, and discarded
MMAPs for even-indexed files.

This became a problem when we wanted to insert new files into the list
of test files as the following files would get shifted by one. To make
this more robust, use Md5sum prefixes instead of array indexes to
decide. This should yield a 50/50 mix of discard vs no-discard and is
immune to adding or removing files.

BUG=chromium:367372
TEST=unit tests pass

Change-Id: I009be2b65a7faf1a78cd6976dceb6455e50b0ef9
Signed-off-by: Simon Que <sque@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/198575
diff --git a/perf_serializer_test.cc b/perf_serializer_test.cc
index 634c933..df5fbb8 100644
--- a/perf_serializer_test.cc
+++ b/perf_serializer_test.cc
@@ -128,8 +128,10 @@
     LOG(INFO) << "Testing " << input_perf_data;
     input_perf_reader.ReadFile(input_perf_data);
 
-    // For every other perf data file, discard unused events.
-    bool discard = (i % 2 == 0);
+    // Discard unused events for a pseudorandom selection of half the test data
+    // files. The selection is based on the Md5sum prefix, so that the files can
+    // be moved around in the |kPerfDataFiles| list.
+    bool discard = (Md5Prefix(test_file) % 2 == 0);
 
     SerializeAndDeserialize(input_perf_data, output_perf_data, false, discard);
     output_perf_reader.ReadFile(output_perf_data);
diff --git a/testdata/perf.data.armv7.serialized.out.pb_text.gz b/testdata/perf.data.armv7.serialized.out.pb_text.gz
index dec335c..b233ca2 100644
--- a/testdata/perf.data.armv7.serialized.out.pb_text.gz
+++ b/testdata/perf.data.armv7.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.branch.next.serialized.out.pb_text.gz b/testdata/perf.data.branch.next.serialized.out.pb_text.gz
index 1696e75..cf146e0 100644
--- a/testdata/perf.data.branch.next.serialized.out.pb_text.gz
+++ b/testdata/perf.data.branch.next.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.busy.0.next.serialized.out.pb_text.gz b/testdata/perf.data.busy.0.next.serialized.out.pb_text.gz
index de34c39..f3aa817 100644
--- a/testdata/perf.data.busy.0.next.serialized.out.pb_text.gz
+++ b/testdata/perf.data.busy.0.next.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.busy.0.serialized.out.pb_text.gz b/testdata/perf.data.busy.0.serialized.out.pb_text.gz
index 0437fca..6218e70 100644
--- a/testdata/perf.data.busy.0.serialized.out.pb_text.gz
+++ b/testdata/perf.data.busy.0.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.busy.1.next.serialized.out.pb_text.gz b/testdata/perf.data.busy.1.next.serialized.out.pb_text.gz
index 411b5d6..7c84318 100644
--- a/testdata/perf.data.busy.1.next.serialized.out.pb_text.gz
+++ b/testdata/perf.data.busy.1.next.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.busy.1.serialized.out.pb_text.gz b/testdata/perf.data.busy.1.serialized.out.pb_text.gz
index f82c922..1bfa2e4 100644
--- a/testdata/perf.data.busy.1.serialized.out.pb_text.gz
+++ b/testdata/perf.data.busy.1.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.cycles_and_branch.serialized.out.pb_text.gz b/testdata/perf.data.cycles_and_branch.serialized.out.pb_text.gz
index 55e0e7d..07863fc 100644
--- a/testdata/perf.data.cycles_and_branch.serialized.out.pb_text.gz
+++ b/testdata/perf.data.cycles_and_branch.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.forkexit.next.serialized.out.pb_text.gz b/testdata/perf.data.forkexit.next.serialized.out.pb_text.gz
index 656401b..b21e1be 100644
--- a/testdata/perf.data.forkexit.next.serialized.out.pb_text.gz
+++ b/testdata/perf.data.forkexit.next.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.i686.serialized.out.pb_text.gz b/testdata/perf.data.i686.serialized.out.pb_text.gz
index 4250de6..8cc9d74 100644
--- a/testdata/perf.data.i686.serialized.out.pb_text.gz
+++ b/testdata/perf.data.i686.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.singleprocess.next.serialized.out.pb_text.gz b/testdata/perf.data.singleprocess.next.serialized.out.pb_text.gz
index 575a142..aa54172 100644
--- a/testdata/perf.data.singleprocess.next.serialized.out.pb_text.gz
+++ b/testdata/perf.data.singleprocess.next.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.systemwide.0.serialized.out.pb_text.gz b/testdata/perf.data.systemwide.0.serialized.out.pb_text.gz
index 3e66f47..e96be12 100644
--- a/testdata/perf.data.systemwide.0.serialized.out.pb_text.gz
+++ b/testdata/perf.data.systemwide.0.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.systemwide.1.next.serialized.out.pb_text.gz b/testdata/perf.data.systemwide.1.next.serialized.out.pb_text.gz
index 4774897..44dfdeb 100644
--- a/testdata/perf.data.systemwide.1.next.serialized.out.pb_text.gz
+++ b/testdata/perf.data.systemwide.1.next.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.systemwide.5.next.serialized.out.pb_text.gz b/testdata/perf.data.systemwide.5.next.serialized.out.pb_text.gz
index b0a52fe..20d4215 100644
--- a/testdata/perf.data.systemwide.5.next.serialized.out.pb_text.gz
+++ b/testdata/perf.data.systemwide.5.next.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.systemwide.5.serialized.out.pb_text.gz b/testdata/perf.data.systemwide.5.serialized.out.pb_text.gz
index 3fb67e2..b1df6ad 100644
--- a/testdata/perf.data.systemwide.5.serialized.out.pb_text.gz
+++ b/testdata/perf.data.systemwide.5.serialized.out.pb_text.gz
Binary files differ
diff --git a/testdata/perf.data.throttle.next.serialized.out.pb_text.gz b/testdata/perf.data.throttle.next.serialized.out.pb_text.gz
index e25e61f..03560e3 100644
--- a/testdata/perf.data.throttle.next.serialized.out.pb_text.gz
+++ b/testdata/perf.data.throttle.next.serialized.out.pb_text.gz
Binary files differ