tools/code_coverage/coverage.py
def _ExecuteCommand(target, command, output_file_path):
  """Runs a single command and generates a profraw data file."""
  # Per Clang "Source-based Code Coverage" doc:
  #
  # "%p" expands out to the process ID. It's not used by this scripts due to:
  # 1) If a target program spawns too many processess, it may exhaust all disk
  #    space available. For example, unit_tests writes thousands of .profraw
  #    files each of size 1GB+.
  # 2) If a target binary uses shared libraries, coverage profile data for them
  #    will be missing, resulting in incomplete coverage reports.
  #
  # "%Nm" expands out to the instrumented binary's signature. When this pattern
  # is specified, the runtime creates a pool of N raw profiles which are used
  # for on-line profile merging. The runtime takes care of selecting a raw
  # profile from the pool, locking it, and updating it before the program exits.
  # N must be between 1 and 9. The merge pool specifier can only occur once per
  # filename pattern.
  #
  # "%1m" is used when tests run in single process, such as fuzz targets.
  #
  # For other cases, "%4m" is chosen as it creates some level of parallelism,
  # but it's not too big to consume too much computing resource or disk space.
  profile_pattern_string = '%1m' if _IsFuzzerTarget(target) else '%4m'
  expected_profraw_file_name = os.extsep.join(
      [target, profile_pattern_string, PROFRAW_FILE_EXTENSION])
  expected_profraw_file_path = os.path.join(
      coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
      expected_profraw_file_name)
  command = command.replace(LLVM_PROFILE_FILE_PATH_SUBSTITUTION,
                            expected_profraw_file_path)

  try:
    # Some fuzz targets or tests may write into stderr, redirect it as well.
    with open(output_file_path, 'wb') as output_file_handle:
      subprocess.check_call(_SplitCommand(command),
                            stdout=output_file_handle,
                            stderr=subprocess.STDOUT,
                            env=_GetEnvironmentVars(expected_profraw_file_path))
  except subprocess.CalledProcessError as e:
    logging.warning('Command: "%s" exited with non-zero return code.', command)

  return open(output_file_path, 'rb').read()
Runs a single command and generates a profraw data file.
Runs a single command and generates a profraw data file.
Runs a single command and generates a profraw data file .
def _ExecuteCommand(target, command, output_file_path):
   "%p" expands out to the process ID. It's not used by this scripts due to:
   1) If a target program spawns too many processess, it may exhaust all disk
      space available. For example, unit_tests writes thousands of .profraw
      files each of size 1GB+.
   2) If a target binary uses shared libraries, coverage profile data for them
      will be missing, resulting in incomplete coverage reports.
   "%Nm" expands out to the instrumented binary's signature. When this pattern
   is specified, the runtime creates a pool of N raw profiles which are used
   for on-line profile merging. The runtime takes care of selecting a raw
   profile from the pool, locking it, and updating it before the program exits.
   N must be between 1 and 9. The merge pool specifier can only occur once per
   filename pattern.
   "%1m" is used when tests run in single process, such as fuzz targets.
   For other cases, "%4m" is chosen as it creates some level of parallelism,
   but it's not too big to consume too much computing resource or disk space.
  profile_pattern_string = '%1m' if _IsFuzzerTarget(target) else '%4m'
  expected_profraw_file_name = os.extsep.join(
      [target, profile_pattern_string, PROFRAW_FILE_EXTENSION])
  expected_profraw_file_path = os.path.join(
      coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
      expected_profraw_file_name)
  command = command.replace(LLVM_PROFILE_FILE_PATH_SUBSTITUTION,
                            expected_profraw_file_path)
  try:
     Some fuzz targets or tests may write into stderr, redirect it as well.
    with open(output_file_path, 'wb') as output_file_handle:
      subprocess.check_call(_SplitCommand(command),
                            stdout=output_file_handle,
                            stderr=subprocess.STDOUT,
                            env=_GetEnvironmentVars(expected_profraw_file_path))
  except subprocess.CalledProcessError as e:
    logging.warning('Command: "%s" exited with non-zero return code.', command)
  return open(output_file_path, 'rb').read()
def _ExecuteCommand ( target , command , output_file_path ) : profile_pattern_string = '%1m' if _IsFuzzerTarget ( target ) else '%4m' expected_profraw_file_name = os . extsep . join ( [ target , profile_pattern_string , PROFRAW_FILE_EXTENSION ] ) expected_profraw_file_path = os . path . join ( coverage_utils . GetCoverageReportRootDirPath ( OUTPUT_DIR ) , expected_profraw_file_name ) command = command . replace ( LLVM_PROFILE_FILE_PATH_SUBSTITUTION , expected_profraw_file_path ) try : with open ( output_file_path , 'wb' ) as output_file_handle : subprocess . check_call ( _SplitCommand ( command ) , stdout = output_file_handle , stderr = subprocess . STDOUT , env = _GetEnvironmentVars ( expected_profraw_file_path ) ) except subprocess . CalledProcessError as e : logging . warning ( 'Command: "%s" exited with non-zero return code.' , command ) return open ( output_file_path , 'rb' ) . read ( )
Runs a single command and generates a profraw data file.
Runs a single command and generates a profraw data file .
"""Runs a single command and generates a profraw data file.""" # Per Clang "Source-based Code Coverage" doc: # # "%p" expands out to the process ID. It's not used by this scripts due to: # 1) If a target program spawns too many processess, it may exhaust all disk #    space available. For example, unit_tests writes thousands of .profraw #    files each of size 1GB+. # 2) If a target binary uses shared libraries, coverage profile data for them #    will be missing, resulting in incomplete coverage reports. # # "%Nm" expands out to the instrumented binary's signature. When this pattern # is specified, the runtime creates a pool of N raw profiles which are used # for on-line profile merging. The runtime takes care of selecting a raw # profile from the pool, locking it, and updating it before the program exits. # N must be between 1 and 9. The merge pool specifier can only occur once per # filename pattern. # # "%1m" is used when tests run in single process, such as fuzz targets. # # For other cases, "%4m" is chosen as it creates some level of parallelism, # but it's not too big to consume too much computing resource or disk space. # Some fuzz targets or tests may write into stderr, redirect it as well.
target
command
output_file_path