How to use TestParsing method of runtest Package

Best Syzkaller code snippet using runtest.TestParsing

runtest.go

Source:runtest.go Github

copy

Full Screen

1// Copyright 2018 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.3// Runtest runs syzkaller test programs in sys/*/test/*. Start as:4// $ syz-runtest -config manager.config5// Also see pkg/runtest docs.6package main7import (8 "errors"9 "flag"10 "fmt"11 "io/ioutil"12 "log"13 "net"14 "os"15 "path/filepath"16 "strings"17 "sync"18 "time"19 "github.com/google/syzkaller/pkg/instance"20 "github.com/google/syzkaller/pkg/mgrconfig"21 "github.com/google/syzkaller/pkg/osutil"22 "github.com/google/syzkaller/pkg/report"23 "github.com/google/syzkaller/pkg/rpctype"24 "github.com/google/syzkaller/pkg/runtest"25 "github.com/google/syzkaller/prog"26 _ "github.com/google/syzkaller/sys"27 "github.com/google/syzkaller/sys/targets"28 "github.com/google/syzkaller/vm"29)30var (31 flagConfig = flag.String("config", "", "manager config")32 flagDebug = flag.Bool("debug", false, "debug mode")33 flagTests = flag.String("tests", "", "prefix to match test file names")34)35func main() {36 flag.Parse()37 cfg, err := mgrconfig.LoadFile(*flagConfig)38 if err != nil {39 log.Fatal(err)40 }41 target, err := prog.GetTarget(cfg.TargetOS, cfg.TargetArch)42 if err != nil {43 log.Fatal(err)44 }45 testDir := filepath.Join(cfg.Syzkaller, "sys", target.OS, "test")46 if err := testParsing(target, testDir); err != nil {47 log.Fatal(err)48 }49 vmPool, err := vm.Create(cfg, *flagDebug)50 if err != nil {51 log.Fatal(err)52 }53 reporter, err := report.NewReporter(cfg)54 if err != nil {55 log.Fatal(err)56 }57 osutil.MkdirAll(cfg.Workdir)58 mgr := &Manager{59 cfg: cfg,60 target: target,61 vmPool: vmPool,62 reporter: reporter,63 debug: *flagDebug,64 requests: make(chan *runtest.RunRequest, 2*vmPool.Count()),65 checkResultC: make(chan *rpctype.CheckArgs, 1),66 checkResultReady: make(chan bool),67 vmStop: make(chan bool),68 reqMap: make(map[int]*runtest.RunRequest),69 lastReq: make(map[string]int),70 }71 s, err := rpctype.NewRPCServer(cfg.RPC, "Manager", mgr)72 if err != nil {73 log.Fatalf("failed to create rpc server: %v", err)74 }75 mgr.port = s.Addr().(*net.TCPAddr).Port76 go s.Serve()77 var wg sync.WaitGroup78 wg.Add(vmPool.Count())79 fmt.Printf("booting VMs...\n")80 for i := 0; i < vmPool.Count(); i++ {81 i := i82 go func() {83 defer wg.Done()84 name := fmt.Sprintf("vm-%v", i)85 for {86 rep, err := mgr.boot(name, i)87 if err != nil {88 log.Fatal(err)89 }90 if rep == nil {91 return92 }93 if err := mgr.finishRequest(name, rep); err != nil {94 log.Fatal(err)95 }96 }97 }()98 }99 mgr.checkResult = <-mgr.checkResultC100 close(mgr.checkResultReady)101 enabledCalls := make(map[string]map[*prog.Syscall]bool)102 for sandbox, ids := range mgr.checkResult.EnabledCalls {103 calls := make(map[*prog.Syscall]bool)104 for _, id := range ids {105 calls[target.Syscalls[id]] = true106 }107 enabledCalls[sandbox] = calls108 }109 for _, feat := range mgr.checkResult.Features.Supported() {110 fmt.Printf("%-24v: %v\n", feat.Name, feat.Reason)111 }112 for sandbox, calls := range enabledCalls {113 if sandbox == "" {114 sandbox = "no"115 }116 fmt.Printf("%-24v: %v calls enabled\n", sandbox+" sandbox", len(calls))117 }118 ctx := &runtest.Context{119 Dir: testDir,120 Target: target,121 Features: mgr.checkResult.Features,122 EnabledCalls: enabledCalls,123 Requests: mgr.requests,124 LogFunc: func(text string) { fmt.Println(text) },125 Verbose: false,126 Debug: *flagDebug,127 Tests: *flagTests,128 }129 err = ctx.Run()130 close(vm.Shutdown)131 wg.Wait()132 if err != nil {133 fmt.Println(err)134 os.Exit(1)135 }136}137type Manager struct {138 cfg *mgrconfig.Config139 target *prog.Target140 vmPool *vm.Pool141 reporter report.Reporter142 requests chan *runtest.RunRequest143 checkResult *rpctype.CheckArgs144 checkResultReady chan bool145 checkResultC chan *rpctype.CheckArgs146 vmStop chan bool147 port int148 debug bool149 reqMu sync.Mutex150 reqSeq int151 reqMap map[int]*runtest.RunRequest152 lastReq map[string]int153}154func (mgr *Manager) boot(name string, index int) (*report.Report, error) {155 inst, err := mgr.vmPool.Create(index)156 if err != nil {157 return nil, fmt.Errorf("failed to create instance: %v", err)158 }159 defer inst.Close()160 fwdAddr, err := inst.Forward(mgr.port)161 if err != nil {162 return nil, fmt.Errorf("failed to setup port forwarding: %v", err)163 }164 fuzzerBin, err := inst.Copy(mgr.cfg.SyzFuzzerBin)165 if err != nil {166 return nil, fmt.Errorf("failed to copy binary: %v", err)167 }168 // If SyzExecutorCmd is provided, it means that syz-executor is already in169 // the image, so no need to copy it.170 executorCmd := targets.Get(mgr.cfg.TargetOS, mgr.cfg.TargetArch).SyzExecutorCmd171 if executorCmd == "" {172 executorCmd, err = inst.Copy(mgr.cfg.SyzExecutorBin)173 if err != nil {174 return nil, fmt.Errorf("failed to copy binary: %v", err)175 }176 }177 cmd := instance.FuzzerCmd(fuzzerBin, executorCmd, name,178 mgr.cfg.TargetOS, mgr.cfg.TargetArch, fwdAddr, mgr.cfg.Sandbox, mgr.cfg.Procs, 0,179 mgr.cfg.Cover, mgr.debug, false, true)180 outc, errc, err := inst.Run(time.Hour, mgr.vmStop, cmd)181 if err != nil {182 return nil, fmt.Errorf("failed to run fuzzer: %v", err)183 }184 rep := inst.MonitorExecution(outc, errc, mgr.reporter, vm.ExitNormal)185 return rep, nil186}187func (mgr *Manager) finishRequest(name string, rep *report.Report) error {188 mgr.reqMu.Lock()189 defer mgr.reqMu.Unlock()190 lastReq := mgr.lastReq[name]191 req := mgr.reqMap[lastReq]192 if lastReq == 0 || req == nil {193 return fmt.Errorf("vm crash: %v\n%s\n%s", rep.Title, rep.Report, rep.Output)194 }195 delete(mgr.reqMap, lastReq)196 delete(mgr.lastReq, name)197 req.Err = fmt.Errorf("%v", rep.Title)198 req.Output = rep.Report199 if len(req.Output) == 0 {200 req.Output = rep.Output201 }202 close(req.Done)203 return nil204}205func (mgr *Manager) Connect(a *rpctype.ConnectArgs, r *rpctype.ConnectRes) error {206 r.GitRevision = prog.GitRevision207 r.TargetRevision = mgr.target.Revision208 r.AllSandboxes = true209 select {210 case <-mgr.checkResultReady:211 r.CheckResult = mgr.checkResult212 default:213 }214 return nil215}216func (mgr *Manager) Check(a *rpctype.CheckArgs, r *int) error {217 if a.Error != "" {218 log.Fatalf("machine check: %v", a.Error)219 }220 select {221 case mgr.checkResultC <- a:222 default:223 }224 return nil225}226func (mgr *Manager) Poll(a *rpctype.RunTestPollReq, r *rpctype.RunTestPollRes) error {227 req := <-mgr.requests228 if req == nil {229 return nil230 }231 mgr.reqMu.Lock()232 if mgr.lastReq[a.Name] != 0 {233 log.Fatalf("double poll req from %v", a.Name)234 }235 mgr.reqSeq++236 r.ID = mgr.reqSeq237 mgr.reqMap[mgr.reqSeq] = req238 mgr.lastReq[a.Name] = mgr.reqSeq239 mgr.reqMu.Unlock()240 if req.Bin != "" {241 data, err := ioutil.ReadFile(req.Bin)242 if err != nil {243 log.Fatalf("failed to read bin file: %v", err)244 }245 r.Bin = data246 return nil247 }248 r.Prog = req.P.Serialize()249 r.Cfg = req.Cfg250 r.Opts = req.Opts251 r.Repeat = req.Repeat252 return nil253}254func (mgr *Manager) Done(a *rpctype.RunTestDoneArgs, r *int) error {255 mgr.reqMu.Lock()256 lastReq := mgr.lastReq[a.Name]257 if lastReq != a.ID {258 log.Fatalf("wrong done id %v from %v", a.ID, a.Name)259 }260 req := mgr.reqMap[a.ID]261 delete(mgr.reqMap, a.ID)262 delete(mgr.lastReq, a.Name)263 mgr.reqMu.Unlock()264 if req == nil {265 log.Fatalf("got done request for unknown id %v", a.ID)266 }267 req.Output = a.Output268 req.Info = a.Info269 if a.Error != "" {270 req.Err = errors.New(a.Error)271 }272 close(req.Done)273 return nil274}275func testParsing(target *prog.Target, dir string) error {276 files, err := ioutil.ReadDir(dir)277 if err != nil {278 return fmt.Errorf("failed to read %v: %v", dir, err)279 }280 for _, file := range files {281 if strings.HasSuffix(file.Name(), "~") {282 continue283 }284 if strings.HasSuffix(file.Name(), ".swp") {285 continue286 }287 if !strings.HasPrefix(file.Name(), *flagTests) {288 continue289 }290 if err := runtest.TestParseProg(target, dir, file.Name()); err != nil {291 return err292 }293 }294 return nil295}...

