public function renderUnitResult(ArcanistUnitTestResult $result) { $result_code = $result->getResult(); $duration = ''; if ($result_code == ArcanistUnitTestResult::RESULT_PASS) { $duration = ' ' . $this->formatTestDuration($result->getDuration()); } $return = sprintf(" %s %s\n", $this->getFormattedResult($result->getResult()) . $duration, $result->getName()); if ($result_code != ArcanistUnitTestResult::RESULT_PASS) { $return .= $result->getUserData() . "\n"; } return $return; }
public function run() { $projectRoot = $this->getWorkingCopy()->getProjectRoot(); $cwd = getcwd(); $buildDir = $this->findBuildDirectory($projectRoot, $cwd); $polliObjDir = $buildDir; if (is_dir($buildDir . DIRECTORY_SEPARATOR . "tools" . DIRECTORY_SEPARATOR . "polly" . DIRECTORY_SEPARATOR . "tools" . DIRECTORY_SEPARATOR . "polli")) { $polliObjDir = $buildDir . DIRECTORY_SEPARATOR . "tools" . DIRECTORY_SEPARATOR . "polly" . DIRECTORY_SEPARATOR . "tools" . DIRECTORY_SEPARATOR . "polli"; } $polliTestDir = $polliObjDir . DIRECTORY_SEPARATOR . "test"; if (is_dir($buildDir . DIRECTORY_SEPARATOR . "bin") && file_exists($buildDir . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "llvm-lit")) { $lit = $buildDir . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "llvm-lit"; $cmd = "ninja -C " . $buildDir; print "Running ninja (" . $cmd . ")\n"; exec($cmd); } else { $makeVars = $this->getMakeVars($buildDir); $lit = $this->findLitExecutable($makeVars); } print "Using lit executable '{$lit}'\n"; // We have to modify the format string, because llvm-lit does not like a '' argument $cmd = '%s %s 2>&1'; $litFuture = new ExecFuture($cmd, $lit, $polliTestDir); $out = ""; $results = array(); $lastTime = microtime(true); $ready = false; $dots = ""; $numTests = 0; while (!$ready) { $ready = $litFuture->isReady(); $newout = $litFuture->readStdout(); if (strlen($newout) == 0) { usleep(100); continue; } $out .= $newout; if ($ready && strlen($out) > 0 && substr($out, -1) != "\n") { $out .= "\n"; } while (($nlPos = strpos($out, "\n")) !== FALSE) { $line = substr($out, 0, $nlPos + 1); $out = substr($out, $nlPos + 1); $res = ArcanistUnitTestResult::RESULT_UNSOUND; if (substr($line, 0, 6) == "PASS: "******"FAIL: ") { $res = ArcanistUnitTestResult::RESULT_FAIL; } elseif (substr($line, 0, 7) == "XPASS: "******"XFAIL: ") { $res = ArcanistUnitTestResult::RESULT_PASS; } elseif (substr($line, 0, 13) == "UNSUPPORTED: ") { $res = ArcanistUnitTestResult::RESULT_SKIP; } elseif (!$numTests && preg_match('/Testing: ([0-9]+) tests/', $line, $matches)) { $numTests = (int) $matches[1]; } if ($res == ArcanistUnitTestResult::RESULT_FAIL) { print "[0A"; } if ($res != ArcanistUnitTestResult::RESULT_SKIP && $res != ArcanistUnitTestResult::RESULT_PASS) { print "[K[0A" . $line . self::progress($results, $numTests); } if ($res == ArcanistUnitTestResult::RESULT_UNSOUND) { continue; } $result = new ArcanistUnitTestResult(); $result->setName(trim(substr($line, strpos($line, ':') + 1))); $result->setResult($res); $newTime = microtime(true); $result->setDuration($newTime - $lastTime); $lastTime = $newTime; $results[] = $result; $dots .= "."; print "\r[K[0A" . self::progress($results, $numTests); } } list($out1, $out2) = $litFuture->read(); print $out1; if ($out2) { throw new Exception('There was error output, even though it should have been redirected to stdout.'); } print "\n"; $timeThreshold = 0.05; $interestingTests = array(); foreach ($results as $result) { if ($result->getResult() != "pass") { $interestingTests[] = $result; } if ($result->getDuration() > $timeThreshold) { $interestingTests[] = $result; } } return $interestingTests; }