зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1846618 - Use mozprocess.run_and_wait in gtests r=hneiva
Bug 1839262 converted the gtest harness to use raw subprocess, but we can get the same functionality more simply now with mozprocess.run_and_wait. Differential Revision: https://phabricator.services.mozilla.com/D185208
This commit is contained in:
Родитель
9bcadda1a4
Коммит
cf4b682780
|
@ -6,14 +6,12 @@
|
|||
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
|
||||
import mozcrash
|
||||
import mozinfo
|
||||
import mozlog
|
||||
import mozprocess
|
||||
from mozrunner.utils import get_stack_fixer_function
|
||||
|
||||
log = mozlog.unstructured.getLogger("gtest")
|
||||
|
@ -60,72 +58,47 @@ class GTests(object):
|
|||
if utility_path:
|
||||
stack_fixer = get_stack_fixer_function(utility_path, symbols_path)
|
||||
|
||||
proc = None
|
||||
timed_out = False
|
||||
GTests.run_gtest.timed_out = False
|
||||
|
||||
def proc_timeout_handler():
|
||||
output_timer.cancel()
|
||||
def output_line_handler(proc, line):
|
||||
if stack_fixer:
|
||||
print(stack_fixer(line))
|
||||
else:
|
||||
print(line)
|
||||
|
||||
def proc_timeout_handler(proc):
|
||||
GTests.run_gtest.timed_out = True
|
||||
log.testFail("gtest | timed out after %d seconds", GTests.TEST_PROC_TIMEOUT)
|
||||
mozcrash.kill_and_get_minidump(proc.pid, cwd, utility_path)
|
||||
|
||||
def output_timeout_handler():
|
||||
nonlocal output_timer
|
||||
seconds_since_last_output = time.time() - output_time
|
||||
next_possible_output_timeout = (
|
||||
GTests.TEST_PROC_NO_OUTPUT_TIMEOUT - seconds_since_last_output
|
||||
def output_timeout_handler(proc):
|
||||
GTests.run_gtest.timed_out = True
|
||||
log.testFail(
|
||||
"gtest | timed out after %d seconds without output",
|
||||
GTests.TEST_PROC_NO_OUTPUT_TIMEOUT,
|
||||
)
|
||||
if next_possible_output_timeout <= 0:
|
||||
proc_timer.cancel()
|
||||
log.testFail(
|
||||
"gtest | timed out after %d seconds without output",
|
||||
GTests.TEST_PROC_NO_OUTPUT_TIMEOUT,
|
||||
)
|
||||
mozcrash.kill_and_get_minidump(proc.pid, cwd, utility_path)
|
||||
else:
|
||||
output_timer = threading.Timer(
|
||||
next_possible_output_timeout, output_timeout_handler
|
||||
)
|
||||
output_timer.start()
|
||||
mozcrash.kill_and_get_minidump(proc.pid, cwd, utility_path)
|
||||
|
||||
with subprocess.Popen(
|
||||
proc = mozprocess.run_and_wait(
|
||||
[prog, "-unittest", "--gtest_death_test_style=threadsafe"],
|
||||
cwd=cwd,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
) as proc:
|
||||
output_line_handler=output_line_handler,
|
||||
timeout=GTests.TEST_PROC_TIMEOUT,
|
||||
timeout_handler=proc_timeout_handler,
|
||||
output_timeout=GTests.TEST_PROC_NO_OUTPUT_TIMEOUT,
|
||||
output_timeout_handler=output_timeout_handler,
|
||||
)
|
||||
|
||||
proc_timer = None
|
||||
proc_timer = threading.Timer(GTests.TEST_PROC_TIMEOUT, proc_timeout_handler)
|
||||
proc_timer.start()
|
||||
|
||||
output_time = time.time()
|
||||
output_timer = None
|
||||
output_timer = threading.Timer(
|
||||
GTests.TEST_PROC_NO_OUTPUT_TIMEOUT, output_timeout_handler
|
||||
)
|
||||
output_timer.start()
|
||||
|
||||
for line in proc.stdout:
|
||||
output_time = time.time()
|
||||
if stack_fixer:
|
||||
print(stack_fixer(line))
|
||||
else:
|
||||
print(line)
|
||||
proc.wait()
|
||||
proc_timer.cancel()
|
||||
output_timer.cancel()
|
||||
|
||||
log.info("gtest | process wait complete, returncode=%s" % proc.returncode)
|
||||
if mozcrash.check_for_crashes(cwd, symbols_path, test_name="gtest"):
|
||||
# mozcrash will output the log failure line for us.
|
||||
return False
|
||||
if timed_out:
|
||||
return False
|
||||
result = proc.returncode == 0
|
||||
if not result:
|
||||
log.testFail("gtest | test failed with return code %d", proc.returncode)
|
||||
log.info("gtest | process wait complete, returncode=%s" % proc.returncode)
|
||||
if mozcrash.check_for_crashes(cwd, symbols_path, test_name="gtest"):
|
||||
# mozcrash will output the log failure line for us.
|
||||
return False
|
||||
if GTests.run_gtest.timed_out:
|
||||
return False
|
||||
result = proc.returncode == 0
|
||||
if not result:
|
||||
log.testFail("gtest | test failed with return code %d", proc.returncode)
|
||||
return result
|
||||
|
||||
def build_core_environment(self, env={}):
|
||||
|
|
Загрузка…
Ссылка в новой задаче