Skip to content

Commit

Permalink
[lit] Add a generic build script with a lit substitution.
Browse files Browse the repository at this point in the history
This adds a script called build.py as well as a lit substitution
called %build that we can use to invoke it.  The idea is that
this allows a lit test to build test inferiors without having
to worry about architecture / platform specific differences,
command line syntax, finding / configurationg a proper toolchain,
and other issues.  They can simply write something like:

%build --arch=32 -o %t.exe %p/Inputs/foo.cpp

and it will just work.  This paves the way for being able to
run lit tests with multiple configurations, platforms, and
compilers with a single test.

Differential Revision: https://reviews.llvm.org/D54914

llvm-svn: 348058
Zachary Turner committed Dec 1, 2018
1 parent e5664b1 commit ba968c0
Showing 17 changed files with 702 additions and 56 deletions.
3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/ast-reconstruction.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test various interesting cases for AST reconstruction.
// RUN: %clang_cl /Z7 /GS- /GR- /c /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/ast-reconstruction.lldbinit 2>&1 | FileCheck %s

3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/bitfields.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test various interesting cases for AST reconstruction.
// RUN: %clang_cl /Z7 /GS- /GR- /std:c++latest -Xclang -fkeep-static-consts /c /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/bitfields.lldbinit 2>&1 | FileCheck %s

19 changes: 9 additions & 10 deletions lldb/lit/SymbolFile/NativePDB/disassembly.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test that we can show disassembly and source.
// RUN: %clang_cl -m64 /Z7 /GS- /GR- /c /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/disassembly.lldbinit | FileCheck %s

