How to use logProgram method of main Package

Best Syzkaller code snippet using main.logProgram

proc.go

Source:proc.go Github

copy

Full Screen

...133 }()134 ct := proc.fuzzer.choiceTable135 p := proc.fuzzer.target.Generate(proc.rnd, programLength, ct)136 proc.fuzzer.writeLog("%s", "# Generate\n")137 proc.fuzzer.logProgram(p)138 _, r := proc.execute(proc.execOpts, p, ProgNormal, StatSmash)139 ret.gainRaw += r.gainRaw140 ret.calls += r.calls141 ret.time += r.time142 ret.timeTotal += r.timeTotal143 // }144 return ret145}146func (proc *Proc) DoMutate(count int) ExecResult {147 ret := ExecResult{148 gainRaw: 0.0,149 time: 0.0,150 calls: 0,151 pidx: -1,152 timeTotal: 0.0,153 }154 ts0 := time.Now().UnixNano()155 defer func() {156 ret.timeTotal = float64(time.Now().UnixNano()-ts0) / proc.fuzzer.fuzzerConfig.MABTimeUnit157 }()158 // corpus := proc.fuzzer.corpusSnapshot()159 fuzzerSnapshot := proc.fuzzer.snapshot()160 ct := proc.fuzzer.choiceTable161 item := proc.fuzzer.workQueue.dequeueType(1, true, true)162 if item != nil { // If there're existing mutate work in the queue163 proc.fuzzer.writeLog("%s", "# WorkSmash\n")164 _, r := proc.ProcessItem(item)165 _r, ok := r.(ExecResult)166 if ok {167 ret.gainRaw = _r.gainRaw168 ret.calls = _r.calls169 ret.time = _r.time170 ret.pidx = _r.pidx171 ret.timeTotal = _r.timeTotal172 }173 } else {174 // MAB seed selection is integrated with chooseProgram175 pidx, _p := fuzzerSnapshot.chooseProgram(proc.rnd)176 K := len(fuzzerSnapshot.corpus)177 // pr := fuzzerSnapshot.corpusPrios178 if proc.fuzzer.fuzzerConfig.MABVerbose {179 proc.fuzzer.writeLog("- MAB Corpus Choice: %v/%v\n", pidx, K)180 }181 for i := 0; i < count; i++ {182 proc.fuzzer.writeLog("# %v Mutate %v\n", i, pidx)183 p := _p.Clone()184 p.ResetMAB()185 proc.fuzzer.logProgram(p)186 p.Mutate(proc.rnd, programLength, ct, fuzzerSnapshot.corpus)187 proc.fuzzer.logProgram(p)188 _, r := proc.execute(proc.execOpts, p, ProgNormal, StatFuzz)189 // proc.fuzzer.MABIncrementCorpusMutateCount(pidx, 1)190 ret.calls += r.calls191 ret.time += r.time192 ret.gainRaw += r.gainRaw193 ret.timeTotal += r.timeTotal194 }195 ret.pidx = pidx196 }197 return ret198}199func (proc *Proc) DoTriage() TriageResult {200 ret := TriageResult{201 minimizeGainRaw: 0.0,202 verifyGainRaw: 0.0,203 verifyTime: 0.0,204 verifyCalls: 0,205 minimizeTime: 0.0,206 minimizeCalls: 0,207 source: -1,208 sourceCost: 0.0,209 minimizeTimeSave: 0.0,210 pidx: -1,211 success: false,212 }213 ts0 := time.Now().UnixNano()214 defer func() {215 ret.timeTotal = float64(time.Now().UnixNano()-ts0) / proc.fuzzer.fuzzerConfig.MABTimeUnit216 }()217 item := proc.fuzzer.workQueue.dequeueType(2, true, true)218 if item == nil {219 return ret220 }221 proc.fuzzer.writeLog("%s", "# WorkTriage\n")222 _, r := proc.ProcessItem(item)223 _ret, ok := r.(TriageResult)224 if !ok {225 return ret226 }227 ret = _ret228 proc.fuzzer.writeLog("# Triage Result: %+v\n", ret)229 return ret230}231func (proc *Proc) MABLoop() {232 // Triage first233 if proc.fuzzer.fuzzerConfig.MABTriageFirst {234 // Skip all MAB stuff for triaging235 item := proc.fuzzer.workQueue.dequeueType(2, true, true)236 if item != nil {237 proc.ProcessItem(item)238 return239 }240 }241 // Compute weight and proba242 ts0 := time.Now().UnixNano()243 weight := proc.fuzzer.MABGetWeight(true)244 // corpus := proc.fuzzer.corpusSnapshot()245 fuzzerSnapshot := proc.fuzzer.snapshot()246 triage_count := 1247 mutate_count := 1248 if len(fuzzerSnapshot.corpus) == 0 { // Check whether mutation is an option249 mutate_count = 0250 }251 proc.fuzzer.workQueue.mu.Lock() // Check whether triage is an option252 ql_triage := len(proc.fuzzer.workQueue.triage)253 ql_triageCandidate := len(proc.fuzzer.workQueue.triageCandidate)254 // proc.fuzzer.writeLog("- Triage Queue Length: %v + %v\n", ql_triage, ql_triageCandidate)255 proc.fuzzer.workQueue.mu.Unlock()256 if ql_triage+ql_triageCandidate == 0 {257 triage_count = 0258 }259 K := 1 + mutate_count + triage_count260 W := weight[0] + float64(mutate_count)*weight[1] + float64(triage_count)*weight[2]261 if W == 0.0 {262 log.Fatalf("WTF: Error total weight W = 0")263 }264 gamma := proc.fuzzer.MABGamma265 if proc.fuzzer.fuzzerConfig.MABAlgorithm == "Exp3-IX" {266 // No explicit exploration for Exp3-IX267 gamma = 0268 }269 pr_generate := (1-gamma)*weight[0]/W + gamma/float64(K)270 pr_mutate := (1-gamma)*weight[1]/W + gamma/float64(K)271 pr_triage := (1-gamma)*weight[2]/W + gamma/float64(K)272 if proc.fuzzer.fuzzerConfig.MABAlgorithm == "Exp3-IX" {273 pr_generate = weight[0] / W274 pr_mutate = weight[1] / W275 pr_triage = weight[2] / W276 }277 _pr_mutate := float64(mutate_count) * pr_mutate278 _pr_triage := float64(triage_count) * pr_triage279 pr_arr := []float64{pr_generate, _pr_mutate, _pr_triage} // Use real weight as pr. Consider cases where triage/mutation might be unavailable280 proc.fuzzer.writeLog("- MAB Probability: [%v, %v, %v]\n", pr_arr[0], pr_arr[1], pr_arr[2])281 // Choose282 rand_num := rand.Float64() * (pr_generate + _pr_mutate + _pr_triage)283 choice := -1284 if rand_num <= pr_generate {285 choice = 0286 } else if rand_num > pr_generate && rand_num <= pr_generate+_pr_mutate {287 choice = 1288 } else {289 choice = 2290 }291 ts1 := time.Now().UnixNano()292 proc.fuzzer.writeLog("- MAB Choose: %v\n", ts1-ts0)293 // Handle choices294 var r interface{}295 if choice == 0 {296 r = proc.DoGenerate()297 } else if choice == 1 {298 r = proc.DoMutate(proc.fuzzer.fuzzerConfig.mutateWeight)299 } else if choice == 2 {300 r = proc.DoTriage()301 // cost_before_min = float64(r.verifyTime) / 3.0 / proc.fuzzer.fuzzerConfig.MABTimeUnit302 }303 proc.fuzzer.writeLog("- MAB Choice: %v, Result: %+v\n", choice, r)304 // Update Weight305 proc.fuzzer.MABUpdateWeight(choice, r, pr_arr, K)306}307func (proc *Proc) loop() {308 generatePeriod := 100309 if proc.fuzzer.config.Flags&ipc.FlagSignal == 0 {310 // If we don't have real coverage signal, generate programs more frequently311 // because fallback signal is weak.312 generatePeriod = 2313 }314 for i := 0; ; i++ {315 // generatePeriod = proc.fuzzer.fuzzerConfig.mutateWeight/proc.fuzzer.fuzzerConfig.generateWeight + 1316 proc.fuzzer.MABRound += 1317 if proc.fuzzer.MABRound <= proc.fuzzer.fuzzerConfig.MABGenerateFirst {318 // Force Generate First319 ct := proc.fuzzer.choiceTable320 ts0 := time.Now().UnixNano()321 p := proc.fuzzer.target.Generate(proc.rnd, programLength, ct)322 proc.fuzzer.writeLog("# %v Generate\n", i)323 proc.fuzzer.logProgram(p)324 _, r := proc.execute(proc.execOpts, p, ProgNormal, StatGenerate)325 r.timeTotal = float64(time.Now().UnixNano()-ts0) / proc.fuzzer.fuzzerConfig.MABTimeUnit326 proc.fuzzer.writeLog("- Work Type: 0, Result: %+v\n", r)327 continue328 }329 if proc.fuzzer.fuzzerConfig.MABAlgorithm != "N/A" {330 proc.DoCandidate() // Deal with candidates first331 if proc.fuzzer.fuzzerConfig.MABDuration <= 0 || proc.fuzzer.MABRound < proc.fuzzer.fuzzerConfig.MABDuration {332 proc.MABLoop()333 continue334 } else if proc.fuzzer.fuzzerConfig.MABDuration > 0 && proc.fuzzer.MABRound >= proc.fuzzer.fuzzerConfig.MABDuration {335 // Reset params336 proc.fuzzer.ResetConfig()337 }338 }339 item := proc.fuzzer.workQueue.dequeue()340 if item != nil {341 itemType, r := proc.ProcessItem(item)342 if itemType == 1 && proc.fuzzer.fuzzerConfig.MABSeedSelection != "N/A" {343 proc.fuzzer.MABUpdateWeight(1, r, []float64{1.0, 1.0, 1.0}, 1.0)344 }345 proc.fuzzer.writeLog("- Work Type: %v, Result: %+v\n", itemType, r)346 // Don't count triage under NoMutations setup347 if itemType == 2 && proc.fuzzer.fuzzerConfig.MABNoMutations > 0 {348 proc.fuzzer.MABRound -= 1349 }350 continue351 }352 ct := proc.fuzzer.choiceTable353 fuzzerSnapshot := proc.fuzzer.snapshot()354 if len(fuzzerSnapshot.corpus) == 0 || i%generatePeriod == 0 || proc.fuzzer.MABRound < proc.fuzzer.fuzzerConfig.MABNoMutations {355 // Generate a new prog.356 ts0 := time.Now().UnixNano()357 p := proc.fuzzer.target.Generate(proc.rnd, programLength, ct)358 proc.fuzzer.writeLog("# %v Generate\n", i)359 proc.fuzzer.logProgram(p)360 _, r := proc.execute(proc.execOpts, p, ProgNormal, StatGenerate)361 r.timeTotal = float64(time.Now().UnixNano()-ts0) / proc.fuzzer.fuzzerConfig.MABTimeUnit362 proc.fuzzer.writeLog("- Work Type: 0, Result: %+v\n", r)363 } else {364 // Mutate an existing prog.365 ts0 := time.Now().UnixNano()366 pidx, p := fuzzerSnapshot.chooseProgram(proc.rnd)367 p = p.Clone()368 p.ResetMAB()369 proc.fuzzer.writeLog("# %v Mutate\n", i)370 proc.fuzzer.logProgram(p)371 p.Mutate(proc.rnd, programLength, ct, fuzzerSnapshot.corpus)372 proc.fuzzer.logProgram(p)373 _, r := proc.execute(proc.execOpts, p, ProgNormal, StatFuzz)374 r.pidx = pidx375 r.timeTotal = float64(time.Now().UnixNano()-ts0) / proc.fuzzer.fuzzerConfig.MABTimeUnit376 if proc.fuzzer.fuzzerConfig.MABSeedSelection != "N/A" {377 proc.fuzzer.MABUpdateWeight(1, r, []float64{1.0, 1.0, 1.0}, 1.0)378 }379 proc.fuzzer.writeLog("- Work Type: 1, Result: %+v\n", r)380 }381 }382}383func (proc *Proc) triageInput(item *WorkTriage) TriageResult {384 // We notify the manager as soon as the triage is scheduled.385 // Otherwise the triage might crash the VM and fuzzer will keep retrying386 ts_bgn := time.Now().UnixNano()387 source_data := item.p.Serialize()388 source_sig := hash.Hash(source_data)389 if proc.fuzzer.fuzzerConfig.syncTriage {390 proc.fuzzer.completeTriage(rpctype.RPCTriage{391 Sig: source_sig,392 CallIndex: item.call,393 Prog: source_data,394 Flags: int(item.flags),395 Info: item.info,396 Source: item.p.Source,397 SourceCost: item.p.CorpusGLC.Cost,398 })399 }400 source := item.p.Source401 sourceCost := item.p.CorpusGLC.Cost402 if _, ok := proc.fuzzer.MABTriageInfo[source_sig]; ok {403 source = proc.fuzzer.MABTriageInfo[source_sig].Source404 sourceCost = proc.fuzzer.MABTriageInfo[source_sig].SourceCost405 }406 ret := TriageResult{407 corpusGainRaw: 0.0,408 minimizeGainRaw: 0.0,409 verifyGainRaw: 0.0,410 verifyTime: 0.0,411 verifyCalls: 0,412 minimizeTime: 0.0,413 minimizeCalls: 0,414 source: source,415 sourceSig: source_sig,416 sourceCost: sourceCost,417 minimizeTimeSave: 0.0,418 pidx: -1,419 success: false,420 timeTotal: 0.0,421 }422 size_bgn := len(item.p.Calls)423 // log.Logf(1, "#%v: triaging type=%x", proc.pid, item.flags)424 prio := signalPrio(item.p, &item.info, item.call)425 inputSignal := signal.FromRaw(item.info.Signal, prio)426 newSignal := proc.fuzzer.corpusSignalDiff(inputSignal)427 if newSignal.Empty() {428 return ret429 }430 callName := ".extra"431 logCallName := "extra"432 if item.call != -1 {433 callName = item.p.Calls[item.call].Meta.Name434 logCallName = fmt.Sprintf("call #%v %v", item.call, callName)435 }436 log.Logf(3, "triaging input for %v (new signal=%v)", logCallName, newSignal.Len())437 proc.fuzzer.writeLog("# Triaging NewSignal %v,%v,%v: %v^%v=%v\n", source_sig.String(), item.call, prio, inputSignal.Len(), proc.fuzzer.corpusSignal.Len(), newSignal.Len())438 var inputCover cover.Cover439 const (440 signalRuns = 3441 minimizeAttempts = 3442 )443 // Compute input coverage and non-flaky signal for minimization.444 notexecuted := 0445 for i := 0; i < signalRuns; i++ {446 info, _time := proc.executeRaw(proc.execOptsCover, item.p, StatTriage)447 ret.verifyTime += _time448 if !reexecutionSuccess(info, &item.info, item.call) {449 // The call was not executed or failed.450 notexecuted++451 if notexecuted > signalRuns/2+1 {452 ret.timeTotal = float64(time.Now().UnixNano()-ts_bgn) / proc.fuzzer.fuzzerConfig.MABTimeUnit453 ret.verifyCalls = (i + 1) * size_bgn454 ret.corpusGainRaw = 0.0455 return ret // if happens too often, give up456 }457 continue458 }459 thisSignal, thisCover := getSignalAndCover(item.p, info, item.call)460 newSignal = newSignal.Intersection(thisSignal)461 // Without !minimized check manager starts losing some considerable amount462 // of coverage after each restart. Mechanics of this are not completely clear.463 if newSignal.Empty() && item.flags&ProgMinimized == 0 {464 ret.timeTotal = float64(time.Now().UnixNano()-ts_bgn) / proc.fuzzer.fuzzerConfig.MABTimeUnit465 ret.verifyCalls = (i + 1) * size_bgn466 ret.verifyGainRaw = 0.0467 return ret468 }469 inputCover.Merge(thisCover)470 }471 ret.success = true472 if ret.sourceCost == 0.0 {473 ret.sourceCost = ret.verifyTime / 3.0474 } else {475 ret.sourceCost = (ret.verifyTime + ret.sourceCost) / 4.0476 }477 proc.fuzzer.writeLog("# %v Minimize\n", 0)478 proc.fuzzer.logProgram(item.p)479 minimizeCalls := 0480 minimizeGainRaw := 0.0481 minimizeTimeAfter := sourceCost482 if item.flags&ProgMinimized == 0 {483 item.p, item.call = prog.Minimize(item.p, item.call, false,484 func(p1 *prog.Prog, call1 int) bool {485 proc.fuzzer.writeLog("%s\n", "# Minimize Attempt")486 p1.Source = 2487 proc.fuzzer.logProgram(p1)488 t_avg := 0.0489 for i := 0; i < minimizeAttempts; i++ {490 var info *ipc.ProgInfo491 var r ExecResult492 info, r = proc.execute(proc.execOptsNoCollide, p1, ProgNormal, StatMinimize)493 minimizeGainRaw += r.gainRaw494 ret.minimizeTime += r.time495 t_avg += r.time496 minimizeCalls += len(p1.Calls)497 if !reexecutionSuccess(info, &item.info, call1) {498 // The call was not executed or failed.499 continue500 }501 thisSignal, _ := getSignalAndCover(p1, info, call1)502 if newSignal.Intersection(thisSignal).Len() == newSignal.Len() {503 proc.fuzzer.writeLog("%s\n", "# Minimize Success")504 t_avg = t_avg / float64(i+1)505 minimizeTimeAfter = t_avg506 return true507 }508 }509 return false510 })511 }512 proc.fuzzer.writeLog("%s\n", "# Minimize Final")513 proc.fuzzer.logProgram(item.p)514 data := item.p.Serialize()515 sig := hash.Hash(data)516 corpusGainRaw := 0.0517 if len(inputSignal) > 0 {518 corpusGainRaw = float64(len(newSignal))519 }520 log.Logf(2, "added new input for %v to corpus:\n%s", logCallName, data)521 proc.fuzzer.sendInputToManager(rpctype.RPCInput{522 Call: callName,523 Prog: data,524 Signal: inputSignal.Serialize(),525 Cover: inputCover.Serialize(),526 CorpusGLC: glc.CorpusGLC{527 VerifyGain: 0.0,528 VerifyCost: ret.verifyTime,529 MinimizeGain: minimizeGainRaw,530 MinimizeCost: ret.minimizeTime,531 MinimizeTimeSave: sourceCost - minimizeTimeAfter,532 },533 })534 proc.fuzzer.writeLog("# addInputToCorpus %x: %v. Source: %v\n", sig, proc.fuzzer.corpusSignal.Len(), ret.source)535 proc.fuzzer.logSignal(inputSignal, "+")536 ret.pidx = proc.fuzzer.addInputToCorpus(item.p, inputSignal, sig)537 if item.flags&ProgSmashed == 0 {538 numSmashes := int(math.Floor(float64(proc.fuzzer.fuzzerConfig.smashWeight) / float64(proc.fuzzer.fuzzerConfig.mutateWeight)))539 // if numSmashes == 0 {540 // numSmashes = 1541 // }542 for i := 0; i < numSmashes; i++ {543 proc.fuzzer.workQueue.enqueue(&WorkSmash{item.p, item.call, proc.fuzzer.fuzzerConfig.mutateWeight})544 }545 }546 ts_end := time.Now().UnixNano()547 ret.timeTotal = float64(ts_end-ts_bgn) / proc.fuzzer.fuzzerConfig.MABTimeUnit548 ret.minimizeGainRaw = minimizeGainRaw549 ret.corpusGainRaw = corpusGainRaw550 ret.minimizeTimeSave = sourceCost - minimizeTimeAfter551 // ret.minimizeTime = t_minimize552 // ret.verifyTime = t_corpus553 ret.minimizeCalls = minimizeCalls554 ret.verifyCalls = size_bgn * signalRuns555 ret.success = true556 return ret557}558func reexecutionSuccess(info *ipc.ProgInfo, oldInfo *ipc.CallInfo, call int) bool {559 if info == nil || len(info.Calls) == 0 {560 return false561 }562 if call != -1 {563 // Don't minimize calls from successful to unsuccessful.564 // Successful calls are much more valuable.565 if oldInfo.Errno == 0 && info.Calls[call].Errno != 0 {566 return false567 }568 return len(info.Calls[call].Signal) != 0569 }570 return len(info.Extra.Signal) != 0571}572func getSignalAndCover(p *prog.Prog, info *ipc.ProgInfo, call int) (signal.Signal, []uint32) {573 inf := &info.Extra574 if call != -1 {575 inf = &info.Calls[call]576 }577 return signal.FromRaw(inf.Signal, signalPrio(p, inf, call)), inf.Cover578}579func (proc *Proc) smashInput(item *WorkSmash) ExecResult {580 ret := ExecResult{581 gainRaw: 0.0,582 time: 0.0,583 calls: 0,584 pidx: -1,585 count: 0,586 timeTotal: 0.0,587 }588 ts_bgn := time.Now().UnixNano()589 sig := hash.Hash(item.p.Serialize())590 if proc.fuzzer.faultInjectionEnabled && item.call != -1 {591 proc.fuzzer.writeLog("- failCall: %v, %v\n", sig.String, item.call)592 proc.failCall(item.p, item.call)593 }594 if proc.fuzzer.comparisonTracingEnabled && item.call != -1 {595 proc.fuzzer.writeLog("- executeHintSeed: %v, %v\n", sig.String, item.call)596 proc.executeHintSeed(item.p, item.call)597 }598 fuzzerSnapshot := proc.fuzzer.snapshot()599 pidx := -1600 if v, ok := proc.fuzzer.corpusHashes[sig]; ok {601 pidx = v602 ret.pidx = pidx603 }604 // Mark for update if we're syncing smash605 if pidx > 0 && proc.fuzzer.fuzzerConfig.syncSmash {606 proc.fuzzer.MABCorpusUpdate[pidx] = 1607 item.p.CorpusGLC.Smashed = true608 proc.fuzzer.smashesFinished = append(proc.fuzzer.smashesFinished, sig)609 }610 for i := 0; i < item.count; i++ {611 p := item.p.Clone()612 p.ResetMAB()613 proc.fuzzer.writeLog("# %v Mutate Smash\n", i)614 proc.fuzzer.logProgram(p)615 p.Mutate(proc.rnd, programLength, proc.fuzzer.choiceTable, fuzzerSnapshot.corpus)616 proc.fuzzer.logProgram(p)617 _, r := proc.execute(proc.execOpts, p, ProgNormal, StatSmash)618 if proc.fuzzer.fuzzerConfig.MABAlgorithm == "N/A" && proc.fuzzer.fuzzerConfig.MABSeedSelection == "N/A" && proc.fuzzer.fuzzerConfig.syncSmash {619 // Without MAB, we need to count mutations for smash syncing620 proc.fuzzer.MABIncrementCorpusMutateCount(pidx, 1)621 }622 ret.count += 1623 ret.calls += r.calls624 ret.gainRaw += r.gainRaw625 ret.time += r.time626 }627 ts_end := time.Now().UnixNano()628 ret.timeTotal = float64(ts_end-ts_bgn) / proc.fuzzer.fuzzerConfig.MABTimeUnit629 return ret630}631func (proc *Proc) failCall(p *prog.Prog, call int) {632 for nth := 0; nth < 100; nth++ {633 log.Logf(1, "#%v: injecting fault into call %v/%v", proc.pid, call, nth)634 opts := *proc.execOpts635 opts.Flags |= ipc.FlagInjectFault636 opts.FaultCall = call637 opts.FaultNth = nth638 info, _ := proc.executeRaw(&opts, p, StatSmash)639 if info != nil && len(info.Calls) > call && info.Calls[call].Flags&ipc.CallFaultInjected == 0 {640 break641 }642 }643}644func (proc *Proc) executeHintSeed(p *prog.Prog, call int) {645 log.Logf(1, "#%v: collecting comparisons", proc.pid)646 // First execute the original program to dump comparisons from KCOV.647 info, _ := proc.execute(proc.execOptsComps, p, ProgNormal, StatSeed)648 if info == nil {649 return650 }651 // Then mutate the initial program for every match between652 // a syscall argument and a comparison operand.653 // Execute each of such mutants to check if it gives new coverage.654 p.MutateWithHints(call, info.Calls[call].Comps, func(p *prog.Prog) {655 log.Logf(1, "#%v: executing comparison hint", proc.pid)656 proc.execute(proc.execOpts, p, ProgNormal, StatHint)657 })658}659func (proc *Proc) execute(execOpts *ipc.ExecOpts, p *prog.Prog, flags ProgTypes, stat Stat) (*ipc.ProgInfo, ExecResult) {660 ret := ExecResult{661 gainRaw: 0.0,662 time: 0,663 calls: 0,664 pidx: -1,665 }666 ts_bgn := time.Now().UnixNano()667 info, _time := proc.executeRaw(execOpts, p, stat)668 if proc.fuzzer.feedback == "NOCOVER" {669 proc.fuzzer.checkNewSignal(p, info) // Still want to update signal to reduce output670 return info, ret671 }672 ret.time += _time673 p.CorpusGLC.Cost = _time674 calls, extra, gainRaw := proc.fuzzer.checkNewSignal(p, info)675 ts_end := time.Now().UnixNano()676 for _, callIndex := range calls {677 proc.enqueueCallTriage(p, flags, callIndex, info.Calls[callIndex])678 }679 if extra {680 proc.enqueueCallTriage(p, flags, -1, info.Extra)681 }682 ret.calls = ((proc.fuzzer.fuzzerConfig.executeRetries + 1) * len(p.Calls))683 ret.timeTotal = float64(ts_end-ts_bgn) / proc.fuzzer.fuzzerConfig.MABTimeUnit684 ret.gainRaw = gainRaw685 return info, ret686}687func (proc *Proc) enqueueCallTriage(p *prog.Prog, flags ProgTypes, callIndex int, info ipc.CallInfo) {688 // info.Signal points to the output shmem region, detach it before queueing.689 info.Signal = append([]uint32{}, info.Signal...)690 // None of the caller use Cover, so just nil it instead of detaching.691 // Note: triage input uses executeRaw to get coverage.692 info.Cover = nil693 proc.fuzzer.workQueue.enqueue(&WorkTriage{694 p: p.Clone(),695 call: callIndex,696 info: info,697 flags: flags,698 })699 if proc.fuzzer.fuzzerConfig.syncTriage {700 data := p.Serialize()701 sig := hash.Hash(data)702 proc.fuzzer.newTriage(rpctype.RPCTriage{703 Sig: sig,704 CallIndex: callIndex,705 Prog: data,706 Flags: int(flags),707 Info: info,708 Source: p.Source,709 SourceCost: p.CorpusGLC.Cost,710 })711 }712}713func (proc *Proc) executeRaw(opts *ipc.ExecOpts, p *prog.Prog, stat Stat) (*ipc.ProgInfo, float64) {714 if opts.Flags&ipc.FlagDedupCover == 0 {715 log.Fatalf("dedup cover is not enabled")716 }717 ts := time.Now().UnixNano()718 // Limit concurrency window and do leak checking once in a while.719 ticket := proc.fuzzer.gate.Enter()720 defer proc.fuzzer.gate.Leave(ticket)721 proc.logProgram(opts, p)722 for try := 0; ; try++ {723 proc.fuzzer.writeLog("- executeRaw %v\n", len(p.Calls))724 atomic.AddUint64(&proc.fuzzer.stats[stat], 1)725 output, info, hanged, err := proc.env.Exec(opts, p)726 if err != nil {727 if try > 10 {728 log.Fatalf("executor %v failed %v times:\n%v", proc.pid, try, err)729 }730 log.Logf(4, "fuzzer detected executor failure='%v', retrying #%d", err, try+1)731 debug.FreeOSMemory()732 time.Sleep(time.Second)733 continue734 }735 log.Logf(2, "result hanged=%v: %s", hanged, output)736 ts_end := time.Now().UnixNano()737 return info, float64(ts_end-ts) / proc.fuzzer.fuzzerConfig.MABTimeUnit738 }739}740func (proc *Proc) logProgram(opts *ipc.ExecOpts, p *prog.Prog) {741 if proc.fuzzer.outputType == OutputNone {742 return743 }744 data := p.Serialize()745 strOpts := ""746 if opts.Flags&ipc.FlagInjectFault != 0 {747 strOpts = fmt.Sprintf(" (fault-call:%v fault-nth:%v)", opts.FaultCall, opts.FaultNth)748 }749 // The following output helps to understand what program crashed kernel.750 // It must not be intermixed.751 switch proc.fuzzer.outputType {752 case OutputStdout:753 now := time.Now()754 proc.fuzzer.logMu.Lock()...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...14)15var (16 listenAddr = flag.String("listen", ":8080", "the address to listen on")17 staticPath = flag.String("static", "static", "path to directory with static files to serve")18 logProgram = flag.String("logProgram", "log.sh", "program to follow logs through")19)20/*21var (22 cmdch = make(chan string)23)24var logBroadcast = NewLineBroadcast(5)25func Log(line string) {26 logBroadcast.Input() <- line27}28func logFromReader(reader io.Reader) {29 scanner := bufio.NewScanner(reader)30 for scanner.Scan() {31 Log(scanner.Text())32 }33}34*/35var upgrader = websocket.Upgrader{36 ReadBufferSize: 1024,37 WriteBufferSize: 1024,38}39func logHandler(w http.ResponseWriter, r *http.Request) {40 cmd := exec.Command(*logProgram)41 out, err := cmd.StdoutPipe()42 if err != nil {43 http.Error(w, err.Error(), 500)44 return45 }46 err = cmd.Start()47 if err != nil {48 http.Error(w, err.Error(), 500)49 return50 }51 conn, err := upgrader.Upgrade(w, r, nil)52 if err != nil {53 log.Println(err)54 cmd.Process.Signal(os.Interrupt)...

