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

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 23 15:51:41 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Connie Zhu (connieyzhu)

<details>
<summary>Changes</summary>

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.

Fixes https://github.com/llvm/llvm-project/issues/102384.

---
Full diff: https://github.com/llvm/llvm-project/pull/105902.diff


3 Files Affected:

- (added) clang/test/Modules/compare-file-size.py (+22) 
- (modified) clang/test/Modules/reduced-bmi-size.cppm (+1-2) 
- (modified) clang/test/lit.cfg.py (+2) 


``````````diff
diff --git a/clang/test/Modules/compare-file-size.py b/clang/test/Modules/compare-file-size.py
new file mode 100644
index 00000000000000..b5dc20642ea6ce
--- /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

``````````

</details>


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


More information about the cfe-commits mailing list