summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel E. Denny <jdenny.ornl@gmail.com>2019-08-19 22:59:37 +0000
committerJoel E. Denny <jdenny.ornl@gmail.com>2019-08-19 22:59:37 +0000
commit971a9f7eea31c6b27bf798cc8c39ede1dae8f0d2 (patch)
tree2f372a4cdb82fe225f8bd650f156f6470b2fa8db
parent3f3a2573c307c4399aa3bc211cfb4d3e148798f5 (diff)
downloadbcm5719-llvm-971a9f7eea31c6b27bf798cc8c39ede1dae8f0d2.tar.gz
bcm5719-llvm-971a9f7eea31c6b27bf798cc8c39ede1dae8f0d2.zip
[lit] Check for accidental external command calls
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 but with its tests, this approach catches accidental external `env` calls. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D66293 llvm-svn: 369309
-rwxr-xr-xllvm/utils/lit/tests/Inputs/fake-externals/cd5
-rwxr-xr-xllvm/utils/lit/tests/Inputs/fake-externals/diff5
-rwxr-xr-xllvm/utils/lit/tests/Inputs/fake-externals/env5
-rwxr-xr-xllvm/utils/lit/tests/Inputs/fake-externals/export5
-rw-r--r--llvm/utils/lit/tests/Inputs/fake-externals/fake_external.py7
-rwxr-xr-xllvm/utils/lit/tests/Inputs/fake-externals/mkdir5
-rwxr-xr-xllvm/utils/lit/tests/Inputs/fake-externals/rm5
-rw-r--r--llvm/utils/lit/tests/lit.cfg11
8 files changed, 48 insertions, 0 deletions
diff --git a/llvm/utils/lit/tests/Inputs/fake-externals/cd b/llvm/utils/lit/tests/Inputs/fake-externals/cd
new file mode 100755
index 00000000000..9d9612dca4d
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/fake-externals/cd
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
diff --git a/llvm/utils/lit/tests/Inputs/fake-externals/diff b/llvm/utils/lit/tests/Inputs/fake-externals/diff
new file mode 100755
index 00000000000..9d9612dca4d
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/fake-externals/diff
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
diff --git a/llvm/utils/lit/tests/Inputs/fake-externals/env b/llvm/utils/lit/tests/Inputs/fake-externals/env
new file mode 100755
index 00000000000..9d9612dca4d
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/fake-externals/env
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
diff --git a/llvm/utils/lit/tests/Inputs/fake-externals/export b/llvm/utils/lit/tests/Inputs/fake-externals/export
new file mode 100755
index 00000000000..9d9612dca4d
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/fake-externals/export
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
diff --git a/llvm/utils/lit/tests/Inputs/fake-externals/fake_external.py b/llvm/utils/lit/tests/Inputs/fake-externals/fake_external.py
new file mode 100644
index 00000000000..1fdc2ee063c
--- /dev/null
+++ b/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)
diff --git a/llvm/utils/lit/tests/Inputs/fake-externals/mkdir b/llvm/utils/lit/tests/Inputs/fake-externals/mkdir
new file mode 100755
index 00000000000..9d9612dca4d
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/fake-externals/mkdir
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
diff --git a/llvm/utils/lit/tests/Inputs/fake-externals/rm b/llvm/utils/lit/tests/Inputs/fake-externals/rm
new file mode 100755
index 00000000000..9d9612dca4d
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/fake-externals/rm
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+import fake_external
+
+fake_external.execute(__file__)
diff --git a/llvm/utils/lit/tests/lit.cfg b/llvm/utils/lit/tests/lit.cfg
index 92f27b02188..26b3a1147d2 100644
--- a/llvm/utils/lit/tests/lit.cfg
+++ b/llvm/utils/lit/tests/lit.cfg
@@ -75,3 +75,14 @@ else:
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. Don't do this for ':' because it doesn't appear to be a valid file
+# name under Windows.
+test_bin = os.path.join(os.path.dirname(__file__), 'Inputs', 'fake-externals')
+config.environment['PATH'] = os.path.pathsep.join((test_bin,
+ config.environment['PATH']))
OpenPOWER on IntegriCloud