daltenty created this revision.
Herald added subscribers: llvm-commits, libcxx-commits, lldb-commits, christof, 
delcypher.
Herald added projects: LLDB, libc++, LLVM.

On AIX psutil can run into problems with permissions to read the process
tree, which causes problems for python tests. This patch adds a workaround
by invoking shell via subprocess and a platform specific
option to ps to list all the decendant processes so we can kill them. This 
removes our dependency on psutil.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64251

Files:
  libcxx/utils/libcxx/util.py
  lldb/lit/lit.cfg.py
  llvm/utils/lit/lit/LitConfig.py
  llvm/utils/lit/lit/util.py
  llvm/utils/lit/tests/googletest-timeout.py
  llvm/utils/lit/tests/lit.cfg
  llvm/utils/lit/tests/shtest-timeout.py

Index: llvm/utils/lit/tests/shtest-timeout.py
===================================================================
--- llvm/utils/lit/tests/shtest-timeout.py
+++ llvm/utils/lit/tests/shtest-timeout.py
@@ -1,4 +1,4 @@
-# REQUIRES: python-psutil
+# REQUIRES: lit-max-individual-test-time
 
 # llvm.org/PR33944
 # UNSUPPORTED: system-windows
Index: llvm/utils/lit/tests/lit.cfg
===================================================================
--- llvm/utils/lit/tests/lit.cfg
+++ llvm/utils/lit/tests/lit.cfg
@@ -1,6 +1,7 @@
 # -*- Python -*-
 
 import os
+import platform
 import sys
 
 import lit.formats
@@ -57,9 +58,10 @@
 
 # Add a feature to detect if psutil is available
 try:
-    import psutil
-    lit_config.note('Found python psutil module')
-    config.available_features.add("python-psutil")
+    if platform.system() != 'AIX':
+        import psutil
+        lit_config.note('Found python psutil module')
+    config.available_features.add("lit-max-individual-test-time")
 except ImportError:
     lit_config.warning('Could not import psutil. Some tests will be skipped and'
                        ' the --timeout command line argument will not work.')
Index: llvm/utils/lit/tests/googletest-timeout.py
===================================================================
--- llvm/utils/lit/tests/googletest-timeout.py
+++ llvm/utils/lit/tests/googletest-timeout.py
@@ -1,4 +1,4 @@
-# REQUIRES: python-psutil
+# REQUIRES: lit-max-individual-test-time
 
 # Check that the per test timeout is enforced when running GTest tests.
 #
Index: llvm/utils/lit/lit/util.py
===================================================================
--- llvm/utils/lit/lit/util.py
+++ llvm/utils/lit/lit/util.py
@@ -433,24 +433,30 @@
     our dependency on it.
 
     """
-    import psutil
-    try:
-        psutilProc = psutil.Process(pid)
-        # Handle the different psutil API versions
+    import platform
+
+    if platform.system() == 'AIX':
+        from subprocess import call
+        call('kill -kill $(ps -o pid= -L{})'.format(pid), shell=True)
+    else:
+        import psutil
         try:
-            # psutil >= 2.x
-            children_iterator = psutilProc.children(recursive=True)
-        except AttributeError:
-            # psutil 1.x
-            children_iterator = psutilProc.get_children(recursive=True)
-        for child in children_iterator:
+            psutilProc = psutil.Process(pid)
+            # Handle the different psutil API versions
             try:
-                child.kill()
-            except psutil.NoSuchProcess:
-                pass
-        psutilProc.kill()
-    except psutil.NoSuchProcess:
-        pass
+                # psutil >= 2.x
+                children_iterator = psutilProc.children(recursive=True)
+            except AttributeError:
+                # psutil 1.x
+                children_iterator = psutilProc.get_children(recursive=True)
+            for child in children_iterator:
+                try:
+                    child.kill()
+                except psutil.NoSuchProcess:
+                    pass
+            psutilProc.kill()
+        except psutil.NoSuchProcess:
+            pass
 
 
 try:
Index: llvm/utils/lit/lit/LitConfig.py
===================================================================
--- llvm/utils/lit/lit/LitConfig.py
+++ llvm/utils/lit/lit/LitConfig.py
@@ -1,6 +1,7 @@
 from __future__ import absolute_import
 import inspect
 import os
+import platform
 import sys
 
 import lit.Test
@@ -86,16 +87,17 @@
             self.fatal('maxIndividualTestTime must set to a value of type int.')
         self._maxIndividualTestTime = value
         if self.maxIndividualTestTime > 0:
-            # The current implementation needs psutil to set
+            # The current implementation needs psutil on some platforms to set
             # a timeout per test. Check it's available.
             # See lit.util.killProcessAndChildren()
-            try:
-                import psutil  # noqa: F401
-            except ImportError:
-                self.fatal("Setting a timeout per test requires the"
-                           " Python psutil module but it could not be"
-                           " found. Try installing it via pip or via"
-                           " your operating system's package manager.")
+            if platform.system() != 'AIX':
+                try:
+                    import psutil  # noqa: F401
+                except ImportError:
+                    self.fatal("Setting a timeout per test requires the"
+                            " Python psutil module but it could not be"
+                            " found. Try installing it via pip or via"
+                            " your operating system's package manager.")
         elif self.maxIndividualTestTime < 0:
             self.fatal('The timeout per test must be >= 0 seconds')
 
Index: lldb/lit/lit.cfg.py
===================================================================
--- lldb/lit/lit.cfg.py
+++ lldb/lit/lit.cfg.py
@@ -1,6 +1,7 @@
 # -*- Python -*-
 
 import os
+import platform
 import re
 import shutil
 import site
@@ -75,10 +76,11 @@
         shutil.rmtree(cachedir)
 
 # Set a default per-test timeout of 10 minutes. Setting a timeout per test
-# requires the psutil module and lit complains if the value is set but the
-# module can't be found.
+# requires the psutil module on some platforms and lit complains if the value
+# is set but the module can't be found on those platforms.
 try:
-    import psutil  # noqa: F401
+    if platform.system() != 'AIX':
+        import psutil  # noqa: F401
     lit_config.maxIndividualTestTime = 600
 except ImportError:
     pass
Index: libcxx/utils/libcxx/util.py
===================================================================
--- libcxx/utils/libcxx/util.py
+++ libcxx/utils/libcxx/util.py
@@ -253,24 +253,28 @@
     TODO: Reimplement this without using psutil so we can
           remove our dependency on it.
     """
-    import psutil
-    try:
-        psutilProc = psutil.Process(pid)
-        # Handle the different psutil API versions
+    if platform.system() == 'AIX':
+        from subprocess import call
+        call('kill -kill $(ps -o pid= -L{})'.format(pid), shell=True)
+    else:
+        import psutil
         try:
-            # psutil >= 2.x
-            children_iterator = psutilProc.children(recursive=True)
-        except AttributeError:
-            # psutil 1.x
-            children_iterator = psutilProc.get_children(recursive=True)
-        for child in children_iterator:
+            psutilProc = psutil.Process(pid)
+            # Handle the different psutil API versions
             try:
-                child.kill()
-            except psutil.NoSuchProcess:
-                pass
-        psutilProc.kill()
-    except psutil.NoSuchProcess:
-        pass
+                # psutil >= 2.x
+                children_iterator = psutilProc.children(recursive=True)
+            except AttributeError:
+                # psutil 1.x
+                children_iterator = psutilProc.get_children(recursive=True)
+            for child in children_iterator:
+                try:
+                    child.kill()
+                except psutil.NoSuchProcess:
+                    pass
+            psutilProc.kill()
+        except psutil.NoSuchProcess:
+            pass
 
 
 def executeCommandVerbose(cmd, *args, **kwargs):
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to