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
This commit is contained in:
Edwin Vane 2013-04-03 15:11:08 +00:00
parent 7ac4592e97
commit c0b7be60f8
11 changed files with 120 additions and 3 deletions

View File

@ -5,3 +5,4 @@ add_subdirectory(modularize)
# Add the common testsuite after all the tools. # Add the common testsuite after all the tools.
add_subdirectory(test) add_subdirectory(test)
add_subdirectory(unittests)

View File

@ -11,7 +11,7 @@ CLANG_LEVEL := ../..
include $(CLANG_LEVEL)/../../Makefile.config 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 include $(CLANG_LEVEL)/Makefile

View File

@ -12,6 +12,11 @@ configure_lit_site_cfg(
${CMAKE_CURRENT_BINARY_DIR}/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) option(CLANG_TOOLS_TEST_USE_VG "Run Clang tools' tests under Valgrind" OFF)
if(CLANG_TOOLS_TEST_USE_VG) if(CLANG_TOOLS_TEST_USE_VG)
set(CLANG_TOOLS_TEST_EXTRA_ARGS ${CLANG_TEST_EXTRA_ARGS} "--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. # Individual tools we test.
remove-cstr-calls cpp11-migrate modularize remove-cstr-calls cpp11-migrate modularize
# Unit tests
ExtraToolsUnitTests
) )
add_lit_testsuite(check-clang-tools "Running the Clang extra tools' regression tests" add_lit_testsuite(check-clang-tools "Running the Clang extra tools' regression tests"

View File

@ -38,7 +38,7 @@ ifdef VG
LIT_ARGS += "--vg" LIT_ARGS += "--vg"
endif endif
all:: lit.site.cfg all:: lit.site.cfg Unit/lit.site.cfg
@ echo '--- Running the Clang extra tools tests for $(TARGET_TRIPLE) ---' @ echo '--- Running the Clang extra tools tests for $(TARGET_TRIPLE) ---'
@ $(PYTHON) $(LLVM_SRC_ROOT)/utils/lit/lit.py \ @ $(PYTHON) $(LLVM_SRC_ROOT)/utils/lit/lit.py \
$(LIT_ARGS) $(TESTARGS) $(TESTDIRS) $(LIT_ARGS) $(TESTARGS) $(TESTDIRS)
@ -46,7 +46,7 @@ all:: lit.site.cfg
FORCE: FORCE:
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_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g > lit.tmp
@$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> lit.tmp @$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> lit.tmp
@$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=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 > $@ @sed -f lit.tmp $(PROJ_SRC_DIR)/lit.site.cfg.in > $@
@-rm -f lit.tmp @-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:: clean::
@ find . -name Output | xargs rm -fr @ find . -name Output | xargs rm -fr

View File

@ -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.

View File

@ -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")

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,13 @@
set(LLVM_LINK_COMPONENTS
support
)
add_extra_unittest(Cpp11MigrateTests
dummy.cpp)
target_link_libraries(Cpp11MigrateTests
clangTooling
clangBasic
clangASTMatchers
)

View File

@ -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

View File

@ -0,0 +1,6 @@
#include "gtest/gtest.h"
// FIXME: Replace this test with something more meaningful.
TEST(SimpleTest, Test) {
ASSERT_TRUE(true);
}