How to use oneOf method of prog Package

Best Syzkaller code snippet using prog.oneOf

rand.go

Source:rand.go Github

copy

Full Screen

...40}41func (r *randGen) bin() bool {42 return r.Intn(2) == 043}44func (r *randGen) oneOf(n int) bool {45 return r.Intn(n) == 046}47func (r *randGen) rand64() uint64 {48 v := uint64(r.Int63())49 if r.bin() {50 v |= 1 << 6351 }52 return v53}54var (55 // Some potentially interesting integers.56 specialInts = []uint64{57 0, 1, 31, 32, 63, 64, 127, 128,58 129, 255, 256, 257, 511, 512,59 1023, 1024, 1025, 2047, 2048, 4095, 4096,60 (1 << 15) - 1, (1 << 15), (1 << 15) + 1,61 (1 << 16) - 1, (1 << 16), (1 << 16) + 1,62 (1 << 31) - 1, (1 << 31), (1 << 31) + 1,63 (1 << 32) - 1, (1 << 32), (1 << 32) + 1,64 }65 // The indexes (exclusive) for the maximum specialInts values that fit in 1, 2, ... 8 bytes.66 specialIntIndex [9]int67)68func init() {69 sort.Slice(specialInts, func(i, j int) bool {70 return specialInts[i] < specialInts[j]71 })72 for i := range specialIntIndex {73 bitSize := uint64(8 * i)74 specialIntIndex[i] = sort.Search(len(specialInts), func(i int) bool {75 return specialInts[i]>>bitSize != 076 })77 }78}79func (r *randGen) randInt64() uint64 {80 return r.randInt(64)81}82func (r *randGen) randInt(bits uint64) uint64 {83 v := r.rand64()84 switch {85 case r.nOutOf(100, 182):86 v %= 1087 case bits >= 8 && r.nOutOf(50, 82):88 v = specialInts[r.Intn(specialIntIndex[bits/8])]89 case r.nOutOf(10, 32):90 v %= 25691 case r.nOutOf(10, 22):92 v %= 4 << 1093 case r.nOutOf(10, 12):94 v %= 64 << 1095 default:96 v %= 1 << 3197 }98 switch {99 case r.nOutOf(100, 107):100 case r.nOutOf(5, 7):101 v = uint64(-int64(v))102 default:103 v <<= uint(r.Intn(int(bits)))104 }105 return truncateToBitSize(v, bits)106}107func truncateToBitSize(v, bitSize uint64) uint64 {108 if bitSize == 0 || bitSize > 64 {109 panic(fmt.Sprintf("invalid bitSize value: %d", bitSize))110 }111 return v & uint64(1<<bitSize-1)112}113func (r *randGen) randRangeInt(begin, end, bitSize, align uint64) uint64 {114 if r.oneOf(100) {115 return r.randInt(bitSize)116 }117 if align != 0 {118 if begin == 0 && int64(end) == -1 {119 // Special [0:-1] range for all possible values.120 end = uint64(1<<bitSize - 1)121 }122 endAlign := (end - begin) / align123 return begin + r.randRangeInt(0, endAlign, bitSize, 0)*align124 }125 return begin + (r.Uint64() % (end - begin + 1))126}127// biasedRand returns a random int in range [0..n),128// probability of n-1 is k times higher than probability of 0.129func (r *randGen) biasedRand(n, k int) int {130 nf, kf := float64(n), float64(k)131 rf := nf * (kf/2 + 1) * r.Float64()132 bf := (-1 + math.Sqrt(1+2*kf*rf/nf)) * nf / kf133 return int(bf)134}135func (r *randGen) randArrayLen() uint64 {136 const maxLen = 10137 // biasedRand produces: 10, 9, ..., 1, 0,138 // we want: 1, 2, ..., 9, 10, 0139 return uint64(maxLen-r.biasedRand(maxLen+1, 10)+1) % (maxLen + 1)140}141func (r *randGen) randBufLen() (n uint64) {142 switch {143 case r.nOutOf(50, 56):144 n = r.rand(256)145 case r.nOutOf(5, 6):146 n = 4 << 10147 }148 return149}150func (r *randGen) randPageCount() (n uint64) {151 switch {152 case r.nOutOf(100, 106):153 n = r.rand(4) + 1154 case r.nOutOf(5, 6):155 n = r.rand(20) + 1156 default:157 n = (r.rand(3) + 1) * r.target.NumPages / 4158 }159 return160}161// Change a flag value or generate a new one.162// If you are changing this function, run TestFlags and examine effect of results.163func (r *randGen) flags(vv []uint64, bitmask bool, oldVal uint64) uint64 {164 // Get these simpler cases out of the way first.165 // Once in a while we want to return completely random values,166 // or 0 which is frequently special.167 if r.oneOf(100) {168 return r.rand64()169 }170 if r.oneOf(50) {171 return 0172 }173 if !bitmask && oldVal != 0 && r.oneOf(100) {174 // Slightly increment/decrement the old value.175 // This is especially important during mutation when len(vv) == 1,176 // otherwise in that case we produce almost no randomness177 // (the value is always mutated to 0).178 inc := uint64(1)179 if r.bin() {180 inc = ^uint64(0)181 }182 v := oldVal + inc183 for r.bin() {184 v += inc185 }186 return v187 }188 if len(vv) == 1 {189 // This usually means that value or 0,190 // at least that's our best (and only) bet.191 if r.bin() {192 return 0193 }194 return vv[0]195 }196 if !bitmask && !r.oneOf(10) {197 // Enumeration, so just choose one of the values.198 return vv[r.rand(len(vv))]199 }200 if r.oneOf(len(vv) + 4) {201 return 0202 }203 // Flip rand bits. Do this for non-bitmask sometimes204 // because we may have detected bitmask incorrectly for complex cases205 // (e.g. part of the vlaue is bitmask and another is not).206 v := oldVal207 if v != 0 && r.oneOf(10) {208 v = 0 // Ignore the old value sometimes.209 }210 // We don't want to return 0 here, because we already given 0211 // fixed probability above (otherwise we get 0 too frequently).212 for v == 0 || r.nOutOf(2, 3) {213 flag := vv[r.rand(len(vv))]214 if r.oneOf(20) {215 // Try choosing adjacent bit values in case we forgot216 // to add all relevant flags to the descriptions.217 if r.bin() {218 flag >>= 1219 } else {220 flag <<= 1221 }222 }223 v ^= flag224 }225 return v226}227func (r *randGen) filename(s *state, typ *BufferType) string {228 fn := r.filenameImpl(s)229 if len(fn) != 0 && fn[len(fn)-1] == 0 {230 panic(fmt.Sprintf("zero-terminated filename: %q", fn))231 }232 if escapingFilename(fn) {233 panic(fmt.Sprintf("sandbox escaping file name %q, s.files are %v", fn, s.files))234 }235 if !typ.Varlen() {236 size := typ.Size()237 if uint64(len(fn)) < size {238 fn += string(make([]byte, size-uint64(len(fn))))239 }240 fn = fn[:size]241 } else if !typ.NoZ {242 fn += "\x00"243 }244 return fn245}246func escapingFilename(file string) bool {247 file = filepath.Clean(file)248 return len(file) >= 1 && file[0] == '/' ||249 len(file) >= 2 && file[0] == '.' && file[1] == '.'250}251var specialFiles = []string{"", "."}252func (r *randGen) filenameImpl(s *state) string {253 if r.oneOf(100) {254 return specialFiles[r.Intn(len(specialFiles))]255 }256 if len(s.files) == 0 || r.oneOf(10) {257 // Generate a new name.258 dir := "."259 if r.oneOf(2) && len(s.files) != 0 {260 dir = r.randFromMap(s.files)261 if len(dir) > 0 && dir[len(dir)-1] == 0 {262 dir = dir[:len(dir)-1]263 }264 if r.oneOf(10) && filepath.Clean(dir)[0] != '.' {265 dir += "/.."266 }267 }268 for i := 0; ; i++ {269 f := fmt.Sprintf("%v/file%v", dir, i)270 if !s.files[f] {271 return f272 }273 }274 }275 return r.randFromMap(s.files)276}277func (r *randGen) randFromMap(m map[string]bool) string {278 files := make([]string, 0, len(m))279 for f := range m {280 files = append(files, f)281 }282 sort.Strings(files)283 return files[r.Intn(len(files))]284}285func (r *randGen) randString(s *state, t *BufferType) []byte {286 if len(t.Values) != 0 {287 return []byte(t.Values[r.Intn(len(t.Values))])288 }289 if len(s.strings) != 0 && r.bin() {290 // Return an existing string.291 // TODO(dvyukov): make s.strings indexed by string SubKind.292 return []byte(r.randFromMap(s.strings))293 }294 punct := []byte{'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '\\',295 '/', ':', '.', ',', '-', '\'', '[', ']', '{', '}'}296 buf := new(bytes.Buffer)297 for r.nOutOf(3, 4) {298 if r.nOutOf(10, 11) {299 buf.Write([]byte{punct[r.Intn(len(punct))]})300 } else {301 buf.Write([]byte{byte(r.Intn(256))})302 }303 }304 if r.oneOf(100) == t.NoZ {305 buf.Write([]byte{0})306 }307 return buf.Bytes()308}309func (r *randGen) allocAddr(s *state, typ Type, dir Dir, size uint64, data Arg) *PointerArg {310 return MakePointerArg(typ, dir, s.ma.alloc(r, size), data)311}312func (r *randGen) allocVMA(s *state, typ Type, dir Dir, numPages uint64) *PointerArg {313 page := s.va.alloc(r, numPages)314 return MakeVmaPointerArg(typ, dir, page*r.target.PageSize, numPages*r.target.PageSize)315}316func (r *randGen) createResource(s *state, res *ResourceType, dir Dir) (arg Arg, calls []*Call) {317 if r.inCreateResource {318 return nil, nil319 }320 r.inCreateResource = true321 defer func() { r.inCreateResource = false }()322 kind := res.Desc.Name323 // We may have no resources, but still be in createResource due to ANYRES.324 if len(r.target.resourceMap) != 0 && r.oneOf(1000) {325 // Spoof resource subkind.326 var all []string327 for kind1 := range r.target.resourceMap {328 if r.target.isCompatibleResource(res.Desc.Kind[0], kind1) {329 all = append(all, kind1)330 }331 }332 if len(all) == 0 {333 panic(fmt.Sprintf("got no spoof resources for %v in %v/%v",334 kind, r.target.OS, r.target.Arch))335 }336 sort.Strings(all)337 kind = all[r.Intn(len(all))]338 }339 // Find calls that produce the necessary resources.340 metas0 := r.target.resourceCtors[kind]341 // TODO: reduce priority of less specialized ctors.342 var metas []*Syscall343 for _, meta := range metas0 {344 if s.ct.Enabled(meta.ID) {345 metas = append(metas, meta)346 }347 }348 if len(metas) == 0 {349 return res.DefaultArg(dir), nil350 }351 // Now we have a set of candidate calls that can create the necessary resource.352 for i := 0; i < 1e3; i++ {353 // Generate one of them.354 meta := metas[r.Intn(len(metas))]355 calls := r.generateParticularCall(s, meta)356 s1 := newState(r.target, s.ct, nil)357 s1.analyze(calls[len(calls)-1])358 // Now see if we have what we want.359 var allres []*ResultArg360 for kind1, res1 := range s1.resources {361 if r.target.isCompatibleResource(kind, kind1) {362 allres = append(allres, res1...)363 }364 }365 sort.SliceStable(allres, func(i, j int) bool {366 return allres[i].Type().Name() < allres[j].Type().Name()367 })368 if len(allres) != 0 {369 // Bingo!370 arg := MakeResultArg(res, dir, allres[r.Intn(len(allres))], 0)371 return arg, calls372 }373 // Discard unsuccessful calls.374 // Note: s.ma/va have already noted allocations of the new objects375 // in discarded syscalls, ideally we should recreate state376 // by analyzing the program again.377 for _, c := range calls {378 ForeachArg(c, func(arg Arg, _ *ArgCtx) {379 if a, ok := arg.(*ResultArg); ok && a.Res != nil {380 delete(a.Res.uses, a)381 }382 })383 }384 }385 // Generally we can loop several times, e.g. when we choose a call that returns386 // the resource in an array, but then generateArg generated that array of zero length.387 // But we must succeed eventually.388 var ctors []string389 for _, meta := range metas {390 ctors = append(ctors, meta.Name)391 }392 panic(fmt.Sprintf("failed to create a resource %v with %v",393 res.Desc.Kind[0], strings.Join(ctors, ", ")))394}395func (r *randGen) generateText(kind TextKind) []byte {396 switch kind {397 case TextTarget:398 if cfg := createTargetIfuzzConfig(r.target); cfg != nil {399 return ifuzz.Generate(cfg, r.Rand)400 }401 fallthrough402 case TextArm64:403 // Just a stub, need something better.404 text := make([]byte, 50)405 for i := range text {406 text[i] = byte(r.Intn(256))407 }408 return text409 default:410 cfg := createIfuzzConfig(kind)411 return ifuzz.Generate(cfg, r.Rand)412 }413}414func (r *randGen) mutateText(kind TextKind, text []byte) []byte {415 switch kind {416 case TextTarget:417 if cfg := createTargetIfuzzConfig(r.target); cfg != nil {418 return ifuzz.Mutate(cfg, r.Rand, text)419 }420 fallthrough421 case TextArm64:422 return mutateData(r, text, 40, 60)423 default:424 cfg := createIfuzzConfig(kind)425 return ifuzz.Mutate(cfg, r.Rand, text)426 }427}428func createTargetIfuzzConfig(target *Target) *ifuzz.Config {429 cfg := &ifuzz.Config{430 Len: 10,431 Priv: false,432 Exec: true,433 MemRegions: []ifuzz.MemRegion{434 {Start: target.DataOffset, Size: target.NumPages * target.PageSize},435 },436 }437 for _, p := range target.SpecialPointers {438 cfg.MemRegions = append(cfg.MemRegions, ifuzz.MemRegion{439 Start: p & ^target.PageSize, Size: p & ^target.PageSize + target.PageSize,440 })441 }442 switch target.Arch {443 case "amd64":444 cfg.Mode = ifuzz.ModeLong64445 case "386":446 cfg.Mode = ifuzz.ModeProt32447 default:448 return nil449 }450 return cfg451}452func createIfuzzConfig(kind TextKind) *ifuzz.Config {453 cfg := &ifuzz.Config{454 Len: 10,455 Priv: true,456 Exec: true,457 MemRegions: []ifuzz.MemRegion{458 {Start: 0 << 12, Size: 1 << 12},459 {Start: 1 << 12, Size: 1 << 12},460 {Start: 2 << 12, Size: 1 << 12},461 {Start: 3 << 12, Size: 1 << 12},462 {Start: 4 << 12, Size: 1 << 12},463 {Start: 5 << 12, Size: 1 << 12},464 {Start: 6 << 12, Size: 1 << 12},465 {Start: 7 << 12, Size: 1 << 12},466 {Start: 8 << 12, Size: 1 << 12},467 {Start: 9 << 12, Size: 1 << 12},468 {Start: 0xfec00000, Size: 0x100}, // ioapic469 },470 }471 switch kind {472 case TextX86Real:473 cfg.Mode = ifuzz.ModeReal16474 case TextX86bit16:475 cfg.Mode = ifuzz.ModeProt16476 case TextX86bit32:477 cfg.Mode = ifuzz.ModeProt32478 case TextX86bit64:479 cfg.Mode = ifuzz.ModeLong64480 default:481 panic("unknown text kind")482 }483 return cfg484}485// nOutOf returns true n out of outOf times.486func (r *randGen) nOutOf(n, outOf int) bool {487 if n <= 0 || n >= outOf {488 panic("bad probability")489 }490 v := r.Intn(outOf)491 return v < n492}493func (r *randGen) generateCall(s *state, p *Prog, insertionPoint int) []*Call {494 biasCall := -1495 if insertionPoint > 0 {496 // Choosing the base call is based on the insertion point of the new calls sequence.497 biasCall = p.Calls[r.Intn(insertionPoint)].Meta.ID498 }499 idx := s.ct.choose(r.Rand, biasCall)500 meta := r.target.Syscalls[idx]501 return r.generateParticularCall(s, meta)502}503func (r *randGen) generateParticularCall(s *state, meta *Syscall) (calls []*Call) {504 if meta.Attrs.Disabled {505 panic(fmt.Sprintf("generating disabled call %v", meta.Name))506 }507 c := &Call{508 Meta: meta,509 Ret: MakeReturnArg(meta.Ret),510 }511 c.Args, calls = r.generateArgs(s, meta.Args, DirIn)512 r.target.assignSizesCall(c)513 return append(calls, c)514}515// GenerateAllSyzProg generates a program that contains all pseudo syz_ calls for testing.516func (target *Target) GenerateAllSyzProg(rs rand.Source) *Prog {517 p := &Prog{518 Target: target,519 }520 r := newRand(target, rs)521 s := newState(target, target.DefaultChoiceTable(), nil)522 handled := make(map[string]bool)523 for _, meta := range target.Syscalls {524 if !strings.HasPrefix(meta.CallName, "syz_") || handled[meta.CallName] || meta.Attrs.Disabled {525 continue526 }527 handled[meta.CallName] = true528 calls := r.generateParticularCall(s, meta)529 for _, c := range calls {530 s.analyze(c)531 p.Calls = append(p.Calls, c)532 }533 }534 if err := p.validate(); err != nil {535 panic(err)536 }537 return p538}539// DataMmapProg creates program that maps data segment.540// Also used for testing as the simplest program.541func (target *Target) DataMmapProg() *Prog {542 return &Prog{543 Target: target,544 Calls: target.MakeDataMmap(),545 }546}547func (r *randGen) generateArgs(s *state, fields []Field, dir Dir) ([]Arg, []*Call) {548 var calls []*Call549 args := make([]Arg, len(fields))550 // Generate all args. Size args have the default value 0 for now.551 for i, field := range fields {552 arg, calls1 := r.generateArg(s, field.Type, dir)553 if arg == nil {554 panic(fmt.Sprintf("generated arg is nil for field '%v', fields: %+v", field.Type.Name(), fields))555 }556 args[i] = arg557 calls = append(calls, calls1...)558 }559 return args, calls560}561func (r *randGen) generateArg(s *state, typ Type, dir Dir) (arg Arg, calls []*Call) {562 return r.generateArgImpl(s, typ, dir, false)563}564func (r *randGen) generateArgImpl(s *state, typ Type, dir Dir, ignoreSpecial bool) (arg Arg, calls []*Call) {565 if dir == DirOut {566 // No need to generate something interesting for output scalar arguments.567 // But we still need to generate the argument itself so that it can be referenced568 // in subsequent calls. For the same reason we do generate pointer/array/struct569 // output arguments (their elements can be referenced in subsequent calls).570 switch typ.(type) {571 case *IntType, *FlagsType, *ConstType, *ProcType, *VmaType, *ResourceType:572 return typ.DefaultArg(dir), nil573 }574 }575 if typ.Optional() && r.oneOf(5) {576 if res, ok := typ.(*ResourceType); ok {577 v := res.Desc.Values[r.Intn(len(res.Desc.Values))]578 return MakeResultArg(typ, dir, nil, v), nil579 }580 return typ.DefaultArg(dir), nil581 }582 // Allow infinite recursion for optional pointers.583 if pt, ok := typ.(*PtrType); ok && typ.Optional() {584 switch pt.Elem.(type) {585 case *StructType, *ArrayType, *UnionType:586 name := pt.Elem.Name()587 r.recDepth[name]++588 defer func() {589 r.recDepth[name]--590 if r.recDepth[name] == 0 {591 delete(r.recDepth, name)592 }593 }()594 if r.recDepth[name] >= 3 {595 return MakeSpecialPointerArg(typ, dir, 0), nil596 }597 }598 }599 if !ignoreSpecial && dir != DirOut {600 switch typ.(type) {601 case *StructType, *UnionType:602 if gen := r.target.SpecialTypes[typ.Name()]; gen != nil {603 return gen(&Gen{r, s}, typ, dir, nil)604 }605 }606 }607 return typ.generate(r, s, dir)608}609func (a *ResourceType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {610 if r.oneOf(3) {611 arg = r.existingResource(s, a, dir)612 if arg != nil {613 return614 }615 }616 if r.nOutOf(2, 3) {617 arg, calls = r.resourceCentric(s, a, dir)618 if arg != nil {619 return620 }621 }622 if r.nOutOf(4, 5) {623 arg, calls = r.createResource(s, a, dir)624 if arg != nil {625 return626 }627 }628 special := a.SpecialValues()629 arg = MakeResultArg(a, dir, nil, special[r.Intn(len(special))])630 return631}632func (a *BufferType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {633 switch a.Kind {634 case BufferBlobRand, BufferBlobRange:635 sz := r.randBufLen()636 if a.Kind == BufferBlobRange {637 sz = r.randRange(a.RangeBegin, a.RangeEnd)638 }639 if dir == DirOut {640 return MakeOutDataArg(a, dir, sz), nil641 }642 data := make([]byte, sz)643 for i := range data {644 data[i] = byte(r.Intn(256))645 }646 return MakeDataArg(a, dir, data), nil647 case BufferString:648 data := r.randString(s, a)649 if dir == DirOut {650 return MakeOutDataArg(a, dir, uint64(len(data))), nil651 }652 return MakeDataArg(a, dir, data), nil653 case BufferFilename:654 if dir == DirOut {655 var sz uint64656 switch {657 case !a.Varlen():658 sz = a.Size()659 case r.nOutOf(1, 3):660 sz = r.rand(100)661 case r.nOutOf(1, 2):662 sz = 108 // UNIX_PATH_MAX663 default:664 sz = 4096 // PATH_MAX665 }666 return MakeOutDataArg(a, dir, sz), nil667 }668 return MakeDataArg(a, dir, []byte(r.filename(s, a))), nil669 case BufferText:670 if dir == DirOut {671 return MakeOutDataArg(a, dir, uint64(r.Intn(100))), nil672 }673 return MakeDataArg(a, dir, r.generateText(a.Text)), nil674 default:675 panic("unknown buffer kind")676 }677}678func (a *VmaType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {679 npages := r.randPageCount()680 if a.RangeBegin != 0 || a.RangeEnd != 0 {681 npages = a.RangeBegin + uint64(r.Intn(int(a.RangeEnd-a.RangeBegin+1)))682 }683 return r.allocVMA(s, a, dir, npages), nil684}685func (a *FlagsType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {686 return MakeConstArg(a, dir, r.flags(a.Vals, a.BitMask, 0)), nil687}688func (a *ConstType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {689 return MakeConstArg(a, dir, a.Val), nil690}691func (a *IntType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {692 bits := a.TypeBitSize()693 v := r.randInt(bits)694 switch a.Kind {695 case IntRange:696 v = r.randRangeInt(a.RangeBegin, a.RangeEnd, bits, a.Align)697 }698 return MakeConstArg(a, dir, v), nil699}700func (a *ProcType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {701 return MakeConstArg(a, dir, r.rand(int(a.ValuesPerProc))), nil702}703func (a *ArrayType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {704 var count uint64705 switch a.Kind {706 case ArrayRandLen:707 count = r.randArrayLen()708 case ArrayRangeLen:709 count = r.randRange(a.RangeBegin, a.RangeEnd)710 }711 var inner []Arg712 for i := uint64(0); i < count; i++ {713 arg1, calls1 := r.generateArg(s, a.Elem, dir)714 inner = append(inner, arg1)715 calls = append(calls, calls1...)716 }717 return MakeGroupArg(a, dir, inner), calls718}719func (a *StructType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {720 args, calls := r.generateArgs(s, a.Fields, dir)721 group := MakeGroupArg(a, dir, args)722 return group, calls723}724func (a *UnionType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {725 index := r.Intn(len(a.Fields))726 optType := a.Fields[index].Type727 opt, calls := r.generateArg(s, optType, dir)728 return MakeUnionArg(a, dir, opt, index), calls729}730func (a *PtrType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {731 if r.oneOf(1000) {732 index := r.rand(len(r.target.SpecialPointers))733 return MakeSpecialPointerArg(a, dir, index), nil734 }735 inner, calls := r.generateArg(s, a.Elem, a.ElemDir)736 arg = r.allocAddr(s, a, dir, inner.Size(), inner)737 return arg, calls738}739func (a *LenType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {740 // Updated later in assignSizesCall.741 return MakeConstArg(a, dir, 0), nil742}743func (a *CsumType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*Call) {744 // Filled at runtime by executor.745 return MakeConstArg(a, dir, 0), nil746}747func (r *randGen) existingResource(s *state, res *ResourceType, dir Dir) Arg {748 alltypes := make([][]*ResultArg, 0, len(s.resources))749 for _, res1 := range s.resources {750 alltypes = append(alltypes, res1)751 }752 sort.Slice(alltypes, func(i, j int) bool {753 return alltypes[i][0].Type().Name() < alltypes[j][0].Type().Name()754 })755 var allres []*ResultArg756 for _, res1 := range alltypes {757 name1 := res1[0].Type().Name()758 if r.target.isCompatibleResource(res.Desc.Name, name1) ||759 r.oneOf(50) && r.target.isCompatibleResource(res.Desc.Kind[0], name1) {760 allres = append(allres, res1...)761 }762 }763 if len(allres) == 0 {764 return nil765 }766 return MakeResultArg(res, dir, allres[r.Intn(len(allres))], 0)767}768// Finds a compatible resource with the type `t` and the calls that initialize that resource.769func (r *randGen) resourceCentric(s *state, t *ResourceType, dir Dir) (arg Arg, calls []*Call) {770 var p *Prog771 var resource *ResultArg772 for idx := range r.Perm(len(s.corpus)) {773 p = s.corpus[idx].Clone()...

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(prog.OneOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))4}5import (6func OneOf(items ...interface{}) interface{} {7 return items[rand.Intn(len(items))]8}

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(prog.OneOf(1, 2, 3, 4, 5, 6))4}5import (6func OneOf(args ...interface{}) interface{} {7 return args[rand.Intn(len(args))]8}9func NewClient() Client {10 return &client{http.DefaultClient}11}12func NewClientWithClient(c *http.Client) Client {13 return &client{c}14}15func TestNewClient(t *testing.T) {16 c := NewClient()17 if c.(*client).client != http.DefaultClient {18 t.Fatalf("NewClient() should return a client with DefaultClient")19 }20}21func TestNewClientWithClient(t *testing.T) {22 c := NewClientWithClient(http.DefaultClient)23 if c.(*client).client != http.DefaultClient {24 t.Fatalf("NewClientWithClient() should return a client with DefaultClient")25 }26}27func TestNewClientWithClientDifferent(t *testing.T) {28 c := NewClientWithClient(&http.Client{})29 if c.(*client).client == http.DefaultClient {30 t.Fatalf("NewClientWithClient() should return a client with a different client")31 }32}33--- FAIL: TestNewClientWithClientDifferent (0.00s)34 client_test.go:37: NewClientWithClient() should return a client with a different client

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import java.util.Scanner;2public class Two {3public static void main(String[] args) {4Scanner sc = new Scanner(System.in);5System.out.println("Enter the first number");6int a = sc.nextInt();7System.out.println("Enter the second number");8int b = sc.nextInt();9System.out.println("Enter the third number");10int c = sc.nextInt();11Prog obj = new Prog();12int result = obj.oneOf(a, b, c);13System.out.println("The result is " + result);14}15}16public class Prog {17public int oneOf(int a, int b, int c) {18if (a > b && a > c) {19return a;20} else if (b > a && b > c) {21return b;22} else {23return c;24}25}26}27public class Prog {28public int oneOf(int a, int b, int c) {29return 0;30}31}32import "fmt"33func main() {34fmt.Println("Enter the first number")35fmt.Scanf("%d", &a)36fmt.Println("Enter the second number")37fmt.Scanf("%d", &b)38fmt.Println("Enter the third number")39fmt.Scanf("%d", &c)40obj := Prog{}41result := obj.OneOf(a, b, c)42fmt.Println("The result is", result)43}44type Prog struct {45}46func (p Prog) OneOf(a, b, c int) int {47}48import java.util.Scanner;49public class Two {50public static void main(String[] args) {51Scanner sc = new Scanner(System.in);52System.out.println("Enter the first number");53int a = sc.nextInt();54System.out.println("Enter the second number");55int b = sc.nextInt();56System.out.println("Enter the third number");57int c = sc.nextInt();58Prog obj = new Prog();59int result = obj.oneOf(a, b, c);60System.out.println("The result is " + result);61}62}

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import java.io.*;2{3 public static void main(String args[])4 {5 oneOf ob1 = new oneOf();6 oneOf ob2 = new oneOf();7 oneOf ob3 = new oneOf();8 oneOf ob4 = new oneOf();9 oneOf ob5 = new oneOf();10 ob1.show();11 ob2.show();12 ob3.show();13 ob4.show();14 ob5.show();15 }16}17{18 static int count;19 int x;20 oneOf()21 {22 count++;23 x = count;24 }25 void show()26 {27 System.out.println("x = "+x);28 }29}30import java.io.*;31{32 public static void main(String args[])33 {34 oneOf ob1 = new oneOf();35 oneOf ob2 = new oneOf();36 oneOf ob3 = new oneOf();37 oneOf.show();38 }39}40{41 static int count;42 int x;43 oneOf()44 {45 count++;46 x = count;47 }48 static void show()49 {50 System.out.println("count = "+count);51 }52}53import java.io.*;54{55 public static void main(String args[])56 {57 oneOf ob1 = new oneOf();58 oneOf ob2 = new oneOf();59 oneOf ob3 = new oneOf();60 oneOf.show();61 }62}63{64 static int count;65 int x;66 oneOf()67 {68 count++;69 x = count;70 }71 static void show()72 {73 System.out.println("count = "+count);74 }75}76import java.io.*;77{78 static int count;79 {

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(prog.OneOf(2, 4, 6, 8, 10))4}5func OneOf(list ...int) int {6}7func TwoOf(list ...int) int {8}9func ThreeOf(list ...int) int {10}11func FourOf(list ...int) int {12}13func FiveOf(list ...int) int {14}15func SixOf(list ...int) int {16}17func SevenOf(list ...int) int {18}19func EightOf(list ...int) int {20}21func NineOf(list ...int) int {22}23func TenOf(list ...int) int {24}25func ElevenOf(list ...int) int {26}27func TwelveOf(list ...int) int {28}29func ThirteenOf(list ...int) int {30}31func FourteenOf(list ...int) int {32}33func FifteenOf(list ...int) int {34}35func SixteenOf(list ...int) int {36}

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a.OneOf(1, 2, 3)4 fmt.Println(a)5}6type Prog struct {7}8func (p *Prog) OneOf(a, b, c int) {9}10prog/prog.go:6: prog redeclared as imported package name11prog/prog.go:6: (prog.Prog) OneOf redeclared in this block

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 fmt.Println(math.Abs(-2.2))5 fmt.Println(math.Ceil(2.2))6 fmt.Println(math.Floor(2.2))7 fmt.Println(math.Max(2.2, 2.3))8 fmt.Println(math.Min(2.2, 2.3))9 fmt.Println(math.Mod(2.2, 2.3))10 fmt.Println(math.Pow(2.2, 2.3))11 fmt.Println(math.Sqrt(2.2))12}13import (14func main() {15 fmt.Println("Hello, playground")16 fmt.Println(rand.Intn(100))17 fmt.Println(rand.Intn(100))18 fmt.Println(rand.Float64())19 fmt.Println((rand.Float64() * 5) + 5)20 fmt.Println(rand.Intn(100) + 1)21 fmt.Println(rand.Intn(100) + 1)22 s1 := rand.NewSource(time.Now().UnixNano())23 r1 := rand.New(s1)24 fmt.Println(r1.Intn(100))25 fmt.Println(r1.Intn(100))26 s2 := rand.NewSource(42)27 r2 := rand.New(s2)28 fmt.Println(r2.Intn(100))29 fmt.Println(r2.Intn(100))30 s3 := rand.NewSource(42)31 r3 := rand.New(s3)32 fmt.Println(r3.Intn(100))33 fmt.Println(r3.Intn(100))34}

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 t := time.Now()4 h := t.Hour()5 m := t.Minute()6 s := t.Second()7 fmt.Println("Current time is", h, ":", m, ":", s)8 fmt.Printf("Current time is %d:%d:%d9 fmt.Printf("Current time is %02d:%02d:%02d10 fmt.Printf("Current time is %02d:%02d:%02d %s11", ((h+11)%12+1), m, s, "AM")12 fmt.Printf("Current time is %02d:%02d:%02d %s13", ((h+11)%12+1), m, s, "PM")14 fmt.Printf("Current time is %02d:%02d:%02d %s15 fmt.Printf("Current time is %02d:%02d:%02d %s16 fmt.Printf("Current time is %02d:%02d:%02d %s17 fmt.Printf("Current time is %02d:%02d:%02d %s18 fmt.Printf("Current time is %02d:%02d:%02d %s19 fmt.Printf("Current time is %02d:%02d:%02d %s

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 for i = 1; i <= 4; i++ {4 fmt.Println(i, "prime is", prog.OneOf(i))5 }6 for i = 1; i <= 4; i++ {7 fmt.Println(i, "non-prime is", prog.OneOf(-i))8 }9}10import (11func main() {12 for i = 1; i <= 4; i++ {13 fmt.Println(i, "prime is", prog.OneOf(i))14 }15 for i = 1; i <= 4; i++ {16 fmt.Println(i, "non-prime is", prog.OneOf(-i))17 }18}19import (20func main() {21 for i = 1; i <= 4; i++ {22 fmt.Println(i, "prime is", prog.OneOf(i))23 }24 for i = 1; i <= 4; i++ {25 fmt.Println(i, "non-prime is", prog.OneOf(-i))26 }27}28import (29func main() {30 for i = 1; i <= 4; i++ {31 fmt.Println(i, "prime is", prog.OneOf(i))32 }33 for i = 1; i <= 4; i++ {34 fmt.Println(i, "non-prime is", prog.OneOf(-i))35 }36}

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