@@ -19,21 +18,21 @@ int main(int argc, char **argv) {


// CHECK: (lldb) disassemble --flavor=intel -m -n main
// CHECK: 13 int foo() { return 42; }
// CHECK-NEXT: 14
// CHECK-NEXT: ** 15 int main(int argc, char **argv) {
// CHECK: 12 int foo() { return 42; }
// CHECK-NEXT: 13
// CHECK-NEXT: ** 14 int main(int argc, char **argv) {
// CHECK: disassembly.cpp.tmp.exe`main:
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+0>: sub rsp, 0x38
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+4>: mov dword ptr [rsp + 0x34], 0x0
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+12>: mov qword ptr [rsp + 0x28], rdx
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+17>: mov dword ptr [rsp + 0x24], ecx
// CHECK: ** 16 foo();
// CHECK: disassembly.cpp.tmp.exe[{{.*}}] <+21>: call {{.*}} ; foo at disassembly.cpp:13
// CHECK: ** 15 foo();
// CHECK: disassembly.cpp.tmp.exe[{{.*}}] <+21>: call {{.*}} ; foo at disassembly.cpp:12
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+26>: xor ecx, ecx
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+28>: mov dword ptr [rsp + 0x20], eax
// CHECK: ** 17 return 0;
// CHECK-NEXT: 18 }
// CHECK-NEXT: 19
// CHECK: ** 16 return 0;
// CHECK-NEXT: 17 }
// CHECK-NEXT: 18
// CHECK: disassembly.cpp.tmp.exe[{{.*}}] <+32>: mov eax, ecx
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+34>: add rsp, 0x38
// CHECK-NEXT: disassembly.cpp.tmp.exe[{{.*}}] <+38>: ret
3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/function-types-builtins.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// clang-format off
// REQUIRES: lld

// RUN: %clang_cl /Z7 /GS- /GR- /c -Xclang -fkeep-static-consts /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/function-types-builtins.lldbinit | FileCheck %s

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// clang-format off
// REQUIRES: lld

// RUN: %clang_cl -m32 /Z7 /GS- /GR- /c -Xclang -fkeep-static-consts /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --arch=32 --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/function-types-calling-conv.lldbinit | FileCheck %s

3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/function-types-classes.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test that we can display function signatures with class types.
// RUN: %clang_cl /Z7 /GS- /GR- /c -fstandalone-debug -Xclang -fkeep-static-consts /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/function-types-classes.lldbinit | FileCheck %s

3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/global-classes.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test that we can display tag types.
// RUN: %clang_cl /Z7 /GS- /GR- /c -Xclang -fkeep-static-consts /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/globals-classes.lldbinit | FileCheck %s

3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/globals-bss.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Make sure we can read variables from BSS
// RUN: %clang_cl /Z7 /GS- /GR- /c /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: llvm-readobj -s %t.exe | FileCheck --check-prefix=BSS %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/globals-bss.lldbinit 2>&1 | FileCheck %s
3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/globals-fundamental.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test that we can display tag types.
// RUN: %clang_cl /Z7 /GS- /GR- /c -Xclang -fkeep-static-consts /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/globals-fundamental.lldbinit | FileCheck %s

3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/nested-types.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test various interesting cases for AST reconstruction.
// RUN: %clang_cl /Z7 /GS- /GR- -Xclang -fkeep-static-consts /c /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/nested-types.lldbinit 2>&1 | FileCheck %s

2 changes: 1 addition & 1 deletion lldb/lit/SymbolFile/NativePDB/s_constant.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
// Test that we can display S_CONSTANT records.

// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-win32 %p/Inputs/s_constant.s > %t.obj
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib --mode=link -o %t.exe -- %t.obj
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/s_constant.lldbinit | FileCheck %s

17 changes: 8 additions & 9 deletions lldb/lit/SymbolFile/NativePDB/simple-breakpoints.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test that we can set simple breakpoints using PDB on any platform.
// RUN: %clang_cl /Z7 /GS- /GR- /c /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/breakpoints.lldbinit | FileCheck %s

@@ -38,27 +37,27 @@ int main(int argc, char **argv) {
// CHECK: Current executable set to '{{.*}}simple-breakpoints.cpp.tmp.exe'
// CHECK: (lldb) break set -n main
// CHECK: Breakpoint 1: where = simple-breakpoints.cpp.tmp.exe`main + {{[0-9]+}}
// CHECK-SAME: at simple-breakpoints.cpp:31
// CHECK-SAME: at simple-breakpoints.cpp:30
// CHECK: (lldb) break set -n OvlGlobalFn
// CHECK: Breakpoint 2: 3 locations.
// CHECK: (lldb) break set -n StaticFn
// CHECK: Breakpoint 3: where = simple-breakpoints.cpp.tmp.exe`StaticFn + {{[0-9]+}}
// CHECK-SAME: at simple-breakpoints.cpp:24
// CHECK-SAME: at simple-breakpoints.cpp:23
// CHECK: (lldb) break set -n DoesntExist
// CHECK: Breakpoint 4: no locations (pending).
// CHECK: (lldb) break list
// CHECK: Current breakpoints:
// CHECK: 1: name = 'main', locations = 1
// CHECK: 1.1: where = simple-breakpoints.cpp.tmp.exe`main + {{[0-9]+}}
// CHECK-SAME: at simple-breakpoints.cpp:31
// CHECK-SAME: at simple-breakpoints.cpp:30
// CHECK: 2: name = 'OvlGlobalFn', locations = 3
// CHECK: 2.1: where = simple-breakpoints.cpp.tmp.exe`OvlGlobalFn + {{[0-9]+}}
// CHECK-SAME: at simple-breakpoints.cpp:13
// CHECK-SAME: at simple-breakpoints.cpp:12
// CHECK: 2.2: where = simple-breakpoints.cpp.tmp.exe`OvlGlobalFn
// CHECK-SAME: at simple-breakpoints.cpp:16
// CHECK-SAME: at simple-breakpoints.cpp:15
// CHECK: 2.3: where = simple-breakpoints.cpp.tmp.exe`OvlGlobalFn + {{[0-9]+}}
// CHECK-SAME: at simple-breakpoints.cpp:20
// CHECK-SAME: at simple-breakpoints.cpp:19
// CHECK: 3: name = 'StaticFn', locations = 1
// CHECK: 3.1: where = simple-breakpoints.cpp.tmp.exe`StaticFn + {{[0-9]+}}
// CHECK-SAME: at simple-breakpoints.cpp:24
// CHECK-SAME: at simple-breakpoints.cpp:23
// CHECK: 4: name = 'DoesntExist', locations = 0 (pending)
29 changes: 14 additions & 15 deletions lldb/lit/SymbolFile/NativePDB/source-list.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test that we can set display source of functions.
// RUN: %clang_cl /Z7 /GS- /GR- /c /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/source-list.lldbinit | FileCheck %s

@@ -27,17 +26,17 @@ int main(int argc, char **argv) {

// CHECK: (lldb) source list -n main
// CHECK: File: {{.*}}source-list.cpp
// CHECK: 11
// CHECK: 12 // Some context lines before
// CHECK: 13 // the function.
// CHECK: 10
// CHECK: 11 // Some context lines before
// CHECK: 12 // the function.
// CHECK: 13
// CHECK: 14
// CHECK: 15
// CHECK: 16 int main(int argc, char **argv) {
// CHECK: 17 // Here are some comments.
// CHECK: 18 // That we should print when listing source.
// CHECK: 19 return 0;
// CHECK: 20 }
// CHECK: 21
// CHECK: 22 // Some context lines after
// CHECK: 23 // the function.
// CHECK: 24
// CHECK: 15 int main(int argc, char **argv) {
// CHECK: 16 // Here are some comments.
// CHECK: 17 // That we should print when listing source.
// CHECK: 18 return 0;
// CHECK: 19 }
// CHECK: 20
// CHECK: 21 // Some context lines after
// CHECK: 22 // the function.
// CHECK: 23
3 changes: 1 addition & 2 deletions lldb/lit/SymbolFile/NativePDB/tag-types.cpp
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
// REQUIRES: lld

// Test that we can display tag types.
// RUN: %clang_cl /Z7 /GS- /GR- /c /Fo%t.obj -- %s
// RUN: lld-link /DEBUG /nodefaultlib /entry:main /OUT:%t.exe /PDB:%t.pdb -- %t.obj
// RUN: %build --compiler=clang-cl --nodefaultlib -o %t.exe -- %s
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
// RUN: %p/Inputs/tag-types.lldbinit | FileCheck %s

644 changes: 644 additions & 0 deletions lldb/lit/helper/build.py

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion lldb/lit/helper/toolchain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import itertools
import platform
import subprocess
import sys
@@ -19,6 +20,15 @@ def use_lldb_substitutions(config):
command=FindTool('lldb-mi'),
extra_args=['--synchronous'],
unresolved='ignore')
build_script = os.path.dirname(__file__)
build_script = os.path.join(build_script, 'build.py')
build_script_args = [build_script,
'--compiler=any', # Default to best compiler
'--arch=64'] # Default to 64-bit, user can override
if config.lldb_lit_tools_dir:
build_script_args.append('--tools-dir={0}'.format(config.lldb_lit_tools_dir))
if config.lldb_tools_dir:
build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
primary_tools = [
ToolSubst('%lldb',
command=FindTool('lldb'),
@@ -30,7 +40,10 @@ def use_lldb_substitutions(config):
command=FindTool(dsname),
extra_args=dsargs,
unresolved='ignore'),
'lldb-test'
'lldb-test',
ToolSubst('%build',
command="'" + sys.executable + "'",
extra_args=build_script_args)
]

llvm_config.add_tool_substitutions(primary_tools,
2 changes: 2 additions & 0 deletions llvm/utils/lit/lit/llvm/config.py
Original file line number Diff line number Diff line change
@@ -33,6 +33,8 @@ def __init__(self, lit_config, config):
['cmp.exe', 'grep.exe', 'sed.exe'])
if path is not None:
self.with_environment('PATH', path, append_path=True)
# Many tools behave strangely if these environment variables aren't set.
self.with_system_environment(['SystemDrive', 'SystemRoot', 'TEMP', 'TMP'])
self.use_lit_shell = True

# Choose between lit's internal shell pipeline runner and a real shell. If

0 comments on commit ba968c0

Please sign in to comment.