Best Syzkaller code snippet using targets.setCompiler
targets.go
Source:targets.go
...147 }148 target.initOther.Do(func() {149 other := new(Target)150 *other = *target151 other.setCompiler(clang)152 other.lazyInit()153 target.other = other154 })155 return target.other156}157// nolint: lll158var List = map[string]map[string]*Target{159 TestOS: {160 TestArch64: {161 PtrSize: 8,162 PageSize: 4 << 10,163 // Compile with -no-pie due to issues with ASan + ASLR on ppc64le.164 CFlags: []string{"-m64", "-fsanitize=address", "-no-pie"},165 osCommon: osCommon{166 SyscallNumbers: true,167 SyscallPrefix: "SYS_",168 ExecutorUsesShmem: false,169 ExecutorUsesForkServer: false,170 },171 },172 TestArch64Fork: {173 PtrSize: 8,174 PageSize: 8 << 10,175 // Compile with -no-pie due to issues with ASan + ASLR on ppc64le.176 CFlags: []string{"-m64", "-fsanitize=address", "-no-pie"},177 osCommon: osCommon{178 SyscallNumbers: true,179 SyscallPrefix: "SYS_",180 ExecutorUsesShmem: false,181 ExecutorUsesForkServer: true,182 },183 },184 TestArch32Shmem: {185 PtrSize: 4,186 PageSize: 8 << 10,187 Int64Alignment: 4,188 CFlags: []string{"-m32", "-static"},189 osCommon: osCommon{190 SyscallNumbers: true,191 Int64SyscallArgs: true,192 SyscallPrefix: "SYS_",193 ExecutorUsesShmem: true,194 ExecutorUsesForkServer: false,195 },196 },197 TestArch32ForkShmem: {198 PtrSize: 4,199 PageSize: 4 << 10,200 CFlags: []string{"-m32", "-static-pie"},201 osCommon: osCommon{202 SyscallNumbers: true,203 Int64SyscallArgs: true,204 SyscallPrefix: "SYS_",205 ExecutorUsesShmem: true,206 ExecutorUsesForkServer: true,207 HostFuzzer: true,208 },209 },210 },211 Windows: {212 AMD64: {213 PtrSize: 8,214 // TODO(dvyukov): what should we do about 4k vs 64k?215 PageSize: 4 << 10,216 LittleEndian: true,217 },218 },219}220var oses = map[string]osCommon{221 Windows: {222 SyscallNumbers: false,223 ExecutorUsesShmem: false,224 ExecutorUsesForkServer: false,225 ExeExtension: ".exe",226 KernelObject: "vmlinux",227 },228}229var (230 commonCFlags = []string{231 "-O2",232 "-pthread",233 "-Wall",234 "-Werror",235 "-Wparentheses",236 "-Wunused-const-variable",237 "-Wframe-larger-than=16384", // executor uses stacks of limited size, so no jumbo frames238 "-Wno-stringop-overflow",239 "-Wno-array-bounds",240 "-Wno-format-overflow",241 }242 optionalCFlags = map[string]bool{243 "-static": true, // some distributions don't have static libraries244 "-static-pie": true, // this flag is also not supported everywhere245 "-Wunused-const-variable": true, // gcc 5 does not support this flag246 "-fsanitize=address": true, // some OSes don't have ASAN247 "-Wno-stringop-overflow": true,248 "-Wno-array-bounds": true,249 "-Wno-format-overflow": true,250 }251 fallbackCFlags = map[string]string{252 "-static-pie": "-static", // if an ASLR static binary is impossible, build just a static one253 }254)255func fuchsiaCFlags(arch, clangArch string) []string {256 out := sourceDirVar + "/out/" + arch257 return []string{258 "-Wno-deprecated",259 "-target", clangArch + "-fuchsia",260 "-ldriver",261 "-lfdio",262 "-lzircon",263 "--sysroot", out + "/zircon_toolchain/obj/zircon/public/sysroot/sysroot",264 "-I", sourceDirVar + "/sdk/lib/fdio/include",265 "-I", sourceDirVar + "/zircon/system/ulib/fidl/include",266 "-I", sourceDirVar + "/src/lib/ddk/include",267 "-I", out + "/fidling/gen/sdk/fidl/fuchsia.device",268 "-I", out + "/fidling/gen/sdk/fidl/fuchsia.device.manager",269 "-I", out + "/fidling/gen/sdk/fidl/fuchsia.hardware.nand",270 "-I", out + "/fidling/gen/sdk/fidl/fuchsia.hardware.power.statecontrol",271 "-I", out + "/fidling/gen/sdk/fidl/fuchsia.hardware.usb.peripheral",272 "-I", out + "/fidling/gen/zircon/vdso/zx",273 "-L", out + "/" + arch + "-shared",274 }275}276func init() {277 for OS, archs := range List {278 for arch, target := range archs {279 initTarget(target, OS, arch)280 }281 }282 goarch := runtime.GOARCH283 goos := runtime.GOOS284 if goos == "android" {285 goos = Linux286 }287 for _, target := range List[TestOS] {288 if List[goos] != nil {289 if host := List[goos][goarch]; host != nil {290 target.CCompiler = host.CCompiler291 target.CPP = host.CPP292 if goos == FreeBSD {293 // For some configurations -no-pie is passed to the compiler,294 // which is not used by clang.295 // Ensure clang does not complain about it.296 target.CFlags = append(target.CFlags, "-Wno-unused-command-line-argument")297 // When building executor for the test OS, clang needs298 // to link against the libc++ library.299 target.CFlags = append(target.CFlags, "-lc++")300 }301 // In ESA/390 mode, the CPU is able to address only 31bit of memory but302 // arithmetic operations are still 32bit303 // Fix cflags by replacing compiler's -m32 option with -m31304 if goarch == S390x {305 for i := range target.CFlags {306 target.CFlags[i] = strings.Replace(target.CFlags[i], "-m32", "-m31", -1)307 }308 }309 }310 if target.PtrSize == 4 && goos == FreeBSD && goarch == AMD64 {311 // A hack to let 32-bit "test" target tests run on FreeBSD:312 // freebsd/386 requires a non-default DataOffset to avoid313 // clobbering mappings created by the C runtime. Since that is the314 // only target with this constraint, just special-case it for now.315 target.DataOffset = List[goos][I386].DataOffset316 }317 }318 target.BuildOS = goos319 }320}321func initTarget(target *Target, OS, arch string) {322 if common, ok := oses[OS]; ok {323 target.osCommon = common324 }325 target.init = new(sync.Once)326 target.initOther = new(sync.Once)327 target.OS = OS328 target.Arch = arch329 if target.KernelArch == "" {330 target.KernelArch = target.Arch331 }332 if target.NeedSyscallDefine == nil {333 target.NeedSyscallDefine = needSyscallDefine334 }335 if target.DataOffset == 0 {336 target.DataOffset = 512 << 20337 }338 target.NumPages = (16 << 20) / target.PageSize339 sourceDir := os.Getenv("SOURCEDIR_" + strings.ToUpper(OS))340 if sourceDir == "" {341 sourceDir = os.Getenv("SOURCEDIR")342 }343 for sourceDir != "" && sourceDir[len(sourceDir)-1] == '/' {344 sourceDir = sourceDir[:len(sourceDir)-1]345 }346 target.replaceSourceDir(&target.CCompiler, sourceDir)347 target.replaceSourceDir(&target.Objdump, sourceDir)348 for i := range target.CFlags {349 target.replaceSourceDir(&target.CFlags[i], sourceDir)350 }351 if OS == Linux && arch == runtime.GOARCH {352 // Don't use cross-compiler for native compilation, there are cases when this does not work:353 // https://github.com/google/syzkaller/pull/619354 // https://github.com/google/syzkaller/issues/387355 // https://github.com/google/syzkaller/commit/06db3cec94c54e1cf720cdd5db72761514569d56356 target.Triple = ""357 }358 if target.CCompiler == "" {359 target.setCompiler(useClang)360 }361 if target.CPP == "" {362 target.CPP = "cpp"363 }364 if target.Objdump == "" {365 target.Objdump = "objdump"366 if target.Triple != "" {367 target.Objdump = target.Triple + "-objdump"368 }369 }370 if target.BuildOS == "" {371 target.BuildOS = OS372 }373 if runtime.GOOS != target.BuildOS {374 // Spoil native binaries if they are not usable, so that nobody tries to use them later.375 target.CCompiler = fmt.Sprintf("cant-build-%v-on-%v", target.OS, runtime.GOOS)376 target.CPP = target.CCompiler377 }378 for _, flags := range [][]string{commonCFlags, target.osCommon.cflags} {379 target.CFlags = append(target.CFlags, flags...)380 }381 if OS == TestOS {382 if runtime.GOARCH != S390x {383 target.LittleEndian = true384 } else {385 target.LittleEndian = false386 }387 }388 if target.LittleEndian {389 target.HostEndian = binary.LittleEndian390 } else {391 target.HostEndian = binary.BigEndian392 }393}394func (target *Target) Timeouts(slowdown int) Timeouts {395 if slowdown <= 0 {396 panic(fmt.Sprintf("bad slowdown %v", slowdown))397 }398 timeouts := target.timeouts399 timeouts.Slowdown = slowdown400 timeouts.Scale = time.Duration(slowdown)401 if timeouts.Scale > 3 {402 timeouts.Scale = 3403 }404 if timeouts.Syscall == 0 {405 timeouts.Syscall = 50 * time.Millisecond406 }407 if timeouts.Program == 0 {408 timeouts.Program = 5 * time.Second409 }410 if timeouts.NoOutput == 0 {411 // The timeout used to be 3 mins for a long time.412 // But (1) we were seeing flakes on linux where net namespace413 // destruction can be really slow, and (2) gVisor watchdog timeout414 // is 3 mins + 1/4 of that for checking period = 3m45s.415 // Current linux max timeout is CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=140416 // and workqueue.watchdog_thresh=140 which both actually result417 // in 140-280s detection delay.418 // So the current timeout is 5 mins (300s).419 // We don't want it to be too long too because it will waste time on real hangs.420 timeouts.NoOutput = 5 * time.Minute421 }422 if timeouts.VMRunningTime == 0 {423 timeouts.VMRunningTime = time.Hour424 }425 timeouts.Syscall *= time.Duration(slowdown)426 timeouts.Program *= timeouts.Scale427 timeouts.NoOutput *= timeouts.Scale428 timeouts.VMRunningTime *= timeouts.Scale429 timeouts.NoOutputRunningTime = timeouts.NoOutput + time.Minute430 return timeouts431}432func (target *Target) setCompiler(clang bool) {433 // setCompiler may be called effectively twice for target.other,434 // so first we remove flags the previous call may have added.435 pos := 0436 for _, flag := range target.CFlags {437 if flag == "-ferror-limit=0" ||438 strings.HasPrefix(flag, "--target=") {439 continue440 }441 target.CFlags[pos] = flag442 pos++443 }444 target.CFlags = target.CFlags[:pos]445 if clang {446 target.CCompiler = "clang"447 target.KernelCompiler = "clang"...
commandBuilder.go
Source:commandBuilder.go
1package proto2import (3 "bytes"4 "fmt"5 "github.com/4nte/protodist/core"6 "log"7 "os/exec"8 "text/template"9)10type CompilerCommandBuilder struct {11 // Additional args (is this needed?)12 args []string13 // Compiler binary (protoc, protowrap, prototools?)14 compiler string15 // Where to save generated proto files16 outputDirectory string17 // protoc -I option18 protoPaths []string19 // Build targets (go, js, java, docs)20 targets []core.BuildTarget21 // Proto package to build22 protoPackage Package23 // Root path (-I param)24 rootPath string25 // Build targets26 plugins []Plugin27}28func NewProtocCmdBuilder() CompilerCommandBuilder {29 return CompilerCommandBuilder{30 compiler: "protoc",31 outputDirectory: "./out",32 rootPath: "",33 }34}35func (p *CompilerCommandBuilder) SetBuildTargets(targets ...core.BuildTarget) {36 p.targets = targets37}38func (p *CompilerCommandBuilder) SetOutputDir(dir string) {39 p.outputDirectory = dir40}41func (p *CompilerCommandBuilder) SetProtoPath(path ...string) {42 p.protoPaths = path43}44func (p *CompilerCommandBuilder) AddProtoPath(path ...string) {45 p.protoPaths = append(p.protoPaths, path...)46}47func (p *CompilerCommandBuilder) AddPlugin(path ...Plugin) {48 p.plugins = append(p.plugins, path...)49}50func (p *CompilerCommandBuilder) SetCompiler(compiler string) {51 p.compiler = compiler52}53func (p *CompilerCommandBuilder) SetProtoPackage(protoPackage Package) {54 p.protoPackage = protoPackage55}56func (p *CompilerCommandBuilder) SetProtoRootPath(rootPath string) {57 p.rootPath = rootPath58}59func (p *CompilerCommandBuilder) SetImportPaths([]string) {60}61func (p *CompilerCommandBuilder) Build() *exec.Cmd {62 type templateVariables struct {63 OutDir string64 ProtocGenTsBinary string65 }66 vars := templateVariables{67 OutDir: p.outputDirectory,68 ProtocGenTsBinary: "protoc-gen-ts",69 }70 var templatedArgs []string71 templatedArgs = append(templatedArgs, "-I"+p.rootPath)72 for _, protoPath := range p.protoPaths {73 templatedArgs = append(templatedArgs, "-I"+protoPath)74 }75 // Plugins76 for _, plugin := range p.plugins {77 for argName, argValue := range plugin.Args {78 argValueTemplate, err := template.New("arg").Parse(argValue)79 if err != nil {80 log.Fatal(fmt.Errorf("failed to template %s", argValue))81 }82 templatedArgValue := bytes.NewBufferString("")83 err = argValueTemplate.Execute(templatedArgValue, vars)84 if err != nil {85 log.Fatal(fmt.Errorf("failed to template arg value: %s: %w", templatedArgs, err))86 }87 arg := fmt.Sprintf("--%s=%s", argName, templatedArgValue)88 templatedArgs = append(templatedArgs, arg)89 }90 }91 if len(p.targets) == 0 {92 panic("no targets set")93 }94 // Add proto files to compile95 for _, protoFile := range p.protoPackage.Files {96 templatedArgs = append(templatedArgs, protoFile)97 }98 for _, target := range p.targets {99 targetConfig, ok := DefaultTargetRegistry[target]100 if !ok {101 log.Fatal(fmt.Errorf("protoc arg creator not found target %s", target))102 }103 argTemplateStrings := targetConfig.protocArgs104 for _, argTemplate := range argTemplateStrings {105 //fmt.Println("arg template", argTemplate)106 template, err := template.New("arg").Parse(argTemplate)107 if err != nil {108 log.Fatal(fmt.Errorf("failed to template %s", target))109 }110 argBuffer := bytes.NewBufferString("")111 err = template.Execute(argBuffer, vars)112 if err != nil {113 log.Fatal(fmt.Errorf("failed to template arg: %s: %w", templatedArgs, err))114 }115 templatedArgs = append(templatedArgs, argBuffer.String())116 }117 //fmt.Printf("target templatedArgs: %v", templatedArgs)118 }119 fmt.Println("templated args", templatedArgs)120 buildCmd := exec.Command(p.compiler, templatedArgs...)121 buildCmd.Dir = p.rootPath122 return buildCmd123}...
version.go
Source:version.go
1// Copyright (c) 2020-2021 C4 Project2//3// This file is part of c4t.4// Licenced under the MIT licence; see `LICENSE`.5package plan6// Version is the type of plan version numbers.7type Version uint328// CurrentVer is the current plan version.9// It changes when the interface between various bits of the tester (generally manifested within the plan version)10// changes.11const CurrentVer Version = 2021_02_1912// Version history since 2020_05_29:13//14// 2021_02_19: Everything tracking time plus duration has been standardised to take a "time_span" key; this contains a15// "start" time and an "end" time. Currently, both can be in different timezones.16// Mutation analysis has changed to associate selections, hits, and kills with such timespans.17// 2021_01_27: Observation structures completely refactored. Instead of "counter_examples" and "witnesses" keys, each18// state has a "tag" key that contains "counter", "witness", "unknown", or is empty. New "occurrences" key19// in each state tracks number of occurrences where available; key-value maps are now inside a "values" key20// inside the state.21// 2021_01_26: New stages: SetCompiler and Mach, resulting from all plan manipulating tools becoming stages.22// 2021_01_24: Fixes to keys.23// 2021_01_22: Changes to 'mutation' key; auto-incrementing config is now in an 'auto' subkey.24// 2021_01_21: Added 'mutation' key to plan, containing information about mutation testing.25// 2021_01_20: Service run info now contains an 'env' key mapping environment variable names to values. If 'env' is26// not provided, the parent process's environment is used. On compilers only, we now have shell-style27// variable interpolation in args and env: the only variable available so far is '${time}' which expands to28// the UNIX timestamp at which the compiler was configured.29// 2020_12_10: Plan backends are now NamedSpecs rather than Specs, and so contain the backend ID.30// 2020_11_12: Compile results now hold the ID of the recipe used. Recipes have extended information about targets.31// 2020_09_24: SSH configuration now uses camel_case tags. The 'compiles' and 'runs' maps have become one32// 'compilations' map, with optional 'compile' and 'run' subkeys (these currently contain exactly the same33// data as the original map entries).34// 2020_08_25: Machine configuration in plans now carries machine-specific quantity overrides.35// 2020_07_30: New 'perturb' stage. Some changes to observations that may alter the interface with the machine node.36// 2020_07_28: No changes to the plan per se, but the machine node no longer supports human-readable output, and the37// JSON mode flag has been removed.38// 2020_07_27: Added new (sub-)stages: Compile and Run. (A typo meant that this version got stored as 2020_07_29,39// but at this point versions are compared for equality rather than ranges, so there is no practical40// issue.)41// 2020_07_21: Added stage information.42// 2020_05_29: Initial version for which this comment was maintained.43// IsCurrent is true if, and only if, v is compatible with the current version.44func (v Version) IsCurrent() bool {45 return v == CurrentVer46}...
setCompiler
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println("Hello, world.")4}5import "fmt"6func main() {7 fmt.Println("Hello, world.")8}9import "fmt"10func main() {11 fmt.Println("Hello, world.")12}13import "fmt"14func main() {15 fmt.Println("Hello, world.")16}17import "fmt"18func main() {19 fmt.Println("Hello, world.")20}21import "fmt"22func main() {23 fmt.Println("Hello, world.")24}25import "fmt"26func main() {27 fmt.Println("Hello, world.")28}29import "fmt"30func main() {31 fmt.Println("Hello, world.")32}33import "fmt"34func main() {35 fmt.Println("Hello, world.")36}37import "fmt"38func main() {39 fmt.Println("Hello, world.")40}41import "fmt"42func main() {43 fmt.Println("Hello, world.")44}45import "fmt"46func main() {47 fmt.Println("Hello, world.")48}49import "fmt"50func main() {51 fmt.Println("Hello, world.")52}53import
setCompiler
Using AI Code Generation
1import "fmt"2import "github.com/ryanuber/go-glob"3import "github.com/ryanuber/go-glob/glob"4import "github.com/ryanuber/go-glob/glob/ast"5import "github.com/ryanuber/go-glob/glob/lexer"6import "github.com/ryanuber/go-glob/glob/parser"7import "github.com/ryanuber/go-glob/glob/token"8import "github.com/ryanuber/go-glob/glob/walker"9import "github.com/ryanuber/go-glob/glob/walker/ast"10import "github.com/ryanuber/go-glob/glob/walker/lexer"11import "github.com/ryanuber/go-glob/glob/walker/parser"12import "github.com/ryanuber/go-glob/glob/walker/token"13import "github.com/ryanuber/go-glob/glob/walker/walker"14import "github.com/ryanuber/go-glob/glob/walker/walker/ast"15import "github.com/ryanuber/go-glob/glob/walker/walker/lexer"16import "github.com/ryanuber/go-glob/glob/walker/walker/parser"17import "github.com/ryanuber/go-glob/glob/walker/walker/token"18import "github.com/ryanuber/go-glob/glob/walker/walker/walker"19import "github.com/ryanuber/go-glob/glob/walker/walker/walker/ast"20import "github.com/ryanuber/go-glob/glob/walker/walker/walker/lexer"21import "github.com/ryanuber/go-glob/glob/walker/walker/walker/parser"22import "github.com/ryanuber/go-glob/glob/walker/walker/walker/token"23import "github.com/ryanuber/go-glob/glob/walker/walker/walker/walker"24import "github.com/ryanuber/go-glob/glob/walker/walker/walker/walker/ast"25import "github.com/ryanuber/go-glob/glob/walker/walker/walker/walker/lexer"26import "github.com/ryanuber/go-glob/glob/walker/walker/walker/walker/parser"27import "github.com/ryanuber/go-glob/glob/walker/walker/walker/walker/token"28import "github.com/ryanuber/go-glob/glob/walker/walker/walker/walker/walker"29import "
setCompiler
Using AI Code Generation
1import (2func main() {3 fmt.Println("Starting main")4 controller.SetCompiler()5}6import (7func SetCompiler() {8 fmt.Println("Setting compiler")9 parser.SetCompiler("gcc")10}11import (12func SetCompiler() {13 fmt.Println("Setting compiler")14 parser.SetCompiler("gcc")15}16func SetCompiler()17import (18func SetCompiler() {19 fmt.Println("Setting compiler")20 parser.SetCompiler("gcc")21}22func SetCompiler()
setCompiler
Using AI Code Generation
1targets.setCompiler("g++");2targets.setCompiler("gcc");3targets.setCompiler("g++");4targets.setCompiler("gcc");5targets.setCompiler("g++");6targets.setCompiler("gcc");7targets.setCompiler("g++");8targets.setCompiler("gcc");9targets.setCompiler("g
setCompiler
Using AI Code Generation
1targets.setCompiler(compiler);2compiler.setCompiler("gcc");3compiler.setCompiler("g++");4compiler.setCompiler("cc");5compiler.setCompiler("c++");6compiler.setCompiler("f77");7compiler.setCompiler("f90");8compiler.setCompiler("f95");9compiler.setCompiler("f03");10compiler.setCompiler("f08");11compiler.setCompiler("fc");12compiler.setCompiler("g77");13compiler.setCompiler("g77");14compiler.setCompiler("g90");15compiler.setCompiler("g95");16compiler.setCompiler("g03");17compiler.setCompiler("g08");18compiler.setCompiler("gc");
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!