Пример #1
0
 function generateCoverageResults()
 {
     // Find all executables, not just the test executables.
     // We need to do this because the test executables may not
     // include all of the possible code (linker decides to omit
     // it from the image) so we see a skewed representation of
     // the source lines.
     $fp = popen("find {$this->repo_root} -type f -name watchman -o " . "-name \\*.a -o -name \\*.so -o -name \\*.dylib", "r");
     while (true) {
         $line = fgets($fp);
         if ($line === false) {
             break;
         }
         $obj_files[] = trim($line);
     }
     // Parse line information from the objects
     foreach ($obj_files as $object) {
         DwarfLineInfo::loadObject($object);
     }
     $CG = new CallgrindFile((string) $this->cg_file);
     $CG->parse();
     $source_files = array();
     foreach ($CG->getSourceFiles() as $filename) {
         if (Filesystem::isDescendant($filename, $this->repo_root) && !preg_match("/(thirdparty|tests)/", $filename)) {
             $source_files[$filename] = $filename;
         }
     }
     $cov = array();
     foreach ($source_files as $filename) {
         $relsrc = substr($filename, strlen($this->repo_root) + 1);
         $cov[$relsrc] = CallgrindFile::mergeSourceLineData($filename, array($CG));
     }
     $res = new ArcanistUnitTestResult();
     $res->setName('coverage');
     $res->setUserData("Collected");
     $res->setResult(ArcanistUnitTestResult::RESULT_PASS);
     $res->setCoverage($cov);
     // Stash it for review with our `arc cov` command
     $wc = ArcanistWorkingCopyIdentity::newFromPath($this->repo_root);
     $api = ArcanistRepositoryAPI::newAPIFromWorkingCopyIdentity($wc);
     $api->writeScratchFile('wman-cov.json', json_encode($cov));
     return array($res);
 }
Пример #2
0
 function collectSourceFileData($sourcefile)
 {
     $all_lines = array();
     $this->getTouchedLines($sourcefile, $all_lines);
     foreach ($this->getObjectFiles() as $objfile) {
         DwarfLineInfo::loadObject($objfile);
     }
     $exe_lines = DwarfLineInfo::mergedSourceLines($sourcefile);
     $max_line = max($exe_lines);
     /* now build a string containing the coverage info.
      * This is compatible with ArcanistUnitTestResult coverage data:
      * N not executable
      * C covered
      * U uncovered
      * X unreachable (we can't detect that here)
      */
     $cov = str_repeat('N', $max_line);
     for ($i = 1; $i <= $max_line; $i++) {
         if (isset($all_lines[$i])) {
             $cov[$i - 1] = 'C';
         } else {
             if (isset($exe_lines[$i])) {
                 $cov[$i - 1] = 'U';
             }
         }
     }
     return $cov;
 }