Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,5 @@
This directory contains source and tests for the lldb test runner
architecture. This directory is not for lldb python tests. It
is the test runner. The tests under this diretory are test-runner
tests (i.e. tests that verify the test runner itself runs properly).

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,146 @@
#!/usr/bin/env python
"""Inferior program used by process control tests."""
from __future__ import print_function
import argparse
import datetime
import signal
import subprocess
import sys
import time
def parse_args(command_line):
"""Parses the command line arguments given to it.
@param command_line a list of command line arguments to be parsed.
@return the argparse options dictionary.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--ignore-signal",
"-i",
dest="ignore_signals",
metavar="SIGNUM",
action="append",
type=int,
default=[],
help="ignore the given signal number (if possible)")
parser.add_argument(
"--launch-child-share-handles",
action="store_true",
help=("launch a child inferior.py that shares stdout/stderr/stdio and "
"never returns"))
parser.add_argument(
"--never-return",
action="store_true",
help="run in an infinite loop, never return")
parser.add_argument(
"--return-code",
"-r",
type=int,
default=0,
help="specify the return code for the inferior upon exit")
parser.add_argument(
"--sleep",
"-s",
metavar="SECONDS",
dest="sleep_seconds",
type=float,
help="sleep for SECONDS seconds before returning")
parser.add_argument(
"--verbose", "-v", action="store_true",
help="log verbose operation details to stdout")
return parser.parse_args(command_line)
def handle_ignore_signals(options, signals):
"""Ignores any signals provided to it.
@param options the command line options parsed by the program.
General used to check flags for things like verbosity.
@param signals the list of signals to ignore. Can be None or zero-length.
Entries should be type int.
"""
if signals is None:
return
for signum in signals:
if options.verbose:
print("disabling signum {}".format(signum))
signal.signal(signum, signal.SIG_IGN)
def handle_sleep(options, sleep_seconds):
"""Sleeps the number of seconds specified, restarting as needed.
@param options the command line options parsed by the program.
General used to check flags for things like verbosity.
@param sleep_seconds the number of seconds to sleep. If None
or <= 0, no sleeping will occur.
"""
if sleep_seconds is None:
return
if sleep_seconds <= 0:
return
end_time = datetime.datetime.now() + datetime.timedelta(0, sleep_seconds)
if options.verbose:
print("sleep end time: {}".format(end_time))
# Do sleep in a loop: signals can interrupt.
while datetime.datetime.now() < end_time:
# We'll wrap this in a try/catch so we don't encounter
# a race if a signal (ignored) knocks us out of this
# loop and causes us to return.
try:
sleep_interval = end_time - datetime.datetime.now()
sleep_seconds = sleep_interval.total_seconds()
if sleep_seconds > 0:
time.sleep(sleep_seconds)
except: # pylint: disable=bare-except
pass
def handle_launch_children(options):
if options.launch_child_share_handles:
# Launch the child, share our file handles.
# We won't bother reaping it since it will likely outlive us.
subprocess.Popen([sys.executable, __file__, "--never-return"])
def handle_never_return(options):
if not options.never_return:
return
# Loop forever.
while True:
try:
time.sleep(10)
except: # pylint: disable=bare-except
# Ignore
pass
def main(command_line):
"""Drives the main operation of the inferior test program.
@param command_line the command line options to process.
@return the exit value (program return code) for the process.
"""
options = parse_args(command_line)
handle_ignore_signals(options, options.ignore_signals)
handle_launch_children(options)
handle_sleep(options, options.sleep_seconds)
handle_never_return(options)
return options.return_code
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

View File

@@ -0,0 +1,243 @@
#!/usr/bin/env python
"""
The LLVM Compiler Infrastructure
This file is distributed under the University of Illinois Open Source
License. See LICENSE.TXT for details.
Provides classes used by the test results reporting infrastructure
within the LLDB test suite.
Tests the process_control module.
"""
from __future__ import print_function
# System imports.
import os
import os.path
import platform
import unittest
import sys
import threading
# Our imports.
from test_runner import process_control
class TestInferiorDriver(process_control.ProcessDriver):
def __init__(self, soft_terminate_timeout=None):
super(TestInferiorDriver, self).__init__(
soft_terminate_timeout=soft_terminate_timeout)
self.started_event = threading.Event()
self.started_event.clear()
self.completed_event = threading.Event()
self.completed_event.clear()
self.was_timeout = False
self.returncode = None
self.output = None
def write(self, content):
# We'll swallow this to keep tests non-noisy.
# Uncomment the following line if you want to see it.
# sys.stdout.write(content)
pass
def on_process_started(self):
self.started_event.set()
def on_process_exited(self, command, output, was_timeout, exit_status):
self.returncode = exit_status
self.was_timeout = was_timeout
self.output = output
self.returncode = exit_status
self.completed_event.set()
class ProcessControlTests(unittest.TestCase):
@classmethod
def _suppress_soft_terminate(cls, command):
# Do the right thing for your platform here.
# Right now only POSIX-y systems are reporting
# soft terminate support, so this is set up for
# those.
helper = process_control.ProcessHelper.process_helper()
signals = helper.soft_terminate_signals()
if signals is not None:
for signum in helper.soft_terminate_signals():
command.extend(["--ignore-signal", str(signum)])
@classmethod
def inferior_command(
cls,
ignore_soft_terminate=False,
options=None):
# Base command.
script_name = "{}/inferior.py".format(os.path.dirname(__file__))
if not os.path.exists(script_name):
raise Exception(
"test inferior python script not found: {}".format(script_name))
command = ([sys.executable, script_name])
if ignore_soft_terminate:
cls._suppress_soft_terminate(command)
# Handle options as string or list.
if isinstance(options, str):
command.extend(options.split())
elif isinstance(options, list):
command.extend(options)
# Return full command.
return command
class ProcessControlNoTimeoutTests(ProcessControlTests):
"""Tests the process_control module."""
def test_run_completes(self):
"""Test that running completes and gets expected stdout/stderr."""
driver = TestInferiorDriver()
driver.run_command(self.inferior_command())
self.assertTrue(
driver.completed_event.wait(5), "process failed to complete")
self.assertEqual(driver.returncode, 0, "return code does not match")
def test_run_completes_with_code(self):
"""Test that running completes and gets expected stdout/stderr."""
driver = TestInferiorDriver()
driver.run_command(self.inferior_command(options="-r10"))
self.assertTrue(
driver.completed_event.wait(5), "process failed to complete")
self.assertEqual(driver.returncode, 10, "return code does not match")
class ProcessControlTimeoutTests(ProcessControlTests):
def test_run_completes(self):
"""Test that running completes and gets expected return code."""
driver = TestInferiorDriver()
timeout_seconds = 5
driver.run_command_with_timeout(
self.inferior_command(),
"{}s".format(timeout_seconds),
False)
self.assertTrue(
driver.completed_event.wait(2 * timeout_seconds),
"process failed to complete")
self.assertEqual(driver.returncode, 0)
def _soft_terminate_works(self, with_core):
# Skip this test if the platform doesn't support soft ti
helper = process_control.ProcessHelper.process_helper()
if not helper.supports_soft_terminate():
self.skipTest("soft terminate not supported by platform")
driver = TestInferiorDriver()
timeout_seconds = 5
driver.run_command_with_timeout(
# Sleep twice as long as the timeout interval. This
# should force a timeout.
self.inferior_command(
options="--sleep {}".format(timeout_seconds * 2)),
"{}s".format(timeout_seconds),
with_core)
# We should complete, albeit with a timeout.
self.assertTrue(
driver.completed_event.wait(2 * timeout_seconds),
"process failed to complete")
# Ensure we received a timeout.
self.assertTrue(driver.was_timeout, "expected to end with a timeout")
self.assertTrue(
helper.was_soft_terminate(driver.returncode, with_core),
("timeout didn't return expected returncode "
"for soft terminate with core: {}").format(driver.returncode))
def test_soft_terminate_works_core(self):
"""Driver uses soft terminate (with core request) when process times out.
"""
self._soft_terminate_works(True)
def test_soft_terminate_works_no_core(self):
"""Driver uses soft terminate (no core request) when process times out.
"""
self._soft_terminate_works(False)
def test_hard_terminate_works(self):
"""Driver falls back to hard terminate when soft terminate is ignored.
"""
driver = TestInferiorDriver(soft_terminate_timeout=2.0)
timeout_seconds = 1
driver.run_command_with_timeout(
# Sleep much longer than the timeout interval,forcing a
# timeout. Do whatever is needed to have the inferior
# ignore soft terminate calls.
self.inferior_command(
ignore_soft_terminate=True,
options="--never-return"),
"{}s".format(timeout_seconds),
True)
# We should complete, albeit with a timeout.
self.assertTrue(
driver.completed_event.wait(60),
"process failed to complete")
# Ensure we received a timeout.
self.assertTrue(driver.was_timeout, "expected to end with a timeout")
helper = process_control.ProcessHelper.process_helper()
self.assertTrue(
helper.was_hard_terminate(driver.returncode),
("timeout didn't return expected returncode "
"for hard teriminate: {} ({})").format(
driver.returncode,
driver.output))
def test_inferior_exits_with_live_child_shared_handles(self):
"""inferior exit detected when inferior children are live with shared
stdout/stderr handles.
"""
# Requires review D13362 or equivalent to be implemented.
self.skipTest("http://reviews.llvm.org/D13362")
driver = TestInferiorDriver()
# Create the inferior (I1), and instruct it to create a child (C1)
# that shares the stdout/stderr handles with the inferior.
# C1 will then loop forever.
driver.run_command_with_timeout(
self.inferior_command(
options="--launch-child-share-handles --return-code 3"),
"5s",
False)
# We should complete without a timetout. I1 should end
# immediately after launching C1.
self.assertTrue(
driver.completed_event.wait(5),
"process failed to complete")
# Ensure we didn't receive a timeout.
self.assertFalse(
driver.was_timeout, "inferior should have completed normally")
self.assertEqual(
driver.returncode, 3,
"expected inferior process to end with expected returncode")
if __name__ == "__main__":
unittest.main()