[PATCH] D66293: [lit] Check for accidental external command calls
Joel E. Denny via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 07:26:17 PDT 2019
jdenny created this revision.
jdenny added reviewers: probinson, stella.stamenova, bd1976llvm, jlpeyton, rnk, mgorny.
Herald added a subscriber: delcypher.
Herald added a project: LLVM.
This patch extends lit's test suite to check that lit's internal shell
doesn't accidentally execute internal commands as external commands.
It does so by putting fake failing versions of those commands in
`PATH` while the entire lit test suite is running. Without the fixes
in D65697 <https://reviews.llvm.org/D65697> but with its tests, this approach catches accidental
external `env` calls.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66293
Files:
llvm/utils/lit/tests/Inputs/fake-externals/:
llvm/utils/lit/tests/Inputs/fake-externals/cd
llvm/utils/lit/tests/Inputs/fake-externals/diff
llvm/utils/lit/tests/Inputs/fake-externals/env
llvm/utils/lit/tests/Inputs/fake-externals/export
llvm/utils/lit/tests/Inputs/fake-externals/fake_external.py
llvm/utils/lit/tests/Inputs/fake-externals/mkdir
llvm/utils/lit/tests/Inputs/fake-externals/rm
llvm/utils/lit/tests/lit.cfg
Index: llvm/utils/lit/tests/lit.cfg
===================================================================
--- llvm/utils/lit/tests/lit.cfg
+++ llvm/utils/lit/tests/lit.cfg
@@ -75,3 +75,13 @@
if not llvm_config:
if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
config.available_features.add('system-windows')
+
+# For each of lit's internal shell commands ('env', 'cd', 'diff', etc.), put
+# a fake command that always fails at the start of PATH. This helps us check
+# that we always use lit's internal version rather than some external version
+# that might not be present or behave correctly on all platforms. Don't do
+# this for 'echo' because an external version is used when it appears in a
+# pipeline.
+test_bin = os.path.join(os.path.dirname(__file__), 'Inputs', 'fake-externals')
+config.environment['PATH'] = os.path.pathsep.join((test_bin,
+ config.environment['PATH']))
Index: llvm/utils/lit/tests/Inputs/fake-externals/rm
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/fake-externals/rm
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
Index: llvm/utils/lit/tests/Inputs/fake-externals/mkdir
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/fake-externals/mkdir
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
Index: llvm/utils/lit/tests/Inputs/fake-externals/fake_external.py
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/fake-externals/fake_external.py
@@ -0,0 +1,7 @@
+import os
+import sys
+
+def execute(fileName):
+ sys.stderr.write("error: external '{}' command called unexpectedly\n"
+ .format(os.path.basename(fileName)));
+ sys.exit(1)
Index: llvm/utils/lit/tests/Inputs/fake-externals/export
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/fake-externals/export
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
Index: llvm/utils/lit/tests/Inputs/fake-externals/env
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/fake-externals/env
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
Index: llvm/utils/lit/tests/Inputs/fake-externals/diff
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/fake-externals/diff
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
Index: llvm/utils/lit/tests/Inputs/fake-externals/cd
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/fake-externals/cd
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
Index: llvm/utils/lit/tests/Inputs/fake-externals/:
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/fake-externals/:
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66293.215395.patch
Type: text/x-patch
Size: 3388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190815/a2f0c157/attachment.bin>
More information about the llvm-commits
mailing list