Commit e0f85c04 authored by Michael Achenbach's avatar Michael Achenbach Committed by Commit Bot

[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/+/2297381Reviewed-by: 's avatarTamer Tas <tmrts@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68868}
parent 32234d02
...@@ -33,6 +33,7 @@ from testrunner.testproc.rerun import RerunProc ...@@ -33,6 +33,7 @@ from testrunner.testproc.rerun import RerunProc
from testrunner.testproc.shard import ShardProc from testrunner.testproc.shard import ShardProc
from testrunner.testproc.sigproc import SignalProc from testrunner.testproc.sigproc import SignalProc
from testrunner.testproc.timeout import TimeoutProc from testrunner.testproc.timeout import TimeoutProc
from testrunner.testproc import util
BASE_DIR = ( BASE_DIR = (
...@@ -266,6 +267,9 @@ class BaseTestRunner(object): ...@@ -266,6 +267,9 @@ class BaseTestRunner(object):
# this less cryptic by printing it ourselves. # this less cryptic by printing it ourselves.
print(' '.join(sys.argv)) print(' '.join(sys.argv))
# Kill stray processes from previous tasks on swarming.
util.kill_processes_linux()
self._load_build_config(options) self._load_build_config(options)
command.setup(self.target_os, options.device) command.setup(self.target_os, options.device)
......
...@@ -10,17 +10,11 @@ import datetime ...@@ -10,17 +10,11 @@ import datetime
import json import json
import os import os
import platform import platform
import subprocess
import sys import sys
import time import time
from . import util
from . import base from . import base
from . import util
# Base dir of the build products for Release and Debug.
OUT_DIR = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', 'out'))
def print_failure_header(test): def print_failure_header(test):
...@@ -165,16 +159,10 @@ class VerboseProgressIndicator(SimpleProgressIndicator): ...@@ -165,16 +159,10 @@ class VerboseProgressIndicator(SimpleProgressIndicator):
# feedback channel from the workers, providing which tests are currently run. # feedback channel from the workers, providing which tests are currently run.
def _print_processes_linux(self): def _print_processes_linux(self):
if platform.system() == 'Linux': if platform.system() == 'Linux':
try: self._print('List of processes:')
cmd = 'ps -aux | grep "%s"' % OUT_DIR for pid, cmd in util.list_processes_linux():
output = subprocess.check_output(cmd, shell=True) # Show command with pid, but other process info cut off.
self._print('List of processes:') self._print('pid: %d cmd: %s' % (pid, cmd))
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
def _ensure_delay(self, delay): def _ensure_delay(self, delay):
return time.time() - self._last_printed_time > delay return time.time() - self._last_printed_time > delay
......
...@@ -4,7 +4,49 @@ ...@@ -4,7 +4,49 @@
# found in the LICENSE file. # found in the LICENSE file.
import heapq import heapq
import os
import platform
import random 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(): class FixedSizeTopList():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment