How to use Format method of csource Package

Best Syzkaller code snippet using csource.Format

repro.go

Source:repro.go Github

copy

Full Screen

1// Copyright 2016 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3package repro4import (5 "bytes"6 "fmt"7 "sort"8 "sync"9 "time"10 "github.com/google/syzkaller/pkg/csource"11 "github.com/google/syzkaller/pkg/host"12 "github.com/google/syzkaller/pkg/instance"13 "github.com/google/syzkaller/pkg/log"14 "github.com/google/syzkaller/pkg/mgrconfig"15 "github.com/google/syzkaller/pkg/report"16 "github.com/google/syzkaller/prog"17 "github.com/google/syzkaller/sys/targets"18 "github.com/google/syzkaller/vm"19)20type Result struct {21 Prog *prog.Prog22 Duration time.Duration23 Opts csource.Options24 CRepro bool25 // Information about the final (non-symbolized) crash that we reproduced.26 // Can be different from what we started reproducing.27 Report *report.Report28}29type Stats struct {30 Log []byte31 ExtractProgTime time.Duration32 MinimizeProgTime time.Duration33 SimplifyProgTime time.Duration34 ExtractCTime time.Duration35 SimplifyCTime time.Duration36}37type reproInstance struct {38 index int39 execProg *instance.ExecProgInstance40}41type context struct {42 target *targets.Target43 reporter *report.Reporter44 crashTitle string45 crashType report.Type46 instances chan *reproInstance47 bootRequests chan int48 testTimeouts []time.Duration49 startOpts csource.Options50 stats *Stats51 report *report.Report52 timeouts targets.Timeouts53}54func Run(crashLog []byte, cfg *mgrconfig.Config, features *host.Features, reporter *report.Reporter,55 vmPool *vm.Pool, vmIndexes []int) (*Result, *Stats, error) {56 if len(vmIndexes) == 0 {57 return nil, nil, fmt.Errorf("no VMs provided")58 }59 entries := cfg.Target.ParseLog(crashLog)60 if len(entries) == 0 {61 return nil, nil, fmt.Errorf("crash log does not contain any programs")62 }63 crashStart := len(crashLog)64 crashTitle, crashType := "", report.Unknown65 if rep := reporter.Parse(crashLog); rep != nil {66 crashStart = rep.StartPos67 crashTitle = rep.Title68 crashType = rep.Type69 }70 testTimeouts := []time.Duration{71 3 * cfg.Timeouts.Program, // to catch simpler crashes (i.e. no races and no hangs)72 20 * cfg.Timeouts.Program,73 cfg.Timeouts.NoOutputRunningTime, // to catch "no output", races and hangs74 }75 switch {76 case crashTitle == "":77 crashTitle = "no output/lost connection"78 // Lost connection can be detected faster,79 // but theoretically if it's caused by a race it may need the largest timeout.80 // No output can only be reproduced with the max timeout.81 // As a compromise we use the smallest and the largest timeouts.82 testTimeouts = []time.Duration{testTimeouts[0], testTimeouts[2]}83 case crashType == report.MemoryLeak:84 // Memory leaks can't be detected quickly because of expensive setup and scanning.85 testTimeouts = testTimeouts[1:]86 case crashType == report.Hang:87 testTimeouts = testTimeouts[2:]88 }89 ctx := &context{90 target: cfg.SysTarget,91 reporter: reporter,92 crashTitle: crashTitle,93 crashType: crashType,94 instances: make(chan *reproInstance, len(vmIndexes)),95 bootRequests: make(chan int, len(vmIndexes)),96 testTimeouts: testTimeouts,97 startOpts: createStartOptions(cfg, features, crashType),98 stats: new(Stats),99 timeouts: cfg.Timeouts,100 }101 ctx.reproLogf(0, "%v programs, %v VMs, timeouts %v", len(entries), len(vmIndexes), testTimeouts)102 var wg sync.WaitGroup103 wg.Add(len(vmIndexes))104 for _, vmIndex := range vmIndexes {105 ctx.bootRequests <- vmIndex106 go func() {107 defer wg.Done()108 for vmIndex := range ctx.bootRequests {109 var inst *instance.ExecProgInstance110 maxTry := 3111 for try := 0; try < maxTry; try++ {112 select {113 case <-vm.Shutdown:114 try = maxTry115 continue116 default:117 }118 var err error119 inst, err = instance.CreateExecProgInstance(vmPool, vmIndex, cfg,120 reporter, &instance.OptionalConfig{Logf: ctx.reproLogf})121 if err != nil {122 ctx.reproLogf(0, "failed to init instance: %v", err)123 time.Sleep(10 * time.Second)124 continue125 }126 break127 }128 if inst == nil {129 break130 }131 ctx.instances <- &reproInstance{execProg: inst, index: vmIndex}132 }133 }()134 }135 go func() {136 wg.Wait()137 close(ctx.instances)138 }()139 defer func() {140 close(ctx.bootRequests)141 for inst := range ctx.instances {142 inst.execProg.VMInstance.Close()143 }144 }()145 res, err := ctx.repro(entries, crashStart)146 if err != nil {147 return nil, nil, err148 }149 if res != nil {150 ctx.reproLogf(3, "repro crashed as (corrupted=%v):\n%s",151 ctx.report.Corrupted, ctx.report.Report)152 // Try to rerun the repro if the report is corrupted.153 for attempts := 0; ctx.report.Corrupted && attempts < 3; attempts++ {154 ctx.reproLogf(3, "report is corrupted, running repro again")155 if res.CRepro {156 _, err = ctx.testCProg(res.Prog, res.Duration, res.Opts)157 } else {158 _, err = ctx.testProg(res.Prog, res.Duration, res.Opts)159 }160 if err != nil {161 return nil, nil, err162 }163 }164 ctx.reproLogf(3, "final repro crashed as (corrupted=%v):\n%s",165 ctx.report.Corrupted, ctx.report.Report)166 res.Report = ctx.report167 }168 return res, ctx.stats, nil169}170func createStartOptions(cfg *mgrconfig.Config, features *host.Features, crashType report.Type) csource.Options {171 opts := csource.DefaultOpts(cfg)172 if crashType == report.MemoryLeak {173 opts.Leak = true174 }175 if features != nil {176 if !features[host.FeatureNetInjection].Enabled {177 opts.NetInjection = false178 }179 if !features[host.FeatureNetDevices].Enabled {180 opts.NetDevices = false181 }182 if !features[host.FeatureDevlinkPCI].Enabled {183 opts.DevlinkPCI = false184 }185 if !features[host.FeatureUSBEmulation].Enabled {186 opts.USB = false187 }188 if !features[host.FeatureVhciInjection].Enabled {189 opts.VhciInjection = false190 }191 if !features[host.FeatureWifiEmulation].Enabled {192 opts.Wifi = false193 }194 if !features[host.Feature802154Emulation].Enabled {195 opts.IEEE802154 = false196 }197 }198 return opts199}200// crash复现,提取出触发crash的C代码201func (ctx *context) repro(entries []*prog.LogEntry, crashStart int) (*Result, error) {202 // Cut programs that were executed after crash.203 for i, ent := range entries {204 if ent.Start > crashStart {205 entries = entries[:i]206 break207 }208 }209 reproStart := time.Now()210 defer func() {211 ctx.reproLogf(3, "reproducing took %s", time.Since(reproStart))212 }()213 // 提取出触发crash的程序214 res, err := ctx.extractProg(entries)215 if err != nil {216 return nil, err217 }218 if res == nil {219 return nil, nil220 }221 defer func() {222 if res != nil {223 res.Opts.Repro = false224 }225 }()226 // 若成功复现,则调用prog.Minmize简化所有的调用和参数227 res, err = ctx.minimizeProg(res)228 if err != nil {229 return nil, err230 }231 // Try extracting C repro without simplifying options first.232 res, err = ctx.extractC(res)233 if err != nil {234 return nil, err235 }236 // Simplify options and try extracting C repro.237 if !res.CRepro {238 res, err = ctx.simplifyProg(res)239 if err != nil {240 return nil, err241 }242 }243 // Simplify C related options.244 if res.CRepro {245 // 简化复现crash时的一些选项,比如线程、并发、沙盒等246 res, err = ctx.simplifyC(res)247 if err != nil {248 return nil, err249 }250 }251 return res, nil252}253// 提取出触发crash的程序254func (ctx *context) extractProg(entries []*prog.LogEntry) (*Result, error) {255 ctx.reproLogf(2, "extracting reproducer from %v programs", len(entries))256 start := time.Now()257 defer func() {258 ctx.stats.ExtractProgTime = time.Since(start)259 }()260 // Extract last program on every proc.261 procs := make(map[int]int)262 for i, ent := range entries {263 procs[ent.Proc] = i264 }265 var indices []int266 for _, idx := range procs {267 indices = append(indices, idx)268 }269 sort.Ints(indices)270 var lastEntries []*prog.LogEntry271 for i := len(indices) - 1; i >= 0; i-- {272 lastEntries = append(lastEntries, entries[indices[i]])273 }274 // 不同类型的漏洞需要不同的复现时间275 for _, timeout := range ctx.testTimeouts {276 // Execute each program separately to detect simple crashes caused by a single program.277 // Programs are executed in reverse order, usually the last program is the guilty one.278 res, err := ctx.extractProgSingle(lastEntries, timeout) // 逆序执行单个程序279 if err != nil {280 return nil, err281 }282 if res != nil {283 ctx.reproLogf(3, "found reproducer with %d syscalls", len(res.Prog.Calls))284 return res, nil285 }286 // Don't try bisecting if there's only one entry.287 if len(entries) == 1 {288 continue289 }290 // Execute all programs and bisect the log to find multiple guilty programs.291 // 若单个程序无法触发crash,则采用二分查找法找出哪几个程序一起触发crash292 res, err = ctx.extractProgBisect(entries, timeout)293 if err != nil {294 return nil, err295 }296 if res != nil {297 ctx.reproLogf(3, "found reproducer with %d syscalls", len(res.Prog.Calls))298 return res, nil299 }300 }301 ctx.reproLogf(0, "failed to extract reproducer")302 return nil, nil303}304func (ctx *context) extractProgSingle(entries []*prog.LogEntry, duration time.Duration) (*Result, error) {305 ctx.reproLogf(3, "single: executing %d programs separately with timeout %s", len(entries), duration)306 opts := ctx.startOpts307 for _, ent := range entries {308 crashed, err := ctx.testProg(ent.P, duration, opts)309 if err != nil {310 return nil, err311 }312 if crashed {313 res := &Result{314 Prog: ent.P,315 Duration: duration * 3 / 2,316 Opts: opts,317 }318 ctx.reproLogf(3, "single: successfully extracted reproducer")319 return res, nil320 }321 }322 ctx.reproLogf(3, "single: failed to extract reproducer")323 return nil, nil324}325func (ctx *context) extractProgBisect(entries []*prog.LogEntry, baseDuration time.Duration) (*Result, error) {326 ctx.reproLogf(3, "bisect: bisecting %d programs with base timeout %s", len(entries), baseDuration)327 opts := ctx.startOpts328 duration := func(entries int) time.Duration {329 return baseDuration + time.Duration(entries/4)*time.Second330 }331 // Bisect the log to find multiple guilty programs.332 entries, err := ctx.bisectProgs(entries, func(progs []*prog.LogEntry) (bool, error) {333 return ctx.testProgs(progs, duration(len(progs)), opts)334 })335 if err != nil {336 return nil, err337 }338 if len(entries) == 0 {339 return nil, nil340 }341 // TODO: Minimize each program before concatenation.342 // TODO: Return multiple programs if concatenation fails.343 ctx.reproLogf(3, "bisect: %d programs left: \n\n%s\n", len(entries), encodeEntries(entries))344 ctx.reproLogf(3, "bisect: trying to concatenate")345 // Concatenate all programs into one.346 prog := &prog.Prog{347 Target: entries[0].P.Target,348 }349 for _, entry := range entries {350 prog.Calls = append(prog.Calls, entry.P.Calls...)351 }352 dur := duration(len(entries)) * 3 / 2353 crashed, err := ctx.testProg(prog, dur, opts)354 if err != nil {355 return nil, err356 }357 if crashed {358 res := &Result{359 Prog: prog,360 Duration: dur,361 Opts: opts,362 }363 ctx.reproLogf(3, "bisect: concatenation succeeded")364 return res, nil365 }366 ctx.reproLogf(3, "bisect: concatenation failed")367 return nil, nil368}369// Minimize calls and arguments.370func (ctx *context) minimizeProg(res *Result) (*Result, error) {371 ctx.reproLogf(2, "minimizing guilty program")372 start := time.Now()373 defer func() {374 ctx.stats.MinimizeProgTime = time.Since(start)375 }()376 res.Prog, _ = prog.Minimize(res.Prog, -1, true,377 func(p1 *prog.Prog, callIndex int) bool {378 crashed, err := ctx.testProg(p1, res.Duration, res.Opts)379 if err != nil {380 ctx.reproLogf(0, "minimization failed with %v", err)381 return false382 }383 return crashed384 })385 return res, nil386}387// Simplify repro options (threaded, sandbox, etc).388func (ctx *context) simplifyProg(res *Result) (*Result, error) {389 ctx.reproLogf(2, "simplifying guilty program options")390 start := time.Now()391 defer func() {392 ctx.stats.SimplifyProgTime = time.Since(start)393 }()394 // Do further simplifications.395 for _, simplify := range progSimplifies {396 opts := res.Opts397 if !simplify(&opts) || !checkOpts(&opts, ctx.timeouts, res.Duration) {398 continue399 }400 crashed, err := ctx.testProg(res.Prog, res.Duration, opts)401 if err != nil {402 return nil, err403 }404 if !crashed {405 continue406 }407 res.Opts = opts408 // Simplification successful, try extracting C repro.409 res, err = ctx.extractC(res)410 if err != nil {411 return nil, err412 }413 if res.CRepro {414 return res, nil415 }416 }417 return res, nil418}419// Try triggering crash with a C reproducer.420func (ctx *context) extractC(res *Result) (*Result, error) {421 ctx.reproLogf(2, "extracting C reproducer")422 start := time.Now()423 defer func() {424 ctx.stats.ExtractCTime = time.Since(start)425 }()426 crashed, err := ctx.testCProg(res.Prog, res.Duration, res.Opts)427 if err != nil {428 return nil, err429 }430 res.CRepro = crashed431 return res, nil432}433// Try to simplify the C reproducer.434func (ctx *context) simplifyC(res *Result) (*Result, error) {435 ctx.reproLogf(2, "simplifying C reproducer")436 start := time.Now()437 defer func() {438 ctx.stats.SimplifyCTime = time.Since(start)439 }()440 for _, simplify := range cSimplifies {441 opts := res.Opts442 if !simplify(&opts) || !checkOpts(&opts, ctx.timeouts, res.Duration) {443 continue444 }445 crashed, err := ctx.testCProg(res.Prog, res.Duration, opts)446 if err != nil {447 return nil, err448 }449 if !crashed {450 continue451 }452 res.Opts = opts453 }454 return res, nil455}456func checkOpts(opts *csource.Options, timeouts targets.Timeouts, timeout time.Duration) bool {457 if !opts.Repeat && timeout >= time.Minute {458 // If we have a non-repeating C reproducer with timeout > vm.NoOutputTimeout and it hangs459 // (the reproducer itself does not terminate on its own, note: it does not have builtin timeout),460 // then we will falsely detect "not output from test machine" kernel bug.461 // We could fix it by adding a builtin timeout to such reproducers (like we have in all other cases).462 // However, then it will exit within few seconds and we will finish the test without actually waiting463 // for full vm.NoOutputTimeout, which breaks the whole reason of using vm.NoOutputTimeout in the first464 // place. So we would need something more elaborate: let the program exist after few seconds, but465 // continue waiting for kernel hang errors for minutes, but at the same time somehow ignore "no output"466 // error because it will be false in this case.467 // Instead we simply prohibit !Repeat with long timeouts.468 // It makes sense on its own to some degree: if we are chasing an elusive bug, repeating the test469 // will increase chances of reproducing it and can make the reproducer less flaky.470 // Syz repros does not have this problem because they always have internal timeout, however471 // (1) it makes sense on its own, (2) we will either not use the whole timeout or waste the remaining472 // time as mentioned above, (3) if we remove repeat for syz repro, we won't be able to handle it473 // when/if we switch to C repro (we can simplify options, but we can't "complicate" them back).474 return false475 }476 return true477}478func (ctx *context) testProg(p *prog.Prog, duration time.Duration, opts csource.Options) (crashed bool, err error) {479 entry := prog.LogEntry{P: p}480 return ctx.testProgs([]*prog.LogEntry{&entry}, duration, opts)481}482func (ctx *context) testWithInstance(callback func(inst *instance.ExecProgInstance) (rep *instance.RunResult,483 err error)) (bool, error) {484 inst := <-ctx.instances485 if inst == nil {486 return false, fmt.Errorf("all VMs failed to boot")487 }488 defer ctx.returnInstance(inst)489 result, err := callback(inst.execProg)490 if err != nil {491 return false, err492 }493 rep := result.Report494 if rep == nil {495 return false, nil496 }497 if rep.Suppressed {498 ctx.reproLogf(2, "suppressed program crash: %v", rep.Title)499 return false, nil500 }501 if ctx.crashType == report.MemoryLeak && rep.Type != report.MemoryLeak {502 ctx.reproLogf(2, "not a leak crash: %v", rep.Title)503 return false, nil504 }505 ctx.report = rep506 return true, nil507}508func encodeEntries(entries []*prog.LogEntry) []byte {509 buf := new(bytes.Buffer)510 for _, ent := range entries {511 fmt.Fprintf(buf, "executing program %v:\n%v", ent.Proc, string(ent.P.Serialize()))512 }513 return buf.Bytes()514}515func (ctx *context) testProgs(entries []*prog.LogEntry, duration time.Duration, opts csource.Options) (516 crashed bool, err error) {517 if len(entries) == 0 {518 return false, fmt.Errorf("no programs to execute")519 }520 pstr := encodeEntries(entries)521 program := entries[0].P.String()522 if len(entries) > 1 {523 program = "["524 for i, entry := range entries {525 program += fmt.Sprintf("%v", len(entry.P.Calls))526 if i != len(entries)-1 {527 program += ", "528 }529 }530 program += "]"531 }532 ctx.reproLogf(2, "testing program (duration=%v, %+v): %s", duration, opts, program)533 ctx.reproLogf(3, "detailed listing:\n%s", pstr)534 return ctx.testWithInstance(func(inst *instance.ExecProgInstance) (*instance.RunResult, error) {535 return inst.RunSyzProg(pstr, duration, opts)536 })537}538func (ctx *context) testCProg(p *prog.Prog, duration time.Duration, opts csource.Options) (crashed bool, err error) {539 return ctx.testWithInstance(func(inst *instance.ExecProgInstance) (*instance.RunResult, error) {540 return inst.RunCProg(p, duration, opts)541 })542}543func (ctx *context) returnInstance(inst *reproInstance) {544 ctx.bootRequests <- inst.index545 inst.execProg.VMInstance.Close()546}547func (ctx *context) reproLogf(level int, format string, args ...interface{}) {548 prefix := fmt.Sprintf("reproducing crash '%v': ", ctx.crashTitle)549 log.Logf(level, prefix+format, args...)550 ctx.stats.Log = append(ctx.stats.Log, []byte(fmt.Sprintf(format, args...)+"\n")...)551}552func (ctx *context) bisectProgs(progs []*prog.LogEntry, pred func([]*prog.LogEntry) (bool, error)) (553 []*prog.LogEntry, error) {554 ctx.reproLogf(3, "bisect: bisecting %d programs", len(progs))555 ctx.reproLogf(3, "bisect: executing all %d programs", len(progs))556 crashed, err := pred(progs)557 if err != nil {558 return nil, err559 }560 if !crashed {561 ctx.reproLogf(3, "bisect: didn't crash")562 return nil, nil563 }564 guilty := [][]*prog.LogEntry{progs}565again:566 if len(guilty) > 8 {567 // This is usually the case for flaky crashes. Continuing bisection at this568 // point would just take a lot of time and likely produce no result.569 ctx.reproLogf(3, "bisect: too many guilty chunks, aborting")570 return nil, nil571 }572 ctx.reproLogf(3, "bisect: guilty chunks: %v", chunksToStr(guilty))573 for i, chunk := range guilty {574 if len(chunk) == 1 {575 continue576 }577 guilty1 := guilty[:i]578 guilty2 := guilty[i+1:]579 ctx.reproLogf(3, "bisect: guilty chunks split: %v, <%v>, %v",580 chunksToStr(guilty1), len(chunk), chunksToStr(guilty2))581 chunk1 := chunk[0 : len(chunk)/2]582 chunk2 := chunk[len(chunk)/2:]583 ctx.reproLogf(3, "bisect: chunk split: <%v> => <%v>, <%v>",584 len(chunk), len(chunk1), len(chunk2))585 ctx.reproLogf(3, "bisect: triggering crash without chunk #1")586 progs = flatenChunks(guilty1, guilty2, chunk2)587 crashed, err := pred(progs)588 if err != nil {589 return nil, err590 }591 if crashed {592 guilty = nil593 guilty = append(guilty, guilty1...)594 guilty = append(guilty, chunk2)595 guilty = append(guilty, guilty2...)596 ctx.reproLogf(3, "bisect: crashed, chunk #1 evicted")597 goto again598 }599 ctx.reproLogf(3, "bisect: triggering crash without chunk #2")600 progs = flatenChunks(guilty1, guilty2, chunk1)601 crashed, err = pred(progs)602 if err != nil {603 return nil, err604 }605 if crashed {606 guilty = nil607 guilty = append(guilty, guilty1...)608 guilty = append(guilty, chunk1)609 guilty = append(guilty, guilty2...)610 ctx.reproLogf(3, "bisect: crashed, chunk #2 evicted")611 goto again612 }613 guilty = nil614 guilty = append(guilty, guilty1...)615 guilty = append(guilty, chunk1)616 guilty = append(guilty, chunk2)617 guilty = append(guilty, guilty2...)618 ctx.reproLogf(3, "bisect: not crashed, both chunks required")619 goto again620 }621 progs = nil622 for _, chunk := range guilty {623 if len(chunk) != 1 {624 return nil, fmt.Errorf("bad bisect result: %v", guilty)625 }626 progs = append(progs, chunk[0])627 }628 ctx.reproLogf(3, "bisect: success, %d programs left", len(progs))629 return progs, nil630}631func flatenChunks(guilty1, guilty2 [][]*prog.LogEntry, chunk []*prog.LogEntry) []*prog.LogEntry {632 var progs []*prog.LogEntry633 for _, c := range guilty1 {634 progs = append(progs, c...)635 }636 progs = append(progs, chunk...)637 for _, c := range guilty2 {638 progs = append(progs, c...)639 }640 return progs641}642func chunksToStr(chunks [][]*prog.LogEntry) string {643 log := "["644 for i, chunk := range chunks {645 log += fmt.Sprintf("<%d>", len(chunk))646 if i != len(chunks)-1 {647 log += ", "648 }649 }650 log += "]"651 return log652}653type Simplify func(opts *csource.Options) bool654var progSimplifies = []Simplify{655 func(opts *csource.Options) bool {656 if opts.Collide || !opts.Threaded {657 return false658 }659 opts.Threaded = false660 return true661 },662 func(opts *csource.Options) bool {663 if !opts.Repeat {664 return false665 }666 opts.Repeat = false667 opts.Cgroups = false668 opts.NetReset = false669 opts.Procs = 1670 return true671 },672 func(opts *csource.Options) bool {673 if opts.Procs == 1 {674 return false675 }676 opts.Procs = 1677 return true678 },679 func(opts *csource.Options) bool {680 if opts.Sandbox == "none" {681 return false682 }683 opts.Sandbox = "none"684 return true685 },686}687var cSimplifies = append(progSimplifies, []Simplify{688 func(opts *csource.Options) bool {689 if opts.Sandbox == "" {690 return false691 }692 opts.Sandbox = ""693 opts.NetInjection = false694 opts.NetDevices = false695 opts.NetReset = false696 opts.Cgroups = false697 opts.BinfmtMisc = false698 opts.CloseFDs = false699 opts.DevlinkPCI = false700 opts.USB = false701 opts.VhciInjection = false702 opts.Wifi = false703 return true704 },705 func(opts *csource.Options) bool {706 if !opts.NetInjection {707 return false708 }709 opts.NetInjection = false710 return true711 },712 func(opts *csource.Options) bool {713 if !opts.NetDevices {714 return false715 }716 opts.NetDevices = false717 return true718 },719 func(opts *csource.Options) bool {720 if !opts.NetReset {721 return false722 }723 opts.NetReset = false724 return true725 },726 func(opts *csource.Options) bool {727 if !opts.Cgroups {728 return false729 }730 opts.Cgroups = false731 return true732 },733 func(opts *csource.Options) bool {734 if !opts.BinfmtMisc {735 return false736 }737 opts.BinfmtMisc = false738 return true739 },740 func(opts *csource.Options) bool {741 // We don't want to remove close_fds() call when repeat is enabled,742 // since that can lead to deadlocks, see executor/common_linux.h.743 if !opts.CloseFDs || opts.Repeat {744 return false745 }746 opts.CloseFDs = false747 return true748 },749 func(opts *csource.Options) bool {750 if !opts.DevlinkPCI {751 return false752 }753 opts.DevlinkPCI = false754 return true755 },756 func(opts *csource.Options) bool {757 if !opts.USB {758 return false759 }760 opts.USB = false761 return true762 },763 func(opts *csource.Options) bool {764 if !opts.VhciInjection {765 return false766 }767 opts.VhciInjection = false768 return true769 },770 func(opts *csource.Options) bool {771 if !opts.Wifi {772 return false773 }774 opts.Wifi = false775 return true776 },777 func(opts *csource.Options) bool {778 if !opts.IEEE802154 {779 return false780 }781 opts.IEEE802154 = false782 return true783 },784 func(opts *csource.Options) bool {785 if !opts.UseTmpDir || opts.Sandbox == "namespace" || opts.Cgroups {786 return false787 }788 opts.UseTmpDir = false789 return true790 },791 func(opts *csource.Options) bool {792 if !opts.HandleSegv {793 return false794 }795 opts.HandleSegv = false796 return true797 },798 func(opts *csource.Options) bool {799 if !opts.Sysctl {800 return false801 }802 opts.Sysctl = false803 return true804 },805}...)...

