How to use minimizeCorpus method of main Package

Best Syzkaller code snippet using main.minimizeCorpus

manager.go

Source:manager.go Github

copy

Full Screen

...227 if mgr.firstConnect.IsZero() {228 mgr.mu.Unlock()229 continue230 }231 mgr.minimizeCorpus()232 vals["corpus"] = uint64(len(mgr.corpus))233 vals["uptime"] = uint64(time.Since(mgr.firstConnect)) / 1e9234 vals["fuzzing"] = uint64(mgr.fuzzingTime) / 1e9235 vals["signal"] = uint64(len(mgr.corpusSignal))236 vals["coverage"] = uint64(len(mgr.corpusCover))237 for k, v := range mgr.stats {238 vals[k] = v239 }240 mgr.mu.Unlock()241 data, err := json.MarshalIndent(vals, "", " ")242 if err != nil {243 Fatalf("failed to serialize bench data")244 }245 if _, err := f.Write(append(data, '\n')); err != nil {246 Fatalf("failed to write bench data")247 }248 }249 }()250 }251 if mgr.cfg.Hub_Addr != "" {252 go func() {253 for {254 time.Sleep(time.Minute)255 mgr.hubSync()256 }257 }()258 }259 go func() {260 c := make(chan os.Signal, 2)261 signal.Notify(c, syscall.SIGINT)262 <-c263 close(vm.Shutdown)264 Logf(0, "shutting down...")265 <-c266 Fatalf("terminating")267 }()268 mgr.vmLoop()269}270type RunResult struct {271 idx int272 crash *Crash273 err error274}275type ReproResult struct {276 instances []int277 crash *Crash278 res *repro.Result279 err error280}281func (mgr *Manager) vmLoop() {282 Logf(0, "booting test machines...")283 reproInstances := 4284 if reproInstances > mgr.cfg.Count {285 reproInstances = mgr.cfg.Count286 }287 instances := make([]int, mgr.cfg.Count)288 for i := range instances {289 instances[i] = mgr.cfg.Count - i - 1290 }291 runDone := make(chan *RunResult, 1)292 pendingRepro := make(map[*Crash]bool)293 reproducing := make(map[string]bool)294 var reproQueue []*Crash295 reproDone := make(chan *ReproResult, 1)296 stopPending := false297 shutdown := vm.Shutdown298 for {299 for crash := range pendingRepro {300 if reproducing[crash.desc] {301 continue302 }303 delete(pendingRepro, crash)304 if !mgr.needRepro(crash.desc) {305 continue306 }307 Logf(1, "loop: add to repro queue '%v'", crash.desc)308 reproducing[crash.desc] = true309 reproQueue = append(reproQueue, crash)310 }311 Logf(1, "loop: shutdown=%v instances=%v/%v %+v repro: pending=%v reproducing=%v queued=%v",312 shutdown == nil, len(instances), mgr.cfg.Count, instances,313 len(pendingRepro), len(reproducing), len(reproQueue))314 if shutdown == nil {315 if len(instances) == mgr.cfg.Count {316 return317 }318 } else {319 for len(reproQueue) != 0 && len(instances) >= reproInstances {320 last := len(reproQueue) - 1321 crash := reproQueue[last]322 reproQueue[last] = nil323 reproQueue = reproQueue[:last]324 vmIndexes := append([]int{}, instances[len(instances)-reproInstances:]...)325 instances = instances[:len(instances)-reproInstances]326 Logf(1, "loop: starting repro of '%v' on instances %+v", crash.desc, vmIndexes)327 go func() {328 res, err := repro.Run(crash.output, mgr.cfg, vmIndexes)329 reproDone <- &ReproResult{vmIndexes, crash, res, err}330 }()331 }332 for len(reproQueue) == 0 && len(instances) != 0 {333 last := len(instances) - 1334 idx := instances[last]335 instances = instances[:last]336 Logf(1, "loop: starting instance %v", idx)337 go func() {338 vmCfg, err := config.CreateVMConfig(mgr.cfg, idx)339 if err != nil {340 Fatalf("failed to create VM config: %v", err)341 }342 crash, err := mgr.runInstance(vmCfg, idx == 0)343 runDone <- &RunResult{idx, crash, err}344 }()345 }346 }347 var stopRequest chan bool348 if len(reproQueue) != 0 && !stopPending {349 stopRequest = mgr.vmStop350 }351 select {352 case stopRequest <- true:353 Logf(1, "loop: issued stop request")354 stopPending = true355 case res := <-runDone:356 Logf(1, "loop: instance %v finished, crash=%v", res.idx, res.crash != nil)357 if res.err != nil && shutdown != nil {358 Logf(0, "%v", res.err)359 }360 stopPending = false361 instances = append(instances, res.idx)362 // On shutdown qemu crashes with "qemu: terminating on signal 2",363 // which we detect as "lost connection". Don't save that as crash.364 if shutdown != nil && res.crash != nil && !mgr.isSuppressed(res.crash) {365 mgr.saveCrash(res.crash)366 if mgr.needRepro(res.crash.desc) {367 Logf(1, "loop: add pending repro for '%v'", res.crash.desc)368 pendingRepro[res.crash] = true369 }370 }371 case res := <-reproDone:372 crepro := false373 if res.res != nil {374 crepro = res.res.CRepro375 }376 Logf(1, "loop: repro on instances %+v finished '%v', repro=%v crepro=%v",377 res.instances, res.crash.desc, res.res != nil, crepro)378 if res.err != nil {379 Logf(0, "repro failed: %v", res.err)380 }381 delete(reproducing, res.crash.desc)382 instances = append(instances, res.instances...)383 mgr.saveRepro(res.crash, res.res)384 case <-shutdown:385 Logf(1, "loop: shutting down...")386 shutdown = nil387 }388 }389}390func (mgr *Manager) runInstance(vmCfg *vm.Config, first bool) (*Crash, error) {391 inst, err := vm.Create(mgr.cfg.Type, vmCfg)392 if err != nil {393 return nil, fmt.Errorf("failed to create instance: %v", err)394 }395 defer inst.Close()396 fwdAddr, err := inst.Forward(mgr.port)397 if err != nil {398 return nil, fmt.Errorf("failed to setup port forwarding: %v", err)399 }400 fuzzerBin, err := inst.Copy(filepath.Join(mgr.cfg.Syzkaller, "bin", "syz-fuzzer"))401 if err != nil {402 return nil, fmt.Errorf("failed to copy binary: %v", err)403 }404 executorBin, err := inst.Copy(filepath.Join(mgr.cfg.Syzkaller, "bin", "syz-executor"))405 if err != nil {406 return nil, fmt.Errorf("failed to copy binary: %v", err)407 }408 // Leak detection significantly slows down fuzzing, so detect leaks only on the first instance.409 leak := first && mgr.cfg.Leak410 fuzzerV := 0411 procs := mgr.cfg.Procs412 if *flagDebug {413 fuzzerV = 100414 procs = 1415 }416 // Run the fuzzer binary.417 start := time.Now()418 atomic.AddUint32(&mgr.numFuzzing, 1)419 defer atomic.AddUint32(&mgr.numFuzzing, ^uint32(0))420 cmd := fmt.Sprintf("%v -executor=%v -name=%v -manager=%v -output=%v -procs=%v -leak=%v -cover=%v -sandbox=%v -debug=%v -v=%d",421 fuzzerBin, executorBin, vmCfg.Name, fwdAddr, mgr.cfg.Output, procs, leak, mgr.cfg.Cover, mgr.cfg.Sandbox, *flagDebug, fuzzerV)422 outc, errc, err := inst.Run(time.Hour, mgr.vmStop, cmd)423 if err != nil {424 return nil, fmt.Errorf("failed to run fuzzer: %v", err)425 }426 desc, text, output, crashed, timedout := vm.MonitorExecution(outc, errc, mgr.cfg.Type == "local", true, mgr.cfg.ParsedIgnores)427 if timedout {428 // This is the only "OK" outcome.429 Logf(0, "%v: running for %v, restarting (%v)", vmCfg.Name, time.Since(start), desc)430 return nil, nil431 }432 if !crashed {433 // syz-fuzzer exited, but it should not.434 desc = "lost connection to test machine"435 }436 return &Crash{vmCfg.Name, desc, text, output}, nil437}438func (mgr *Manager) isSuppressed(crash *Crash) bool {439 for _, re := range mgr.cfg.ParsedSuppressions {440 if !re.Match(crash.output) {441 continue442 }443 Logf(1, "%v: suppressing '%v' with '%v'", crash.vmName, crash.desc, re.String())444 mgr.mu.Lock()445 mgr.stats["suppressed"]++446 mgr.mu.Unlock()447 return true448 }449 return false450}451func (mgr *Manager) saveCrash(crash *Crash) {452 Logf(0, "%v: crash: %v", crash.vmName, crash.desc)453 mgr.mu.Lock()454 mgr.stats["crashes"]++455 if !mgr.crashTypes[crash.desc] {456 mgr.crashTypes[crash.desc] = true457 mgr.stats["crash types"]++458 }459 mgr.mu.Unlock()460 sig := hash.Hash([]byte(crash.desc))461 id := sig.String()462 dir := filepath.Join(mgr.crashdir, id)463 os.MkdirAll(dir, 0700)464 if err := ioutil.WriteFile(filepath.Join(dir, "description"), []byte(crash.desc+"\n"), 0660); err != nil {465 Logf(0, "failed to write crash: %v", err)466 }467 // Save up to 100 reports. If we already have 100, overwrite the oldest one.468 // Newer reports are generally more useful. Overwriting is also needed469 // to be able to understand if a particular bug still happens or already fixed.470 oldestI := 0471 var oldestTime time.Time472 for i := 0; i < 100; i++ {473 info, err := os.Stat(filepath.Join(dir, fmt.Sprintf("log%v", i)))474 if err != nil {475 oldestI = i476 break477 }478 if oldestTime.IsZero() || info.ModTime().Before(oldestTime) {479 oldestI = i480 oldestTime = info.ModTime()481 }482 }483 ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("log%v", oldestI)), crash.output, 0660)484 if len(mgr.cfg.Tag) > 0 {485 ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("tag%v", oldestI)), []byte(mgr.cfg.Tag), 0660)486 }487 if len(crash.text) > 0 {488 symbolized, err := report.Symbolize(mgr.cfg.Vmlinux, crash.text)489 if err != nil {490 Logf(0, "failed to symbolize crash: %v", err)491 } else {492 crash.text = symbolized493 }494 ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("report%v", oldestI)), crash.text, 0660)495 }496 if mgr.dash != nil {497 dc := &dashboard.Crash{498 Tag: mgr.cfg.Tag,499 Desc: crash.desc,500 Log: crash.output,501 Report: crash.text,502 }503 if err := mgr.dash.ReportCrash(dc); err != nil {504 Logf(0, "failed to report crash to dashboard: %v", err)505 }506 }507}508const maxReproAttempts = 3509func (mgr *Manager) needRepro(desc string) bool {510 if !mgr.cfg.Reproduce {511 return false512 }513 sig := hash.Hash([]byte(desc))514 dir := filepath.Join(mgr.crashdir, sig.String())515 if _, err := os.Stat(filepath.Join(dir, "repro.prog")); err == nil {516 return false517 }518 for i := 0; i < maxReproAttempts; i++ {519 if _, err := os.Stat(filepath.Join(dir, fmt.Sprintf("repro%v", i))); err != nil {520 return true521 }522 }523 return false524}525func (mgr *Manager) saveRepro(crash *Crash, res *repro.Result) {526 sig := hash.Hash([]byte(crash.desc))527 dir := filepath.Join(mgr.crashdir, sig.String())528 if res == nil {529 if mgr.dash != nil {530 dr := &dashboard.Repro{531 Crash: dashboard.Crash{532 Tag: mgr.cfg.Tag,533 Desc: crash.desc,534 },535 Reproduced: false,536 }537 if err := mgr.dash.ReportRepro(dr); err != nil {538 Logf(0, "failed to report repro to dashboard: %v", err)539 }540 }541 for i := 0; i < maxReproAttempts; i++ {542 name := filepath.Join(dir, fmt.Sprintf("repro%v", i))543 if _, err := os.Stat(name); err != nil {544 ioutil.WriteFile(name, nil, 0660)545 break546 }547 }548 return549 }550 opts := fmt.Sprintf("# %+v\n", res.Opts)551 prog := res.Prog.Serialize()552 ioutil.WriteFile(filepath.Join(dir, "repro.prog"), append([]byte(opts), prog...), 0660)553 if len(mgr.cfg.Tag) > 0 {554 ioutil.WriteFile(filepath.Join(dir, "repro.tag"), []byte(mgr.cfg.Tag), 0660)555 }556 if len(crash.text) > 0 {557 ioutil.WriteFile(filepath.Join(dir, "repro.report"), []byte(crash.text), 0660)558 }559 var cprogText []byte560 if res.CRepro {561 cprog, err := csource.Write(res.Prog, res.Opts)562 if err == nil {563 formatted, err := csource.Format(cprog)564 if err == nil {565 cprog = formatted566 }567 ioutil.WriteFile(filepath.Join(dir, "repro.cprog"), cprog, 0660)568 cprogText = cprog569 } else {570 Logf(0, "failed to write C source: %v", err)571 }572 }573 if mgr.dash != nil {574 dr := &dashboard.Repro{575 Crash: dashboard.Crash{576 Tag: mgr.cfg.Tag,577 Desc: crash.desc,578 Report: crash.text,579 },580 Reproduced: true,581 Opts: fmt.Sprintf("%+v", res.Opts),582 Prog: res.Prog.Serialize(),583 CProg: cprogText,584 }585 if err := mgr.dash.ReportRepro(dr); err != nil {586 Logf(0, "failed to report repro to dashboard: %v", err)587 }588 }589}590func (mgr *Manager) minimizeCorpus() {591 if mgr.cfg.Cover && len(mgr.corpus) != 0 {592 var cov []cover.Cover593 var inputs []RpcInput594 for _, inp := range mgr.corpus {595 cov = append(cov, inp.Signal)596 inputs = append(inputs, inp)597 }598 newCorpus := make(map[string]RpcInput)599 for _, idx := range cover.Minimize(cov) {600 inp := inputs[idx]601 newCorpus[hash.String(inp.Prog)] = inp602 }603 Logf(1, "minimized corpus: %v -> %v", len(mgr.corpus), len(newCorpus))604 mgr.corpus = newCorpus605 }606 // Don't minimize persistent corpus until fuzzers have triaged all inputs from it.607 if len(mgr.candidates) == 0 {608 for key := range mgr.corpusDB.Records {609 _, ok1 := mgr.corpus[key]610 _, ok2 := mgr.disabledHashes[key]611 if !ok1 && !ok2 {612 mgr.corpusDB.Delete(key)613 }614 }615 mgr.corpusDB.Flush()616 }617}618func (mgr *Manager) Connect(a *ConnectArgs, r *ConnectRes) error {619 Logf(1, "fuzzer %v connected", a.Name)620 mgr.mu.Lock()621 defer mgr.mu.Unlock()622 if mgr.firstConnect.IsZero() {623 mgr.firstConnect = time.Now()624 }625 mgr.stats["vm restarts"]++626 f := &Fuzzer{627 name: a.Name,628 }629 mgr.fuzzers[a.Name] = f630 mgr.minimizeCorpus()631 if mgr.prios == nil || time.Since(mgr.lastPrioCalc) > 30*time.Minute {632 // Deserializing all programs is slow, so we do it episodically and without holding the mutex.633 mgr.lastPrioCalc = time.Now()634 inputs := make([][]byte, 0, len(mgr.corpus))635 for _, inp := range mgr.corpus {636 inputs = append(inputs, inp.Prog)637 }638 mgr.mu.Unlock()639 corpus := make([]*prog.Prog, 0, len(inputs))640 for _, inp := range inputs {641 p, err := prog.Deserialize(inp)642 if err != nil {643 panic(err)644 }645 corpus = append(corpus, p)646 }647 prios := prog.CalculatePriorities(corpus, mgr.cfg.Weight_Syscalls, mgr.cfg.Weight)648 // fmt.Println("Prios below:")649 // fmt.Printf("%+v\n", prios) 650 Logf(0, "Prios Calculated")651 mgr.mu.Lock()652 mgr.prios = prios653 }654 f.inputs = nil655 for _, inp := range mgr.corpus {656 r.Inputs = append(r.Inputs, inp)657 }658 r.Prios = mgr.prios659 r.EnabledCalls = mgr.enabledSyscalls660 r.NeedCheck = !mgr.vmChecked661 r.MaxSignal = make([]uint32, 0, len(mgr.maxSignal))662 for s := range mgr.maxSignal {663 r.MaxSignal = append(r.MaxSignal, s)664 }665 f.newMaxSignal = nil666 for i := 0; i < mgr.cfg.Procs && len(mgr.candidates) > 0; i++ {667 last := len(mgr.candidates) - 1668 r.Candidates = append(r.Candidates, mgr.candidates[last])669 mgr.candidates = mgr.candidates[:last]670 }671 if len(mgr.candidates) == 0 {672 mgr.candidates = nil673 }674 return nil675}676func (mgr *Manager) Check(a *CheckArgs, r *int) error {677 mgr.mu.Lock()678 defer mgr.mu.Unlock()679 if mgr.vmChecked {680 return nil681 }682 Logf(1, "fuzzer %v vm check: %v calls enabled", a.Name, len(a.Calls))683 if len(a.Calls) == 0 {684 Fatalf("no system calls enabled")685 }686 if mgr.cfg.Cover && !a.Kcov {687 Fatalf("/sys/kernel/debug/kcov is missing. Enable CONFIG_KCOV and mount debugfs")688 }689 mgr.vmChecked = true690 mgr.enabledCalls = a.Calls691 return nil692}693func (mgr *Manager) NewInput(a *NewInputArgs, r *int) error {694 Logf(2, "new input from %v for syscall %v (signal=%v cover=%v)", a.Name, a.Call, len(a.Signal), len(a.Cover))695 mgr.mu.Lock()696 defer mgr.mu.Unlock()697 f := mgr.fuzzers[a.Name]698 if f == nil {699 Fatalf("fuzzer %v is not connected", a.Name)700 }701 if !cover.SignalNew(mgr.corpusSignal, a.Signal) {702 return nil703 }704 mgr.stats["manager new inputs"]++705 cover.SignalAdd(mgr.corpusSignal, a.Signal)706 cover.SignalAdd(mgr.corpusCover, a.Cover)707 sig := hash.String(a.RpcInput.Prog)708 if inp, ok := mgr.corpus[sig]; ok {709 // The input is already present, but possibly with diffent signal/coverage/call.710 inp.Signal = cover.Union(inp.Signal, a.RpcInput.Signal)711 inp.Cover = cover.Union(inp.Cover, a.RpcInput.Cover)712 mgr.corpus[sig] = inp713 } else {714 mgr.corpus[sig] = a.RpcInput715 mgr.corpusDB.Save(sig, a.RpcInput.Prog, 0)716 if err := mgr.corpusDB.Flush(); err != nil {717 Logf(0, "failed to save corpus database: %v", err)718 }719 for _, f1 := range mgr.fuzzers {720 if f1 == f {721 continue722 }723 inp := a.RpcInput724 inp.Cover = nil // Don't send coverage back to all fuzzers.725 f1.inputs = append(f1.inputs, inp)726 }727 }728 return nil729}730func (mgr *Manager) Poll(a *PollArgs, r *PollRes) error {731 mgr.mu.Lock()732 defer mgr.mu.Unlock()733 for k, v := range a.Stats {734 mgr.stats[k] += v735 }736 f := mgr.fuzzers[a.Name]737 if f == nil {738 Fatalf("fuzzer %v is not connected", a.Name)739 }740 var newMaxSignal []uint32741 for _, s := range a.MaxSignal {742 if _, ok := mgr.maxSignal[s]; ok {743 continue744 }745 mgr.maxSignal[s] = struct{}{}746 newMaxSignal = append(newMaxSignal, s)747 }748 for _, f1 := range mgr.fuzzers {749 if f1 == f {750 continue751 }752 f1.newMaxSignal = append(f1.newMaxSignal, newMaxSignal...)753 }754 r.MaxSignal = f.newMaxSignal755 f.newMaxSignal = nil756 for i := 0; i < 100 && len(f.inputs) > 0; i++ {757 last := len(f.inputs) - 1758 r.NewInputs = append(r.NewInputs, f.inputs[last])759 f.inputs = f.inputs[:last]760 }761 if len(f.inputs) == 0 {762 f.inputs = nil763 }764 for i := 0; i < mgr.cfg.Procs && len(mgr.candidates) > 0; i++ {765 last := len(mgr.candidates) - 1766 r.Candidates = append(r.Candidates, mgr.candidates[last])767 mgr.candidates = mgr.candidates[:last]768 }769 if len(mgr.candidates) == 0 {770 mgr.candidates = nil771 }772 Logf(2, "poll from %v: recv maxsignal=%v, send maxsignal=%v candidates=%v inputs=%v",773 a.Name, len(a.MaxSignal), len(r.MaxSignal), len(r.Candidates), len(r.NewInputs))774 return nil775}776func (mgr *Manager) hubSync() {777 mgr.mu.Lock()778 defer mgr.mu.Unlock()779 if !mgr.vmChecked || len(mgr.candidates) != 0 {780 return781 }782 mgr.minimizeCorpus()783 if mgr.hub == nil {784 a := &HubConnectArgs{785 Name: mgr.cfg.Name,786 Key: mgr.cfg.Hub_Key,787 Fresh: mgr.fresh,788 Calls: mgr.enabledCalls,789 }790 hubCorpus := make(map[hash.Sig]bool)791 for _, inp := range mgr.corpus {792 hubCorpus[hash.Hash(inp.Prog)] = true793 a.Corpus = append(a.Corpus, inp.Prog)794 }795 mgr.mu.Unlock()796 // Hub.Connect request can be very large, so do it on a transient connection...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...67 execThreads = c.GlobalInt(execThreadsFlag.Name)68 configFile = c.GlobalString(configFileFlag.Name)69 )70 if c.GlobalBool(corpusMinimizeFlag.Name) {71 minimizeCorpus()72 return73 }74 vms, err := getVMsFromConfig(configFile)75 if err != nil {76 panic(err)77 }78 exec := executor.NewExecutor(vms, true)79 ensureDirs(dirName, outDir)80 if c.GlobalBool(buildFlag.Name) {81 if err := startBuilder(); err != nil {82 panic(err)83 }84 } else if c.GlobalString(retestFlag.Name) != "" {85 retest(c, exec)86 } else if c.GlobalBool(execNoGen.Name) {87 if err := exec.Execute(dirName, outDir, execThreads); err != nil {88 panic(err)89 }90 } else if c.GlobalInt(benchFlag.Name) != 0 {91 benchmark.RunFullBench(c.GlobalInt(benchFlag.Name), execThreads)92 } else if c.GlobalInt(corpusFlag.Name) != 0 {93 createCorpus(c.GlobalInt(corpusFlag.Name))94 } else {95 generatorLoop(c, exec)96 }97}98func startBuilder() error {99 cmdName := "go-fuzz-build"100 cmd := exec.Command(cmdName)101 cmd.Dir = "fuzzer"102 cmd.Stdout = os.Stdout103 cmd.Stderr = os.Stderr104 // We have to disable CGO105 cgo := "CGO_ENABLED=0"106 env := append(os.Environ(), cgo)107 cmd.Env = env108 return cmd.Run()109}110func retest(c *cli.Context, exec *executor.Executor) {111 p := c.GlobalString(retestFlag.Name)112 dir := path.Dir(p)113 test := path.Base(p)114 exec.ExecuteFullTest(dirName, dir, test, false)115}116func generatorLoop(c *cli.Context, exec *executor.Executor) {117 var (118 genThreads = c.GlobalInt(genThreadsFlag.Name)119 execThreads = c.GlobalInt(execThreadsFlag.Name)120 minTests = c.GlobalInt(minTestsFlag.Name)121 maxTests = c.GlobalInt(maxTestsFlag.Name)122 errChan = make(chan error)123 )124 for {125 fmt.Println("Starting generator")126 cmd := startGenerator(genThreads)127 go func() {128 for {129 // Sleep a bit to ensure some tests have been generated.130 time.Sleep(30 * time.Second)131 fmt.Println("Starting executor")132 if err := exec.Execute(dirName, outDir, execThreads); err != nil {133 errChan <- err134 return135 }136 errChan <- nil137 }138 }()139 go watcher(cmd, errChan, maxTests)140 err := <-errChan141 cmd.Process.Signal(os.Kill)142 if err != nil {143 panic(err)144 }145 infos, err := ioutil.ReadDir(dirName)146 if err != nil {147 panic(err)148 }149 if len(infos) > minTests {150 fmt.Println("Tests exceed minTests after execution")151 return152 }153 }154}155func startGenerator(genThreads int) *exec.Cmd {156 cmdName := "go-fuzz"157 dir := "./fuzzer/fuzzer-fuzz.zip"158 cmd := exec.Command(cmdName, "--bin", dir, "--procs", fmt.Sprint(genThreads))159 cmd.Stdout = os.Stdout160 cmd.Stderr = os.Stderr161 if err := cmd.Start(); err != nil {162 panic(err)163 }164 return cmd165}166func watcher(cmd *exec.Cmd, errChan chan error, maxTests int) {167 for {168 time.Sleep(time.Second * 5)169 infos, err := ioutil.ReadDir(dirName)170 if err != nil {171 fmt.Printf("Error killing process: %v\n", err)172 cmd.Process.Kill()173 errChan <- errors.Wrapf(err, "can't open the directory %q", dirName)174 }175 if len(infos) > maxTests {176 fmt.Printf("Max tests exceeded, pausing\n")177 cmd.Process.Signal(os.Interrupt)178 return179 }180 }181}182func createCorpus(n int) {183 const dir = "corpus"184 ensureDirs(dir)185 for i := 0; i < n; i++ {186 elem, err := fuzzer.CreateNewCorpusElement()187 if err != nil {188 fmt.Printf("Error while creating corpus: %v\n", err)189 }190 hash := sha1.Sum(elem)191 filename := fmt.Sprintf("%v/%v", dir, common.Bytes2Hex(hash[:]))192 if err := ioutil.WriteFile(filename, elem, 0755); err != nil {193 fmt.Printf("Error while writing corpus element: %v\n", err)194 }195 }196}197func minimizeCorpus() {198 const dir = "corpus"199 ensureDirs(dir)200 infos, err := ioutil.ReadDir(dirName)201 if err != nil {202 panic(err)203 }204 toDelete := make(map[string]struct{})205 for i, info := range infos {206 f, err := ioutil.ReadFile(info.Name())207 if err != nil {208 continue209 }210 for k, info2 := range infos {211 if k == i {...

Full Screen

Full Screen

flags.go

Source:flags.go Github

copy

Full Screen

...60 Name: "corpus",61 Usage: "Number of corpus elements that should be created",62 }63 corpusMinimizeFlag = cli.BoolFlag{64 Name: "minimizeCorpus",65 Usage: "If minimizeCorpus is set we run the corpus minimizer",66 }67 configFileFlag = cli.StringFlag{68 Name: "config",69 Usage: "Path to the config file required to run FuzzyVM",70 Value: "config.toml",71 }72)...

Full Screen

Full Screen

minimizeCorpus

Using AI Code Generation

copy

Full Screen

1import java.io.IOException;2import java.util.ArrayList;3import java.util.List;4import java.util.Scanner;5public class Main {6 public static void main(String[] args) throws IOException {7 Scanner sc = new Scanner(System.in);8 List<String> corpus = new ArrayList<>();9 String str = sc.nextLine();10 corpus.add(str);11 while(!str.equals("")){12 str = sc.nextLine();13 corpus.add(str);14 }15 corpus.remove(corpus.size()-1);16 List<String> newCorpus = minimizeCorpus(corpus);17 for(String s : newCorpus){18 System.out.println(s);19 }20 }21 public static List<String> minimizeCorpus(List<String> corpus){22 List<String> newCorpus = new ArrayList<>();23 for(String s : corpus){24 if(!newCorpus.contains(s)){25 newCorpus.add(s);26 }27 }28 return newCorpus;29 }30}

Full Screen

Full Screen

minimizeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the lazy dog"))4 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the dog"))5 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the lazy"))6 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the"))7 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over"))8 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps"))9 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox"))10 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown"))11 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick"))12 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The"))13 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", ""))14}15import (16func main() {17 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the lazy dog"))18 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the dog"))19 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the lazy"))20 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over the"))21 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps over"))22 fmt.Println(minimizeCorpus("The quick brown fox jumps over the lazy dog", "The quick brown fox jumps"))23 fmt.Println(minimizeCorpus

Full Screen

Full Screen

minimizeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 rand.Seed(time.Now().UnixNano())4 var (5 canvas := svg.New(os.Stdout)6 canvas.Start(width, height)7 canvas.Rect(0, 0, width, height)8 canvas.Gstyle("fill:none;stroke:black;stroke-width:2")9 canvas.Circle(width/2, height/2, 100)10 canvas.Circle(width/2, height/2, 200)11 canvas.Circle(width/2, height/2, 300)12 canvas.Gend()13 canvas.End()14}15import (16func main() {17 rand.Seed(time.Now().UnixNano())18 var (19 canvas := svg.New(os.Stdout)20 canvas.Start(width, height)21 canvas.Rect(0, 0, width, height)22 canvas.Gstyle("fill:none;stroke:black;stroke-width:2")23 canvas.Circle(width/2, height/2, 100)24 canvas.Circle(width/2, height/2, 200)25 canvas.Circle(width/2, height/2, 300)26 canvas.Gend()27 canvas.End()28}29import (30func main() {31 rand.Seed(time.Now().UnixNano())32 var (33 canvas := svg.New(os.Stdout)34 canvas.Start(width, height)35 canvas.Rect(0, 0, width, height)36 canvas.Gstyle("fill:none;stroke:black;stroke-width:2")37 canvas.Circle(width/2, height/2, 100)38 canvas.Circle(width/2, height/2, 200)39 canvas.Circle(width/2, height/2, 300)40 canvas.Gend()41 canvas.End()42}

Full Screen

Full Screen

minimizeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 corpus, err := ioutil.ReadFile("corpus.txt")4 if err != nil {5 log.Fatal(err)6 }7 stopwords, err := ioutil.ReadFile("stopwords.txt")8 if err != nil {9 log.Fatal(err)10 }11 corpusString := string(corpus)12 stopwordsString := string(stopwords)13 corpusSlice := strings.Fields(corpusString)14 stopwordsSlice := strings.Fields(stopwordsString)15 m := new(main)16 minimizedCorpus := m.minimizeCorpus(corpusSlice, stopwordsSlice)17 err = ioutil.WriteFile("minimizedCorpus.txt", []byte(strings.Join(minimizedCorpus, "18 if err != nil {19 log.Fatal(err)20 }21}22import (23func main() {24 corpus, err := ioutil.ReadFile("corpus.txt")25 if err != nil {26 log.Fatal(err)27 }28 stopwords, err := ioutil.ReadFile("stopwords.txt")29 if err != nil {30 log.Fatal(err)31 }32 corpusString := string(corpus)33 stopwordsString := string(stopwords)34 corpusSlice := strings.Fields(corpusString)35 stopwordsSlice := strings.Fields(stopwordsString)36 m := new(main)37 minimizedCorpus := m.minimizeCorpus(corpusSlice, stopwordsSlice)38 err = ioutil.WriteFile("minimizedCorpus.txt", []byte(strings.Join(minimized

Full Screen

Full Screen

minimizeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f := fuzzy.New()4 f.Add("dog")5 f.Add("dogs")6 f.Add("do

Full Screen

Full Screen

minimizeCorpus

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 file, err := os.Open("C:\\Users\\siddh\\Desktop\\corpus.txt")4 if err != nil {5 fmt.Println(err)6 }7 scanner := bufio.NewScanner(file)8 for scanner.Scan() {

Full Screen

Full Screen

minimizeCorpus

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/ajaykumargupta/MinimizeCorpus/minimizecorpus"3func main() {4 corpus = append(corpus, "Hello")5 corpus = append(corpus, "Hello World")6 corpus = append(corpus, "Hello World!")7 corpus = append(corpus, "Hello World!!")8 corpus = append(corpus, "Hello World!!!")9 corpus = append(corpus, "Hello World!!!!")10 corpus = append(corpus, "Hello World!!!!!")11 corpus = append(corpus, "Hello World!!!!!!")12 corpus = append(corpus, "Hello World!!!!!!!")13 corpus = append(corpus, "Hello World!!!!!!!!")14 corpus = append(corpus, "Hello World!!!!!!!!!")15 corpus = append(corpus, "Hello World!!!!!!!!!!")16 corpus = append(corpus, "Hello World!!!!!!!!!!!")17 corpus = append(corpus, "Hello World!!!!!!!!!!!!")18 corpus = append(corpus, "Hello World!!!!!!!!!!!!!")19 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!")20 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!")21 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!")22 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!")23 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!")24 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!")25 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!")26 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!")27 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!")28 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!")29 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!")30 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!!")31 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!!!")32 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!!!!")33 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!!!!!")34 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")35 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")36 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")37 corpus = append(corpus, "Hello World!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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