Full Screen

Full Screen

config.go

Source:config.go Github

copy

Full Screen

1package main2import (3 "LogProgram/config"4 "strings"5)6// AppConfig 用于存放读取的配置7type AppConfig struct {8 logPath string9 logLevel string10 kafkaAddr string11 kafkaThread int12 collectLogs []string13}14func initConfig(confFile string) (err error) {15 conf, err := config.NewConf(confFile)16 if err != nil {17 return18 }19 logPath := conf.GetDefaultString("logPath", "./logs/server.log")20 logLevel := conf.GetDefaultString("logLevel", "info")21 kafkaAddr, err := conf.GetString("kafkaAddr")22 if err != nil {23 return24 }25 kafkaThread := conf.GetDefaultInt("kafkaThread", 8)26 collectLogs, err := conf.GetString("collectLogs")27 if err != nil {28 return29 }30 logFiles := strings.Split(collectLogs, ",")31 for _, v := range logFiles {32 v = strings.TrimSpace(v)33 if len(v) == 0 {34 continue35 }36 appConf.collectLogs = append(appConf.collectLogs, v)37 }38 appConf.logPath = logPath39 appConf.logLevel = logLevel40 appConf.kafkaAddr = kafkaAddr41 appConf.kafkaThread = kafkaThread42 return43}...

Full Screen

Full Screen

logProgram

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

logProgram

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 log.SetOutput(os.Stdout)4 log.Println("This is a standard log entry")5 log.Println("This is a standard log entry")6}7import (8func main() {9 logProgram := log.New(os.Stdout, "LOG: ", log.Ldate|log.Ltime|log.Lshortfile)10 logProgram.Println("This is a custom log entry")11 logProgram.Println("This is a custom log entry")12 fmt.Println("This is a standard print statement")13}

Full Screen

Full Screen

logProgram

Using AI Code Generation

copy

Full Screen

1import "log"2func main() {3 logProgram("This is an error message", "ERROR")4}5import "log"6func logProgram(message string, level string) {7 log.Println(message)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.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful