llvm.org GIT mirror llvm / cc57128
[AIX][lit] Don't depend on psutil on AIX Summary: On AIX psutil can run into problems with permissions to read the process tree, which causes problems for python timeout tests which need to kill off a test and it's children. This patch adds a workaround by invoking shell via subprocess and using a platform specific option to ps to list all the descendant processes so we can kill them. We add some checks so lit can tell whether timeout tests are supported with out exposing whether we are utilizing the psutil implementation or the alternative. Reviewers: hubert.reinterpretcast, andusy, davide, delcypher Reviewed By: delcypher Subscribers: davide, delcypher, christof, lldb-commits, libcxx-commits, llvm-commits Tags: #lldb, #libc, #llvm Differential Revision: https://reviews.llvm.org/D64251 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366912 91177308-0d34-0410-b5e6-96231b3b80d8 David Tenty a month ago
5 changed file(s) with 74 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
0 from __future__ import absolute_import
11 import inspect
22 import os
3 import platform
34 import sys
45
56 import lit.Test
7576 """
7677 return self._maxIndividualTestTime
7778
79 @property
80 def maxIndividualTestTimeIsSupported(self):
81 """
82 Returns a tuple ( , )
83 where
84 `` is True if setting maxIndividualTestTime is supported
85 on the current host, returns False otherwise.
86 `` is an empty string if `` is True,
87 otherwise is contains a string describing why setting
88 maxIndividualTestTime is not supported.
89 """
90 return lit.util.killProcessAndChildrenIsSupported()
91
7892 @maxIndividualTestTime.setter
7993 def maxIndividualTestTime(self, value):
8094 """
8599 self.fatal('maxIndividualTestTime must set to a value of type int.')
86100 self._maxIndividualTestTime = value
87101 if self.maxIndividualTestTime > 0:
88 # The current implementation needs psutil to set
102 # The current implementation needs psutil on some platforms to set
89103 # a timeout per test. Check it's available.
90104 # See lit.util.killProcessAndChildren()
91 try:
92 import psutil # noqa: F401
93 except ImportError:
94 self.fatal("Setting a timeout per test requires the"
95 " Python psutil module but it could not be"
96 " found. Try installing it via pip or via"
97 " your operating system's package manager.")
105 supported, errormsg = self.maxIndividualTestTimeIsSupported
106 if not supported:
107 self.fatal('Setting a timeout per test not supported. ' +
108 errormsg)
98109 elif self.maxIndividualTestTime < 0:
99110 self.fatal('The timeout per test must be >= 0 seconds')
100111
422422 return out.decode()
423423 return None
424424
425 def killProcessAndChildrenIsSupported():
426 """
427 Returns a tuple ( , )
428 where
429 `` is True if `killProcessAndChildren()` is supported on
430 the current host, returns False otherwise.
431 `` is an empty string if `` is True,
432 otherwise is contains a string describing why the function is
433 not supported.
434 """
435 if platform.system() == 'AIX':
436 return (True, "")
437 try:
438 import psutil # noqa: F401
439 return (True, "")
440 except ImportError:
441 return (False, "Requires the Python psutil module but it could"
442 " not be found. Try installing it via pip or via"
443 " your operating system's package manager.")
425444
426445 def killProcessAndChildren(pid):
427446 """This function kills a process with ``pid`` and all its running children
428 (recursively). It is currently implemented using the psutil module which
429 provides a simple platform neutral implementation.
430
431 TODO: Reimplement this without using psutil so we can remove
432 our dependency on it.
433
434 """
435 import psutil
436 try:
437 psutilProc = psutil.Process(pid)
438 # Handle the different psutil API versions
447 (recursively). It is currently implemented using the psutil module on some
448 platforms which provides a simple platform neutral implementation.
449
450 TODO: Reimplement this without using psutil on all platforms so we can
451 remove our dependency on it.
452
453 """
454 if platform.system() == 'AIX':
455 subprocess.call('kill -kill $(ps -o pid= -L{})'.format(pid), shell=True)
456 else:
457 import psutil
439458 try:
440 # psutil >= 2.x
441 children_iterator = psutilProc.children(recursive=True)
442 except AttributeError:
443 # psutil 1.x
444 children_iterator = psutilProc.get_children(recursive=True)
445 for child in children_iterator:
459 psutilProc = psutil.Process(pid)
460 # Handle the different psutil API versions
446461 try:
447 child.kill()
448 except psutil.NoSuchProcess:
449 pass
450 psutilProc.kill()
451 except psutil.NoSuchProcess:
452 pass
462 # psutil >= 2.x
463 children_iterator = psutilProc.children(recursive=True)
464 except AttributeError:
465 # psutil 1.x
466 children_iterator = psutilProc.get_children(recursive=True)
467 for child in children_iterator:
468 try:
469 child.kill()
470 except psutil.NoSuchProcess:
471 pass
472 psutilProc.kill()
473 except psutil.NoSuchProcess:
474 pass
453475
454476
455477 try:
None # REQUIRES: python-psutil
0 # REQUIRES: lit-max-individual-test-time
11
22 # Check that the per test timeout is enforced when running GTest tests.
33 #
0 # -*- Python -*-
11
22 import os
3 import platform
34 import sys
45
56 import lit.formats
5556 os.path.dirname(__file__), ".coveragerc")
5657
5758 # Add a feature to detect if psutil is available
58 try:
59 import psutil
60 lit_config.note('Found python psutil module')
61 config.available_features.add("python-psutil")
62 except ImportError:
63 lit_config.warning('Could not import psutil. Some tests will be skipped and'
64 ' the --timeout command line argument will not work.')
59 supported, errormsg = lit_config.maxIndividualTestTimeIsSupported
60 if supported:
61 config.available_features.add("lit-max-individual-test-time")
62 else:
63 lit_config.warning('Setting a timeout per test not supported. ' + errormsg
64 + ' Some tests will be skipped and the --timeout'
65 ' command line argument will not work.')
None # REQUIRES: python-psutil
0 # REQUIRES: lit-max-individual-test-time
11
22 # llvm.org/PR33944
33 # UNSUPPORTED: system-windows