summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorTodd Fiala <todd.fiala@gmail.com>2016-09-26 20:25:47 +0000
committerTodd Fiala <todd.fiala@gmail.com>2016-09-26 20:25:47 +0000
commit2cd84c905df4fe9a6005320a45e98cd4b8ade045 (patch)
tree4165388cdc668b91a41117d96078e15e6671dce0 /lldb/packages/Python/lldbsuite/test
parent9eddaeb5340035f1ed36940f7478999616a898f0 (diff)
downloadbcm5719-llvm-2cd84c905df4fe9a6005320a45e98cd4b8ade045.tar.gz
bcm5719-llvm-2cd84c905df4fe9a6005320a45e98cd4b8ade045.zip
added Linux support for test timeout sampling
This is the Linux counterpart to the sampling support I added on the macOS side. This change also introduces zip-file compression if the size of the sample output is greater than 10 KB. The Linux side can be quite large and the textual content is averaging over a 10x compression factor on tests that I force to time out. When compression takes place, the filename becomes: {session_dir}/{TestFilename.py}-{pid}.sample.zip This support relies on the linux 'perf' tool. If it isn't present, the behavior is to ignore pre-kill processing of the timed out test process. Note calling the perf tool under the timeout command appears to nuke the profiled process. This was causing the timeout kill logic to fail due to the process having disappeared. I modified the kill logic to catch the case of the process not existing, and I have it ignore the kill request in that case. Any other exception is still raised. Reviewers: labath Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D24890 llvm-svn: 282436
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/dosep.py21
-rw-r--r--lldb/packages/Python/lldbsuite/test/test_runner/process_control.py34
2 files changed, 39 insertions, 16 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/dosep.py b/lldb/packages/Python/lldbsuite/test/dosep.py
index 0e6b277e47c..4cdffa653f1 100644
--- a/lldb/packages/Python/lldbsuite/test/dosep.py
+++ b/lldb/packages/Python/lldbsuite/test/dosep.py
@@ -243,7 +243,7 @@ class DoTestProcessDriver(process_control.ProcessDriver):
except ImportError:
# We don't have one for this platform. Skip.
sys.stderr.write("\nwarning: no timeout handler module: " +
- module_name)
+ module_name + "\n")
return
# Try to run the pre-kill-hook method.
@@ -254,13 +254,26 @@ class DoTestProcessDriver(process_control.ProcessDriver):
# Write the output to a filename associated with the test file and
# pid.
+ MAX_UNCOMPRESSED_BYTE_COUNT = 10 * 1024
+
+ content = output_io.getvalue()
+ compress_output = len(content) > MAX_UNCOMPRESSED_BYTE_COUNT
basename = "{}-{}.sample".format(self.file_name, self.pid)
sample_path = os.path.join(g_session_dir, basename)
- with open(sample_path, "w") as output_file:
- output_file.write(output_io.getvalue())
+
+ if compress_output:
+ # Write compressed output into a .zip file.
+ from zipfile import ZipFile, ZIP_DEFLATED
+ zipfile = sample_path + ".zip"
+ with ZipFile(zipfile, "w", ZIP_DEFLATED) as sample_zip:
+ sample_zip.writestr(basename, content)
+ else:
+ # Write raw output into a text file.
+ with open(sample_path, "w") as output_file:
+ output_file.write(content)
except Exception as e:
sys.stderr.write("caught exception while running "
- "pre-kill action: {}".format(e))
+ "pre-kill action: {}\n".format(e))
return
def is_exceptional_exit(self):
diff --git a/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py b/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
index 005500ab6bf..720f5112a4c 100644
--- a/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
+++ b/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py
@@ -360,18 +360,28 @@ class UnixProcessHelper(ProcessHelper):
# Choose kill mechanism based on whether we're targeting
# a process group or just a process.
- if popen_process.using_process_groups:
- # if log_file:
- # log_file.write(
- # "sending signum {} to process group {} now\n".format(
- # signum, popen_process.pid))
- os.killpg(popen_process.pid, signum)
- else:
- # if log_file:
- # log_file.write(
- # "sending signum {} to process {} now\n".format(
- # signum, popen_process.pid))
- os.kill(popen_process.pid, signum)
+ try:
+ if popen_process.using_process_groups:
+ # if log_file:
+ # log_file.write(
+ # "sending signum {} to process group {} now\n".format(
+ # signum, popen_process.pid))
+ os.killpg(popen_process.pid, signum)
+ else:
+ # if log_file:
+ # log_file.write(
+ # "sending signum {} to process {} now\n".format(
+ # signum, popen_process.pid))
+ os.kill(popen_process.pid, signum)
+ except OSError as error:
+ import errno
+ if error.errno == errno.ESRCH:
+ # This is okay - failed to find the process. It may be that
+ # that the timeout pre-kill hook eliminated the process. We'll
+ # ignore.
+ pass
+ else:
+ raise
def soft_terminate(self, popen_process, log_file=None, want_core=True):
# Choose signal based on desire for core file.
OpenPOWER on IntegriCloud