quipper: Combine multiple unit tests into one binary

This speeds up execution within the cros build/test framework.

Keep perf_recorder_test as a separate binary because it does not run on
systems without perf.

BUG=chromium:568870
TEST=unit tests pass
CQ-DEPEND=I7925ba0351c47535219e1ea5f15ba08278a92ec5

Change-Id: I0e7f3b44ce0b4e59c13769e9893e647320e1c280
Signed-off-by: Simon Que <sque@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/321158
Reviewed-by: David Sharp <dhsharp@chromium.org>
diff --git a/chromiumos-wide-profiling/Makefile.external b/chromiumos-wide-profiling/Makefile.external
index 05a2783..fe3c415 100644
--- a/chromiumos-wide-profiling/Makefile.external
+++ b/chromiumos-wide-profiling/Makefile.external
@@ -18,25 +18,33 @@
 MAIN_SOURCES = quipper.cc perf_converter.cc
 PROGRAMS = $(MAIN_SOURCES:.cc=)
 
-LIBRARY_SOURCES_WITH_TESTS = \
+LIBRARY_SOURCES = \
 	address_mapper.cc buffer_reader.cc buffer_writer.cc \
-	conversion_utils.cc file_reader.cc perf_parser.cc perf_reader.cc \
-	perf_option_parser.cc perf_recorder.cc perf_serializer.cc \
-	perf_stat_parser.cc run_command.cc sample_info_reader.cc \
-	scoped_temp_path.cc utils.cc
-LIBRARY_SOURCES = compat/log_level.cc data_reader.cc data_writer.cc \
-		  mybase/base/logging.cc perf_protobuf_io.cc \
-		  $(LIBRARY_SOURCES_WITH_TESTS)
-TEST_SOURCES = $(LIBRARY_SOURCES_WITH_TESTS:.cc=_test.cc)
+	conversion_utils.cc compat/log_level.cc data_reader.cc data_writer.cc \
+	file_reader.cc mybase/base/logging.cc perf_option_parser.cc \
+	perf_parser.cc perf_protobuf_io.cc perf_reader.cc perf_recorder.cc \
+	perf_serializer.cc perf_stat_parser.cc run_command.cc \
+	sample_info_reader.cc scoped_temp_path.cc utils.cc
 GENERATED_SOURCES = perf_data.pb.cc perf_stat.pb.cc
 GENERATED_HEADERS = $(GENERATED_SOURCES:.pb.cc=.pb.h)
 
 COMMON_SOURCES = $(LIBRARY_SOURCES) $(GENERATED_SOURCES)
 COMMON_OBJECTS = $(COMMON_SOURCES:.cc=.o)
-TEST_COMMON_SOURCES = test_perf_data.cc test_utils.cc
+TEST_COMMON_SOURCES = perf_test_files.cc test_perf_data.cc test_utils.cc
 TEST_COMMON_OBJECTS = $(TEST_COMMON_SOURCES:.cc=.o)
 
-TESTS = $(TEST_SOURCES:.cc=)
+INTEGRATION_TEST_SOURCES = conversion_utils_test.cc
+PERF_RECORDER_TEST_SOURCES = perf_recorder_test.cc
+UNIT_TEST_SOURCES = \
+	address_mapper_test.cc buffer_reader_test.cc buffer_writer_test.cc \
+	file_reader_test.cc perf_option_parser_test.cc perf_parser_test.cc \
+	perf_reader_test.cc perf_serializer_test.cc perf_stat_parser_test.cc \
+	run_command_test.cc sample_info_reader_test.cc \
+	scoped_temp_path_test.cc utils_test.cc
+
+TEST_SOURCES = $(INTEGRATION_TEST_SOURCES) $(PERF_RECORDER_TEST_SOURCES) \
+	       $(UNIT_TEST_SOURCES) $(TEST_COMMON_SOURCES) test_runner.cc
+TEST_OBJECTS = $(TEST_SOURCES:.cc=.o)
 
 ALL_SOURCES = $(MAIN_SOURCES) $(COMMON_SOURCES) $(TEST_SOURCES)
 
