Skip to content

Commit

Permalink
[lld] Add test suite mode for running LLD main twice
Browse files Browse the repository at this point in the history
LLD_IN_TEST determines how many times each port's `main` function is
run in each LLD process, and setting LLD_IN_TEST=2 (or higher) is useful
for checking if we're cleaning up and resetting global state correctly.
Add a test suite parameter to enable this easily. There's work in
progress to remove global state (e.g. D108850), but this seems useful in
the interim.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D112898
  • Loading branch information
smeenai committed Nov 1, 2021
1 parent 59d7f99 commit 7a4b276
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lld/test/MachO/error-limit.test
@@ -1,3 +1,7 @@
## We're intentionally testing fatal errors, which isn't supported for testing
## when main is run twice.
XFAIL: main-run-twice

## Check that we only see 20 (the default error-limit) "cannot open" errors
RUN: not %lld A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 2>&1 | \
RUN: FileCheck -check-prefix=DEFAULT %s
Expand Down
4 changes: 4 additions & 0 deletions lld/test/MachO/invalid/bad-archive.s
@@ -1,3 +1,7 @@
## We're intentionally testing fatal errors (for malformed input files), and
## fatal errors aren't supported for testing when main is run twice.
# XFAIL: main-run-twice

# REQUIRES: x86
# RUN: echo "!<arch>" > %t.a
# RUN: echo "foo" >> %t.a
Expand Down
4 changes: 4 additions & 0 deletions lld/test/MachO/invalid/cstring-dedup.s
@@ -1,3 +1,7 @@
## We're intentionally testing fatal errors (for malformed input files), and
## fatal errors aren't supported for testing when main is run twice.
# XFAIL: main-run-twice

# REQUIRES: x86
# RUN: rm -rf %t; split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/not-terminated.s -o %t/not-terminated.o
Expand Down
4 changes: 4 additions & 0 deletions lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
@@ -1,3 +1,7 @@
;; We're intentionally testing fatal errors (for malformed input files), and
;; fatal errors aren't supported for testing when main is run twice.
; XFAIL: main-run-twice

; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: not %lld %t.o -o /dev/null 2>&1 | FileCheck %s
Expand Down
4 changes: 4 additions & 0 deletions lld/test/MachO/invalid/reserved-section-name.s
@@ -1,3 +1,7 @@
## We're intentionally testing fatal errors (for malformed input files), and
## fatal errors aren't supported for testing when main is run twice.
# XFAIL: main-run-twice

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not %lld -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
Expand Down
4 changes: 4 additions & 0 deletions lld/test/MachO/time-trace.s
@@ -1,3 +1,7 @@
## When running main twice, we'll also output the time trace JSON twice, which
## breaks JSON parsing.
# XFAIL: main-run-twice

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o

Expand Down
17 changes: 16 additions & 1 deletion lld/test/lit.cfg.py
Expand Up @@ -81,7 +81,22 @@

# Set a fake constant version so that we get consistent output.
config.environment['LLD_VERSION'] = 'LLD 1.0'
config.environment['LLD_IN_TEST'] = '1'

# LLD_IN_TEST determines how many times `main` is run inside each process, which
# lets us test that it's cleaning up after itself and resetting global state
# correctly (which is important for usage as a library).
run_lld_main_twice = lit_config.params.get('RUN_LLD_MAIN_TWICE', False)
if not run_lld_main_twice:
config.environment['LLD_IN_TEST'] = '1'
else:
config.environment['LLD_IN_TEST'] = '2'
# Many ELF tests fail in this mode.
config.excludes.append('ELF')
# Some old Mach-O backend tests fail, and it's due for removal anyway.
config.excludes.append('mach-o')
# Some new Mach-O backend tests fail; give them a way to mark themselves
# unsupported in this mode.
config.available_features.add('main-run-twice')

# Indirectly check if the mt.exe Microsoft utility exists by searching for
# cvtres, which always accompanies it. Alternatively, check if we can use
Expand Down

0 comments on commit 7a4b276

Please sign in to comment.