[Lldb-commits] [lldb] r281651 - [LIT] First pass of LLDB LIT support
Chris Bieneman via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 15 13:13:56 PDT 2016
Author: cbieneman
Date: Thu Sep 15 15:13:55 2016
New Revision: 281651
URL: http://llvm.org/viewvc/llvm-project?rev=281651&view=rev
Log:
[LIT] First pass of LLDB LIT support
Summary:
This patch supplies basic infrastructure for LLDB to use LIT, and ports a few basic test cases from the LLDB test suite into LIT.
With this patch the LLDB lit system is not capable or intended to fully replace the existing LLDB test suite, but this first patch enables people to write lit tests for LLDB.
The lit substitution for %cc and %cxx default to the host compiler unless the CMake option LLDB_TEST_CLANG is On, in which case the in-tree clang will be used.
The target check-lldb-lit will run all lit tests including the lit-based executor for the unit tests. Alternatively there is a target generated for each subdirectory under the lit directory, so check-lldb-unit and check-lldb-expr will run just the tests under their respective directories.
The ported tests are not removed from the existing suite, and should not be until such a time when the lit runner is mature and in use by bots and workflows.
Reviewers: zturner, labath, jingham, tfiala
Subscribers: beanz, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D24591
Added:
lldb/trunk/lit/Expr/
lldb/trunk/lit/Expr/Inputs/
lldb/trunk/lit/Expr/Inputs/anonymous-struct.cpp
lldb/trunk/lit/Expr/Inputs/call-function.cpp
lldb/trunk/lit/Expr/TestCallStdStringFunction.test
lldb/trunk/lit/Expr/TestCallStopAndContinue.test
lldb/trunk/lit/Expr/TestCallUserAnonTypedef.test
lldb/trunk/lit/Expr/TestCallUserDefinedFunction.test
lldb/trunk/lit/Expr/lit.local.cfg
Modified:
lldb/trunk/lit/CMakeLists.txt
lldb/trunk/lit/Unit/lit.cfg
lldb/trunk/lit/Unit/lit.site.cfg.in
lldb/trunk/lit/lit.cfg
lldb/trunk/lit/lit.site.cfg.in
Modified: lldb/trunk/lit/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/CMakeLists.txt?rev=281651&r1=281650&r2=281651&view=diff
==============================================================================
--- lldb/trunk/lit/CMakeLists.txt (original)
+++ lldb/trunk/lit/CMakeLists.txt Thu Sep 15 15:13:55 2016
@@ -11,6 +11,10 @@ else()
set(ENABLE_SHARED 0)
endif(BUILD_SHARED_LIBS)
+option(LLDB_TEST_CLANG "Use in-tree clang when testing lldb" Off)
+set(LLDB_TEST_C_COMPILER "" CACHE STRING "C compiler to use when testing LLDB")
+set(LLDB_TEST_CXX_COMPILER "" CACHE STRING "C++ compiler to use when testing LLDB")
+
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
@@ -20,17 +24,36 @@ configure_lit_site_cfg(
)
set(LLDB_TEST_DEPS
+ FileCheck
+ debugserver
LLDBUnitTests
+ lldb
+ lldb-server
+ not
)
+
+if(LLDB_TEST_CLANG)
+ if(LLDB_TEST_C_COMPILER OR LLDB_TEST_CXX_COMPILER)
+ message(SEND_ERROR "Cannot override LLDB_TEST_<LANG>_COMPILER and set LLDB_TEST_CLANG.")
+ endif()
+ list(APPEND LLDB_TEST_DEPS clang)
+endif()
+
set(LLDB_TEST_PARAMS
lldb_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
)
-add_lit_testsuite(check-lldb-unit "Running lldb unit test suite"
+add_lit_testsuite(check-lldb-lit "Running lldb lit test suite"
${CMAKE_CURRENT_BINARY_DIR}
PARAMS lldb_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
lldb_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
DEPENDS ${LLDB_TEST_DEPS}
)
-set_target_properties(check-lldb-unit PROPERTIES FOLDER "LLDB tests")
+set_target_properties(check-lldb-lit PROPERTIES FOLDER "LLDB tests")
+
+add_lit_testsuites(LLDB ${CMAKE_CURRENT_SOURCE_DIR}
+ PARAMS lldb_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+ lldb_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
+ DEPENDS ${LLDB_TEST_DEPS}
+ )
Added: lldb/trunk/lit/Expr/Inputs/anonymous-struct.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/Inputs/anonymous-struct.cpp?rev=281651&view=auto
==============================================================================
--- lldb/trunk/lit/Expr/Inputs/anonymous-struct.cpp (added)
+++ lldb/trunk/lit/Expr/Inputs/anonymous-struct.cpp Thu Sep 15 15:13:55 2016
@@ -0,0 +1,26 @@
+#include <tgmath.h>
+
+typedef struct {
+ float f;
+ int i;
+} my_untagged_struct;
+
+double multiply(my_untagged_struct *s)
+{
+ return s->f * s->i;
+}
+
+double multiply(my_untagged_struct *s, int x)
+{
+ return multiply(s) * x;
+}
+
+int main(int argc, char **argv)
+{
+ my_untagged_struct s = {
+ .f = (float)argc,
+ .i = argc,
+ };
+ // lldb testsuite break
+ return !(multiply(&s, argc) == pow(argc, 3));
+}
Added: lldb/trunk/lit/Expr/Inputs/call-function.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/Inputs/call-function.cpp?rev=281651&view=auto
==============================================================================
--- lldb/trunk/lit/Expr/Inputs/call-function.cpp (added)
+++ lldb/trunk/lit/Expr/Inputs/call-function.cpp Thu Sep 15 15:13:55 2016
@@ -0,0 +1,53 @@
+#include <iostream>
+#include <string>
+#include <cstring>
+
+struct Five
+{
+ int number;
+ const char *name;
+};
+
+Five
+returnsFive()
+{
+ Five my_five = {5, "five"};
+ return my_five;
+}
+
+unsigned int
+fib(unsigned int n)
+{
+ if (n < 2)
+ return n;
+ else
+ return fib(n - 1) + fib(n - 2);
+}
+
+int
+add(int a, int b)
+{
+ return a + b;
+}
+
+bool
+stringCompare(const char *str)
+{
+ if (strcmp( str, "Hello world" ) == 0)
+ return true;
+ else
+ return false;
+}
+
+int main (int argc, char const *argv[])
+{
+ std::string str = "Hello world";
+ std::cout << str << std::endl;
+ std::cout << str.c_str() << std::endl;
+ Five main_five = returnsFive();
+#if 0
+ print str
+ print str.c_str()
+#endif
+ return 0; // Please test these expressions while stopped at this line:
+}
Added: lldb/trunk/lit/Expr/TestCallStdStringFunction.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/TestCallStdStringFunction.test?rev=281651&view=auto
==============================================================================
--- lldb/trunk/lit/Expr/TestCallStdStringFunction.test (added)
+++ lldb/trunk/lit/Expr/TestCallStdStringFunction.test Thu Sep 15 15:13:55 2016
@@ -0,0 +1,14 @@
+# XFAIL: windows
+# -> llvm.org/pr21765
+
+# XFAIL: freebsd
+# -> llvm.org/pr17807
+
+# RUN: %cxx %p/Inputs/call-function.cpp -g -o %t && %lldb -b -s %s -- %t | FileCheck %s
+
+breakpoint set --file call-function.cpp --line 52
+run
+print str
+# CHECK: Hello world
+print str.c_str()
+# CHECK: Hello world
Added: lldb/trunk/lit/Expr/TestCallStopAndContinue.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/TestCallStopAndContinue.test?rev=281651&view=auto
==============================================================================
--- lldb/trunk/lit/Expr/TestCallStopAndContinue.test (added)
+++ lldb/trunk/lit/Expr/TestCallStopAndContinue.test Thu Sep 15 15:13:55 2016
@@ -0,0 +1,12 @@
+# XFAIL: windows
+# -> llvm.org/pr24489
+
+# RUN: %cxx %p/Inputs/call-function.cpp -g -o %t && %lldb -b -s %s -o continue -o "thread list" -- %t 2>&1 | FileCheck %s
+
+breakpoint set --file call-function.cpp --line 52
+run
+breakpoint set --file call-function.cpp --line 14
+expression -i false -- returnsFive()
+# CHECK: Execution was interrupted, reason: breakpoint
+# CHECK: stop reason = User Expression thread plan
+# CHECK: Completed expression: (Five) $0 = (number = 5 {{.*}}, name = "five")
Added: lldb/trunk/lit/Expr/TestCallUserAnonTypedef.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/TestCallUserAnonTypedef.test?rev=281651&view=auto
==============================================================================
--- lldb/trunk/lit/Expr/TestCallUserAnonTypedef.test (added)
+++ lldb/trunk/lit/Expr/TestCallUserAnonTypedef.test Thu Sep 15 15:13:55 2016
@@ -0,0 +1,11 @@
+# XFAIL: windows
+
+# XFAIL: armhf-linux
+# -> llvm.org/pr27868
+
+# RUN: %cxx %p/Inputs/anonymous-struct.cpp -g -o %t && %lldb -b -s %s -- %t | FileCheck %s
+
+breakpoint set --file anonymous-struct.cpp --line 24
+run
+expression multiply(&s)
+# CHECK: $0 = 1
Added: lldb/trunk/lit/Expr/TestCallUserDefinedFunction.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/TestCallUserDefinedFunction.test?rev=281651&view=auto
==============================================================================
--- lldb/trunk/lit/Expr/TestCallUserDefinedFunction.test (added)
+++ lldb/trunk/lit/Expr/TestCallUserDefinedFunction.test Thu Sep 15 15:13:55 2016
@@ -0,0 +1,20 @@
+# XFAIL: windows
+# -> llvm.org/pr24489
+
+# RUN: %cxx %p/Inputs/call-function.cpp -g -o %t && %lldb -b -s %s -- %t | FileCheck %s
+
+breakpoint set --file call-function.cpp --line 52
+run
+expression fib(5)
+# CHECK: $0 = 5
+expression add(4,8)
+# CHECK: $1 = 12
+
+expression add(add(5,2),add(3,4))
+# CHECK: $2 = 14
+expression add(add(5,2),fib(5))
+# CHECK: $3 = 12
+expression stringCompare((const char*) "Hello world")
+# CHECK: $4 = true
+expression stringCompare((const char*) "Hellworld")
+# CHECK: $5 = false
Added: lldb/trunk/lit/Expr/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/lit.local.cfg?rev=281651&view=auto
==============================================================================
--- lldb/trunk/lit/Expr/lit.local.cfg (added)
+++ lldb/trunk/lit/Expr/lit.local.cfg Thu Sep 15 15:13:55 2016
@@ -0,0 +1 @@
+config.suffixes = ['.test']
Modified: lldb/trunk/lit/Unit/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Unit/lit.cfg?rev=281651&r1=281650&r2=281651&view=diff
==============================================================================
--- lldb/trunk/lit/Unit/lit.cfg (original)
+++ lldb/trunk/lit/Unit/lit.cfg Thu Sep 15 15:13:55 2016
@@ -6,6 +6,19 @@ import os
import lit.formats
+# Check that the object root is known.
+if config.test_exec_root is None:
+ # Otherwise, we haven't loaded the site specific configuration (the user is
+ # probably trying to run on a test file directly, and either the site
+ # configuration hasn't been created by the build system, or we are in an
+ # out-of-tree build situation).
+
+ # Check for 'llvm_unit_site_config' user parameter, and use that if available.
+ site_cfg = lit_config.params.get('lldb_unit_site_config', None)
+ if site_cfg and os.path.exists(site_cfg):
+ lit_config.load_config(config, site_cfg)
+ raise SystemExit
+
# name: The name of this test suite.
config.name = 'lldb-Unit'
Modified: lldb/trunk/lit/Unit/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Unit/lit.site.cfg.in?rev=281651&r1=281650&r2=281651&view=diff
==============================================================================
--- lldb/trunk/lit/Unit/lit.site.cfg.in (original)
+++ lldb/trunk/lit/Unit/lit.site.cfg.in Thu Sep 15 15:13:55 2016
@@ -1,5 +1,6 @@
@LIT_SITE_CFG_IN_HEADER@
+config.test_exec_root = "@LLVM_BINARY_DIR@"
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
Modified: lldb/trunk/lit/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/lit.cfg?rev=281651&r1=281650&r2=281651&view=diff
==============================================================================
--- lldb/trunk/lit/lit.cfg (original)
+++ lldb/trunk/lit/lit.cfg Thu Sep 15 15:13:55 2016
@@ -112,17 +112,80 @@ if config.test_exec_root is None:
lit_config.load_config(config, site_cfg)
raise SystemExit
+# Register substitutions
+config.substitutions.append(('%python', config.python_executable))
+
+debugserver = lit.util.which('debugserver', llvm_tools_dir)
+lldb = lit.util.which('lldb', llvm_tools_dir)
+
+if not os.path.exists(config.cc):
+ config.cc = lit.util.which(config.cc, llvm_tools_dir)
+
+if not os.path.exists(config.cxx):
+ config.cxx = lit.util.which(config.cxx, llvm_tools_dir)
+
+if platform.system() in ['Darwin']:
+ try:
+ out = lit.util.capture(['xcrun', '--show-sdk-path']).strip()
+ res = 0
+ except OSError:
+ res = -1
+ if res == 0 and out:
+ sdk_path = out
+ lit_config.note('using SDKROOT: %r' % sdk_path)
+ config.cc += " -isysroot %s" % sdk_path
+ config.cxx += " -isysroot %s" % sdk_path
+
+config.substitutions.append(('%cc', config.cc))
+config.substitutions.append(('%cxx', config.cxx))
+
+config.substitutions.append(('%lldb', lldb))
+config.substitutions.append(('%debugserver', debugserver))
+
+for pattern in [r"\bFileCheck\b",
+ r"\| \bnot\b"]:
+ tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
+ pattern)
+ tool_pipe = tool_match.group(2)
+ tool_name = tool_match.group(4)
+ tool_path = lit.util.which(tool_name, config.llvm_tools_dir)
+ if not tool_path:
+ # Warn, but still provide a substitution.
+ lit_config.note(
+ 'Did not find ' + tool_name + ' in ' + config.llvm_tools_dir)
+ config.substitutions.append((pattern, tool_pipe + tool_path))
+
# Shell execution
if platform.system() not in ['Windows'] or lit_config.getBashPath() != '':
config.available_features.add('shell')
# Running on Darwin OS
if platform.system() in ['Darwin']:
+ config.available_features.add('darwin')
config.available_features.add('system-linker-mach-o')
# Running on ELF based *nix
if platform.system() in ['FreeBSD', 'Linux']:
config.available_features.add('system-linker-elf')
+ if platform.system() in ['FreeBSD']:
+ config.available_features.add('freebsd')
+ else:
+ config.available_features.add('linux')
+
+if platform.system() in ['Windows']:
+ config.available_features.add('windows')
+
+if re.match(r'^arm(hf.*-linux)|(.*-linux-gnuabihf)', config.target_triple):
+ config.available_features.add("armhf-linux")
+
+if re.match(r'icc', config.cc):
+ config.available_features.add("compiler-icc")
+elif re.match(r'clang', config.cc):
+ config.available_features.add("compiler-clang")
+elif re.match(r'gcc', config.cc):
+ config.available_features.add("compiler-gcc")
+elif re.match(r'cl', config.cc):
+ config.available_features.add("compiler-msvc")
# llvm-config knows whether it is compiled with asserts (and)
# whether we are operating in release/debug mode.
Modified: lldb/trunk/lit/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/lit.site.cfg.in?rev=281651&r1=281650&r2=281651&view=diff
==============================================================================
--- lldb/trunk/lit/lit.site.cfg.in (original)
+++ lldb/trunk/lit/lit.site.cfg.in Thu Sep 15 15:13:55 2016
@@ -8,6 +8,22 @@ config.lit_tools_dir = "@LLVM_LIT_TOOLS_
config.lldb_obj_root = "@LLDB_BINARY_DIR@"
config.target_triple = "@TARGET_TRIPLE@"
config.python_executable = "@PYTHON_EXECUTABLE@"
+config.cc = "@CMAKE_C_COMPILER@"
+config.cxx = "@CMAKE_CXX_COMPILER@"
+
+test_c_compiler = "@LLDB_TEST_C_COMPILER@"
+test_cxx_compiler = "@LLDB_TEST_CXX_COMPILER@"
+test_clang = "@LLDB_TEST_CLANG@".lower()
+test_clang = test_clang == "on" or test_clang == "true" or test_clang == "1"
+
+if len(test_c_compiler) > 0:
+ config.cc = test_c_compiler
+if len(test_c_compiler) > 0:
+ config.cxx = test_cxx_compiler
+
+if test_clang:
+ config.cc = 'clang'
+ config.cxx = 'clang++'
# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
More information about the lldb-commits
mailing list