How to use coverageEnabled method of build Package

Best Syzkaller code snippet using build.coverageEnabled

coverage.go

Source:coverage.go Github

copy

Full Screen

1// Copyright 2017 Google Inc. All rights reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14package cc15import (16 "strconv"17 "github.com/google/blueprint"18 "android/soong/android"19)20type CoverageProperties struct {21 Native_coverage *bool22 NeedCoverageVariant bool `blueprint:"mutated"`23 NeedCoverageBuild bool `blueprint:"mutated"`24 CoverageEnabled bool `blueprint:"mutated"`25 IsCoverageVariant bool `blueprint:"mutated"`26}27type coverage struct {28 Properties CoverageProperties29 // Whether binaries containing this module need --coverage added to their ldflags30 linkCoverage bool31}32func (cov *coverage) props() []interface{} {33 return []interface{}{&cov.Properties}34}35func getGcovProfileLibraryName(ctx ModuleContextIntf) string {36 // This function should only ever be called for a cc.Module, so the37 // following statement should always succeed.38 if ctx.useSdk() {39 return "libprofile-extras_ndk"40 } else {41 return "libprofile-extras"42 }43}44func getClangProfileLibraryName(ctx ModuleContextIntf) string {45 if ctx.useSdk() {46 return "libprofile-clang-extras_ndk"47 } else {48 return "libprofile-clang-extras"49 }50}51func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {52 if cov.Properties.NeedCoverageVariant {53 ctx.AddVariationDependencies([]blueprint.Variation{54 {Mutator: "link", Variation: "static"},55 }, coverageDepTag, getGcovProfileLibraryName(ctx))56 ctx.AddVariationDependencies([]blueprint.Variation{57 {Mutator: "link", Variation: "static"},58 }, coverageDepTag, getClangProfileLibraryName(ctx))59 }60 return deps61}62func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {63 clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled()64 gcovCoverage := ctx.DeviceConfig().GcovCoverageEnabled()65 if !gcovCoverage && !clangCoverage {66 return flags, deps67 }68 if cov.Properties.CoverageEnabled {69 cov.linkCoverage = true70 if gcovCoverage {71 flags.GcovCoverage = true72 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "--coverage", "-O0")73 // Override -Wframe-larger-than and non-default optimization74 // flags that the module may use.75 flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=", "-O0")76 } else if clangCoverage {77 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-fprofile-instr-generate", "-fcoverage-mapping")78 }79 }80 // Even if we don't have coverage enabled, if any of our object files were compiled81 // with coverage, then we need to add --coverage to our ldflags.82 if !cov.linkCoverage {83 if ctx.static() && !ctx.staticBinary() {84 // For static libraries, the only thing that changes our object files85 // are included whole static libraries, so check to see if any of86 // those have coverage enabled.87 ctx.VisitDirectDepsWithTag(wholeStaticDepTag, func(m android.Module) {88 if cc, ok := m.(*Module); ok && cc.coverage != nil {89 if cc.coverage.linkCoverage {90 cov.linkCoverage = true91 }92 }93 })94 } else {95 // For executables and shared libraries, we need to check all of96 // our static dependencies.97 ctx.VisitDirectDeps(func(m android.Module) {98 cc, ok := m.(*Module)99 if !ok || cc.coverage == nil {100 return101 }102 if static, ok := cc.linker.(libraryInterface); !ok || !static.static() {103 return104 }105 if cc.coverage.linkCoverage {106 cov.linkCoverage = true107 }108 })109 }110 }111 if cov.linkCoverage {112 if gcovCoverage {113 flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage")114 coverage := ctx.GetDirectDepWithTag(getGcovProfileLibraryName(ctx), coverageDepTag).(*Module)115 deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())116 flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")117 } else if clangCoverage {118 flags.Local.LdFlags = append(flags.Local.LdFlags, "-fprofile-instr-generate")119 coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), coverageDepTag).(*Module)120 deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())121 }122 }123 return flags, deps124}125func (cov *coverage) begin(ctx BaseModuleContext) {126 // Coverage is disabled globally127 if !ctx.DeviceConfig().NativeCoverageEnabled() {128 return129 }130 var needCoverageVariant bool131 var needCoverageBuild bool132 if ctx.Host() {133 // TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a134 // Just turn off for now.135 } else if !ctx.nativeCoverage() {136 // Native coverage is not supported for this module type.137 } else {138 // Check if Native_coverage is set to false. This property defaults to true.139 needCoverageVariant = BoolDefault(cov.Properties.Native_coverage, true)140 if sdk_version := ctx.sdkVersion(); ctx.useSdk() && sdk_version != "current" {141 // Native coverage is not supported for SDK versions < 23142 if fromApi, err := strconv.Atoi(sdk_version); err == nil && fromApi < 23 {143 needCoverageVariant = false144 }145 }146 if needCoverageVariant {147 // Coverage variant is actually built with coverage if enabled for its module path148 needCoverageBuild = ctx.DeviceConfig().NativeCoverageEnabledForPath(ctx.ModuleDir())149 }150 }151 cov.Properties.NeedCoverageBuild = needCoverageBuild152 cov.Properties.NeedCoverageVariant = needCoverageVariant153}154// Coverage is an interface for non-CC modules to implement to be mutated for coverage155type Coverage interface {156 android.Module157 IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool158 PreventInstall()159 HideFromMake()160 MarkAsCoverageVariant(bool)161}162func coverageMutator(mctx android.BottomUpMutatorContext) {163 if c, ok := mctx.Module().(*Module); ok && c.coverage != nil {164 needCoverageVariant := c.coverage.Properties.NeedCoverageVariant165 needCoverageBuild := c.coverage.Properties.NeedCoverageBuild166 if needCoverageVariant {167 m := mctx.CreateVariations("", "cov")168 // Setup the non-coverage version and set HideFromMake and169 // PreventInstall to true.170 m[0].(*Module).coverage.Properties.CoverageEnabled = false171 m[0].(*Module).coverage.Properties.IsCoverageVariant = false172 m[0].(*Module).Properties.HideFromMake = true173 m[0].(*Module).Properties.PreventInstall = true174 // The coverage-enabled version inherits HideFromMake,175 // PreventInstall from the original module.176 m[1].(*Module).coverage.Properties.CoverageEnabled = needCoverageBuild177 m[1].(*Module).coverage.Properties.IsCoverageVariant = true178 }179 } else if cov, ok := mctx.Module().(Coverage); ok && cov.IsNativeCoverageNeeded(mctx) {180 // APEX modules fall here181 // Note: variant "" is also created because an APEX can be depended on by another182 // module which are split into "" and "cov" variants. e.g. when cc_test refers183 // to an APEX via 'data' property.184 m := mctx.CreateVariations("", "cov")185 m[0].(Coverage).MarkAsCoverageVariant(true)186 m[0].(Coverage).PreventInstall()187 m[0].(Coverage).HideFromMake()188 }189}...

Full Screen

Full Screen

coverageEnabled

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(build.Default.CoverageEnabled())4}5Recommended Posts: Go | build.ImportDir() method6Go | build.Import() method7Go | build.ImportComment() method8Go | build.ImportFrom() method9Go | build.ImportFromDir() method10Go | build.ImportFromPath() method11Go | build.ImportPath() method12Go | build.ImportPaths() method13Go | build.ImportTree() method14Go | build.ImportTreeFrom() method15Go | build.ImportTreeFromDir() method16Go | build.ImportTreeFromPath() method17Go | build.ImportTreePath() method18Go | build.ImportTreePaths() method19Go | build.ImportTreeTo() method20Go | build.ImportTreeToDir() method21Go | build.ImportTreeToPath() method22Go | build.ImportTreeToPaths() method23Go | build.ImportDirTo() method24Go | build.ImportDirToPath() method25Go | build.ImportDirToPaths() method26Go | build.ImportTo() method27Go | build.ImportToDir() method28Go | build.ImportToPath() method29Go | build.ImportToPaths() method30Go | build.ImportTreeFromPaths() method31Go | build.ImportTreeToPaths() method32Go | build.ImportDirToPaths() method33Go | build.ImportToPaths() method34Go | build.ImportTreeFromPaths() method35Go | build.ImportTreeToPaths() method36Go | build.ImportDirToPaths() method37Go | build.ImportToPaths() method38Go | build.ImportTreeFromPaths() method39Go | build.ImportTreeToPaths() method40Go | build.ImportDirToPaths() method41Go | build.ImportToPaths() method42Go | build.ImportTreeFromPaths() method43Go | build.ImportTreeToPaths() method44Go | build.ImportDirToPaths() method45Go | build.ImportToPaths() method46Go | build.ImportTreeFromPaths() method47Go | build.ImportTreeToPaths() method48Go | build.ImportDirToPaths() method49Go | build.ImportToPaths() method50Go | build.ImportTreeFromPaths() method51Go | build.ImportTreeToPaths() method52Go | build.ImportDirToPaths()

Full Screen

Full Screen

coverageEnabled

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(build.Default.CoverageEnabled())4}5import (6func main() {7 fmt.Println(build.Default.CoverMode())8}9import (10func main() {11 fmt.Println(build.Default.GOARCH)12}13import (14func main() {15 fmt.Println(build.Default.GOOS)16}17import (18func main() {19 fmt.Println(build.Default.GOROOT)20}21import (22func main() {23 fmt.Println(build.Default.InstallSuffix)24}25import (26func main() {27 fmt.Println(build.Default.ToolDir())28}29import (30func main() {31 fmt.Println(build.Default.UseAllFiles())32}33import (34func main() {35 fmt.Println(build.Default.UseCache())36}37import (38func main() {39 fmt.Println(build.Default.UseVendor())40}41import (42func main() {43 fmt.Println(build.Default.WorkDir())44}

Full Screen

Full Screen

coverageEnabled

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Coverage Enabled:", build.Default.CoverageEnabled())4}5Go | Golang - build.Default.GOROOT()6Go | Golang - build.Default.GOPATH()7Go | Golang - build.Default.GOROOT_FINAL()8Go | Golang - build.Default.CgoEnabled()9Go | Golang - build.Default.UseCgo()10Go | Golang - build.Default.SplitPathList()11Go | Golang - build.Default.IsAbsPath()12Go | Golang - build.Default.IsLocalImport()13Go | Golang - build.Default.Import()14Go | Golang - build.Default.ImportDir()15Go | Golang - build.Default.ImportFrom()16Go | Golang - build.Default.ImportComment()17Go | Golang - build.Default.ImportForCompiler()18Go | Golang - build.Default.ImportPkgs()19Go | Golang - build.Default.ReadDir()20Go | Golang - build.Default.Context()21Go | Golang - build.Default.JoinPath()22Go | Golang - build.Default.IsDir()23Go | Golang - build.Default.HasSubdir()24Go | Golang - build.Default.IsRoot()25Go | Golang - build.Default.Root()26Go | Golang - build.Default.CleanPath()27Go | Golang - build.Default.DirChar()28Go | Golang - build.Default.FromSlash()29Go | Golang - build.Default.ToSlash()30Go | Golang - build.Default.IsAbs()31Go | Golang - build.Default.Rel()32Go | Golang - build.Default.SplitPath()

Full Screen

Full Screen

coverageEnabled

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(build.Default.CoverageEnabled())4}5import (6func main() {7 fmt.Println(build.Default.CoverageEnabled())8}9Recommended Posts: Go | os.ExpandEnv() method10Go | os.Expand() method11Go | os.Getenv() method12Go | os.LookupEnv() method13Go | os.Setenv() method14Go | os.Unsetenv() method15Go | os.UserCacheDir() method16Go | os.UserConfigDir() method17Go | os.UserHomeDir() method18Go | os.UserLookup() method19Go | os.UserLookupId() method20Go | os.Hostname() method21Go | os.Getwd() method22Go | os.Chdir() method23Go | os.Chmod() method24Go | os.Chown() method25Go | os.Chtimes() method26Go | os.Create() method27Go | os.Open() method28Go | os.OpenFile() method29Go | os.Readlink() method30Go | os.Remove() method31Go | os.RemoveAll() method32Go | os.Rename() method33Go | os.SameFile() method34Go | os.Stat() method35Go | os.Symlink() method36Go | os.Truncate() method37Go | os.WriteFile() method38Go | os.Exit() method39Go | os.FindProcess() method40Go | os.Getpagesize() method41Go | os.Getpid() method42Go | os.Getppid() method43Go | os.Getuid() method44Go | os.Geteuid() method45Go | os.Getgid() method46Go | os.Getegid() method47Go | os.Getgroups() method

Full Screen

Full Screen

coverageEnabled

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(build.Default.CoverageEnabled())4}5import (6func main() {7 fmt.Println(build.Default.CoverageEnabled())8}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful