From c0b7be60f8ec3047ad1610da76a2859e733379b4 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Wed, 3 Apr 2013 15:11:08 +0000 Subject: [PATCH] Unit test support for Clang extra tools Added support to CMake and autoconf for unit tests in clang-tools-extra. A dummy test exists for now until more meaningful tests can be written. llvm-svn: 178661 --- clang-tools-extra/CMakeLists.txt | 1 + clang-tools-extra/Makefile | 2 +- clang-tools-extra/test/CMakeLists.txt | 8 +++++ clang-tools-extra/test/Makefile | 13 +++++++-- clang-tools-extra/test/Unit/lit.cfg | 29 +++++++++++++++++++ clang-tools-extra/test/Unit/lit.site.cfg.in | 6 ++++ clang-tools-extra/unittests/CMakeLists.txt | 8 +++++ clang-tools-extra/unittests/Makefile | 15 ++++++++++ .../unittests/cpp11-migrate/CMakeLists.txt | 13 +++++++++ .../unittests/cpp11-migrate/Makefile | 22 ++++++++++++++ .../unittests/cpp11-migrate/dummy.cpp | 6 ++++ 11 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 clang-tools-extra/test/Unit/lit.cfg create mode 100644 clang-tools-extra/test/Unit/lit.site.cfg.in create mode 100644 clang-tools-extra/unittests/CMakeLists.txt create mode 100644 clang-tools-extra/unittests/Makefile create mode 100644 clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt create mode 100644 clang-tools-extra/unittests/cpp11-migrate/Makefile create mode 100644 clang-tools-extra/unittests/cpp11-migrate/dummy.cpp diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt index 88c2c48c3915..6a4d3793215d 100644 --- a/clang-tools-extra/CMakeLists.txt +++ b/clang-tools-extra/CMakeLists.txt @@ -5,3 +5,4 @@ add_subdirectory(modularize) # Add the common testsuite after all the tools. add_subdirectory(test) +add_subdirectory(unittests) diff --git a/clang-tools-extra/Makefile b/clang-tools-extra/Makefile index 6610f91a1483..ad1d2be4cf20 100644 --- a/clang-tools-extra/Makefile +++ b/clang-tools-extra/Makefile @@ -11,7 +11,7 @@ CLANG_LEVEL := ../.. include $(CLANG_LEVEL)/../../Makefile.config -PARALLEL_DIRS := remove-cstr-calls tool-template cpp11-migrate modularize +PARALLEL_DIRS := remove-cstr-calls tool-template cpp11-migrate modularize unittests include $(CLANG_LEVEL)/Makefile diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt index 50c0966fb74e..3baa7d18a97b 100644 --- a/clang-tools-extra/test/CMakeLists.txt +++ b/clang-tools-extra/test/CMakeLists.txt @@ -12,6 +12,11 @@ configure_lit_site_cfg( ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg ) +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg + ) + option(CLANG_TOOLS_TEST_USE_VG "Run Clang tools' tests under Valgrind" OFF) if(CLANG_TOOLS_TEST_USE_VG) set(CLANG_TOOLS_TEST_EXTRA_ARGS ${CLANG_TEST_EXTRA_ARGS} "--vg") @@ -23,6 +28,9 @@ set(CLANG_TOOLS_TEST_DEPS # Individual tools we test. remove-cstr-calls cpp11-migrate modularize + + # Unit tests + ExtraToolsUnitTests ) add_lit_testsuite(check-clang-tools "Running the Clang extra tools' regression tests" diff --git a/clang-tools-extra/test/Makefile b/clang-tools-extra/test/Makefile index e75b68fe79c3..484c24bcd4fc 100644 --- a/clang-tools-extra/test/Makefile +++ b/clang-tools-extra/test/Makefile @@ -38,7 +38,7 @@ ifdef VG LIT_ARGS += "--vg" endif -all:: lit.site.cfg +all:: lit.site.cfg Unit/lit.site.cfg @ echo '--- Running the Clang extra tools tests for $(TARGET_TRIPLE) ---' @ $(PYTHON) $(LLVM_SRC_ROOT)/utils/lit/lit.py \ $(LIT_ARGS) $(TESTARGS) $(TESTDIRS) @@ -46,7 +46,7 @@ all:: lit.site.cfg FORCE: lit.site.cfg: FORCE - @echo "Making Clang extra tools' 'lit.site.cfg' file..." + @echo "Making lit.site.cfg for Clang extra tools..." @$(ECHOPATH) s=@LLVM_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g > lit.tmp @$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> lit.tmp @$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=g >> lit.tmp @@ -57,6 +57,15 @@ lit.site.cfg: FORCE @sed -f lit.tmp $(PROJ_SRC_DIR)/lit.site.cfg.in > $@ @-rm -f lit.tmp +Unit/lit.site.cfg: FORCE + @echo "Making Unit/lit.site.cfg for Clang extra tools..." + @$(MKDIR) $(dir $@) + @$(ECHOPATH) s=@CLANG_TOOLS_BINARY_DIR@=$(PROJ_OBJ_DIR)/..=g >> lit.tmp + @$(ECHOPATH) s=@TARGET_TRIPLE@=$(TARGET_TRIPLE)=g >> lit.tmp + @$(ECHOPATH) s=@CLANG_TOOLS_SOURCE_DIR@=$(PROJ_SRC_DIR)/..=g >> lit.tmp + @sed -f lit.tmp $(PROJ_SRC_DIR)/Unit/lit.site.cfg.in > $@ + @-rm -f lit.tmp + clean:: @ find . -name Output | xargs rm -fr diff --git a/clang-tools-extra/test/Unit/lit.cfg b/clang-tools-extra/test/Unit/lit.cfg new file mode 100644 index 000000000000..cc10f58b2ffb --- /dev/null +++ b/clang-tools-extra/test/Unit/lit.cfg @@ -0,0 +1,29 @@ +# -*- Python -*- + +config.name = "Extra Tools Unit Tests" +config.suffixes = [] # Seems not to matter for google tests? + +# Test Source and Exec root dirs both point to the same directory where google +# test binaries are built. +extra_tools_obj_dir = getattr(config, 'extra_tools_obj_dir', None) +if extra_tools_obj_dir is not None: + config.test_source_root = os.path.join(extra_tools_obj_dir, 'unittests') + config.test_exec_root = config.test_source_root + +# All GoogleTests are named to have 'Tests' as their suffix. The '.' option is +# a special value for GoogleTest indicating that it should look through the +# entire testsuite recursively for tests (alternatively, one could provide a +# ;-separated list of subdirectories). +config.test_format = lit.formats.GoogleTest('.', 'Tests') + +# If the site-specific configuration wasn't loaded (e.g. the build system failed +# to create it or the user is running a test file directly) try to come up with +# sane config options. +if config.test_exec_root is None: + # Look for a --param=extra_tools_unit_site_config option. + site_cfg = lit.params.get('extra_tools_unit_site_config', None) + if site_cfg and os.path.exists(site_cfg): + lit.load_config(config, site_cfg) + raise SystemExit + + # FIXME: Support out-of-tree builds? See clang/test/Unit/lit.cfg if we care. diff --git a/clang-tools-extra/test/Unit/lit.site.cfg.in b/clang-tools-extra/test/Unit/lit.site.cfg.in new file mode 100644 index 000000000000..2e60b9da2328 --- /dev/null +++ b/clang-tools-extra/test/Unit/lit.site.cfg.in @@ -0,0 +1,6 @@ +## Autogenerated by LLVM/Clang configuration. +# Do not edit! +config.extra_tools_obj_dir = "@CLANG_TOOLS_BINARY_DIR@" +config.target_triple = "@TARGET_TRIPLE@" + +lit.load_config(config, "@CLANG_TOOLS_SOURCE_DIR@/test/Unit/lit.cfg") diff --git a/clang-tools-extra/unittests/CMakeLists.txt b/clang-tools-extra/unittests/CMakeLists.txt new file mode 100644 index 000000000000..444f9496750e --- /dev/null +++ b/clang-tools-extra/unittests/CMakeLists.txt @@ -0,0 +1,8 @@ +add_custom_target(ExtraToolsUnitTests) +set_target_properties(ExtraToolsUnitTests PROPERTIES FOLDER "Extra Tools Unit Tests") + +function(add_extra_unittest test_dirname) + add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN}) +endfunction() + +add_subdirectory(cpp11-migrate) diff --git a/clang-tools-extra/unittests/Makefile b/clang-tools-extra/unittests/Makefile new file mode 100644 index 000000000000..39e155afa8eb --- /dev/null +++ b/clang-tools-extra/unittests/Makefile @@ -0,0 +1,15 @@ +##===- tools/extra/test/Unit/Makefile ----------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +CLANG_LEVEL := ../../.. +include $(CLANG_LEVEL)/../../Makefile.config + +PARALLEL_DIRS := cpp11-migrate + +include $(CLANG_LEVEL)/Makefile diff --git a/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt b/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt new file mode 100644 index 000000000000..da0eebeed42b --- /dev/null +++ b/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_LINK_COMPONENTS + support + ) + +add_extra_unittest(Cpp11MigrateTests + dummy.cpp) + +target_link_libraries(Cpp11MigrateTests + clangTooling + clangBasic + clangASTMatchers + ) + diff --git a/clang-tools-extra/unittests/cpp11-migrate/Makefile b/clang-tools-extra/unittests/cpp11-migrate/Makefile new file mode 100644 index 000000000000..46afa30571e3 --- /dev/null +++ b/clang-tools-extra/unittests/cpp11-migrate/Makefile @@ -0,0 +1,22 @@ +##===- unittests/cpp11-migrate/Makefile --------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +CLANG_LEVEL = ../../../.. +include $(CLANG_LEVEL)/../../Makefile.config + +TESTNAME = Cpp11MigrateTests +LINK_COMPONENTS := asmparser bitreader support mc +USEDLIBS = clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \ + clangRewriteFrontend.a clangRewriteCore.a clangParse.a \ + clangSema.a clangAnalysis.a \ + clangAST.a clangASTMatchers.a clangEdit.a clangLex.a clangBasic.a + +include $(CLANG_LEVEL)/Makefile +MAKEFILE_UNITTEST_NO_INCLUDE_COMMON := 1 +include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/clang-tools-extra/unittests/cpp11-migrate/dummy.cpp b/clang-tools-extra/unittests/cpp11-migrate/dummy.cpp new file mode 100644 index 000000000000..f837fa8c24fd --- /dev/null +++ b/clang-tools-extra/unittests/cpp11-migrate/dummy.cpp @@ -0,0 +1,6 @@ +#include "gtest/gtest.h" + +// FIXME: Replace this test with something more meaningful. +TEST(SimpleTest, Test) { + ASSERT_TRUE(true); +}