[lld] 7a4b276 - [lld] Add test suite mode for running LLD main twice
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 1 14:27:24 PDT 2021
Author: Shoaib Meenai
Date: 2021-11-01T14:26:54-07:00
New Revision: 7a4b27609d450d70fb072306446b1c0414066b74
URL: https://github.com/llvm/llvm-project/commit/7a4b27609d450d70fb072306446b1c0414066b74
DIFF: https://github.com/llvm/llvm-project/commit/7a4b27609d450d70fb072306446b1c0414066b74.diff
LOG: [lld] Add test suite mode for running LLD main twice
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
Added:
Modified:
lld/test/MachO/error-limit.test
lld/test/MachO/invalid/bad-archive.s
lld/test/MachO/invalid/cstring-dedup.s
lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
lld/test/MachO/invalid/reserved-section-name.s
lld/test/MachO/time-trace.s
lld/test/lit.cfg.py
Removed:
################################################################################
diff --git a/lld/test/MachO/error-limit.test b/lld/test/MachO/error-limit.test
index 79eaa3d522311..75f55084bbd59 100644
--- a/lld/test/MachO/error-limit.test
+++ b/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
diff --git a/lld/test/MachO/invalid/bad-archive.s b/lld/test/MachO/invalid/bad-archive.s
index 24f7a5d6f8354..0a405ed896653 100644
--- a/lld/test/MachO/invalid/bad-archive.s
+++ b/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
diff --git a/lld/test/MachO/invalid/cstring-dedup.s b/lld/test/MachO/invalid/cstring-dedup.s
index c2af78d344641..287f7d2156a31 100644
--- a/lld/test/MachO/invalid/cstring-dedup.s
+++ b/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
diff --git a/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll b/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
index 5e1c43c928d91..f2ab80213a2c3 100644
--- a/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
+++ b/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
diff --git a/lld/test/MachO/invalid/reserved-section-name.s b/lld/test/MachO/invalid/reserved-section-name.s
index 7614a1001f16a..97dd4376c88f1 100644
--- a/lld/test/MachO/invalid/reserved-section-name.s
+++ b/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
diff --git a/lld/test/MachO/time-trace.s b/lld/test/MachO/time-trace.s
index c4e5cc3d92cce..e75bcd2722993 100644
--- a/lld/test/MachO/time-trace.s
+++ b/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
diff --git a/lld/test/lit.cfg.py b/lld/test/lit.cfg.py
index 225104243bf26..d03a383cc8758 100644
--- a/lld/test/lit.cfg.py
+++ b/lld/test/lit.cfg.py
@@ -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
More information about the llvm-commits
mailing list