How to use resourceCentric method of prog Package

Best Syzkaller code snippet using prog.resourceCentric

rand.go

Source:rand.go Github

copy

Full Screen

...610 return typ.generate(r, s, dir)611}612func (a *ResourceType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {613 if !r.inGenerateResource {614 // Don't allow recursion for resourceCentric/createResource.615 // That can lead to generation of huge programs and may be very slow616 // (esp. if we are generating some failing attempts in createResource already).617 r.inGenerateResource = true618 defer func() { r.inGenerateResource = false }()619 if r.oneOf(4) {620 arg, calls = r.resourceCentric(s, a, dir)621 if arg != nil {622 return623 }624 }625 if r.oneOf(3) {626 arg, calls = r.createResource(s, a, dir)627 if arg != nil {628 return629 }630 }631 }632 if r.nOutOf(9, 10) {633 arg = r.existingResource(s, a, dir)634 if arg != nil {635 return636 }637 }638 special := a.SpecialValues()639 arg = MakeResultArg(a, dir, nil, special[r.Intn(len(special))])640 return641}642func (a *BufferType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {643 switch a.Kind {644 case BufferBlobRand, BufferBlobRange:645 sz := r.randBufLen()646 if a.Kind == BufferBlobRange {647 sz = r.randRange(a.RangeBegin, a.RangeEnd)648 }649 if dir == DirOut {650 return MakeOutDataArg(a, dir, sz), nil651 }652 data := make([]byte, sz)653 for i := range data {654 data[i] = byte(r.Intn(256))655 }656 return MakeDataArg(a, dir, data), nil657 case BufferString:658 data := r.randString(s, a)659 if dir == DirOut {660 return MakeOutDataArg(a, dir, uint64(len(data))), nil661 }662 return MakeDataArg(a, dir, data), nil663 case BufferFilename:664 if dir == DirOut {665 var sz uint64666 switch {667 case !a.Varlen():668 sz = a.Size()669 case r.nOutOf(1, 3):670 sz = r.rand(100)671 case r.nOutOf(1, 2):672 sz = 108 // UNIX_PATH_MAX673 default:674 sz = 4096 // PATH_MAX675 }676 return MakeOutDataArg(a, dir, sz), nil677 }678 return MakeDataArg(a, dir, []byte(r.filename(s, a))), nil679 case BufferGlob:680 return MakeDataArg(a, dir, r.randString(s, a)), nil681 case BufferText:682 if dir == DirOut {683 return MakeOutDataArg(a, dir, uint64(r.Intn(100))), nil684 }685 return MakeDataArg(a, dir, r.generateText(a.Text)), nil686 default:687 panic("unknown buffer kind")688 }689}690func (a *VmaType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {691 npages := r.randPageCount()692 if a.RangeBegin != 0 || a.RangeEnd != 0 {693 npages = a.RangeBegin + uint64(r.Intn(int(a.RangeEnd-a.RangeBegin+1)))694 }695 return r.allocVMA(s, a, dir, npages), nil696}697func (a *FlagsType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {698 return MakeConstArg(a, dir, r.flags(a.Vals, a.BitMask, 0)), nil699}700func (a *ConstType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {701 return MakeConstArg(a, dir, a.Val), nil702}703func (a *IntType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {704 bits := a.TypeBitSize()705 v := r.randInt(bits)706 switch a.Kind {707 case IntRange:708 v = r.randRangeInt(a.RangeBegin, a.RangeEnd, bits, a.Align)709 }710 return MakeConstArg(a, dir, v), nil711}712func (a *ProcType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {713 return MakeConstArg(a, dir, r.rand(int(a.ValuesPerProc))), nil714}715func (a *ArrayType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {716 var count uint64717 switch a.Kind {718 case ArrayRandLen:719 count = r.randArrayLen()720 case ArrayRangeLen:721 count = r.randRange(a.RangeBegin, a.RangeEnd)722 }723 // The resource we are trying to generate may be in the array elements, so create at least 1.724 if r.inGenerateResource && count == 0 {725 count = 1726 }727 var inner []Arg728 for i := uint64(0); i < count; i++ {729 arg1, calls1 := r.generateArg(s, a.Elem, dir)730 inner = append(inner, arg1)731 calls = append(calls, calls1...)732 }733 return MakeGroupArg(a, dir, inner), calls734}735func (a *StructType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {736 args, calls := r.generateArgs(s, a.Fields, dir)737 group := MakeGroupArg(a, dir, args)738 return group, calls739}740func (a *UnionType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {741 index := r.Intn(len(a.Fields))742 optType, optDir := a.Fields[index].Type, a.Fields[index].Dir(dir)743 opt, calls := r.generateArg(s, optType, optDir)744 return MakeUnionArg(a, dir, opt, index), calls745}746func (a *PtrType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {747 // The resource we are trying to generate may be in the pointer,748 // so don't try to create an empty special pointer during resource generation.749 if !r.inGenerateResource && r.oneOf(1000) {750 index := r.rand(len(r.target.SpecialPointers))751 return MakeSpecialPointerArg(a, dir, index), nil752 }753 inner, calls := r.generateArg(s, a.Elem, a.ElemDir)754 arg = r.allocAddr(s, a, dir, inner.Size(), inner)755 return arg, calls756}757func (a *LenType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {758 // Updated later in assignSizesCall.759 return MakeConstArg(a, dir, 0), nil760}761func (a *CsumType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {762 // Filled at runtime by executor.763 return MakeConstArg(a, dir, 0), nil764}765func (r *randGen) existingResource(s *state, res *ResourceType, dir Dir) Arg {766 alltypes := make([][]*ResultArg, 0, len(s.resources))767 for _, res1 := range s.resources {768 alltypes = append(alltypes, res1)769 }770 sort.Slice(alltypes, func(i, j int) bool {771 return alltypes[i][0].Type().Name() < alltypes[j][0].Type().Name()772 })773 var allres []*ResultArg774 for _, res1 := range alltypes {775 name1 := res1[0].Type().Name()776 if r.target.isCompatibleResource(res.Desc.Name, name1) ||777 r.oneOf(50) && r.target.isCompatibleResource(res.Desc.Kind[0], name1) {778 allres = append(allres, res1...)779 }780 }781 if len(allres) == 0 {782 return nil783 }784 return MakeResultArg(res, dir, allres[r.Intn(len(allres))], 0)785}786// Finds a compatible resource with the type `t` and the calls that initialize that resource.787func (r *randGen) resourceCentric(s *state, t *ResourceType, dir Dir) (arg Arg, calls []*Call) {788 var p *Prog789 var resource *ResultArg790 for idx := range r.Perm(len(s.corpus)) {791 p = s.corpus[idx].Clone()792 resources := getCompatibleResources(p, t.TypeName, r)793 if len(resources) > 0 {794 resource = resources[r.Intn(len(resources))]795 break796 }797 }798 // No compatible resource was found.799 if resource == nil {800 return nil, nil801 }...

Full Screen

Full Screen

resourceCentric

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.Open("test.txt")4 if err != nil {5 fmt.Println(err)6 }7 defer f.Close()8 buf := make([]byte, 1024)9 for {10 n, err := f.Read(buf)11 if err != nil {12 fmt.Println(err)13 }14 if n == 0 {15 }16 fmt.Println(string(buf[:n]))17 }18}19import (20func main() {21 f, err := os.Open("test.txt")22 if err != nil {23 fmt.Println(err)24 }25 defer f.Close()26 buf := make([]byte, 1024)27 for {28 n, err := f.Read(buf)29 if err != nil {30 fmt.Println(err)31 }32 if n == 0 {33 }34 fmt.Println(string(buf[:n]))35 }36}37import (38func main() {39 f, err := os.Open("test.txt")40 if err != nil {41 fmt.Println(err)42 }43 defer f.Close()44 buf := make([]byte, 1024)45 for {46 n, err := f.Read(buf)47 if err != nil {48 fmt.Println(err)49 }50 if n == 0 {51 }52 fmt.Println(string(buf[:n]))53 }54}55import (56func main() {57 f, err := os.Open("test.txt")58 if err != nil {59 fmt.Println(err)60 }61 defer f.Close()62 buf := make([]byte, 1024)63 for {64 n, err := f.Read(buf)65 if err != nil {66 fmt.Println(err)67 }68 if n == 0 {69 }70 fmt.Println(string

Full Screen

Full Screen

resourceCentric

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 prog.ResourceCentric()5}6import "fmt"7func ResourceCentric() {8 fmt.Println("Hello ResourceCentric")9}10 /usr/lib/go-1.6/src/prog (from $GOROOT)11 /home/username/go/src/prog (from $GOPATH)12 /usr/lib/go-1.6/src/prog (from $GOROOT)13 /home/username/go/src/prog (from $GOPATH)14 /usr/lib/go-1.6/src/prog (from $GOROOT)15 /home/username/go/src/prog (from $GOPATH)16 /usr/lib/go-1.6/src/prog (from $GOROOT)17 /home/username/go/src/prog (from $GOPATH)18 /usr/lib/go-1.6/src/prog (from $GOROOT)19 /home/username/go/src/prog (from $GOPATH)20 /usr/lib/go-1.6/src/prog (from $GOROOT)21 /home/username/go/src/prog (from $GOPATH)22 /usr/lib/go-1.6/src/prog (from $GOROOT)23 /home/username/go/src/prog (from $GOPATH)24import (

Full Screen

Full Screen

resourceCentric

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := NewProgram()4 res := NewResource()5 prog.resourceCentric(res)6}7import (8func main() {9 prog := NewProgram()10 res := NewResource()11 prog.resourceCentric(res)12}13import (14func main() {15 prog := NewProgram()16 res := NewResource()17 prog.resourceCentric(res)18}19import (20func main() {21 prog := NewProgram()22 res := NewResource()23 prog.resourceCentric(res)24}25import (26func main() {27 prog := NewProgram()28 res := NewResource()29 prog.resourceCentric(res)30}31import (32func main() {33 prog := NewProgram()34 res := NewResource()35 prog.resourceCentric(res)36}37import (38func main() {39 prog := NewProgram()

Full Screen

Full Screen

resourceCentric

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := program.New()4 p.ResourceCentric()5 fmt.Println("Using Resource Centric Method")6}7import (8func main() {9 p := program.New()10 p.ObjectCentric()11 fmt.Println("Using Object Centric Method")12}13import (14func main() {15 p := program.New()16 p.ResourceCentric()17 fmt.Println("Using Resource Centric Method")18}19import (20func main() {21 p := program.New()22 p.ObjectCentric()23 fmt.Println("Using Object Centric Method")24}25import (26func main() {27 p := program.New()28 p.ResourceCentric()29 fmt.Println("Using Resource Centric Method")30}31import (32func main() {33 p := program.New()34 p.ObjectCentric()35 fmt.Println("Using Object Centric Method")36}37import (38func main() {39 p := program.New()40 p.ResourceCentric()41 fmt.Println("Using Resource Centric Method")42}43import (44func main() {

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