How to use assignSizesCall method of prog Package

Best Syzkaller code snippet using prog.assignSizesCall

minimization.go

Source:minimization.go Github

copy

Full Screen

...78 (typ.Kind == ArrayRandLen) {79 copy(a.Inner[i:], a.Inner[i+1:])80 a.Inner = a.Inner[:len(a.Inner)-1]81 removeArg(innerArg)82 p.Target.assignSizesCall(call)83 if pred(p, callIndex0) {84 p0 = p85 } else {86 triedPaths[innerPath] = true87 }88 return true89 }90 }91 if rec(p, call, innerArg, innerPath) {92 return true93 }94 }95 case *IntType, *FlagsType, *ProcType:96 // TODO: try to reset bits in ints97 // TODO: try to set separate flags98 if crash {99 return false100 }101 if triedPaths[path] {102 return false103 }104 triedPaths[path] = true105 a := arg.(*ConstArg)106 if a.Val == typ.Default() {107 return false108 }109 v0 := a.Val110 a.Val = typ.Default()111 if pred(p, callIndex0) {112 p0 = p113 return true114 }115 a.Val = v0116 case *ResourceType:117 if crash {118 return false119 }120 if triedPaths[path] {121 return false122 }123 triedPaths[path] = true124 a := arg.(*ResultArg)125 if a.Res == nil {126 return false127 }128 r0 := a.Res129 a.Res = nil130 a.Val = typ.Default()131 if pred(p, callIndex0) {132 p0 = p133 return true134 }135 a.Res = r0136 a.Val = 0137 case *BufferType:138 // TODO: try to set individual bytes to 0139 if triedPaths[path] {140 return false141 }142 triedPaths[path] = true143 if typ.Kind != BufferBlobRand && typ.Kind != BufferBlobRange ||144 typ.Dir() == DirOut {145 return false146 }147 a := arg.(*DataArg)148 minLen := int(typ.RangeBegin)149 for step := len(a.Data()) - minLen; len(a.Data()) > minLen && step > 0; {150 if len(a.Data())-step >= minLen {151 a.data = a.Data()[:len(a.Data())-step]152 p.Target.assignSizesCall(call)153 if pred(p, callIndex0) {154 continue155 }156 a.data = a.Data()[:len(a.Data())+step]157 p.Target.assignSizesCall(call)158 }159 step /= 2160 if crash {161 break162 }163 }164 p0 = p165 case *VmaType, *LenType, *CsumType, *ConstType:166 return false167 default:168 panic(fmt.Sprintf("unknown arg type '%+v'", typ))169 }170 return false171 }172 // Try to minimize individual args.173 for i := 0; i < len(p0.Calls); i++ {174 triedPaths = make(map[string]bool)175 again:176 p := p0.Clone()177 call := p.Calls[i]178 for j, arg := range call.Args {179 if rec(p, call, arg, fmt.Sprintf("%v", j)) {180 goto again181 }182 }183 }184 if callIndex0 != -1 {185 if callIndex0 < 0 || callIndex0 >= len(p0.Calls) || name0 != p0.Calls[callIndex0].Meta.Name {186 panic(fmt.Sprintf("bad call index after minimization: ncalls=%v index=%v call=%v/%v",187 len(p0.Calls), callIndex0, name0, p0.Calls[callIndex0].Meta.Name))188 }189 }190 return p0, callIndex0191}192func MinimizeRace(p0 *Prog, callIndex0 int, crash bool, pred0 func(*Prog, int, [2]int) bool, index0 [2]int) (*Prog, int, [2]int) {193 pred := pred0194 if debug {195 pred = func(p *Prog, callIndex int, index [2]int) bool {196 if err := p.validate(); err != nil {197 panic(err)198 }199 return pred0(p, callIndex, index)200 }201 }202 name0 := ""203 if callIndex0 != -1 {204 if callIndex0 < 0 || callIndex0 >= len(p0.Calls) {205 panic("bad call index")206 }207 name0 = p0.Calls[callIndex0].Meta.Name208 }209 // Try to remove all calls except the last one one-by-one.210 for i := len(p0.Calls) - 1; i >= 0; i-- {211 if i == callIndex0 || i == index0[0] || i == index0[1] {212 continue213 }214 callIndex := callIndex0215 index := index0216 if i < callIndex {217 callIndex--218 }219 if i < index[0] {220 index[0]--221 }222 if i < index[1] {223 index[1]--224 }225 p := p0.Clone()226 p.removeCall(i)227 if !pred(p, callIndex, index) {228 continue229 }230 p0 = p231 callIndex0 = callIndex232 index0 = index233 }234 var triedPaths map[string]bool235 var rec func(p *Prog, call *Call, arg Arg, path string) bool236 rec = func(p *Prog, call *Call, arg Arg, path string) bool {237 path += fmt.Sprintf("-%v", arg.Type().FieldName())238 switch typ := arg.Type().(type) {239 case *StructType:240 a := arg.(*GroupArg)241 for _, innerArg := range a.Inner {242 if rec(p, call, innerArg, path) {243 return true244 }245 }246 case *UnionType:247 a := arg.(*UnionArg)248 if rec(p, call, a.Option, path) {249 return true250 }251 case *PtrType:252 // TODO: try to remove optional ptrs253 a, ok := arg.(*PointerArg)254 if !ok {255 // Can also be *ConstArg.256 return false257 }258 if a.Res != nil {259 return rec(p, call, a.Res, path)260 }261 case *ArrayType:262 a := arg.(*GroupArg)263 for i, innerArg := range a.Inner {264 innerPath := fmt.Sprintf("%v-%v", path, i)265 if !triedPaths[innerPath] && !crash {266 if (typ.Kind == ArrayRangeLen && len(a.Inner) > int(typ.RangeBegin)) ||267 (typ.Kind == ArrayRandLen) {268 copy(a.Inner[i:], a.Inner[i+1:])269 a.Inner = a.Inner[:len(a.Inner)-1]270 removeArg(innerArg)271 p.Target.assignSizesCall(call)272 if pred(p, callIndex0, index0) {273 p0 = p274 } else {275 triedPaths[innerPath] = true276 }277 return true278 }279 }280 if rec(p, call, innerArg, innerPath) {281 return true282 }283 }284 case *IntType, *FlagsType, *ProcType:285 // TODO: try to reset bits in ints286 // TODO: try to set separate flags287 if crash {288 return false289 }290 if triedPaths[path] {291 return false292 }293 triedPaths[path] = true294 a := arg.(*ConstArg)295 if a.Val == typ.Default() {296 return false297 }298 v0 := a.Val299 a.Val = typ.Default()300 if pred(p, callIndex0, index0) {301 p0 = p302 return true303 }304 a.Val = v0305 case *ResourceType:306 if crash {307 return false308 }309 if triedPaths[path] {310 return false311 }312 triedPaths[path] = true313 a := arg.(*ResultArg)314 if a.Res == nil {315 return false316 }317 r0 := a.Res318 a.Res = nil319 a.Val = typ.Default()320 if pred(p, callIndex0, index0) {321 p0 = p322 return true323 }324 a.Res = r0325 a.Val = 0326 case *BufferType:327 // TODO: try to set individual bytes to 0328 if triedPaths[path] {329 return false330 }331 triedPaths[path] = true332 if typ.Kind != BufferBlobRand && typ.Kind != BufferBlobRange ||333 typ.Dir() == DirOut {334 return false335 }336 a := arg.(*DataArg)337 minLen := int(typ.RangeBegin)338 for step := len(a.Data()) - minLen; len(a.Data()) > minLen && step > 0; {339 if len(a.Data())-step >= minLen {340 a.data = a.Data()[:len(a.Data())-step]341 p.Target.assignSizesCall(call)342 if pred(p, callIndex0, index0) {343 continue344 }345 a.data = a.Data()[:len(a.Data())+step]346 p.Target.assignSizesCall(call)347 }348 step /= 2349 if crash {350 break351 }352 }353 p0 = p354 case *VmaType, *LenType, *CsumType, *ConstType:355 return false356 default:357 panic(fmt.Sprintf("unknown arg type '%+v'", typ))358 }359 return false360 }...

