Rename cxx-benchmark-unittests target and convert to LIT.

This patch renames the cxx-benchmark-unittests to check-cxx-benchmarks
and converts the target to use LIT in order to make the tests run faster
and provide better output.

In particular this runs each benchmark in a suite one by one, allowing
more parallelism while ensuring output isn't garbage with multiple threads.

Additionally, it adds the CMake flag '-DLIBCXX_BENCHMARK_TEST_ARGS=<list>'
to specify what options are passed when running the benchmarks.

llvm-svn: 346888
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 336a1a681189bf2b50b7bd0f8229656c58ac1b37
diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt
index c5b4bf0..8931161 100644
--- a/benchmarks/CMakeLists.txt
+++ b/benchmarks/CMakeLists.txt
@@ -180,15 +180,22 @@
   add_benchmark_test(${test_name} ${test_file})
 endforeach()
 
+if (LIBCXX_INCLUDE_TESTS)
+  include(AddLLVM)
 
-add_custom_target(cxx-benchmark-unittests)
-foreach(libcxx_tg ${libcxx_benchmark_targets})
-  message("Adding test ${libcxx_tg}")
-  # Add a target that runs the benchmark for the smallest possible time, simply so we get test
-  # and sanitizer coverage on the targets.
-  add_custom_target(${libcxx_tg}_test
-          COMMAND ${libcxx_tg} --benchmark_min_time=0.01
-          COMMENT "Running test ${libcxx_tg}"
-          )
-  add_dependencies(cxx-benchmark-unittests ${libcxx_tg}_test)
-endforeach()
+  if (NOT DEFINED LIBCXX_TEST_DEPS)
+    message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined")
+  endif()
+
+  configure_lit_site_cfg(
+          ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+          ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py)
+
+  set(BENCHMARK_LIT_ARGS "--show-all --show-xfail --show-unsupported ${LIT_ARGS_DEFAULT}")
+
+  add_lit_testsuite(check-cxx-benchmarks
+          "Running libcxx benchmarks tests"
+          ${CMAKE_CURRENT_BINARY_DIR}
+          DEPENDS cxx-benchmarks ${LIBCXX_TEST_DEPS}
+          ARGS ${BENCHMARK_LIT_ARGS})
+endif()
diff --git a/benchmarks/lit.cfg.py b/benchmarks/lit.cfg.py
new file mode 100644
index 0000000..84857d5
--- /dev/null
+++ b/benchmarks/lit.cfg.py
@@ -0,0 +1,23 @@
+# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
+# Configuration file for the 'lit' test runner.
+import os
+import site
+
+site.addsitedir(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'utils'))
+from libcxx.test.googlebenchmark import GoogleBenchmark
+
+# Tell pylint that we know config and lit_config exist somewhere.
+if 'PYLINT_IMPORT' in os.environ:
+    config = object()
+    lit_config = object()
+
+# name: The name of this test suite.
+config.name = 'libc++ benchmarks'
+config.suffixes = []
+
+config.test_exec_root = os.path.join(config.libcxx_obj_root, 'benchmarks')
+config.test_source_root = config.test_exec_root
+
+config.test_format = GoogleBenchmark(test_sub_dirs='.',
+                                     test_suffix='.libcxx.out',
+                                     benchmark_args=config.benchmark_args)
\ No newline at end of file
diff --git a/benchmarks/lit.site.cfg.py.in b/benchmarks/lit.site.cfg.py.in
new file mode 100644
index 0000000..e3ce8b2
--- /dev/null
+++ b/benchmarks/lit.site.cfg.py.in
@@ -0,0 +1,10 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+import sys
+
+config.libcxx_src_root = "@LIBCXX_SOURCE_DIR@"
+config.libcxx_obj_root = "@LIBCXX_BINARY_DIR@"
+config.benchmark_args = "@LIBCXX_BENCHMARK_TEST_ARGS@".split(';')
+
+# Let the main config do the real work.
+lit_config.load_config(config, "@LIBCXX_SOURCE_DIR@/benchmarks/lit.cfg.py")
\ No newline at end of file