Full Screen

Full Screen

TestParsing

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 runtest.TestParsing()5}6import (7type Person struct {8}9func TestParsing() {10 data := []byte(`{"Name": "Bob", "Age": 32}`)11 err := json.Unmarshal(data, &p)12 if err != nil {13 fmt.Println("error:", err)14 }15 fmt.Printf("%+v16}17{Name:Bob Age:32}

Full Screen

Full Screen

TestParsing

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "log"3import "os"4import "os/exec"5func main() {6cmd := exec.Command("go", "test", "-v")7err := cmd.Run()8if err != nil {9log.Fatal(err)10}11}12import "fmt"13import "log"14import "os"15import "os/exec"16func main() {17cmd := exec.Command("go", "test", "-v")18err := cmd.Run()19if err != nil {20log.Fatal(err)21}22}23import "fmt"24import "log"25import "os"26import "os/exec"27func main() {28cmd := exec.Command("go", "test", "-v")29err := cmd.Run()30if err != nil {31log.Fatal(err)32}33}34import "fmt"35import "log"36import "os"37import "os/exec"38func main() {39cmd := exec.Command("go", "test", "-v")40err := cmd.Run()41if err != nil {42log.Fatal(err)43}44}45import "fmt"46import "log"47import "os"48import "os/exec"49func main() {50cmd := exec.Command("go", "test", "-v")51err := cmd.Run()52if err != nil {53log.Fatal(err)54}55}56import "fmt"57import "log"58import "os"59import "os/exec"60func main() {61cmd := exec.Command("go", "test", "-v")62err := cmd.Run()63if err != nil {64log.Fatal(err)65}66}

Full Screen

Full Screen

TestParsing

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 runtest.TestParsing()4 fmt.Println("Hello World")5}6import (7func TestParsing() {8 fmt.Println("Test Parsing")9 reader := bufio.NewReader(os.Stdin)10 fmt.Print("Enter text: ")11 text, _ := reader.ReadString('12 fmt.Println(text)13 fmt.Print("Enter a number: ")14 text, _ = reader.ReadString('15 fmt.Println(text)16 f, err := strconv.ParseFloat(strings.TrimSpace(text), 64)17 if err != nil {18 fmt.Println(err)19 } else {20 fmt.Println("Value of number:", f)21 }22}23import (24func main() {25 fmt.Println("Hello World")26 fmt.Println("My favorite number is", rand.Intn(10))27}28You can import multiple packages

Full Screen

Full Screen

TestParsing

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 runtest.TestParsing()5}6import (7func TestParsing() {8 if err != nil {9 log.Fatal(err)10 }11 defer resp.Body.Close()12 body, err := ioutil.ReadAll(resp.Body)13 fmt.Println(string(body))14}15× Email codedump link for How to resolve "imported and not used" error in Go

Full Screen

Full Screen

TestParsing

Using AI Code Generation

copy

Full Screen

1import "testing"2func TestParsing(t *testing.T) {3 var tests = []struct {4 }{5 {"1+2", true},6 {"1+2+3", true},7 {"1+2+3+4", true},8 {"1+2+3+4+5", true},9 {"1+2+3+4+5+6", true},10 {"1+2+3+4+5+6+7", true},11 {"1+2+3+4+5+6+7+8", true},12 {"1+2+3+4+5+6+7+8+9", true},13 {"1+2+3+4+5+6+7+8+9+10", true},14 {"1+2+3+4+5+6+7+8+9+10+11", true},15 {"1+2+3+4+5+6+7+8+9+10+11+12", true},16 {"1+2+3+4+5+6+7+8+9+10+11+12+13", true},17 {"1+2+3+4+5+6+7+8+9+10+11+12+13+14", true},18 {"1+2+3+4+5+6+7+8+9+10+11+12+13+14+15", true},19 {"1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16", true},20 {"1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17", true},21 {"1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18", true},22 {"1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19", true},23 {"1+2+3+4+5+6

Full Screen

Full Screen

TestParsing

Using AI Code Generation

copy

Full Screen

1import (2type runtest struct {3}4func main() {5 jsonFile, err := os.Open("test.json")6 if err != nil {7 fmt.Println(err)8 }9 fmt.Println("Successfully Opened test.json")10 defer jsonFile.Close()11 byteValue, _ := ioutil.ReadAll(jsonFile)12 err = json.Unmarshal(byteValue, &conf)13 if err != nil {14 fmt.Println(err)15 }16 fmt.Println("TestName: " + TestName)17 fmt.Println("TestID: " + strconv.Itoa(TestID))18 fmt.Println("TestDuration: " + strconv.FormatFloat(TestDuration, 'f', 6, 64))19 fmt.Println("TestType: " + TestType)20 fmt.Println("TestStatus: " + TestStatus)21 fmt.Println("TestResult: " + TestResult)22 fmt.Println("TestStartTime: " + TestStartTime)23 fmt.Println("TestEndTime: " +

Full Screen

Full Screen

TestParsing

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(runtest.TestParsing())4}5import (6func main() {7 fmt.Println(runtest.TestParsing())8}9import (10func TestParsing() string {11 t, err := time.Parse(time.RFC3339, timeString)12 if err != nil {13 return fmt.Sprintf("Error: %s", err)14 }15 return fmt.Sprintf("Success: %s", t)16}17 /usr/local/go/src/github.com/ashishra0/GoLangExercises/test/runtest (from $GOROOT)18 /home/ashish/go/src/github.com/ashishra0/GoLangExercises/test/runtest (from $GOPATH)

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