[llvm] 2ae5843 - [lit][test] Improve testing of use_llvm_tool

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu May 27 03:31:27 PDT 2021


Author: James Henderson
Date: 2021-05-27T11:25:43+01:00
New Revision: 2ae58431873d449f63fa6dd20dbd280fa43b3ac2

URL: https://github.com/llvm/llvm-project/commit/2ae58431873d449f63fa6dd20dbd280fa43b3ac2
DIFF: https://github.com/llvm/llvm-project/commit/2ae58431873d449f63fa6dd20dbd280fa43b3ac2.diff

LOG: [lit][test] Improve testing of use_llvm_tool

Reviewed by: MaskRay

Differential Revision: https://reviews.llvm.org/D103154

Added: 
    llvm/utils/lit/tests/Inputs/use-llvm-tool-required/found
    llvm/utils/lit/tests/Inputs/use-llvm-tool-required/found.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool-required/lit.cfg
    llvm/utils/lit/tests/Inputs/use-llvm-tool-required/true.txt
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case2
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case2.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case3
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case3.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case6
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case6.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case7
    llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case7.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/env-case1
    llvm/utils/lit/tests/Inputs/use-llvm-tool/env-case6
    llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case4
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case4.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case5
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case5.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case6
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case6.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case7
    llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case7.exe
    llvm/utils/lit/tests/Inputs/use-llvm-tool/true.txt
    llvm/utils/lit/tests/use-llvm-tool.py

Modified: 
    

Removed: 
    llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg
    llvm/utils/lit/tests/Inputs/use-tool-search-env/test.tool
    llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt
    llvm/utils/lit/tests/use-tool-search-env.py


################################################################################
diff  --git a/llvm/utils/lit/tests/Inputs/use-tool-search-env/test.tool b/llvm/utils/lit/tests/Inputs/use-llvm-tool-required/found
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/use-tool-search-env/test.tool
rename to llvm/utils/lit/tests/Inputs/use-llvm-tool-required/found

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool-required/found.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool-required/found.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool-required/lit.cfg b/llvm/utils/lit/tests/Inputs/use-llvm-tool-required/lit.cfg
new file mode 100644
index 0000000000000..b1c510e05ab74
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/use-llvm-tool-required/lit.cfg
@@ -0,0 +1,12 @@
+import lit.formats
+config.name = 'use-llvm-tool-required'
+config.suffixes = ['.txt']
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
+import os.path
+config.llvm_tools_dir = os.path.realpath(os.path.dirname(__file__))
+import lit.llvm
+lit.llvm.initialize(lit_config, config)
+lit.llvm.llvm_config.use_llvm_tool('found', required=True)
+lit.llvm.llvm_config.use_llvm_tool('not-found', required=True)

diff  --git a/llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt b/llvm/utils/lit/tests/Inputs/use-llvm-tool-required/true.txt
similarity index 100%
rename from llvm/utils/lit/tests/Inputs/use-tool-search-env/true.txt
rename to llvm/utils/lit/tests/Inputs/use-llvm-tool-required/true.txt

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case2 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case2
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case2.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case2.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case3 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case3
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case3.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case3.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case6 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case6
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case6.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case6.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case7 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case7
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case7.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/build/case7.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/env-case1 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/env-case1
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/env-case6 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/env-case6
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg b/llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg
new file mode 100644
index 0000000000000..7c2263c68cd5c
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/use-llvm-tool/lit.cfg
@@ -0,0 +1,22 @@
+import lit.formats
+config.name = 'use-llvm-tool'
+config.suffixes = ['.txt']
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
+import os.path
+this_dir = os.path.realpath(os.path.dirname(__file__))
+config.llvm_tools_dir = os.path.join(this_dir, 'build')
+import lit.llvm
+lit.llvm.initialize(lit_config, config)
+lit.llvm.llvm_config.with_environment('CASE1', os.path.join(this_dir, 'env-case1'))
+lit.llvm.llvm_config.with_environment('CASE6', os.path.join(this_dir, 'env-case6'))
+lit.llvm.llvm_config.with_environment('PATH', os.path.join(this_dir, 'path'), append_path=True)
+lit.llvm.llvm_config.use_llvm_tool('case1', search_env='CASE1')
+lit.llvm.llvm_config.use_llvm_tool('case2', search_env='CASE2')
+lit.llvm.llvm_config.use_llvm_tool('case3')
+lit.llvm.llvm_config.use_llvm_tool('case4', use_installed=True)
+lit.llvm.llvm_config.use_llvm_tool('case5')
+lit.llvm.llvm_config.use_llvm_tool('case6', search_env='CASE6', use_installed=True)
+lit.llvm.llvm_config.use_llvm_tool('case7', use_installed=True)
+lit.llvm.llvm_config.use_llvm_tool('case8', use_installed=True)

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case4 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case4
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case4.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case4.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case5 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case5
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case5.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case5.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case6 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case6
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case6.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case6.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case7 b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case7
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case7.exe b/llvm/utils/lit/tests/Inputs/use-llvm-tool/path/case7.exe
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/llvm/utils/lit/tests/Inputs/use-llvm-tool/true.txt b/llvm/utils/lit/tests/Inputs/use-llvm-tool/true.txt
new file mode 100644
index 0000000000000..b80b60b7a2794
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/use-llvm-tool/true.txt
@@ -0,0 +1 @@
+# RUN: true

