Index: libc/test/CMakeLists.txt =================================================================== --- libc/test/CMakeLists.txt +++ libc/test/CMakeLists.txt @@ -2,3 +2,7 @@ add_subdirectory(config) add_subdirectory(src) + +if (LIBC_LIT_TESTS) + add_subdirectory(test) +endif() Index: libc/test/test/CMakeLists.txt =================================================================== --- /dev/null +++ libc/test/test/CMakeLists.txt @@ -0,0 +1,20 @@ +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py +) + + +set(LLVM_TEST_DEPENDS + not + FileCheck +) + +add_lit_testsuite(check-libc-lit "Running llvm libc lit tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS + llvmlibc +) + +set_target_properties(check-libc-lit PROPERTIES FOLDER "Tests") Index: libc/test/test/lit.cfg.py =================================================================== --- /dev/null +++ libc/test/test/lit.cfg.py @@ -0,0 +1,50 @@ +# -*- Python -*- + +import os +import platform +import re +import subprocess +import tempfile + +import lit.formats +import lit.util + +from lit.llvm import llvm_config +from lit.llvm.subst import ToolSubst +from lit.llvm.subst import FindTool + +# Configuration file for the 'lit' test runner. + +# name: The name of this test suite. +config.name = 'libc' + +# testFormat: The test format to use to interpret tests. +# +# For now we require '&&' between commands, until they get globally killed and +# the test runner updated. +config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = ['.c', '.cpp', '.test', '.s'] + +# excludes: A list of directories to exclude from the testsuite. The 'Inputs' +# subdirectories contain auxiliary inputs for various tests in their parent +# directories. +config.excludes = ['CMakeLists.txt'] + +# test_source_root: The root path where tests are located. +config.test_source_root = os.path.dirname(__file__) + +llvm_config.use_default_substitutions() + +def findLibcIncDir(): + return config.libc_build_dir + '/include/' + +def findLibcDotA(): + return config.libc_build_dir + '/lib/libllvmlibc.a' + +# TODO: in the future when we provide the crt, make sure we aren't linking +# against the system libc at all. +config.substitutions.append( + ('%clang_libc', 'clang -nostdinc -isystem ' + + findLibcIncDir() + ' ' + findLibcDotA())) Index: libc/test/test/lit.site.cfg.py.in =================================================================== --- /dev/null +++ libc/test/test/lit.site.cfg.py.in @@ -0,0 +1,24 @@ +@LIT_SITE_CFG_IN_HEADER@ + +import sys + +config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" +config.llvm_src_root = "@LLVM_SOURCE_DIR@" +config.llvm_obj_root = "@LLVM_BINARY_DIR@" +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.libc_build_dir = "@LIBC_BUILD_DIR@" + +# Support substitution of the tools_dir with user parameters. +# This is used when we can't determine the tool dir at configuration time. +try: + config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params +except KeyError: + e = sys.exc_info()[1] + key, = e.args + lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) + +import lit.llvm +lit.llvm.initialize(lit_config, config) + +# Let the main config do the real work. +lit_config.load_config(config, "@LIBC_SOURCE_DIR@/test/test/lit.cfg.py") Index: libc/test/test/sanity/includes.c =================================================================== --- /dev/null +++ libc/test/test/sanity/includes.c @@ -0,0 +1,18 @@ +// This tests that all of the expected includes are available in their expected +// directories and are syntactically valid. + +// RUN: %clang_libc %s -fsyntax-only + +#include +// #include This fails because ctype.h is never copied into the +// build's include directory. +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#include +#endif Index: libc/test/test/sanity/sanity.c =================================================================== --- /dev/null +++ libc/test/test/sanity/sanity.c @@ -0,0 +1,9 @@ +// This is a sanity check to ensure llvm libc headers are in our include path +// and that the llvm libc lit tests are set up correctly. + +// RUN: %clang_libc %s -fsyntax-only 2>&1 | FileCheck %s +// CHECK: sanity check compiled successfully + +#include <__llvm-libc-common.h> + +#warning "sanity check compiled successfully" Index: libc/test/test/src/assert/assert.c =================================================================== --- /dev/null +++ libc/test/test/src/assert/assert.c @@ -0,0 +1,15 @@ +// This tests that asserts error message is as we expect. + +// RUN: %clang_libc %s -o %t +// RUN: not %t | FileCheck %s + +// RUN: %clang_libc %s -o %t -DNDEBUG +// RUN: %t + +// CHECK: assert.c: Assertion failed '0' in function 'int main()' + +#include + +int main() { + assert(0); +}