[clang] [clang][test] Rewrote test to work with lit internal shell syntax (PR #105902)

Connie Zhu via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 23 15:57:35 PDT 2024


https://github.com/connieyzhu updated https://github.com/llvm/llvm-project/pull/105902

>From b7cf36a247e480ddefc1708cb68078b440011d63 Mon Sep 17 00:00:00 2001
From: Connie Zhu <connieyzhu at google.com>
Date: Fri, 23 Aug 2024 17:23:22 +0000
Subject: [PATCH] [clang][test] Rewrote test to work with lit internal shell
 syntax

This patch rewrites a test that uses command substitution $() and the
stat command, which are not supported by lit's internal shell. Instead
of using this syntax to perform the file size comparison done in this
test, a Python script is used instead to perform the same operation.
---
 clang/test/Modules/compare-file-size.py  | 22 ++++++++++++++++++++++
 clang/test/Modules/reduced-bmi-size.cppm |  3 +--
 clang/test/lit.cfg.py                    |  2 ++
 3 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Modules/compare-file-size.py

diff --git a/clang/test/Modules/compare-file-size.py b/clang/test/Modules/compare-file-size.py
new file mode 100644
index 00000000000000..ca3b16442353c7
--- /dev/null
+++ b/clang/test/Modules/compare-file-size.py
@@ -0,0 +1,22 @@
+import argparse
+import os
+
+def get_file_size(file_path):
+    try:
+        return os.path.getsize(file_path)
+    except:
+        print(f"Unable to get file size of {file_path}")
+        return None
+
+def main():
+    parser = argparse.ArgumentParser()
+
+    parser.add_argument("file1", type=str)
+    parser.add_argument("file2", type=str)
+
+    args = parser.parse_args()
+
+    return get_file_size(args.file1) < get_file_size(args.file2)
+
+if __name__ == "__main__":
+    main()
diff --git a/clang/test/Modules/reduced-bmi-size.cppm b/clang/test/Modules/reduced-bmi-size.cppm
index 664f45f5c6a5a7..6d62573bc7aa39 100644
--- a/clang/test/Modules/reduced-bmi-size.cppm
+++ b/clang/test/Modules/reduced-bmi-size.cppm
@@ -10,7 +10,6 @@
 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -o %t/a.pcm
 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %s -o %t/a.reduced.pcm
 //
-// %s implies the current source file. So we can't use it directly.
-// RUN: [ $(stat -c%\s "%t/a.pcm") -le $(stat -c%\s "%t/a.reduced.pcm") ]
+// RUN: %{python} %S/compare-file-size.py %t/a.pcm %t/a.reduced.pcm
 
 export module a;
diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index 92a3361ce672e2..59330a6d51a611 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -74,6 +74,8 @@
 
 config.substitutions.append(("%PATH%", config.environment["PATH"]))
 
+config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))
+
 
 # For each occurrence of a clang tool name, replace it with the full path to
 # the build directory holding that tool.  We explicitly specify the directories



More information about the cfe-commits mailing list