Full Screen

Full Screen

size_test.go

Source:size_test.go Github

copy

Full Screen

...11 for i := 0; i < iters; i++ {12 p := target.Generate(rs, 10, nil)13 data0 := p.Serialize()14 for _, call := range p.Calls {15 target.assignSizesCall(call)16 }17 if data1 := p.Serialize(); !bytes.Equal(data0, data1) {18 t.Fatalf("different lens assigned, initial: %v, new: %v", data0, data1)19 }20 p.Mutate(rs, 10, nil, nil)21 data0 = p.Serialize()22 for _, call := range p.Calls {23 target.assignSizesCall(call)24 }25 if data1 := p.Serialize(); !bytes.Equal(data0, data1) {26 t.Fatalf("different lens assigned, initial: %v, new: %v", data0, data1)27 }28 }29}30func TestAssignSize(t *testing.T) {31 target, _, _ := initTest(t)32 tests := []struct {33 unsizedProg string34 sizedProg string35 }{36 {37 "syz_test$length0(&(0x7f0000000000)={0xff, 0x0})",38 "syz_test$length0(&(0x7f0000000000)={0xff, 0x2})",39 },40 {41 "syz_test$length1(&(0x7f0000001000)={0xff, 0x0})",42 "syz_test$length1(&(0x7f0000001000)={0xff, 0x4})",43 },44 {45 "syz_test$length2(&(0x7f0000001000)={0xff, 0x0})",46 "syz_test$length2(&(0x7f0000001000)={0xff, 0x8})",47 },48 {49 "syz_test$length3(&(0x7f0000005000)={0xff, 0x0, 0x0})",50 "syz_test$length3(&(0x7f0000005000)={0xff, 0x4, 0x2})",51 },52 {53 "syz_test$length4(&(0x7f0000003000)={0x0, 0x0})",54 "syz_test$length4(&(0x7f0000003000)={0x2, 0x2})",55 },56 {57 "syz_test$length5(&(0x7f0000002000)={0xff, 0x0})",58 "syz_test$length5(&(0x7f0000002000)={0xff, 0x4})",59 },60 {61 "syz_test$length6(&(0x7f0000002000)={[0xff, 0xff, 0xff, 0xff], 0x0})",62 "syz_test$length6(&(0x7f0000002000)={[0xff, 0xff, 0xff, 0xff], 0x4})",63 },64 {65 "syz_test$length7(&(0x7f0000003000)={[0xff, 0xff, 0xff, 0xff], 0x0})",66 "syz_test$length7(&(0x7f0000003000)={[0xff, 0xff, 0xff, 0xff], 0x8})",67 },68 {69 "syz_test$length8(&(0x7f000001f000)={0x00, {0xff, 0x0, 0x00, [0xff, 0xff, 0xff]}, [{0xff, 0x0, 0x00, [0xff, 0xff, 0xff]}], 0x00, 0x0, [0xff, 0xff]})",70 "syz_test$length8(&(0x7f000001f000)={0x32, {0xff, 0x1, 0x10, [0xff, 0xff, 0xff]}, [{0xff, 0x1, 0x10, [0xff, 0xff, 0xff]}], 0x10, 0x1, [0xff, 0xff]})",71 },72 {73 "syz_test$length9(&(0x7f000001f000)={&(0x7f0000000000/0x5000)=nil, 0x0000})",74 "syz_test$length9(&(0x7f000001f000)={&(0x7f0000000000/0x5000)=nil, 0x5000})",75 },76 {77 "syz_test$length10(&(0x7f0000000000/0x5000)=nil, 0x0000)",78 "syz_test$length10(&(0x7f0000000000/0x5000)=nil, 0x5000)",79 },80 {81 "syz_test$length11(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, 0x00)",82 "syz_test$length11(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, 0x30)",83 },84 {85 "syz_test$length12(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, 0x00)",86 "syz_test$length12(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, 0x30)",87 },88 {89 "syz_test$length13(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, &(0x7f0000001000)=0x00)",90 "syz_test$length13(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, &(0x7f0000001000)=0x30)",91 },92 {93 "syz_test$length14(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, &(0x7f0000001000)=0x00)",94 "syz_test$length14(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, &(0x7f0000001000)=0x30)",95 },96 {97 "syz_test$length15(0xff, 0x0)",98 "syz_test$length15(0xff, 0x2)",99 },100 {101 "syz_test$length16(&(0x7f0000000000)={[0x42, 0x42], 0xff, 0xff, 0xff, 0xff, 0xff})",102 "syz_test$length16(&(0x7f0000000000)={[0x42, 0x42], 0x2, 0x10, 0x8, 0x4, 0x2})",103 },104 {105 "syz_test$length17(&(0x7f0000000000)={0x42, 0xff, 0xff, 0xff, 0xff})",106 "syz_test$length17(&(0x7f0000000000)={0x42, 0x8, 0x4, 0x2, 0x1})",107 },108 {109 "syz_test$length18(&(0x7f0000000000)={0x42, 0xff, 0xff, 0xff, 0xff})",110 "syz_test$length18(&(0x7f0000000000)={0x42, 0x8, 0x4, 0x2, 0x1})",111 },112 {113 "syz_test$length19(&(0x7f0000000000)={{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xff}, 0xff, 0xff, 0xff})",114 "syz_test$length19(&(0x7f0000000000)={{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x14}, 0x14, 0x14, 0x5})",115 },116 {117 "syz_test$length20(&(0x7f0000000000)={{{0xff, 0xff, 0xff, 0xff}, 0xff, 0xff, 0xff}, 0xff, 0xff})",118 "syz_test$length20(&(0x7f0000000000)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9})",119 },120 }121 for i, test := range tests {122 p, err := target.Deserialize([]byte(test.unsizedProg))123 if err != nil {124 t.Fatalf("failed to deserialize prog %v: %v", i, err)125 }126 for _, call := range p.Calls {127 target.assignSizesCall(call)128 }129 p1 := strings.TrimSpace(string(p.Serialize()))130 if p1 != test.sizedProg {131 t.Fatalf("failed to assign sizes in prog %v\ngot %v\nwant %v", i, p1, test.sizedProg)132 }133 }134}...

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