diff  --git a/llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg b/llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg
deleted file mode 100644
index a64d3f7ee3389..0000000000000
--- a/llvm/utils/lit/tests/Inputs/use-tool-search-env/lit.cfg
+++ /dev/null
@@ -1,12 +0,0 @@
-import lit.formats
-config.name = 'search-env'
-config.suffixes = ['.txt']
-config.test_format = lit.formats.ShTest()
-config.test_source_root = None
-config.test_exec_root = None
-import lit.llvm
-lit.llvm.initialize(lit_config, config)
-import os.path
-path = os.path.realpath(os.path.join(os.path.dirname(__file__), 'test.tool'))
-lit.llvm.llvm_config.with_environment('TOOL_LOCATION', path)
-lit.llvm.llvm_config.use_llvm_tool('test-tool', search_env='TOOL_LOCATION')

diff  --git a/llvm/utils/lit/tests/use-llvm-tool.py b/llvm/utils/lit/tests/use-llvm-tool.py
new file mode 100644
index 0000000000000..c1eb496254fc3
--- /dev/null
+++ b/llvm/utils/lit/tests/use-llvm-tool.py
@@ -0,0 +1,36 @@
+## Show that lit reports the path of tools found via use_llvm_tool.
+## Additionally show that use_llvm_tool uses in order of preference:
+## 1) The path specified in an environment variable,
+## 2) The LLVM tools build directory,
+## 3) The PATH, if requested.
+
+# RUN: %{lit} %{inputs}/use-llvm-tool 2>&1 | \
+# RUN:   FileCheck %s -DDIR=%p
+
+## The exact breakdown of cases is:
+## Case | Env | Build Dir | PATH |
+##   1  |  /  |     X     |  N/S | <- Can be found via env
+##   2  |  X  |     /     |  N/S | <- Can be found via build dir if env specified
+##   3  | N/S |     /     |  N/S | <- Can be found via build dir
+##   4  | N/S |     X     |   /  | <- Can be found via PATH, if requested
+##   5  | N/S |     X     |  N/S | <- Cannot be found via PATH, if not requested
+##   6  |  /  |     /     |   /  | <- Env is preferred over build, PATH
+##   7  | N/S |     /     |   /  | <- Build dir is preferred over PATH
+##   8  |  X  |     X     |   X  | <- Say nothing if cannot be found if not required
+
+## Check the exact path reported for the first case, but don't bother for the
+## others.
+# CHECK:      note: using case1: [[DIR]]{{[\\/]}}Inputs{{[\\/]}}use-llvm-tool{{[\\/]}}env-case1
+# CHECK-NEXT: note: using case2: {{.*}}build{{[\\/]}}case2
+# CHECK-NEXT: note: using case3: {{.*}}build{{[\\/]}}case3
+# CHECK-NEXT: note: using case4: {{.*}}path{{[\\/]}}case4
+# CHECK-NOT:  case5
+# CHECK-NEXT: note: using case6: {{.*}}env-case6
+# CHECK-NEXT: note: using case7: {{.*}}build{{[\\/]}}case7
+# CHECK-NOT:  case8
+
+## Test that if required is True, lit errors if the tool is not found.
+# RUN: not %{lit} %{inputs}/use-llvm-tool-required 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=ERROR
+# ERROR:      note: using found: {{.*}}found
+# ERROR-NEXT: fatal: couldn't find 'not-found' program

diff  --git a/llvm/utils/lit/tests/use-tool-search-env.py b/llvm/utils/lit/tests/use-tool-search-env.py
deleted file mode 100644
index 6fe7d3c058281..0000000000000
--- a/llvm/utils/lit/tests/use-tool-search-env.py
+++ /dev/null
@@ -1,7 +0,0 @@
-## Show that lit reports the path to tools picked up via the use_llvm_tool
-## function when the tool is found via an environment variable.
-
-# RUN: %{lit} %{inputs}/use-tool-search-env 2>&1 | \
-# RUN:   FileCheck %s -DDIR=%p
-
-# CHECK: note: using test-tool: [[DIR]]{{[\\/]}}Inputs{{[\\/]}}use-tool-search-env{{[\\/]}}test.tool


        


More information about the llvm-commits mailing list