[test] Clean up stray processes before running tests on swarming

Bug: v8:10680
Change-Id: I3a6055372b757fac4c5e28840536d1389e857437
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2297381
Reviewed-by: Tamer Tas <tmrts@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68868}
This commit is contained in:
Michael Achenbach 2020-07-14 14:10:38 +02:00 committed by Commit Bot
parent 32234d0251
commit e0f85c04f9
3 changed files with 51 additions and 17 deletions

View File

@ -33,6 +33,7 @@ from testrunner.testproc.rerun import RerunProc
from testrunner.testproc.shard import ShardProc
from testrunner.testproc.sigproc import SignalProc
from testrunner.testproc.timeout import TimeoutProc
from testrunner.testproc import util
BASE_DIR = (
@ -266,6 +267,9 @@ class BaseTestRunner(object):
# this less cryptic by printing it ourselves.
print(' '.join(sys.argv))
# Kill stray processes from previous tasks on swarming.
util.kill_processes_linux()
self._load_build_config(options)
command.setup(self.target_os, options.device)

View File

@ -10,17 +10,11 @@ import datetime
import json
import os
import platform
import subprocess
import sys
import time
from . import util
from . import base
# Base dir of the build products for Release and Debug.
OUT_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'out'))
from . import util
def print_failure_header(test):
@ -165,16 +159,10 @@ class VerboseProgressIndicator(SimpleProgressIndicator):
# feedback channel from the workers, providing which tests are currently run.
def _print_processes_linux(self):
if platform.system() == 'Linux':
try:
cmd = 'ps -aux | grep "%s"' % OUT_DIR
output = subprocess.check_output(cmd, shell=True)
self._print('List of processes:')
for line in (output or '').splitlines():
# Show command with pid, but other process info cut off.
self._print('pid: %s cmd: %s' %
(line.split()[1], line[line.index(OUT_DIR):]))
except:
pass
self._print('List of processes:')
for pid, cmd in util.list_processes_linux():
# Show command with pid, but other process info cut off.
self._print('pid: %d cmd: %s' % (pid, cmd))
def _ensure_delay(self, delay):
return time.time() - self._last_printed_time > delay

View File

@ -4,7 +4,49 @@
# found in the LICENSE file.
import heapq
import os
import platform
import random
import signal
import subprocess
# Base dir of the build products for Release and Debug.
OUT_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'out'))
def list_processes_linux():
"""Returns list of tuples (pid, command) of processes running in the same out
directory as this checkout.
"""
if platform.system() != 'Linux':
return []
try:
cmd = 'pgrep -fa %s' % OUT_DIR
output = subprocess.check_output(cmd, shell=True) or ''
processes = [
(int(line.split()[0]), line[line.index(OUT_DIR):])
for line in output.splitlines()
]
# Filter strange process with name as out dir.
return [p for p in processes if p[1] != OUT_DIR]
except:
return []
def kill_processes_linux():
"""Kill stray processes on the system that started in the same out directory.
All swarming tasks share the same out directory location.
"""
if platform.system() != 'Linux':
return
for pid, cmd in list_processes_linux():
try:
print('Attempting to kill %d - %s' % (pid, cmd))
os.kill(pid, signal.SIGKILL)
except:
pass
class FixedSizeTopList():