1func main() {2 p := new(prog)3 p.assignSizesCall()4}5func main() {6 p := new(prog)7 p.assignSizes()8}9func main() {10 p := new(prog)11 p.assignSizesCall()12}13import "fmt"14func main() {15 fmt.Println("Hello, pla

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p.assignSizesCall()4 fmt.Println("Size of int is", p.sizeofInt)5 fmt.Println("Size of float is", p.sizeofFloat)6 fmt.Println("Size of double is", p.sizeofDouble)7}

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

1import (2type prog struct {3}4func (p *prog) assignSizesCall() {5}6func main() {7 p := new(prog)8 p.assignSizesCall()9 fmt.Printf("%v10}11&{1 2 3}12&{1 2 3}13import (14type prog struct {15}16func (p *prog) assignSizesCall() {17}18func main() {19 p := new(prog)20 p.assignSizesCall()21 fmt.Printf("%v22}

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p.assignSizesCall()4}5import (6func main() {7 p.assignSizesCall()8}9import (10func main() {11 p.assignSizesCall()12}13import (14func main() {15 p.assignSizesCall()16}17import (18func main() {19 p.assignSizesCall()20}21import (22func main() {23 p.assignSizesCall()24}25import (26func main() {27 p.assignSizesCall()28}29import (30func main() {31 p.assignSizesCall()32}33import (34func main() {35 p.assignSizesCall()36}37import (38func main() {39 p.assignSizesCall()40}41import (42func main() {43 p.assignSizesCall()44}

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

1prog.assignSizesCall();2prog.assignOffsetsCall();3prog.assignOffsetsCall();4prog.assignOffsetsCall();5prog.assignOffsetsCall();6prog.assignOffsetsCall();7prog.assignOffsetsCall();8prog.assignOffsetsCall();9prog.assignOffsetsCall();10prog.assignOffsetsCall();11prog.assignOffsetsCall();12prog.assignOffsetsCall();13prog.assignOffsetsCall();

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

1import "fmt"2type prog struct {3}4func (p *prog) assignSizesCall() {5p.assignSizes("Go", 1)6}7func (p *prog) assignSizes(name string, size int) {8}9func main() {10p := new(prog)11p.assignSizesCall()12fmt.Println(p.name, p.size)13}14import "fmt"15type prog struct {16}17func (p *prog) assignSizesCall() {18p.assignSizes("Go", 1)19}20func (p *prog) assignSizes(name string, size int) {21}22func main() {23p := new(prog)24p.assignSizesCall()25fmt.Println(p.name, p.size)26}27import "fmt"28type prog struct {29}30func (p *prog) assignSizesCall() {31p.assignSizes("Go", 1)32}33func (p *prog) assignSizes(name string, size int) {34}35func main() {36p := new(prog)37p.assignSizesCall()38fmt.Println(p.name, p.size)39}40import "fmt"41type prog struct {42}43func (p *prog) assignSizesCall() {44p.assignSizes("Go", 1)45}46func (p *prog) assignSizes(name string, size int) {47}48func main() {49p := new(prog)50p.assignSizesCall()51fmt.Println(p.name, p.size)52}53import "fmt"54type prog struct {55}

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog.assignSizesCall()4 fmt.Println(prog)5}6type prog struct {7}8func (p *prog) assignSizesCall() {9}10{100 true}

Full Screen

Full Screen

assignSizesCall

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := newProgram()4 progFunc := newFunction()5 progNode := newNode()6 progNode2 := newNode()7 progNode3 := newNode()8 progNode4 := newNode()9 progNode5 := newNode()10 progFunc.nodes = append(progFunc.nodes, progNode)11 progFunc.nodes = append(progFunc.nodes, progNode2)12 progFunc.nodes = append(progFunc.nodes, progNode3)13 progFunc.nodes = append(progFunc.nodes, progNode4)14 progFunc.nodes = append(progFunc.nodes, progNode5)15 prog.funcs = append(prog.funcs, progFunc)16 prog.assignSizesCall()17 fmt.Println("Node ID\t\tNode Size")18 for i := 0; i < len(prog.funcs[0].nodes); i++ {19 fmt.Println(prog.funcs[0].nodes[i].id, "\t\t", prog.funcs[0].nodes[i].size)20 }21}22type Program struct {23}24type Function struct {25}26type Node struct {27}28func newProgram() *Program {29 return &Program{}30}31func newFunction() *Function {32 return &Function{}33}

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