How to use testRepro method of instance Package

Best Syzkaller code snippet using instance.testRepro

instance.go

Source:instance.go Github

copy

Full Screen

...213 if err := inst.testInstance(); err != nil {214 return err215 }216 if len(inst.reproSyz) != 0 {217 if err := inst.testRepro(); err != nil {218 return err219 }220 }221 return nil222}223// testInstance tests basic operation of the provided VM224// (that we can copy binaries, run binaries, they can connect to host, run syzkaller programs, etc).225// TestError is returned if there is a problem with the kernel (e.g. crash).226func (inst *inst) testInstance() error {227 ln, err := net.Listen("tcp", ":")228 if err != nil {229 return fmt.Errorf("failed to open listening socket: %v", err)230 }231 defer ln.Close()232 acceptErr := make(chan error, 1)233 go func() {234 conn, err := ln.Accept()235 if err == nil {236 conn.Close()237 }238 acceptErr <- err239 }()240 fwdAddr, err := inst.vm.Forward(ln.Addr().(*net.TCPAddr).Port)241 if err != nil {242 return fmt.Errorf("failed to setup port forwarding: %v", err)243 }244 fuzzerBin, err := inst.vm.Copy(inst.cfg.SyzFuzzerBin)245 if err != nil {246 return &TestError{Title: fmt.Sprintf("failed to copy test binary to VM: %v", err)}247 }248 executorBin, err := inst.vm.Copy(inst.cfg.SyzExecutorBin)249 if err != nil {250 return &TestError{Title: fmt.Sprintf("failed to copy test binary to VM: %v", err)}251 }252 cmd := FuzzerCmd(fuzzerBin, executorBin, "test", inst.cfg.TargetOS, inst.cfg.TargetArch, fwdAddr,253 inst.cfg.Sandbox, 0, 0, false, false, true, false)254 outc, errc, err := inst.vm.Run(5*time.Minute, nil, cmd)255 if err != nil {256 return fmt.Errorf("failed to run binary in VM: %v", err)257 }258 rep := inst.vm.MonitorExecution(outc, errc, inst.reporter, true)259 if rep != nil {260 if err := inst.reporter.Symbolize(rep); err != nil {261 // TODO(dvyukov): send such errors to dashboard.262 log.Logf(0, "failed to symbolize report: %v", err)263 }264 return &TestError{265 Title: rep.Title,266 Report: rep,267 }268 }269 select {270 case err := <-acceptErr:271 return err272 case <-time.After(10 * time.Second):273 return fmt.Errorf("test machine failed to connect to host")274 }275}276func (inst *inst) testRepro() error {277 cfg := inst.cfg278 execprogBin, err := inst.vm.Copy(cfg.SyzExecprogBin)279 if err != nil {280 return &TestError{Title: fmt.Sprintf("failed to copy test binary to VM: %v", err)}281 }282 executorBin, err := inst.vm.Copy(cfg.SyzExecutorBin)283 if err != nil {284 return &TestError{Title: fmt.Sprintf("failed to copy test binary to VM: %v", err)}285 }286 progFile := filepath.Join(cfg.Workdir, "repro.prog")287 if err := osutil.WriteFile(progFile, inst.reproSyz); err != nil {288 return fmt.Errorf("failed to write temp file: %v", err)289 }290 vmProgFile, err := inst.vm.Copy(progFile)...

Full Screen

Full Screen

Repo_test.go

Source:Repo_test.go Github

copy

Full Screen

1package repro2import (3 "context"4 "log"5 "sync"6 "sync/atomic"7 "testing"8 "time"9 "github.com/sttp/goapi/sttp"10)11const (12 query = "FILTER TOP 20 ActiveMeasurements WHERE SignalType <> 'STAT'"13 target = "127.0.0.1:7165" // 7165 default for openPDC, 7175 default for openHistorian14)15func run(dst string, query string, count int, instance int) {16 sub := sttp.NewSubscriber()17 conf := sttp.NewConfig()18 if instance < 0 {19 // Disable screen feedback for benchmarking20 sub.SetStatusMessageLogger(nil)21 sub.SetErrorMessageLogger(nil)22 } else {23 sub.SetStatusMessageLogger(func(msg string) {24 log.Println("Instance", instance, msg)25 })26 sub.SetErrorMessageLogger(func(msg string) {27 log.Println("Instance", instance, "error:", msg)28 })29 }30 sub.Subscribe(query, nil)31 conf.AutoRequestMetadata = false32 conf.MaxRetries = 333 if err := sub.Dial(dst, conf); err != nil {34 log.Println("Instance", instance, err, "-- canceling instance")35 return36 }37 reader := sub.ReadMeasurements()38 const timeout = 5 // seconds39 ctx, cancel := context.WithTimeout(context.Background(), timeout*time.Second)40 defer cancel()41 for sub.IsConnected() {42 if _, timeoutExpired := reader.NextMeasurement(ctx); timeoutExpired {43 log.Println("Instance", instance, "measurement read timed out after", timeout, "seconds -- canceling instance")44 break45 }46 count--47 if count <= 0 {48 break49 }50 if count%200 == 0 && instance > -1 {51 log.Println("Instance", instance, "received", count, "measurements so far...")52 }53 }54 sub.Close()55}56func TestRepro(t *testing.T) {57 const (58 instances = 10059 measurements = 100060 )61 wg := sync.WaitGroup{}62 wg.Add(instances)63 var count int32 = instances64 for i := 0; i < instances; i++ {65 go func(instance int) {66 run(target, query, measurements, instance)67 wg.Done()68 atomic.AddInt32(&count, -1)69 log.Println("Instance", instance, "done,", atomic.LoadInt32(&count), "remaining")70 }(i)71 }72 wg.Wait()73}74// Execute this bench test only: go test -bench ProcessMeasurements -run=^$ -count 575func BenchmarkProcessMeasurements(b *testing.B) {76 run(target, query, 1000, -1)77}...

Full Screen

Full Screen

testRepro

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

testRepro

Using AI Code Generation

copy

Full Screen

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

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