Skip to content
Snippets Groups Projects
Commit 5058c692 authored by Craig Tiller's avatar Craig Tiller
Browse files

Initial porting of run_tests to Windows

parent 55b7306c
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
import hashlib import hashlib
import multiprocessing import multiprocessing
import os import os
import platform
import random import random
import signal import signal
import subprocess import subprocess
...@@ -43,17 +44,19 @@ import time ...@@ -43,17 +44,19 @@ import time
_DEFAULT_MAX_JOBS = 16 * multiprocessing.cpu_count() _DEFAULT_MAX_JOBS = 16 * multiprocessing.cpu_count()
have_alarm = False
def alarm_handler(unused_signum, unused_frame):
global have_alarm
have_alarm = False
# setup a signal handler so that signal.pause registers 'something' # setup a signal handler so that signal.pause registers 'something'
# when a child finishes # when a child finishes
# not using futures and threading to avoid a dependency on subprocess32 # not using futures and threading to avoid a dependency on subprocess32
signal.signal(signal.SIGCHLD, lambda unused_signum, unused_frame: None) if platform.system() == "Windows":
signal.signal(signal.SIGALRM, alarm_handler) pass
else:
have_alarm = False
def alarm_handler(unused_signum, unused_frame):
global have_alarm
have_alarm = False
signal.signal(signal.SIGCHLD, lambda unused_signum, unused_frame: None)
signal.signal(signal.SIGALRM, alarm_handler)
def shuffle_iteratable(it): def shuffle_iteratable(it):
...@@ -109,6 +112,11 @@ _TAG_COLOR = { ...@@ -109,6 +112,11 @@ _TAG_COLOR = {
def message(tag, message, explanatory_text=None, do_newline=False): def message(tag, message, explanatory_text=None, do_newline=False):
if platform.system() == 'Windows':
if explanatory_text:
print explanatory_text
print '%s: %s' % (tag, message)
return
try: try:
sys.stdout.write('%s%s%s\x1b[%d;%dm%s\x1b[0m: %s%s' % ( sys.stdout.write('%s%s%s\x1b[%d;%dm%s\x1b[0m: %s%s' % (
_BEGINNING_OF_LINE, _BEGINNING_OF_LINE,
...@@ -136,7 +144,7 @@ def which(filename): ...@@ -136,7 +144,7 @@ def which(filename):
class JobSpec(object): class JobSpec(object):
"""Specifies what to run for a job.""" """Specifies what to run for a job."""
def __init__(self, cmdline, shortname=None, environ=None, hash_targets=None): def __init__(self, cmdline, shortname=None, environ=None, hash_targets=None, cwd=None):
""" """
Arguments: Arguments:
cmdline: a list of arguments to pass as the command line cmdline: a list of arguments to pass as the command line
...@@ -152,6 +160,7 @@ class JobSpec(object): ...@@ -152,6 +160,7 @@ class JobSpec(object):
self.environ = environ self.environ = environ
self.shortname = cmdline[0] if shortname is None else shortname self.shortname = cmdline[0] if shortname is None else shortname
self.hash_targets = hash_targets or [] self.hash_targets = hash_targets or []
self.cwd = cwd
def identity(self): def identity(self):
return '%r %r %r' % (self.cmdline, self.environ, self.hash_targets) return '%r %r %r' % (self.cmdline, self.environ, self.hash_targets)
...@@ -174,9 +183,11 @@ class Job(object): ...@@ -174,9 +183,11 @@ class Job(object):
for k, v in spec.environ.iteritems(): for k, v in spec.environ.iteritems():
env[k] = v env[k] = v
self._start = time.time() self._start = time.time()
print spec.cwd
self._process = subprocess.Popen(args=spec.cmdline, self._process = subprocess.Popen(args=spec.cmdline,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
stdout=self._tempfile, stdout=self._tempfile,
cwd=spec.cwd,
env=env) env=env)
self._state = _RUNNING self._state = _RUNNING
self._newline_on_success = newline_on_success self._newline_on_success = newline_on_success
...@@ -241,10 +252,15 @@ class Jobset(object): ...@@ -241,10 +252,15 @@ class Jobset(object):
bin_hash = None bin_hash = None
should_run = True should_run = True
if should_run: if should_run:
self._running.add(Job(spec, try:
bin_hash, self._running.add(Job(spec,
self._newline_on_success, bin_hash,
self._travis)) self._newline_on_success,
self._travis))
except:
message('FAILED', spec.shortname)
self._cancelled = True
return False
return True return True
def reap(self): def reap(self):
...@@ -264,11 +280,14 @@ class Jobset(object): ...@@ -264,11 +280,14 @@ class Jobset(object):
if (not self._travis): if (not self._travis):
message('WAITING', '%d jobs running, %d complete, %d failed' % ( message('WAITING', '%d jobs running, %d complete, %d failed' % (
len(self._running), self._completed, self._failures)) len(self._running), self._completed, self._failures))
global have_alarm if platform.system() == 'Windows':
if not have_alarm: time.sleep(0.1)
have_alarm = True else:
signal.alarm(10) global have_alarm
signal.pause() if not have_alarm:
have_alarm = True
signal.alarm(10)
signal.pause()
def cancelled(self): def cancelled(self):
"""Poll for cancellation.""" """Poll for cancellation."""
......
...@@ -39,6 +39,7 @@ import os ...@@ -39,6 +39,7 @@ import os
import re import re
import sys import sys
import time import time
import platform
import jobset import jobset
import watch_dirs import watch_dirs
...@@ -314,17 +315,27 @@ if len(build_configs) > 1: ...@@ -314,17 +315,27 @@ if len(build_configs) > 1:
print language, 'does not support multiple build configurations' print language, 'does not support multiple build configurations'
sys.exit(1) sys.exit(1)
build_steps = [jobset.JobSpec(['make', if platform.system() == 'Windows':
'-j', '%d' % (multiprocessing.cpu_count() + 1), def make_jobspec(cfg, targets):
'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' % args.slowdown, return jobset.JobSpec(['nmake', '/f', 'Grpc.mak', 'CONFIG=%s' % cfg] + targets,
'CONFIG=%s' % cfg] + list(set( cwd='vsprojects\\vs2013')
itertools.chain.from_iterable( else:
l.make_targets() for l in languages)))) def make_jobspec(cfg, targets):
for cfg in build_configs] + list(set( return jobset.JobSpec(['make',
'-j', '%d' % (multiprocessing.cpu_count() + 1),
'EXTRA_DEFINES=GRPC_TEST_SLOWDOWN_MACHINE_FACTOR=%f' %
args.slowdown,
'CONFIG=%s' % cfg] + targets)
build_steps = [make_jobspec(cfg,
list(set(itertools.chain.from_iterable(
l.make_targets() for l in languages))))
for cfg in build_configs]
build_steps.extend(set(
jobset.JobSpec(cmdline, environ={'CONFIG': cfg}) jobset.JobSpec(cmdline, environ={'CONFIG': cfg})
for cfg in build_configs for cfg in build_configs
for l in languages for l in languages
for cmdline in l.build_steps())) for cmdline in l.build_steps()))
one_run = set( one_run = set(
spec spec
for config in run_configs for config in run_configs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment