Skip to content

Commit

Permalink
Add antagonist processes to run_tests.py arsenal
Browse files Browse the repository at this point in the history
These are processes consume CPU for the purpose of slowing down tests, allowing more timing related issues to be exposed.
  • Loading branch information
ctiller committed May 24, 2015
1 parent a152b1c commit 234b6e7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
34 changes: 34 additions & 0 deletions tools/run_tests/antagonist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# Copyright 2015, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""This is used by run_tests.py to create cpu load on a machine"""

while True:
pass
25 changes: 17 additions & 8 deletions tools/run_tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import sys
import time
import platform
import subprocess

import jobset
import watch_dirs
Expand Down Expand Up @@ -350,6 +351,7 @@ def __str__(self):
choices=sorted(_LANGUAGES.keys()),
nargs='+',
default=sorted(_LANGUAGES.keys()))
argp.add_argument('-a', '--antagonists', default=0, type=int)
args = argp.parse_args()

# grab config
Expand Down Expand Up @@ -444,14 +446,21 @@ def _build_and_run(check_cancelled, newline_on_success, travis, cache):
newline_on_success=newline_on_success, travis=travis):
return 1

# run all the tests
all_runs = itertools.chain.from_iterable(
itertools.repeat(one_run, runs_per_test))
if not jobset.run(all_runs, check_cancelled,
newline_on_success=newline_on_success, travis=travis,
maxjobs=min(args.jobs, min(c.maxjobs for c in run_configs)),
cache=cache):
return 2
# start antagonists
antagonists = [subprocess.Popen(['tools/run_tests/antagonist.py'])
for _ in range(0, args.antagonists)]
try:
# run all the tests
all_runs = itertools.chain.from_iterable(
itertools.repeat(one_run, runs_per_test))
if not jobset.run(all_runs, check_cancelled,
newline_on_success=newline_on_success, travis=travis,
maxjobs=min(args.jobs, min(c.maxjobs for c in run_configs)),
cache=cache):
return 2
finally:
for antagonist in antagonists:
antagonist.kill()

return 0

Expand Down

0 comments on commit 234b6e7

Please sign in to comment.