def schedule_jobs(self): """scheduler. """ if not self.tests_list: return num_of_workers = self._get_workers_num() console.info('spawn %d worker(s) to run tests' % num_of_workers) for i in self.tests_list: target = i[0] if target.data.get('exclusive'): self.exclusive_job_queue.put(i) else: self.job_queue.put(i) quiet = console.verbosity_le('quiet') redirect = num_of_workers > 1 or quiet threads = [] for i in range(num_of_workers): t = WorkerThread(i, self.job_queue, self._process_job, redirect) t.start() threads.append(t) self._wait_worker_threads(threads) if not self.exclusive_job_queue.empty(): console.info('spawn 1 worker to run exclusive tests') last_t = WorkerThread(num_of_workers, self.exclusive_job_queue, self._process_job, quiet) last_t.start() self._wait_worker_threads([last_t])
def _show_progress(self, cmd): console.info('[%s/%s/%s] Running %s' % (self.num_of_finished_tests, self.num_of_running_tests, len(self.tests_list), cmd)) if console.verbosity_le('quiet'): console.show_progress_bar(self.num_of_finished_tests, len(self.tests_list))
def _run_job_redirect(self, job, job_thread): """run job and redirect the output. """ target, run_dir, test_env, cmd = job test_name = target.fullname shell = target.data.get('run_in_shell', False) if shell: cmd = subprocess.list2cmdline(cmd) timeout = target.data.get('test_timeout') self._show_progress(cmd) p = subprocess.Popen(cmd, env=test_env, cwd=run_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, shell=shell) job_thread.set_job_data(p, test_name, timeout) stdout = p.communicate()[0] result = self._get_result(p.returncode) msg = 'Output of //%s:\n%s\n//%s finished: %s\n' % ( test_name, stdout, test_name, result) if console.verbosity_le('quiet') and p.returncode != 0: console.error(msg, prefix=False) else: console.info(msg) console.flush() return p.returncode
def _show_progress(self, cmd): console.info('%s Start %s' % (self._progress(), cmd)) if console.verbosity_le('quiet'): console.show_progress_bar(self.num_of_finished_tests, len(self.tests_list))