1# Copyright 2012 the V8 project authors. All rights reserved. 2# Redistribution and use in source and binary forms, with or without 3# modification, are permitted provided that the following conditions are 4# met: 5# 6# * Redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer. 8# * Redistributions in binary form must reproduce the above 9# copyright notice, this list of conditions and the following 10# disclaimer in the documentation and/or other materials provided 11# with the distribution. 12# * Neither the name of Google Inc. nor the names of its 13# contributors may be used to endorse or promote products derived 14# from this software without specific prior written permission. 15# 16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 29import multiprocessing 30import os 31import Queue 32import threading 33import time 34 35from ..local import execution 36from ..local import progress 37from ..local import testsuite 38from ..local import utils 39from ..server import compression 40 41 42class EndpointProgress(progress.ProgressIndicator): 43 def __init__(self, sock, server, ctx): 44 super(EndpointProgress, self).__init__() 45 self.sock = sock 46 self.server = server 47 self.context = ctx 48 self.results_queue = [] # Accessors must synchronize themselves. 49 self.sender_lock = threading.Lock() 50 self.senderthread = threading.Thread(target=self._SenderThread) 51 self.senderthread.start() 52 53 def HasRun(self, test, has_unexpected_output): 54 # The runners that call this have a lock anyway, so this is safe. 55 self.results_queue.append(test) 56 57 def _SenderThread(self): 58 keep_running = True 59 tests = [] 60 self.sender_lock.acquire() 61 while keep_running: 62 time.sleep(0.1) 63 # This should be "atomic enough" without locking :-) 64 # (We don't care which list any new elements get appended to, as long 65 # as we don't lose any and the last one comes last.) 66 current = self.results_queue 67 self.results_queue = [] 68 for c in current: 69 if c is None: 70 keep_running = False 71 else: 72 tests.append(c) 73 if keep_running and len(tests) < 1: 74 continue # Wait for more results. 75 if len(tests) < 1: break # We're done here. 76 result = [] 77 for t in tests: 78 result.append(t.PackResult()) 79 try: 80 compression.Send(result, self.sock) 81 except: 82 self.runner.terminate = True 83 for t in tests: 84 self.server.CompareOwnPerf(t, self.context.arch, self.context.mode) 85 tests = [] 86 self.sender_lock.release() 87 88 89def Execute(workspace, ctx, tests, sock, server): 90 suite_paths = utils.GetSuitePaths(os.path.join(workspace, "test")) 91 suites = [] 92 for root in suite_paths: 93 suite = testsuite.TestSuite.LoadTestSuite( 94 os.path.join(workspace, "test", root)) 95 if suite: 96 suite.SetupWorkingDirectory() 97 suites.append(suite) 98 99 suites_dict = {} 100 for s in suites: 101 suites_dict[s.name] = s 102 s.tests = [] 103 for t in tests: 104 suite = suites_dict[t.suite] 105 t.suite = suite 106 suite.tests.append(t) 107 108 suites = [ s for s in suites if len(s.tests) > 0 ] 109 for s in suites: 110 s.DownloadData() 111 112 progress_indicator = EndpointProgress(sock, server, ctx) 113 runner = execution.Runner(suites, progress_indicator, ctx) 114 try: 115 runner.Run(server.jobs) 116 except IOError, e: 117 if e.errno == 2: 118 message = ("File not found: %s, maybe you forgot to 'git add' it?" % 119 e.filename) 120 else: 121 message = "%s" % e 122 compression.Send([[-1, message]], sock) 123 progress_indicator.HasRun(None, None) # Sentinel to signal the end. 124 progress_indicator.sender_lock.acquire() # Released when sending is done. 125 progress_indicator.sender_lock.release() 126