Full Screen

Full Screen

prog2c.go

Source:prog2c.go Github

copy

Full Screen

...94 if err != nil {95 fmt.Fprintf(os.Stderr, "failed to generate C source: %v\n", err)96 os.Exit(1)97 }98 if formatted, err := csource.Format(src); err != nil {99 fmt.Fprintf(os.Stderr, "%v\n", err)100 } else {101 src = formatted102 }103 os.Stdout.Write(src)104 if !*flagBuild {105 return106 }107 bin, err := csource.Build(target, src)108 if err != nil {109 fmt.Fprintf(os.Stderr, "failed to build C source: %v\n", err)110 os.Exit(1)111 }112 os.Remove(bin)...

Full Screen

Full Screen

adapter.go

Source:adapter.go Github

copy

Full Screen

...29 return options30}31func serializeOptions(n drafter.Options) *C.drafter_serialize_options {32 options := C.drafter_init_serialize_options()33 if n.Format == drafter.JSON {34 C.drafter_set_format(options, C.DRAFTER_SERIALIZE_JSON)35 }36 if n.SourceMaps {37 C.drafter_set_sourcemaps_included(options)38 }39 return options40}41func Parse(r io.Reader, n drafter.Options) ([]byte, error) {42 s, err := readString(r)43 if err != nil {44 return nil, err45 }46 cOptions := parseOptions(n)47 cSource := C.CString(s)...

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("hello world")4}5import (6func main() {7 fmt.Println("hello world")8}9import (10func main() {11 fmt.Println("hello world")12}13import (14func main() {15 fmt.Println("hello world")16}17import (18func main() {19 fmt.Println("hello world")20}21import (22func main() {23 fmt.Println("hello world")24}25import (26func main() {27 fmt.Println("hello world")28}29import (30func main() {31 fmt.Println("hello world")32}33import (34func main() {35 fmt.Println("hello world")36}37import (38func main() {39 fmt.Println("hello world")40}41import (42func main() {43 fmt.Println("hello world")44}45import (46func main() {47 fmt.Println("hello world")48}49import (50func main() {51 fmt.Println("

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import (2func main() {3int main() {4 printf("Hello World!");5 return 0;6}`7 c := c2go.NewCSource(code)8 fmt.Println(c.Format())9}10int main() {11 printf("Hello World!");12 return 0;13}14import (15func main() {16int main() {17 printf("Hello World!");18 return 0;19}`20 c := c2go.NewCSource(code)21 fmt.Println(c.Format())22}23int main() {24 printf("Hello World!");25 return 0;26}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 csource.Format(a, b, c, d, e, f, g, h, i, j)4}5import (6func TestMain(m *testing.M) {7 fmt.Println("Testing csource")8 if _, err := exec.LookPath("clang"); err != nil {9 fmt.Println("clang not found")10 os.Exit(0)11 }12 if _, err := exec.LookPath("gcc"); err != nil {13 fmt.Println("gcc not found")14 os.Exit(0)15 }16 if _, err := exec.LookPath("go"); err != nil {17 fmt.Println("go not found")18 os.Exit(0)19 }20 os.Exit(m.Run())21}22func TestCsource(t *testing.T) {23 out, err := exec.Command("go", "run", "2.go").Output()24 if err != nil {25 t.Error(err)26 }27 if string(out) != "10 20 30 40 50 60 70 80 90 100" {28 t.Errorf("Expected 10 20 30 40 50 60 70 80 90 100, got %s", string(out))29 }30}31import (32func main() {33 csource.Format(a, b, c, d, e, f, g, h, i, j)34}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(csource.Format("a"))4 fmt.Println(csource.Format("a+b"))5 fmt.Println(csource.Format("a+b+c"))6 fmt.Println(csource.Format("a+b+c+d"))7 fmt.Println(csource.Format("a+b+c+d+e"))8 fmt.Println(csource.Format("a+b+c+d+e+f"))9 fmt.Println(csource.Format("a+b+c+d+e+f+g"))10 fmt.Println(csource.Format("a+b+c+d+e+f+g+h"))11}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 pretty.Println("Hello, playground")5}6import (7func main() {8 fmt.Println("Hello, playground")9 pretty.Println("Hello, playground")10}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 c1 = csource{1, 2, 3}4 c1.Format()5}6import "fmt"7type csource struct {8}9func (c *csource) Format() {10 fmt.Println(c.a, c.b, c.c)11}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 obj.Format()4 fmt.Println("In 2.go")5}6import (7func main() {8 obj.Format()9 fmt.Println("In 3.go")10}11import (12func main() {13 obj.Format()14 fmt.Println("In main.go")15}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := blas.NewCSource(os.Stdout)4 c.Format("int main() {5 printf(\"Hello world\");6 return 0;7 }")8}9int main() {10 printf("Hello world");11 return 0;12}

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