[clang] [DTLTO][TEST] Make Clang driver tests more robust (PR #159151)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 17 00:53:40 PDT 2025


https://github.com/bd1976bris updated https://github.com/llvm/llvm-project/pull/159151

>From 42b3a5d533f3b6855949b9b44439a441943862ca Mon Sep 17 00:00:00 2001
From: Dunbobbin <Ben.Dunbobbin at sony.com>
Date: Tue, 16 Sep 2025 19:34:48 +0100
Subject: [PATCH 1/3] [DTLTO][TEST] Make Clang driver tests more robust

The Clang driver tests tried to match the Clang executable name via a
regular expression. This failed on some buildbots where the name was not
anticipated.

Make the test more robust by extracting the filename with Python and
appending a line to the output. This is then captured into a FileCheck
variable and used directly in the check for the executable name.

Should fix buildbot failures caused by the merge of PR #159129.
---
 clang/test/Driver/DTLTO/dtlto.c     | 26 +++++++++++++++-----------
 clang/test/Driver/DTLTO/filename.py |  3 +++
 clang/test/Driver/DTLTO/ps5-dtlto.c | 29 +++++++++++++++++------------
 3 files changed, 35 insertions(+), 23 deletions(-)
 create mode 100644 clang/test/Driver/DTLTO/filename.py

diff --git a/clang/test/Driver/DTLTO/dtlto.c b/clang/test/Driver/DTLTO/dtlto.c
index 053955a9e3d4a..8f086584e6ba7 100644
--- a/clang/test/Driver/DTLTO/dtlto.c
+++ b/clang/test/Driver/DTLTO/dtlto.c
@@ -6,14 +6,16 @@
 /// Check DTLTO options are forwarded to the linker.
 
 /// Check that options are forwarded as expected with --thinlto-distributor=.
+// RUN: %python %S/filename.py %clang > %t_forward.log
 // RUN: %clang -flto=thin %s -### -fuse-ld=lld --target=x86_64-linux-gnu \
 // RUN:   -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 \
-// RUN:   -fthinlto-distributor=d.exe -Werror 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=FORWARD
+// RUN:   -fthinlto-distributor=d.exe -Werror >>%t_forward.log 2>&1
+// RUN: FileCheck %s --input-file=%t_forward.log --check-prefix=FORWARD
 
+// FORWARD: filename.py:[[CLANG:.*]]
 // FORWARD: ld.lld
 // FORWARD-SAME: "--thinlto-distributor=d.exe"
-// FORWARD-SAME: "--thinlto-remote-compiler={{.*}}clang{{[^\"]*}}"
+// FORWARD-SAME: "--thinlto-remote-compiler={{.*}}[[CLANG]]"
 // FORWARD-SAME: "--thinlto-distributor-arg=a1"
 // FORWARD-SAME: "--thinlto-distributor-arg=a2"
 // FORWARD-SAME: "--thinlto-distributor-arg=a3"
@@ -22,8 +24,8 @@
 /// that a warning is issued for unused -Xthinlto-distributor options.
 // RUN: %clang -flto=thin %s -### -fuse-ld=lld --target=x86_64-linux-gnu \
 // RUN:   -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=NODIST --implicit-check-not=distributor \
-// RUN:     --implicit-check-not=remote-compiler
+// RUN: FileCheck %s --check-prefix=NODIST --implicit-check-not=distributor \
+// RUN:   --implicit-check-not=remote-compiler
 
 // NODIST: warning: argument unused during compilation: '-Xthinlto-distributor=a1'
 // NODIST: warning: argument unused during compilation: '-Xthinlto-distributor=a2,a3'
@@ -31,10 +33,11 @@
 
 /// Check the expected arguments are forwarded by default with only
 /// --thinlto-distributor=.
+// RUN: %python %S/filename.py %clang > %t_default.log
 // RUN: %clang -flto=thin %s -### -fuse-ld=lld --target=x86_64-linux-gnu \
-// RUN:   -fthinlto-distributor=d.exe -Werror 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor \
-// RUN:     --implicit-check-not=remote-compiler
+// RUN:   -fthinlto-distributor=d.exe -Werror >>%t_default.log 2>&1
+// RUN: FileCheck %s --input-file=%t_default.log --check-prefix=DEFAULT \
+// RUN:   --implicit-check-not=distributor --implicit-check-not=remote-compiler
 
 // DEFAULT: ld.lld
 // DEFAULT-SAME: "--thinlto-distributor=d.exe"
@@ -42,10 +45,11 @@
 
 /// Check that nothing is forwarded when the compiler is not in LTO mode, and that
 /// appropriate unused option warnings are issued.
+// RUN: %python %S/filename.py %clang > %t_noflto.log
 // RUN: %clang %s -### -fuse-ld=lld --target=x86_64-linux-gnu \
-// RUN:   -fthinlto-distributor=d.exe 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=NOFLTO --implicit-check-not=distributor \
-// RUN:     --implicit-check-not=remote-compiler
+// RUN:   -fthinlto-distributor=d.exe  >>%t_noflto.log 2>&1
+// RUN: FileCheck %s --input-file=%t_noflto.log --check-prefix=NOFLTO \
+// RUN:   --implicit-check-not=distributor --implicit-check-not=remote-compiler
 
 // NOFLTO: warning: argument unused during compilation: '-fthinlto-distributor=d.exe'
 // NOFLTO: ld.lld
diff --git a/clang/test/Driver/DTLTO/filename.py b/clang/test/Driver/DTLTO/filename.py
new file mode 100644
index 0000000000000..6b6d483a2fd2a
--- /dev/null
+++ b/clang/test/Driver/DTLTO/filename.py
@@ -0,0 +1,3 @@
+from pathlib import Path
+import sys
+print(f"filename.py:{Path(sys.argv[1]).name}")
diff --git a/clang/test/Driver/DTLTO/ps5-dtlto.c b/clang/test/Driver/DTLTO/ps5-dtlto.c
index eb4691da9d2fc..b52765db5b1c7 100644
--- a/clang/test/Driver/DTLTO/ps5-dtlto.c
+++ b/clang/test/Driver/DTLTO/ps5-dtlto.c
@@ -6,14 +6,16 @@
 /// Check DTLTO options are forwarded to the linker.
 
 /// Check that options are forwarded as expected with --thinlto-distributor=.
+// RUN: %python %S/filename.py %clang > %t_forward.log
 // RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
 // RUN:   -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 \
-// RUN:   -fthinlto-distributor=d.exe -Werror 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=FORWARD
+// RUN:   -fthinlto-distributor=d.exe -Werror >>%t_forward.log 2>&1
+// RUN: FileCheck %s --input-file=%t_forward.log --check-prefix=FORWARD
 
+// FORWARD: filename.py:[[CLANG:.*]]
 // FORWARD: prospero-lld
 // FORWARD-SAME: "--thinlto-distributor=d.exe"
-// FORWARD-SAME: "--thinlto-remote-compiler={{.*}}clang{{[^\"]*}}"
+// FORWARD-SAME: "--thinlto-remote-compiler={{.*}}[[CLANG]]"
 // FORWARD-SAME: "--thinlto-distributor-arg=a1"
 // FORWARD-SAME: "--thinlto-distributor-arg=a2"
 // FORWARD-SAME: "--thinlto-distributor-arg=a3"
@@ -22,8 +24,8 @@
 /// that a warning is issued for unused -Xthinlto-distributor options.
 // RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
 // RUN:   -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=NODIST --implicit-check-not=distributor \
-// RUN:     --implicit-check-not=remote-compiler
+// RUN: FileCheck %s --check-prefix=NODIST --implicit-check-not=distributor \
+// RUN:   --implicit-check-not=remote-compiler
 
 // NODIST: warning: argument unused during compilation: '-Xthinlto-distributor=a1'
 // NODIST: warning: argument unused during compilation: '-Xthinlto-distributor=a2,a3'
@@ -31,18 +33,21 @@
 
 /// Check the expected arguments are forwarded by default with only
 /// --thinlto-distributor=.
+// RUN: %python %S/filename.py %clang > %t_default.log
 // RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
-// RUN:   -fthinlto-distributor=d.exe -Werror 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor \
-// RUN:     --implicit-check-not=remote-compiler
+// RUN:   -fthinlto-distributor=d.exe -Werror >>%t_default.log 2>&1
+// RUN: FileCheck %s --input-file=%t_default.log --check-prefix=DEFAULT \
+// RUN:   --implicit-check-not=distributor --implicit-check-not=remote-compiler
 
+// DEFAULT: filename.py:[[CLANG:.*]]
 // DEFAULT: prospero-lld
 // DEFAULT-SAME: "--thinlto-distributor=d.exe"
-// DEFAULT-SAME: "--thinlto-remote-compiler={{.*}}clang{{[^\"]*}}"
+// DEFAULT-SAME: "--thinlto-remote-compiler={{.*}}[[CLANG]]"
 
 /// Check that the arguments are forwarded unconditionally even when the
 /// compiler is not in LTO mode.
+// RUN: %python %S/filename.py %clang > %t_noflto.log
 // RUN: %clang %s -### --target=x86_64-sie-ps5 \
-// RUN:   -fthinlto-distributor=d.exe -Werror 2>&1 | \
-// RUN:   FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor \
-// RUN:     --implicit-check-not=remote-compiler
+// RUN:   -fthinlto-distributor=d.exe -Werror >>%t_noflto.log 2>&1
+// RUN: FileCheck %s --input-file=%t_noflto.log --check-prefix=DEFAULT \
+// RUN:   --implicit-check-not=distributor --implicit-check-not=remote-compiler

>From eb35d1520e17900e2f6c7eabe03ecf5d1eaee0b3 Mon Sep 17 00:00:00 2001
From: Dunbobbin <Ben.Dunbobbin at sony.com>
Date: Tue, 16 Sep 2025 19:56:01 +0100
Subject: [PATCH 2/3] Format python with black

---
 clang/test/Driver/DTLTO/filename.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/test/Driver/DTLTO/filename.py b/clang/test/Driver/DTLTO/filename.py
index 6b6d483a2fd2a..281f84c85ad72 100644
--- a/clang/test/Driver/DTLTO/filename.py
+++ b/clang/test/Driver/DTLTO/filename.py
@@ -1,3 +1,4 @@
 from pathlib import Path
 import sys
+
 print(f"filename.py:{Path(sys.argv[1]).name}")

>From 8631e6cc91cf771a8fd3b182786e0534559c15fa Mon Sep 17 00:00:00 2001
From: Dunbobbin <Ben.Dunbobbin at sony.com>
Date: Tue, 16 Sep 2025 20:41:38 +0100
Subject: [PATCH 3/3] Add resolving of symlinks

---
 clang/test/Driver/DTLTO/filename.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/DTLTO/filename.py b/clang/test/Driver/DTLTO/filename.py
index 281f84c85ad72..df1aeb6682543 100644
--- a/clang/test/Driver/DTLTO/filename.py
+++ b/clang/test/Driver/DTLTO/filename.py
@@ -1,4 +1,4 @@
 from pathlib import Path
 import sys
 
-print(f"filename.py:{Path(sys.argv[1]).name}")
+print(f"filename.py:{Path(sys.argv[1]).resolve().name}")



More information about the cfe-commits mailing list