1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tradefed.testtype.coverage; 18 19 import com.android.tradefed.config.Option; 20 21 import com.google.common.collect.ImmutableList; 22 23 import java.io.File; 24 import java.util.ArrayList; 25 import java.util.List; 26 27 /** Tradefed object to hold coverage options. */ 28 public final class CoverageOptions { 29 30 @Option( 31 name = "coverage", 32 description = 33 "Collect code coverage for this test run. Note that the build under test must be a " 34 + "coverage build or else this will fail." 35 ) 36 private boolean mCoverage = false; 37 38 @Option( 39 name = "coverage-toolchain", 40 description = 41 "The coverage toolchains that were used to compile the coverage build to " 42 + "collect coverage from." 43 ) 44 private List<Toolchain> mToolchains = new ArrayList<>(); 45 46 public enum Toolchain { 47 CLANG, 48 GCOV, 49 JACOCO; 50 } 51 52 @Option( 53 name = "coverage-flush", 54 description = "Forces coverage data to be flushed at the end of the test." 55 ) 56 private boolean mCoverageFlush = false; 57 58 @Option( 59 name = "coverage-processes", 60 description = "Name of processes to collect coverage data from." 61 ) 62 private List<String> mCoverageProcesses = new ArrayList<>(); 63 64 @Option(name = "llvm-profdata-path", description = "Path to llvm-profdata tool.") 65 private File mLlvmProfdataPath = null; 66 67 /** 68 * Returns whether coverage measurements should be collected from this run. 69 * 70 * @return whether to collect coverage measurements 71 */ isCoverageEnabled()72 public boolean isCoverageEnabled() { 73 return mCoverage; 74 } 75 76 /** 77 * Returns the coverage toolchains to collect coverage from. 78 * 79 * @return the toolchains to collect coverage from 80 */ getCoverageToolchains()81 public List<Toolchain> getCoverageToolchains() { 82 return ImmutableList.copyOf(mToolchains); 83 } 84 85 /** 86 * Returns whether coverage measurements should be flushed from running processes after the test 87 * has completed. 88 * 89 * @return whether to flush processes for coverage measurements after the test 90 */ isCoverageFlushEnabled()91 public boolean isCoverageFlushEnabled() { 92 return mCoverageFlush; 93 } 94 95 /** 96 * Returns the name of processes to flush coverage from after the test has completed. 97 * 98 * @return a {@link List} of process names to flush coverage from after the test 99 */ getCoverageProcesses()100 public List<String> getCoverageProcesses() { 101 return ImmutableList.copyOf(mCoverageProcesses); 102 } 103 104 /** 105 * Returns the directory containing the llvm-profdata tool. 106 * 107 * @return a {@link File} containing the llvm-profdata tool and its dependencies 108 */ getLlvmProfdataPath()109 public File getLlvmProfdataPath() { 110 return mLlvmProfdataPath; 111 } 112 } 113