#!/usr/bin/env python3 # # Copyright (C) 2021 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
# acov-llvm.py is a tool for gathering coverage information from a device and # generating an LLVM coverage report from that information. To use: # # This script would work only when the device image was built with the following # build variables: # CLANG_COVERAGE=true NATIVE_COVERAGE_PATHS="<list-of-paths>" # # 1. [optional] Reset coverage information on the device # $ acov-llvm.py clean-device # # 2. Run tests # # 3. Flush coverage # from select daemons and system processes on the device # $ acov-llvm.py flush [list of process names] # $ acov-llvm.py flush -p [list of process pids] # or from all processes on the device: # $ acov-llvm.py flush # # 4. Pull coverage from device and generate coverage report # $ acov-llvm.py report -s <one-or-more-source-paths-in-$ANDROID_BUILD_TOP> \ # -b <one-or-more-binaries-in-$OUT> \ # E.g.: # acov-llvm.py report \ # -s bionic \ # -b \ # $OUT/symbols/apex/com.android.runtime/lib/bionic/libc.so \ # $OUT/symbols/apex/com.android.runtime/lib/bionic/libm.so
import argparse import logging import os import re import subprocess import time import tempfile
def _has_handler_sig37(pid): try:
status = adb_shell(['cat', f'/proc/{pid}/status'],
text=True,
stderr=subprocess.DEVNULL) except subprocess.CalledProcessError:
logging.warning(f'Process {pid} is no longer active') returnFalse
status = status.split('\n')
sigcgt = [
line.split(':\t')[1] for line in status if line.startswith('SigCgt')
] ifnot sigcgt:
logging.warning(f'Cannot find \'SigCgt:\' in /proc/{pid}/status') returnFalse return int(sigcgt[0], base=16) & (1 << 36)
ifnot pids:
output = adb_shell(['ps', '-eo', 'pid'], text=True)
pids = [pid.strip() for pid in output.split()]
pids = pids[1:] # ignore the column header
pids = [pid for pid in pids if _has_handler_sig37(pid)]
ifnot pids:
logging.warning(
f'couldn\'t find any process with handler for signal 37')
# Some processes may have exited after we run `ps` command above - ignore failures when # sending flush signal. # We rely on kill(1) sending the signal to all pids on the command line even if some don't # exist. This is true of toybox and "probably implied" by POSIX, even if not explicitly called # out [https://pubs.opengroup.org/onlinepubs/9699919799/utilities/kill.html]. try:
adb_shell(['kill', '-37'] + pids) except subprocess.CalledProcessError:
logging.warning('Sending flush signal failed - some pids no longer active')
def do_clean_device(args):
adb_root()
logging.info('resetting coverage on device')
send_flush_signal()
logging.info(
f'sleeping for {FLUSH_SLEEP} seconds for coverage to be written')
time.sleep(FLUSH_SLEEP)
logging.info('deleting coverage data from device')
adb_shell(['rm', '-rf', '/data/misc/trace/*.profraw'])
def do_flush(args):
adb_root()
if args.procnames:
pids = adb_shell(['pidof'] + args.procnames, text=True).split()
logging.info(f'flushing coverage for pids: {pids}') elif args.pids:
pids = args.pids
logging.info(f'flushing coverage for pids: {pids}') else:
pids = None
logging.info('flushing coverage for all processes on device')
send_flush_signal(pids)
logging.info(
f'sleeping for {FLUSH_SLEEP} seconds for coverage to be written')
time.sleep(FLUSH_SLEEP)
clean_device = subparsers.add_parser( 'clean-device', help='reset coverage on device')
clean_device.set_defaults(func=do_clean_device)
flush = subparsers.add_parser( 'flush', help='flush coverage for processes on device')
flush.add_argument( 'procnames',
nargs='*',
metavar='PROCNAME',
help='flush coverage for one or more processes with name PROCNAME')
flush.add_argument( '-p', '--pids',
nargs='+',
metavar='PROCID',
required=False,
help='flush coverage for one or more processes with name PROCID')
flush.set_defaults(func=do_flush)
report = subparsers.add_parser( 'report', help='fetch coverage from device and generate report')
report.add_argument( '-b', '--binary',
nargs='+',
metavar='BINARY',
action='extend',
required=True,
help='generate coverage report for BINARY')
report.add_argument( '-s', '--source-dir',
nargs='+',
action='extend',
metavar='PATH',
required=True,
help='generate coverage report for source files in PATH')
report.set_defaults(func=do_report) return parser.parse_args()
def main():
args = parse_args() if args.verbose:
logging.basicConfig(level=logging.DEBUG)
args.func(args)
if __name__ == '__main__':
main()
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.