How to use getMutationPrio method of prog Package

Best Syzkaller code snippet using prog.getMutationPrio

mutation.go

Source:mutation.go Github

copy

Full Screen

...195 var callPriorities []float64196 for _, c := range p.Calls {197 var totalPrio float64198 ForeachArg(c, func(arg Arg, ctx *ArgCtx) {199 prio, stopRecursion := arg.Type().getMutationPrio(p.Target, arg, false)200 totalPrio += prio201 ctx.Stop = stopRecursion202 })203 prioSum += totalPrio204 callPriorities = append(callPriorities, prioSum)205 }206 if prioSum == 0 {207 return -1 // All calls are without arguments.208 }209 return sort.SearchFloat64s(callPriorities, prioSum*r.Float64())210}211func (target *Target) mutateArg(r *randGen, s *state, arg Arg, ctx ArgCtx, updateSizes *bool) ([]*Call, bool) {212 var baseSize uint64213 if ctx.Base != nil {214 baseSize = ctx.Base.Res.Size()215 }216 calls, retry, preserve := arg.Type().mutate(r, s, arg, ctx)217 if retry {218 return nil, false219 }220 if preserve {221 *updateSizes = false222 }223 // Update base pointer if size has increased.224 if base := ctx.Base; base != nil && baseSize < base.Res.Size() {225 newArg := r.allocAddr(s, base.Type(), base.Dir(), base.Res.Size(), base.Res)226 replaceArg(base, newArg)227 }228 return calls, true229}230func regenerate(r *randGen, s *state, arg Arg) (calls []*Call, retry, preserve bool) {231 var newArg Arg232 newArg, calls = r.generateArg(s, arg.Type(), arg.Dir())233 replaceArg(arg, newArg)234 return235}236func mutateInt(r *randGen, a *ConstArg, t *IntType) uint64 {237 switch {238 case r.nOutOf(1, 3):239 return a.Val + (uint64(r.Intn(4)) + 1)240 case r.nOutOf(1, 2):241 return a.Val - (uint64(r.Intn(4)) + 1)242 default:243 return a.Val ^ (1 << uint64(r.Intn(int(t.TypeBitSize()))))244 }245}246func mutateAlignedInt(r *randGen, a *ConstArg, t *IntType) uint64 {247 rangeEnd := t.RangeEnd248 if t.RangeBegin == 0 && int64(rangeEnd) == -1 {249 // Special [0:-1] range for all possible values.250 rangeEnd = uint64(1<<t.TypeBitSize() - 1)251 }252 index := (a.Val - t.RangeBegin) / t.Align253 misalignment := (a.Val - t.RangeBegin) % t.Align254 switch {255 case r.nOutOf(1, 3):256 index += uint64(r.Intn(4)) + 1257 case r.nOutOf(1, 2):258 index -= uint64(r.Intn(4)) + 1259 default:260 index ^= 1 << uint64(r.Intn(int(t.TypeBitSize())))261 }262 lastIndex := (rangeEnd - t.RangeBegin) / t.Align263 index %= lastIndex + 1264 return t.RangeBegin + index*t.Align + misalignment265}266func (t *IntType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {267 if r.bin() {268 return regenerate(r, s, arg)269 }270 a := arg.(*ConstArg)271 if t.Align == 0 {272 a.Val = mutateInt(r, a, t)273 } else {274 a.Val = mutateAlignedInt(r, a, t)275 }276 a.Val = truncateToBitSize(a.Val, t.TypeBitSize())277 return278}279func (t *FlagsType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {280 a := arg.(*ConstArg)281 for oldVal := a.Val; oldVal == a.Val; {282 a.Val = r.flags(t.Vals, t.BitMask, a.Val)283 }284 return285}286func (t *LenType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {287 if !r.mutateSize(arg.(*ConstArg), *ctx.Parent, ctx.Fields) {288 retry = true289 return290 }291 preserve = true292 return293}294func (t *ResourceType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {295 return regenerate(r, s, arg)296}297func (t *VmaType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {298 return regenerate(r, s, arg)299}300func (t *ProcType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {301 return regenerate(r, s, arg)302}303func (t *BufferType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {304 minLen, maxLen := uint64(0), maxBlobLen305 if t.Kind == BufferBlobRange {306 minLen, maxLen = t.RangeBegin, t.RangeEnd307 }308 a := arg.(*DataArg)309 if a.Dir() == DirOut {310 mutateBufferSize(r, a, minLen, maxLen)311 return312 }313 switch t.Kind {314 case BufferBlobRand, BufferBlobRange:315 data := append([]byte{}, a.Data()...)316 a.data = mutateData(r, data, minLen, maxLen)317 case BufferString:318 if len(t.Values) != 0 {319 a.data = r.randString(s, t)320 } else {321 if t.TypeSize != 0 {322 minLen, maxLen = t.TypeSize, t.TypeSize323 }324 data := append([]byte{}, a.Data()...)325 a.data = mutateData(r, data, minLen, maxLen)326 }327 case BufferFilename:328 a.data = []byte(r.filename(s, t))329 case BufferText:330 data := append([]byte{}, a.Data()...)331 a.data = r.mutateText(t.Text, data)332 default:333 panic("unknown buffer kind")334 }335 return336}337func mutateBufferSize(r *randGen, arg *DataArg, minLen, maxLen uint64) {338 for oldSize := arg.Size(); oldSize == arg.Size(); {339 arg.size += uint64(r.Intn(33)) - 16340 if arg.size < minLen {341 arg.size = minLen342 }343 if arg.size > maxLen {344 arg.size = maxLen345 }346 }347}348func (t *ArrayType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {349 // TODO: swap elements of the array350 a := arg.(*GroupArg)351 count := uint64(0)352 switch t.Kind {353 case ArrayRandLen:354 if r.bin() {355 for count = uint64(len(a.Inner)); r.bin(); {356 count++357 }358 } else {359 for count == uint64(len(a.Inner)) {360 count = r.randArrayLen()361 }362 }363 case ArrayRangeLen:364 if t.RangeBegin == t.RangeEnd {365 panic("trying to mutate fixed length array")366 }367 for count == uint64(len(a.Inner)) {368 count = r.randRange(t.RangeBegin, t.RangeEnd)369 }370 }371 if count > uint64(len(a.Inner)) {372 for count > uint64(len(a.Inner)) {373 newArg, newCalls := r.generateArg(s, t.Elem, a.Dir())374 a.Inner = append(a.Inner, newArg)375 calls = append(calls, newCalls...)376 for _, c := range newCalls {377 s.analyze(c)378 }379 }380 } else if count < uint64(len(a.Inner)) {381 for _, arg := range a.Inner[count:] {382 removeArg(arg)383 }384 a.Inner = a.Inner[:count]385 }386 return387}388func (t *PtrType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {389 a := arg.(*PointerArg)390 if r.oneOf(1000) {391 removeArg(a.Res)392 index := r.rand(len(r.target.SpecialPointers))393 newArg := MakeSpecialPointerArg(t, a.Dir(), index)394 replaceArg(arg, newArg)395 return396 }397 newArg := r.allocAddr(s, t, a.Dir(), a.Res.Size(), a.Res)398 replaceArg(arg, newArg)399 return400}401func (t *StructType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {402 gen := r.target.SpecialTypes[t.Name()]403 if gen == nil {404 panic("bad arg returned by mutationArgs: StructType")405 }406 var newArg Arg407 newArg, calls = gen(&Gen{r, s}, t, arg.Dir(), arg)408 a := arg.(*GroupArg)409 for i, f := range newArg.(*GroupArg).Inner {410 replaceArg(a.Inner[i], f)411 }412 return413}414func (t *UnionType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {415 if gen := r.target.SpecialTypes[t.Name()]; gen != nil {416 var newArg Arg417 newArg, calls = gen(&Gen{r, s}, t, arg.Dir(), arg)418 replaceArg(arg, newArg)419 return420 }421 a := arg.(*UnionArg)422 index := r.Intn(len(t.Fields) - 1)423 if index >= a.Index {424 index++425 }426 optType := t.Fields[index].Type427 removeArg(a.Option)428 var newOpt Arg429 newOpt, calls = r.generateArg(s, optType, a.Dir())430 replaceArg(arg, MakeUnionArg(t, a.Dir(), newOpt, index))431 return432}433func (t *CsumType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {434 panic("CsumType can't be mutated")435}436func (t *ConstType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {437 panic("ConstType can't be mutated")438}439type mutationArgs struct {440 target *Target441 ignoreSpecial bool442 prioSum float64443 args []mutationArg444 argsBuffer [16]mutationArg445}446type mutationArg struct {447 arg Arg448 ctx ArgCtx449 priority float64450}451const (452 maxPriority = float64(10)453 minPriority = float64(1)454 dontMutate = float64(0)455)456func (ma *mutationArgs) collectArg(arg Arg, ctx *ArgCtx) {457 ignoreSpecial := ma.ignoreSpecial458 ma.ignoreSpecial = false459 typ := arg.Type()460 prio, stopRecursion := typ.getMutationPrio(ma.target, arg, ignoreSpecial)461 ctx.Stop = stopRecursion462 if prio == dontMutate {463 return464 }465 _, isArrayTyp := typ.(*ArrayType)466 _, isBufferTyp := typ.(*BufferType)467 if !isBufferTyp && !isArrayTyp && arg.Dir() == DirOut || !typ.Varlen() && typ.Size() == 0 {468 return469 }470 if len(ma.args) == 0 {471 ma.args = ma.argsBuffer[:0]472 }473 ma.prioSum += prio474 ma.args = append(ma.args, mutationArg{arg, *ctx, ma.prioSum})475}476func (ma *mutationArgs) chooseArg(r *rand.Rand) (Arg, ArgCtx) {477 goal := ma.prioSum * r.Float64()478 chosenIdx := sort.Search(len(ma.args), func(i int) bool { return ma.args[i].priority >= goal })479 arg := ma.args[chosenIdx]480 return arg.arg, arg.ctx481}482// TODO: find a way to estimate optimal priority values.483// Assign a priority for each type. The boolean is the reference type and it has484// the minimum priority, since it has only two possible values.485func (t *IntType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {486 // For a integer without a range of values, the priority is based on487 // the number of bits occupied by the underlying type.488 plainPrio := math.Log2(float64(t.TypeBitSize())) + 0.1*maxPriority489 if t.Kind != IntRange {490 return plainPrio, false491 }492 size := t.RangeEnd - t.RangeBegin + 1493 if t.Align != 0 {494 if t.RangeBegin == 0 && int64(t.RangeEnd) == -1 {495 // Special [0:-1] range for all possible values.496 size = (1<<t.TypeBitSize()-1)/t.Align + 1497 } else {498 size = (t.RangeEnd-t.RangeBegin)/t.Align + 1499 }500 }501 switch {502 case size <= 15:503 // For a small range, we assume that it is effectively504 // similar with FlagsType and we need to try all possible values.505 prio = rangeSizePrio(size)506 case size <= 256:507 // We consider that a relevant range has at most 256508 // values (the number of values that can be represented on a byte).509 prio = maxPriority510 default:511 // Ranges larger than 256 are equivalent with a plain integer.512 prio = plainPrio513 }514 return prio, false515}516func (t *StructType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {517 if target.SpecialTypes[t.Name()] == nil || ignoreSpecial {518 return dontMutate, false519 }520 return maxPriority, true521}522func (t *UnionType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {523 if target.SpecialTypes[t.Name()] == nil && len(t.Fields) == 1 || ignoreSpecial {524 return dontMutate, false525 }526 // For a non-special type union with more than one option527 // we mutate the union itself and also the value of the current option.528 if target.SpecialTypes[t.Name()] == nil {529 return maxPriority, false530 }531 return maxPriority, true532}533func (t *FlagsType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {534 prio = rangeSizePrio(uint64(len(t.Vals)))535 if t.BitMask {536 // We want a higher priority because the mutation will include537 // more possible operations (bitwise operations).538 prio += 0.1 * maxPriority539 }540 return prio, false541}542// Assigns a priority based on the range size.543func rangeSizePrio(size uint64) (prio float64) {544 switch size {545 case 0:546 prio = dontMutate547 case 1:548 prio = minPriority549 default:550 // Priority proportional with the number of values. After a threshold, the priority is constant.551 // The threshold is 15 because most of the calls have <= 15 possible values for a flag.552 prio = math.Min(float64(size)/3+0.4*maxPriority, 0.9*maxPriority)553 }554 return prio555}556func (t *PtrType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {557 if arg.(*PointerArg).IsSpecial() {558 // TODO: we ought to mutate this, but we don't have code for this yet.559 return dontMutate, false560 }561 return 0.3 * maxPriority, false562}563func (t *ConstType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {564 return dontMutate, false565}566func (t *CsumType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {567 return dontMutate, false568}569func (t *ProcType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {570 return 0.5 * maxPriority, false571}572func (t *ResourceType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {573 return 0.5 * maxPriority, false574}575func (t *VmaType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {576 return 0.5 * maxPriority, false577}578func (t *LenType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {579 // Mutating LenType only produces "incorrect" results according to descriptions.580 return 0.1 * maxPriority, false581}582func (t *BufferType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {583 if arg.Dir() == DirOut && !t.Varlen() {584 return dontMutate, false585 }586 if t.Kind == BufferString && len(t.Values) == 1 {587 // These are effectively consts (and frequently file names).588 return dontMutate, false589 }590 return 0.8 * maxPriority, false591}592func (t *ArrayType) getMutationPrio(target *Target, arg Arg, ignoreSpecial bool) (prio float64, stopRecursion bool) {593 if t.Kind == ArrayRangeLen && t.RangeBegin == t.RangeEnd {594 return dontMutate, false595 }596 return maxPriority, false597}598func mutateData(r *randGen, data []byte, minLen, maxLen uint64) []byte {599 for stop := false; !stop; stop = stop && r.oneOf(3) {600 f := mutateDataFuncs[r.Intn(len(mutateDataFuncs))]601 data, stop = f(r, data, minLen, maxLen)602 }603 return data604}605// The maximum delta for integer mutations.606const maxDelta = 35...

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, world.")4}5import "fmt"6func getMutationPrio() {7 fmt.Println("Hello, world.")8}

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p.getMutationPrio()4}5type prog struct {6}7func (p prog) getMutationPrio() {8 fmt.Println("Hi")9}10prog.go:6: prog.x (type int) is not an expression11import "fmt"12import "prog"13func main() {14 p.getMutationPrio()15}16type prog struct {17}18func (p prog) getMutationPrio() {19 fmt.Println("Hi")20}21prog.go:6: prog.x (type int) is not an expression22import "fmt"23import "prog"24func main() {25 p.getMutationPrio()26}27type prog struct {28}29func (p prog) getMutationPrio() {30 fmt.Println("Hi")31}32prog.go:6: prog.x (type int) is not an expression

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p1.getMutationPrio()4 p2.getMutationPrio()5 p3.getMutationPrio()6}7import (8func main() {9 p1.getMutationPrio()10 p2.getMutationPrio()11 p3.getMutationPrio()12}13import (14func main() {15 p1.getMutationPrio()16 p2.getMutationPrio()17 p3.getMutationPrio()18}

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog1 := new(Prog.Prog)4 prog1.SetValues(1, 2, 3)5 prio := prog1.GetMutationPrio()6 fmt.Println(prio)7}8import (9func main() {10 prog1 := new(Prog.Prog)11 prog1.SetValues(1, 2, 3)12 prio := prog1.GetMutationPrio()13 fmt.Println(prio)14}15import (16func main() {17 prog1 := new(Prog.Prog)18 prog1.SetValues(1, 2, 3)19 prio := prog1.GetMutationPrio()20 fmt.Println(prio)21}22import (23func main() {24 prog1 := new(Prog.Prog)25 prog1.SetValues(1, 2, 3)26 prio := prog1.GetMutationPrio()27 fmt.Println(prio)28}29import (30func main() {31 prog1 := new(Prog.Prog)32 prog1.SetValues(1, 2, 3)33 prio := prog1.GetMutationPrio()34 fmt.Println(prio)35}

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

1import (2type Prog struct {3}4func (p *Prog) getMutationPrio() {5 for i := 0; i < len(p.op); i++ {6 p.mutPrio[i] = rand.Intn(10)7 }8}9func (p *Prog) getMutation() string {10 r := rand.Intn(len(p.op))11}12func main() {13 rand.Seed(time.Now().UnixNano())14 p := Prog{}15 p.op = []string{"+", "-", "/", "*"}16 p.mutPrio = make([]int, len(p.op))17 p.getMutationPrio()18 fmt.Println(p.mutPrio)19 mut := p.getMutation()20 fmt.Println(mut)21}

Full Screen

Full Screen

getMutationPrio

Using AI Code Generation

copy

Full Screen

1func main() {2 prog := prog.New()3 prog := prog.NewWithParams(params)4 prio := prog.getMutationPrio()5}6func (p *Prog) getMutationPrio() int {7 prio := p.Target.GetMutationPrio()8}9func (t *Target) GetMutationPrio() int {10}11func (t *Target) GetMutationPrio() int {12}13func (t *Target) GetMutationPrio() int {14}15func (t *Target) GetMutationPrio() int {16}17func (t *Target) GetMutationPrio() int {18}19func (t *Target) GetMutationPrio() int {20}

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