How to use testProgs method of repro Package

Best Syzkaller code snippet using repro.testProgs

repro.go

Source:repro.go Github

copy

Full Screen

...314 return baseDuration + time.Duration((entries/4))*time.Second315 }316 // Bisect the log to find multiple guilty programs.317 entries, err := ctx.bisectProgs(entries, func(progs []*prog.LogEntry) (bool, error) {318 return ctx.testProgs(progs, duration(len(progs)), opts)319 })320 if err != nil {321 return nil, err322 }323 if len(entries) == 0 {324 return nil, nil325 }326 // TODO: Minimize each program before concatenation.327 // TODO: Return multiple programs if concatenation fails.328 ctx.reproLog(3, "bisect: %d programs left: \n\n%s\n", len(entries), encodeEntries(entries))329 ctx.reproLog(3, "bisect: trying to concatenate")330 // Concatenate all programs into one.331 prog := &prog.Prog{332 Target: entries[0].P.Target,333 }334 for _, entry := range entries {335 prog.Calls = append(prog.Calls, entry.P.Calls...)336 }337 dur := duration(len(entries)) * 3 / 2338 // Execute the program without fault injection.339 crashed, err := ctx.testProg(prog, dur, opts)340 if err != nil {341 return nil, err342 }343 if crashed {344 res := &Result{345 Prog: prog,346 Duration: dur,347 Opts: opts,348 }349 ctx.reproLog(3, "bisect: concatenation succeeded")350 return res, nil351 }352 // Try with fault injection.353 calls := 0354 for _, entry := range entries {355 if entry.Fault {356 opts.FaultCall = calls + entry.FaultCall357 opts.FaultNth = entry.FaultNth358 if entry.FaultCall < 0 || entry.FaultCall >= len(entry.P.Calls) {359 opts.FaultCall = calls + len(entry.P.Calls) - 1360 }361 crashed, err := ctx.testProg(prog, dur, opts)362 if err != nil {363 return nil, err364 }365 if crashed {366 res := &Result{367 Prog: prog,368 Duration: dur,369 Opts: opts,370 }371 ctx.reproLog(3, "bisect: concatenation succeeded with fault injection")372 return res, nil373 }374 }375 calls += len(entry.P.Calls)376 }377 ctx.reproLog(3, "bisect: concatenation failed")378 return nil, nil379}380// Minimize calls and arguments.381func (ctx *context) minimizeProg(res *Result) (*Result, error) {382 ctx.reproLog(2, "minimizing guilty program")383 start := time.Now()384 defer func() {385 ctx.stats.MinimizeProgTime = time.Since(start)386 }()387 call := -1388 if res.Opts.Fault {389 call = res.Opts.FaultCall390 }391 res.Prog, res.Opts.FaultCall = prog.Minimize(res.Prog, call, true,392 func(p1 *prog.Prog, callIndex int) bool {393 crashed, err := ctx.testProg(p1, res.Duration, res.Opts)394 if err != nil {395 ctx.reproLog(0, "minimization failed with %v", err)396 return false397 }398 return crashed399 })400 return res, nil401}402// Simplify repro options (threaded, collide, sandbox, etc).403func (ctx *context) simplifyProg(res *Result) (*Result, error) {404 ctx.reproLog(2, "simplifying guilty program")405 start := time.Now()406 defer func() {407 ctx.stats.SimplifyProgTime = time.Since(start)408 }()409 for _, simplify := range progSimplifies {410 opts := res.Opts411 if simplify(&opts) {412 crashed, err := ctx.testProg(res.Prog, res.Duration, opts)413 if err != nil {414 return nil, err415 }416 if crashed {417 res.Opts = opts418 // Simplification successful, try extracting C repro.419 res, err := ctx.extractC(res)420 if err != nil {421 return nil, err422 }423 if res.CRepro {424 return res, nil425 }426 }427 }428 }429 return res, nil430}431// Try triggering crash with a C reproducer.432func (ctx *context) extractC(res *Result) (*Result, error) {433 ctx.reproLog(2, "extracting C reproducer")434 start := time.Now()435 defer func() {436 ctx.stats.ExtractCTime = time.Since(start)437 }()438 crashed, err := ctx.testCProg(res.Prog, res.Duration, res.Opts)439 if err != nil {440 return nil, err441 }442 res.CRepro = crashed443 return res, nil444}445// Try to simplify the C reproducer.446func (ctx *context) simplifyC(res *Result) (*Result, error) {447 ctx.reproLog(2, "simplifying C reproducer")448 start := time.Now()449 defer func() {450 ctx.stats.SimplifyCTime = time.Since(start)451 }()452 for _, simplify := range cSimplifies {453 opts := res.Opts454 if simplify(&opts) {455 crashed, err := ctx.testCProg(res.Prog, res.Duration, opts)456 if err != nil {457 return nil, err458 }459 if crashed {460 res.Opts = opts461 }462 }463 }464 return res, nil465}466func (ctx *context) testProg(p *prog.Prog, duration time.Duration, opts csource.Options) (crashed bool, err error) {467 entry := prog.LogEntry{P: p}468 if opts.Fault {469 entry.Fault = true470 entry.FaultCall = opts.FaultCall471 entry.FaultNth = opts.FaultNth472 }473 return ctx.testProgs([]*prog.LogEntry{&entry}, duration, opts)474}475func (ctx *context) testProgs(entries []*prog.LogEntry, duration time.Duration, opts csource.Options) (476 crashed bool, err error) {477 inst := <-ctx.instances478 if inst == nil {479 return false, fmt.Errorf("all VMs failed to boot")480 }481 defer ctx.returnInstance(inst)482 if len(entries) == 0 {483 return false, fmt.Errorf("no programs to execute")484 }485 pstr := encodeEntries(entries)486 progFile, err := osutil.WriteTempFile(pstr)487 if err != nil {488 return false, err489 }...

Full Screen

Full Screen

testProgs

Using AI Code Generation

copy

Full Screen

1func testProgs() {2}3func main() {4}5func main() {6}7func testProgs() {

Full Screen

Full Screen

testProgs

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

testProgs

Using AI Code Generation

copy

Full Screen

1import (2func main() {3}4type Repro struct {5}6func (r *Repro) testProgs() {

Full Screen

Full Screen

testProgs

Using AI Code Generation

copy

Full Screen

1import (2type repro struct {3}4func (r repro) testProgs() string {5 cmd := exec.Command(r.testProgPath)6 out, err := cmd.CombinedOutput()7 if err != nil {8 panic(err)9 }10 return string(out)11}12func main() {13 r := repro{14 }15 output := r.testProgs()16 fmt.Println(output)17 if output == r.expectedOutput {18 fmt.Println("Test Passed!")19 } else {20 fmt.Println("Test Failed!")21 }22}

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