@@ -66,8 +74,21 @@
 $(PROGRAMS): %: %.o $(COMMON_OBJECTS)
 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
 
-$(TESTS): LDLIBS += -lgtest
-$(TESTS): %: %.o $(COMMON_OBJECTS) $(TEST_COMMON_OBJECTS)
+INTEGRATION_TEST_OBJECTS = $(INTEGRATION_TEST_SOURCES:.cc=.o) test_runner.o
+integration_tests: LDLIBS += -lgtest
+integration_tests: %: $(COMMON_OBJECTS) $(TEST_COMMON_OBJECTS) \
+		      $(INTEGRATION_TEST_OBJECTS)
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
+
+PERF_RECORDER_TEST_OBJECTS = $(PERF_RECORDER_TEST_SOURCES:.cc=.o)
+perf_recorder_test: LDLIBS += -lgtest
+perf_recorder_test: %: $(COMMON_OBJECTS) $(TEST_COMMON_OBJECTS) \
+		       $(PERF_RECORDER_TEST_OBJECTS)
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
+
+UNIT_TEST_OBJECTS = $(UNIT_TEST_SOURCES:.cc=.o) test_runner.o
+unit_tests: LDLIBS += -lgtest
+unit_tests: %: $(COMMON_OBJECTS) $(TEST_COMMON_OBJECTS) $(UNIT_TEST_OBJECTS)
 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
 
 # With large perf.data files, the tests will spew a lot of logging.  The
diff --git a/chromiumos-wide-profiling/address_mapper_test.cc b/chromiumos-wide-profiling/address_mapper_test.cc
index b2613c0..5ada00c 100644
--- a/chromiumos-wide-profiling/address_mapper_test.cc
+++ b/chromiumos-wide-profiling/address_mapper_test.cc
@@ -460,8 +460,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char * argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/buffer_reader_test.cc b/chromiumos-wide-profiling/buffer_reader_test.cc
index a3a7a16..9c28197 100644
--- a/chromiumos-wide-profiling/buffer_reader_test.cc
+++ b/chromiumos-wide-profiling/buffer_reader_test.cc
@@ -238,8 +238,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/buffer_writer_test.cc b/chromiumos-wide-profiling/buffer_writer_test.cc
index cb4c498..cecad1c 100644
--- a/chromiumos-wide-profiling/buffer_writer_test.cc
+++ b/chromiumos-wide-profiling/buffer_writer_test.cc
@@ -270,8 +270,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/conversion_utils_test.cc b/chromiumos-wide-profiling/conversion_utils_test.cc
index 9ed9c0e..b966dab 100644
--- a/chromiumos-wide-profiling/conversion_utils_test.cc
+++ b/chromiumos-wide-profiling/conversion_utils_test.cc
@@ -4,6 +4,7 @@
 
 #include "base/logging.h"
 
+#include "chromiumos-wide-profiling/compat/string.h"
 #include "chromiumos-wide-profiling/compat/test.h"
 #include "chromiumos-wide-profiling/conversion_utils.h"
 #include "chromiumos-wide-profiling/perf_test_files.h"
@@ -11,14 +12,6 @@
 #include "chromiumos-wide-profiling/test_utils.h"
 #include "chromiumos-wide-profiling/utils.h"
 
-namespace {
-
-// The number for perf data files in our test files that we have protobuf text
-// representation for.
-const unsigned int kNumProtoTextFormatPerfFiles = 1;
-
-}  // namespace
-
 namespace quipper {
 
 TEST(ConversionUtilsTest, TestTextOutput) {
@@ -27,9 +20,8 @@
   string output_path = output_dir.path();
 
   // TODO(asharif): Generate more test files.
-  for (unsigned int i = 0; i < kNumProtoTextFormatPerfFiles; ++i) {
+  for (const char* test_file : perf_test_files::GetPerfDataFiles()) {
     FormatAndFile input, output;
-    string test_file = perf_test_files::kPerfDataFiles[i];
 
     input.filename = GetTestInputFilePath(test_file);
     input.format = kPerfFormat;
@@ -37,7 +29,7 @@
     output.format = kProtoTextFormat;
     EXPECT_TRUE(ConvertFile(input, output));
 
-    string golden_file = GetTestInputFilePath(test_file + ".pb_text");
+    string golden_file = GetTestInputFilePath(string(test_file) + ".pb_text");
     LOG(INFO) << "golden: " << golden_file;
     LOG(INFO) << "output: " << output.filename;
     EXPECT_TRUE(CompareFileContents(golden_file, output.filename));
@@ -45,8 +37,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/file_reader_test.cc b/chromiumos-wide-profiling/file_reader_test.cc
index 25c294a..bac46e9 100644
--- a/chromiumos-wide-profiling/file_reader_test.cc
+++ b/chromiumos-wide-profiling/file_reader_test.cc
@@ -266,8 +266,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/perf_option_parser_test.cc b/chromiumos-wide-profiling/perf_option_parser_test.cc
index eed46e8..c3c9bd1 100644
--- a/chromiumos-wide-profiling/perf_option_parser_test.cc
+++ b/chromiumos-wide-profiling/perf_option_parser_test.cc
@@ -179,8 +179,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/perf_parser_test.cc b/chromiumos-wide-profiling/perf_parser_test.cc
index a26a206..dbb6b02 100644
--- a/chromiumos-wide-profiling/perf_parser_test.cc
+++ b/chromiumos-wide-profiling/perf_parser_test.cc
@@ -222,7 +222,7 @@
   string output_path = output_dir.path();
 
   int seed = 0;
-  for (const char* test_file : perf_test_files::kPerfDataFiles) {
+  for (const char* test_file : perf_test_files::GetPerfDataFiles()) {
     string input_perf_data = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing " << input_perf_data;
 
@@ -310,7 +310,7 @@
   string output_path = output_dir.path();
 
   int seed = 0;
-  for (const char* test_file : perf_test_files::kPerfPipedDataFiles) {
+  for (const char* test_file : perf_test_files::GetPerfPipedDataFiles()) {
     string input_perf_data = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing " << input_perf_data;
     string output_perf_data = output_path + test_file + ".pr.out";
@@ -763,8 +763,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/perf_reader_test.cc b/chromiumos-wide-profiling/perf_reader_test.cc
index 9482953..ccffc73 100644
--- a/chromiumos-wide-profiling/perf_reader_test.cc
+++ b/chromiumos-wide-profiling/perf_reader_test.cc
@@ -129,7 +129,8 @@
 }
 
 TEST(PerfReaderTest, CorruptedFiles) {
-  for (const char* test_file : perf_test_files::kCorruptedPerfPipedDataFiles) {
+  for (const char* test_file :
+       perf_test_files::GetCorruptedPerfPipedDataFiles()) {
     string input_perf_data = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing " << input_perf_data;
     ASSERT_TRUE(FileExists(input_perf_data)) << "Test file does not exist!";
@@ -1606,8 +1607,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/perf_serializer_test.cc b/chromiumos-wide-profiling/perf_serializer_test.cc
index 0f6a7c4..64e8305 100644
--- a/chromiumos-wide-profiling/perf_serializer_test.cc
+++ b/chromiumos-wide-profiling/perf_serializer_test.cc
@@ -180,7 +180,7 @@
   // Dump it to a protobuf.
   // Read the protobuf, and reconstruct the perf data.
   // TODO(sque): test exact number of events after discarding unused events.
-  for (const char* test_file : perf_test_files::kPerfDataFiles) {
+  for (const char* test_file : perf_test_files::GetPerfDataFiles()) {
     PerfReader input_perf_reader, output_perf_reader, output_perf_reader1,
                output_perf_reader2;
     PerfDataProto perf_data_proto, perf_data_proto1;
@@ -241,14 +241,14 @@
   // Read perf data using the PerfReader class with address remapping.
   // Dump it to a protobuf.
   // Read the protobuf, and reconstruct the perf data.
-  for (const char* test_file : perf_test_files::kPerfDataFiles) {
+  for (const char* test_file : perf_test_files::GetPerfDataFiles()) {
     const string input_perf_data = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing " << input_perf_data;
     const string output_perf_data = output_path + test_file + ".ser.remap.out";
     SerializeAndDeserialize(input_perf_data, output_perf_data, true, true);
   }
 
-  for (const char* test_file : perf_test_files::kPerfPipedDataFiles) {
+  for (const char* test_file : perf_test_files::GetPerfPipedDataFiles()) {
     const string input_perf_data = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing " << input_perf_data;
     const string output_perf_data = output_path + test_file + ".ser.remap.out";
@@ -263,7 +263,7 @@
 
   // Replace command strings with their Md5sums.  Test size adjustment for
   // command strings.
-  for (const char* test_file : perf_test_files::kPerfDataFiles) {
+  for (const char* test_file : perf_test_files::GetPerfDataFiles()) {
     const string input_perf_data = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing COMM Md5sum for " << input_perf_data;
 
@@ -304,7 +304,7 @@
 
   // Replace MMAP filename strings with their Md5sums.  Test size adjustment for
   // MMAP filename strings.
-  for (const char* test_file : perf_test_files::kPerfDataFiles) {
+  for (const char* test_file : perf_test_files::GetPerfDataFiles()) {
     const string input_perf_data = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing MMAP Md5sum for " << input_perf_data;
 
@@ -340,7 +340,7 @@
 }
 
 TEST(PerfSerializerTest, TestProtoFiles) {
-  for (const char* test_file : perf_test_files::kPerfDataProtoFiles) {
+  for (const char* test_file : perf_test_files::GetPerfDataProtoFiles()) {
     string perf_data_proto_file = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing " << perf_data_proto_file;
     std::vector<char> data;
@@ -359,7 +359,7 @@
 }
 
 TEST(PerfSerializerTest, TestBuildIDs) {
-  for (const char* test_file : perf_test_files::kPerfDataFiles) {
+  for (const char* test_file : perf_test_files::GetPerfDataFiles()) {
     string perf_data_file = GetTestInputFilePath(test_file);
     LOG(INFO) << "Testing " << perf_data_file;
 
@@ -804,8 +804,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char * argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/perf_stat_parser_test.cc b/chromiumos-wide-profiling/perf_stat_parser_test.cc
index 88b16ec..473eb56 100644
--- a/chromiumos-wide-profiling/perf_stat_parser_test.cc
+++ b/chromiumos-wide-profiling/perf_stat_parser_test.cc
@@ -138,8 +138,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/perf_test_files.cc b/chromiumos-wide-profiling/perf_test_files.cc
new file mode 100644
index 0000000..c777bf5
--- /dev/null
+++ b/chromiumos-wide-profiling/perf_test_files.cc
@@ -0,0 +1,149 @@
+// Copyright 2016 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.
+
+#include "chromiumos-wide-profiling/perf_test_files.h"
+
+// TODO(sque): Re-enable callgraph testing when longer-term
+// changes to quipper are done.
+// #define TEST_CALLGRAPH
+
+namespace perf_test_files {
+
+const std::vector<const char*>& GetPerfDataFiles() {
+  static const std::vector<const char*>* files = new std::vector<const char*> {
+    // The following perf data contains the following event types, as passed to
+    // perf record via the -e option:
+    // - cycles
+    // - instructions
+    // - cache-references
+    // - cache-misses
+    // - branches
+    // - branch-misses
+
+    // Obtained with "perf record -- echo > /dev/null"
+    "perf.data.singleprocess-3.4",
+
+    // Obtained with "perf record -a -- sleep $N", for N in {0, 1, 5}.
+    "perf.data.systemwide.0-3.4",
+#ifdef TEST_LARGE_PERF_DATA
+    "perf.data.systemwide.1-3.4",
+    "perf.data.systemwide.5-3.4",
+
+    // Obtained with "perf record -a -- sleep $N", for N in {0, 1, 5}.
+    // While in the background, this loop is running:
+    //   while true; do ls > /dev/null; done
+    "perf.data.busy.0-3.4",
+    "perf.data.busy.1-3.4",
+    "perf.data.busy.5-3.4",
+#endif  // defined(TEST_LARGE_PERF_DATA)
+
+    // Obtained with "perf record -a -- sleep 2"
+    // While in the background, this loop is running:
+    //   while true; do restart powerd; sleep .2; done
+    "perf.data.forkexit-3.4",
+
+#ifdef TEST_CALLGRAPH
+    // Obtained with "perf record -a -g -- sleep 2"
+    "perf.data.callgraph-3.4",
+#endif
+    // Obtained with "perf record -a -b -- sleep 2"
+    "perf.data.branch-3.4",
+#ifdef TEST_CALLGRAPH
+    // Obtained with "perf record -a -g -b -- sleep 2"
+    "perf.data.callgraph_and_branch-3.4",
+#endif
+
+    // Obtained with "perf record -a -R -- sleep 2"
+    "perf.data.raw-3.4",
+#ifdef TEST_CALLGRAPH
+    // Obtained with "perf record -a -R -g -b -- sleep 2"
+    "perf.data.raw_callgraph_branch-3.4",
+#endif
+
+    // Data from other architectures.
+    "perf.data.i686-3.4",     // 32-bit x86
+    "perf.data.armv7-3.4",    // ARM v7
+
+    // Same as above, obtained from a system running kernel v3.8.
+    "perf.data.singleprocess-3.8",
+    "perf.data.systemwide.0-3.8",
+#ifdef TEST_LARGE_PERF_DATA
+    "perf.data.systemwide.1-3.8",
+    "perf.data.systemwide.5-3.8",
+    "perf.data.busy.0-3.8",
+    "perf.data.busy.1-3.8",
+    "perf.data.busy.5-3.8",
+#endif  // defined(TEST_LARGE_PERF_DATA)
+
+    "perf.data.forkexit-3.8",
+#ifdef TEST_CALLGRAPH
+    "perf.data.callgraph-3.8",
+#endif
+    "perf.data.branch-3.8",
+#ifdef TEST_CALLGRAPH
+    "perf.data.callgraph_and_branch-3.8",
+#endif
+    "perf.data.armv7.perf_3.14-3.8",      // ARM v7 obtained using perf 3.14.
+
+    // Obtained from a system that uses NUMA topology.
+    "perf.data.numatopology-3.2",
+
+    // Perf data that contains hardware and software events.
+    // Command:
+    //    perf record -a -c 1000000 -e cycles,branch-misses,cpu-clock -- sleep 2
+    // HW events are cycles and branch-misses, SW event is cpu-clock.
+    // This also tests non-consecutive event types.
+    "perf.data.hw_and_sw-3.4",
+
+    // This test first mmap()s a DSO, then fork()s to copy the mapping to the
+    // child and then modifies the mapping by mmap()ing a DSO on top of the old
+    // one. It then records SAMPLEs events in the child. It ensures the SAMPLEs
+    // in the child are attributed to the first DSO that was mmap()ed, not the
+    // second one.
+    "perf.data.remmap-3.2",
+
+    // This is sample with a frequency higher than the max frequency, so it has
+    // throttle and unthrottle events.
+    "perf.data.throttle-3.8",
+  };
+  return *files;
+}
+
+const std::vector<const char*>& GetPerfPipedDataFiles() {
+  static const std::vector<const char*>* files = new std::vector<const char*> {
+    "perf.data.piped.host-3.2",
+    "perf.data.piped.target-3.4",
+    "perf.data.piped.target.throttled-3.4",
+    "perf.data.piped.target-3.8",
+
+    // Piped data that contains hardware and software events.
+    // Command:
+    //    perf record -a -c 1000000 -e cycles,branch-misses,cpu-clock -o -
+    //        -- sleep 2
+    // HW events are cycles and branch-misses, SW event is cpu-clock.
+    "perf.data.piped.hw_and_sw-3.4",
+
+    // Piped data with extra data at end.
+    "perf.data.piped.extrabyte-3.4",
+    "perf.data.piped.extradata-3.4",
+  };
+  return *files;
+}
+
+const std::vector<const char*>& GetCorruptedPerfPipedDataFiles()  {
+  static const std::vector<const char*>* files = new std::vector<const char*> {
+    // Has a SAMPLE event with size set to zero. Don't go into an infinite loop!
+    "perf.data.piped.corrupted.zero_size_sample-3.2",
+  };
+  return *files;
+}
+
+const std::vector<const char*>& GetPerfDataProtoFiles()  {
+  static const std::vector<const char*>* files = new std::vector<const char*> {
+    "perf.callgraph.pb_text",
+  };
+  return *files;
+}
+
+}  // namespace perf_test_files
diff --git a/chromiumos-wide-profiling/perf_test_files.h b/chromiumos-wide-profiling/perf_test_files.h
index 381d173..8758f01 100644
--- a/chromiumos-wide-profiling/perf_test_files.h
+++ b/chromiumos-wide-profiling/perf_test_files.h
@@ -5,135 +5,14 @@
 #ifndef CHROMIUMOS_WIDE_PROFILING_PERF_TEST_FILES_H_
 #define CHROMIUMOS_WIDE_PROFILING_PERF_TEST_FILES_H_
 
-// TODO(sque): Re-enable callgraph testing when longer-term
-// changes to quipper are done.
-// #define TEST_CALLGRAPH
+#include <vector>
 
 namespace perf_test_files {
 
-// The following perf data contains the following event types, as passed to
-// perf record via the -e option:
-// - cycles
-// - instructions
-// - cache-references
-// - cache-misses
-// - branches
-// - branch-misses
-
-const char* kPerfDataFiles[] = {
-  // Obtained with "perf record -- echo > /dev/null"
-  "perf.data.singleprocess-3.4",
-
-  // Obtained with "perf record -a -- sleep $N", for N in {0, 1, 5}.
-  "perf.data.systemwide.0-3.4",
-#ifdef TEST_LARGE_PERF_DATA
-  "perf.data.systemwide.1-3.4",
-  "perf.data.systemwide.5-3.4",
-
-  // Obtained with "perf record -a -- sleep $N", for N in {0, 1, 5}.
-  // While in the background, this loop is running:
-  //   while true; do ls > /dev/null; done
-  "perf.data.busy.0-3.4",
-  "perf.data.busy.1-3.4",
-  "perf.data.busy.5-3.4",
-#endif  // defined(TEST_LARGE_PERF_DATA)
-
-  // Obtained with "perf record -a -- sleep 2"
-  // While in the background, this loop is running:
-  //   while true; do restart powerd; sleep .2; done
-  "perf.data.forkexit-3.4",
-
-#ifdef TEST_CALLGRAPH
-  // Obtained with "perf record -a -g -- sleep 2"
-  "perf.data.callgraph-3.4",
-#endif
-  // Obtained with "perf record -a -b -- sleep 2"
-  "perf.data.branch-3.4",
-#ifdef TEST_CALLGRAPH
-  // Obtained with "perf record -a -g -b -- sleep 2"
-  "perf.data.callgraph_and_branch-3.4",
-#endif
-
-  // Obtained with "perf record -a -R -- sleep 2"
-  "perf.data.raw-3.4",
-#ifdef TEST_CALLGRAPH
-  // Obtained with "perf record -a -R -g -b -- sleep 2"
-  "perf.data.raw_callgraph_branch-3.4",
-#endif
-
-  // Data from other architectures.
-  "perf.data.i686-3.4",     // 32-bit x86
-  "perf.data.armv7-3.4",    // ARM v7
-
-  // Same as above, obtained from a system running kernel v3.8.
-  "perf.data.singleprocess-3.8",
-  "perf.data.systemwide.0-3.8",
-#ifdef TEST_LARGE_PERF_DATA
-  "perf.data.systemwide.1-3.8",
-  "perf.data.systemwide.5-3.8",
-  "perf.data.busy.0-3.8",
-  "perf.data.busy.1-3.8",
-  "perf.data.busy.5-3.8",
-#endif  // defined(TEST_LARGE_PERF_DATA)
-
-  "perf.data.forkexit-3.8",
-#ifdef TEST_CALLGRAPH
-  "perf.data.callgraph-3.8",
-#endif
-  "perf.data.branch-3.8",
-#ifdef TEST_CALLGRAPH
-  "perf.data.callgraph_and_branch-3.8",
-#endif
-  "perf.data.armv7.perf_3.14-3.8",      // ARM v7 obtained using perf 3.14.
-
-  // Obtained from a system that uses NUMA topology.
-  "perf.data.numatopology-3.2",
-
-  // Perf data that contains hardware and software events.
-  // Command:
-  //    perf record -a -c 1000000 -e cycles,branch-misses,cpu-clock -- sleep 2
-  // HW events are cycles and branch-misses, SW event is cpu-clock.
-  // This also tests non-consecutive event types.
-  "perf.data.hw_and_sw-3.4",
-
-  // This test first mmap()s a DSO, then fork()s to copy the mapping to the
-  // child and then modifies the mapping by mmap()ing a DSO on top of the old
-  // one. It then records SAMPLEs events in the child. It ensures the SAMPLEs in
-  // the child are attributed to the first DSO that was mmap()ed, not the second
-  // one.
-  "perf.data.remmap-3.2",
-
-  // This is sample with a frequency higher than the max frequency, so it has
-  // throttle and unthrottle events.
-  "perf.data.throttle-3.8",
-};
-
-const char* kPerfPipedDataFiles[] = {
-  "perf.data.piped.host-3.2",
-  "perf.data.piped.target-3.4",
-  "perf.data.piped.target.throttled-3.4",
-  "perf.data.piped.target-3.8",
-
-  // Piped data that contains hardware and software events.
-  // Command:
-  //    perf record -a -c 1000000 -e cycles,branch-misses,cpu-clock -o -
-  //        -- sleep 2
-  // HW events are cycles and branch-misses, SW event is cpu-clock.
-  "perf.data.piped.hw_and_sw-3.4",
-
-  // Piped data with extra data at end.
-  "perf.data.piped.extrabyte-3.4",
-  "perf.data.piped.extradata-3.4",
-};
-
-const char* kCorruptedPerfPipedDataFiles[] = {
-  // Has a SAMPLE event with size set to zero. Don't go into an infinite loop!
-  "perf.data.piped.corrupted.zero_size_sample-3.2",
-};
-
-const char* kPerfDataProtoFiles[] = {
-  "perf.callgraph.pb_text",
-};
+const std::vector<const char*>& GetPerfDataFiles();
+const std::vector<const char*>& GetPerfPipedDataFiles();
+const std::vector<const char*>& GetCorruptedPerfPipedDataFiles();
+const std::vector<const char*>& GetPerfDataProtoFiles();
 
 }  // namespace perf_test_files
 
diff --git a/chromiumos-wide-profiling/quipper.gyp b/chromiumos-wide-profiling/quipper.gyp
index bcbd5fa..06663cb 100644
--- a/chromiumos-wide-profiling/quipper.gyp
+++ b/chromiumos-wide-profiling/quipper.gyp
@@ -55,6 +55,7 @@
       'target_name': 'common_test',
       'type': 'static_library',
       'sources': [
+        'perf_test_files.cc',
         'test_utils.cc',
         'test_perf_data.cc',
       ],
@@ -115,43 +116,8 @@
     ['USE_test == 1', {
       'targets': [
         {
-          'target_name': 'address_mapper_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
-            'address_mapper_test.cc',
-          ]
-        },
-        {
-          'target_name': 'buffer_reader_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
-            'buffer_reader_test.cc',
-          ]
-        },
-        {
-          'target_name': 'buffer_writer_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
-            'buffer_writer_test.cc',
-          ]
-        },
-        {
-          'target_name': 'conversion_utils_test',
+          # TODO(sque): Separate out longer tests and move into this target.
+          'target_name': 'integration_tests',
           'type': 'executable',
           'dependencies': [
             'common',
@@ -161,54 +127,7 @@
           'includes': ['../common-mk/common_test.gypi'],
           'sources': [
             'conversion_utils_test.cc',
-          ]
-        },
-        {
-          'target_name': 'file_reader_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
-            'file_reader_test.cc',
-          ]
-        },
-        {
-          'target_name': 'perf_option_parser_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
-            'perf_option_parser_test.cc',
-          ]
-        },
-        {
-          'target_name': 'perf_parser_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
-            'perf_parser_test.cc',
-          ]
-        },
-        {
-          'target_name': 'perf_reader_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
-            'perf_reader_test.cc',
+            'test_runner.cc',
           ]
         },
         {
@@ -224,7 +143,7 @@
           ]
         },
         {
-          'target_name': 'perf_serializer_test',
+          'target_name': 'unit_tests',
           'type': 'executable',
           'dependencies': [
             'common',
@@ -232,65 +151,19 @@
           ],
           'includes': ['../common-mk/common_test.gypi'],
           'sources': [
+            'address_mapper_test.cc',
+            'buffer_reader_test.cc',
+            'buffer_writer_test.cc',
+            'file_reader_test.cc',
+            'perf_option_parser_test.cc',
+            'perf_parser_test.cc',
+            'perf_reader_test.cc',
             'perf_serializer_test.cc',
-          ]
-        },
-        {
-          'target_name': 'perf_stat_parser_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
             'perf_stat_parser_test.cc',
-          ]
-        },
-        {
-          'target_name': 'run_command_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
             'run_command_test.cc',
-          ]
-        },
-        {
-          'target_name': 'sample_info_reader_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
             'sample_info_reader_test.cc',
-          ]
-        },
-        {
-          'target_name': 'scoped_temp_path_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
             'scoped_temp_path_test.cc',
-          ]
-        },
-        {
-          'target_name': 'utils_test',
-          'type': 'executable',
-          'dependencies': [
-            'common',
-            'common_test',
-          ],
-          'includes': ['../common-mk/common_test.gypi'],
-          'sources': [
+            'test_runner.cc',
             'utils_test.cc',
           ]
         },
diff --git a/chromiumos-wide-profiling/run_command_test.cc b/chromiumos-wide-profiling/run_command_test.cc
index 107a2a9..afa4942 100644
--- a/chromiumos-wide-profiling/run_command_test.cc
+++ b/chromiumos-wide-profiling/run_command_test.cc
@@ -55,8 +55,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char * argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/sample_info_reader_test.cc b/chromiumos-wide-profiling/sample_info_reader_test.cc
index 0140476..7c935b5 100644
--- a/chromiumos-wide-profiling/sample_info_reader_test.cc
+++ b/chromiumos-wide-profiling/sample_info_reader_test.cc
@@ -205,8 +205,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char* argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/scoped_temp_path_test.cc b/chromiumos-wide-profiling/scoped_temp_path_test.cc
index 141ce4a..90844a7 100644
--- a/chromiumos-wide-profiling/scoped_temp_path_test.cc
+++ b/chromiumos-wide-profiling/scoped_temp_path_test.cc
@@ -147,8 +147,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char * argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
diff --git a/chromiumos-wide-profiling/test_runner.cc b/chromiumos-wide-profiling/test_runner.cc
new file mode 100644
index 0000000..2499190
--- /dev/null
+++ b/chromiumos-wide-profiling/test_runner.cc
@@ -0,0 +1,10 @@
+// Copyright 2016 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.
+
+#include "chromiumos-wide-profiling/compat/test.h"
+
+int main(int argc, char * argv[]) {
+  ::testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}
diff --git a/chromiumos-wide-profiling/utils_test.cc b/chromiumos-wide-profiling/utils_test.cc
index 09dd92e..66bc9ab 100644
--- a/chromiumos-wide-profiling/utils_test.cc
+++ b/chromiumos-wide-profiling/utils_test.cc
@@ -68,8 +68,3 @@
 }
 
 }  // namespace quipper
-
-int main(int argc, char * argv[]) {
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}