[PATCH] D99728: [lit, test] Fix test cancellation feature detection

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 1 07:15:00 PDT 2021


thopre created this revision.
thopre added reviewers: lebedev.ri, davezarzycki, yln, jdenny, probinson, jhenderson, jmorse, mehdi_amini.
Herald added a subscriber: delcypher.
thopre requested review of this revision.
Herald added a project: LLVM.

A lit feature guards tests for the lit timeout functionality because on
most system it depends on the availability of the psutil Python module.
However, that feature is defined based on the ability of the testing lit
to cancel test, which does not necessarily apply to the ability of the
tested lit.

In particular, RUN commands have a cleared PYTHONPATH and user site
packages are disabled. In the case where psutil is found by the testing
lit from one of those two source of python path, the tested lit would
not be able to find it, causing timeout tests to fail.

This commit fixes the issue by testing the ability to cancel tests in
the RUN command environment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99728

Files:
  llvm/utils/lit/tests/check-tested-lit-timeout-ability
  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
@@ -3,6 +3,7 @@
 import os
 import platform
 import sys
+import subprocess
 
 import lit.formats
 from lit.llvm import llvm_config
@@ -71,11 +72,19 @@
     config.environment['COVERAGE_PROCESS_START'] = os.path.join(
         os.path.dirname(__file__), ".coveragerc")
 
-# Add a feature to detect if psutil is available
-supported, errormsg = lit_config.maxIndividualTestTimeIsSupported
-if supported:
+# Add a feature to detect if test cancellation is available. Check the ability
+# to do cancellation in the same environment as where RUN commands are run.
+# The reason is that on most systems cancellation depends on psutil being
+# available and RUN commands are run with a cleared PYTHONPATH and user site
+# packages disabled.
+cwd = os.path.dirname(os.path.realpath(__file__))
+proc = subprocess.run(["./check-tested-lit-timeout-ability"], cwd=cwd,
+                      stderr=subprocess.PIPE, env=config.environment,
+                      universal_newlines=True)
+if proc.returncode == 0:
     config.available_features.add("lit-max-individual-test-time")
 else:
+    errormsg = proc.stderr
     lit_config.warning('Setting a timeout per test not supported. ' + errormsg
                        + ' Some tests will be skipped and the --timeout'
                          ' command line argument will not work.')
Index: llvm/utils/lit/tests/check-tested-lit-timeout-ability
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/check-tested-lit-timeout-ability
@@ -0,0 +1,11 @@
+#!/usr/bin/python3.6
+
+import sys
+from lit.util import killProcessAndChildrenIsSupported
+
+supported, errormsg = killProcessAndChildrenIsSupported()
+
+if not supported:
+    sys.exit(errormsg)
+
+sys.exit()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99728.334681.patch
Type: text/x-patch
Size: 1925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210401/3a30c433/attachment.bin>


More information about the llvm-commits mailing list