[PATCH] D112898: [lld] Add test suite mode for running LLD main twice

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 31 17:01:35 PDT 2021


smeenai created this revision.
smeenai added reviewers: lld-macho, aganea, rnk, MaskRay.
Herald added subscribers: ormris, steven_wu, hiraditya.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
smeenai requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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 <https://reviews.llvm.org/D108850>), but this seems useful in
the interim.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112898

Files:
  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


Index: lld/test/lit.cfg.py
===================================================================
--- lld/test/lit.cfg.py
+++ 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
Index: lld/test/MachO/time-trace.s
===================================================================
--- lld/test/MachO/time-trace.s
+++ 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.
+# UNSUPPORTED: main-run-twice
+
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
 
Index: lld/test/MachO/invalid/reserved-section-name.s
===================================================================
--- lld/test/MachO/invalid/reserved-section-name.s
+++ 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.
+# UNSUPPORTED: 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
Index: lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
===================================================================
--- lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
+++ 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.
+; UNSUPPORTED: main-run-twice
+
 ; REQUIRES: x86
 ; RUN: llvm-as %s -o %t.o
 ; RUN: not %lld %t.o -o /dev/null 2>&1 | FileCheck %s
Index: lld/test/MachO/invalid/cstring-dedup.s
===================================================================
--- lld/test/MachO/invalid/cstring-dedup.s
+++ 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.
+# UNSUPPORTED: 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
Index: lld/test/MachO/invalid/bad-archive.s
===================================================================
--- lld/test/MachO/invalid/bad-archive.s
+++ 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.
+# UNSUPPORTED: main-run-twice
+
 # REQUIRES: x86
 # RUN: echo "!<arch>" > %t.a
 # RUN: echo "foo" >> %t.a
Index: lld/test/MachO/error-limit.test
===================================================================
--- lld/test/MachO/error-limit.test
+++ 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.
+UNSUPPORTED: 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112898.383695.patch
Type: text/x-patch
Size: 4299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211101/90ecd048/attachment.bin>


More information about the llvm-commits mailing list