OLD | NEW |
(Empty) | |
| 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 |
| 29 import multiprocessing |
| 30 import os |
| 31 import Queue |
| 32 import threading |
| 33 import time |
| 34 |
| 35 from ..local import execution |
| 36 from ..local import progress |
| 37 from ..local import testsuite |
| 38 from ..local import utils |
| 39 from ..server import compression |
| 40 |
| 41 |
| 42 class 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.senderthread = threading.Thread(target=self._SenderThread) |
| 50 self.senderthread.start() |
| 51 self.done_lock = threading.Lock() |
| 52 self.done_lock.acquire() |
| 53 |
| 54 def HasRun(self, test): |
| 55 # The runners that call this have a lock anyway, so this is safe. |
| 56 self.results_queue.append(test) |
| 57 |
| 58 def _SenderThread(self): |
| 59 queuetime = 0.0 |
| 60 packtime = 0.0 |
| 61 compresstime = 0.0 |
| 62 comparetime = 0.0 |
| 63 keep_running = True |
| 64 tests = [] |
| 65 while keep_running: |
| 66 time.sleep(0.1) |
| 67 t1 = time.time() |
| 68 # This should be "atomic enough" without locking :-) |
| 69 # (We don't care which list any new elements get appended to, as long |
| 70 # as we don't lose any and the last one comes last.) |
| 71 current = self.results_queue |
| 72 self.results_queue = [] |
| 73 for c in current: |
| 74 if c is None: |
| 75 keep_running = False |
| 76 else: |
| 77 tests.append(c) |
| 78 if keep_running and len(tests) < 1: |
| 79 continue # Wait for more results. |
| 80 t2 = time.time() |
| 81 result = [] |
| 82 for t in tests: |
| 83 result.append(t.PackResult()) |
| 84 t3 = time.time() |
| 85 compression.Send(result, self.sock) |
| 86 t4 = time.time() |
| 87 for t in tests: |
| 88 self.server.CompareOwnPerf(t, self.context.arch, self.context.mode) |
| 89 comparetime += time.time() - t4 |
| 90 compresstime += t4 - t3 |
| 91 packtime += t3 - t2 |
| 92 queuetime += t2 - t1 |
| 93 tests = [] |
| 94 self.done_lock.release() |
| 95 |
| 96 |
| 97 def Execute(workspace, ctx, tests, sock, server): |
| 98 suite_paths = utils.GetSuitePaths(os.path.join(workspace, "test")) |
| 99 suites = [] |
| 100 for root in suite_paths: |
| 101 suite = testsuite.TestSuite.LoadTestSuite( |
| 102 os.path.join(workspace, "test", root)) |
| 103 if suite: |
| 104 suites.append(suite) |
| 105 |
| 106 suites_dict = {} |
| 107 for s in suites: |
| 108 suites_dict[s.name] = s |
| 109 s.tests = [] |
| 110 for t in tests: |
| 111 suite = suites_dict[t.suite] |
| 112 t.suite = suite |
| 113 suite.tests.append(t) |
| 114 |
| 115 suites = [ s for s in suites if len(s.tests) > 0 ] |
| 116 for s in suites: |
| 117 s.DownloadData() |
| 118 |
| 119 progress_indicator = EndpointProgress(sock, server, ctx) |
| 120 runner = execution.Runner(suites, progress_indicator, ctx) |
| 121 runner.Run(server.jobs) |
| 122 progress_indicator.HasRun(None) # Sentinel to signal the end. |
| 123 progress_indicator.done_lock.acquire() # Released when the indicator is done. |
OLD | NEW |