How to use DefaultChoiceTable method of prog Package

Best Syzkaller code snippet using prog.DefaultChoiceTable

prog_test.go

Source:prog_test.go Github

copy

Full Screen

...9 "testing"10)11func TestGeneration(t *testing.T) {12 target, rs, iters := initTest(t)13 ct := target.DefaultChoiceTable()14 for i := 0; i < iters; i++ {15 target.Generate(rs, 20, ct)16 }17}18func TestDefault(t *testing.T) {19 target, _, _ := initTest(t)20 ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) {21 arg := typ.DefaultArg(ctx.Dir)22 if !isDefault(arg) {23 t.Errorf("default arg is not default: %s\ntype: %#v\narg: %#v",24 typ, typ, arg)25 }26 })27}28func TestDefaultCallArgs(t *testing.T) {29 target, _, _ := initTest(t)30 for _, meta := range target.SyscallMap {31 if meta.Attrs.Disabled {32 continue33 }34 // Ensure that we can restore all arguments of all calls.35 prog := fmt.Sprintf("%v()", meta.Name)36 p, err := target.Deserialize([]byte(prog), NonStrict)37 if err != nil {38 t.Fatalf("failed to restore default args in prog %q: %v", prog, err)39 }40 if len(p.Calls) != 1 || p.Calls[0].Meta.Name != meta.Name {41 t.Fatalf("restored bad program from prog %q: %q", prog, p.Serialize())42 }43 }44}45func testSerialize(t *testing.T, verbose bool) {46 target, rs, iters := initTest(t)47 ct := target.DefaultChoiceTable()48 for i := 0; i < iters; i++ {49 p := target.Generate(rs, 10, ct)50 var data []byte51 mode := NonStrict52 if verbose {53 data = p.SerializeVerbose()54 mode = Strict55 } else {56 data = p.Serialize()57 }58 p1, err := target.Deserialize(data, mode)59 if err != nil {60 t.Fatalf("failed to deserialize program: %v\n%s", err, data)61 }62 if p1 == nil {63 t.Fatalf("deserialized nil program:\n%s", data)64 }65 var data1 []byte66 if verbose {67 data1 = p1.SerializeVerbose()68 } else {69 data1 = p1.Serialize()70 }71 if len(p.Calls) != len(p1.Calls) {72 t.Fatalf("different number of calls")73 }74 if !bytes.Equal(data, data1) {75 t.Fatalf("program changed after serialize/deserialize\noriginal:\n%s\n\nnew:\n%s\n", data, data1)76 }77 }78}79func TestSerialize(t *testing.T) {80 testSerialize(t, false)81}82func TestSerializeVerbose(t *testing.T) {83 testSerialize(t, true)84}85func TestVmaType(t *testing.T) {86 target, rs, iters := initRandomTargetTest(t, "test", "64")87 ct := target.DefaultChoiceTable()88 meta := target.SyscallMap["test$vma0"]89 r := newRand(target, rs)90 pageSize := target.PageSize91 for i := 0; i < iters; i++ {92 s := newState(target, ct, nil)93 calls := r.generateParticularCall(s, meta)94 c := calls[len(calls)-1]95 if c.Meta.Name != "test$vma0" {96 t.Fatalf("generated wrong call %v", c.Meta.Name)97 }98 if len(c.Args) != 6 {99 t.Fatalf("generated wrong number of args %v", len(c.Args))100 }101 check := func(v, l Arg, min, max uint64) {102 va, ok := v.(*PointerArg)103 if !ok {104 t.Fatalf("vma has bad type: %v", v)105 }106 la, ok := l.(*ConstArg)107 if !ok {108 t.Fatalf("len has bad type: %v", l)109 }110 if va.VmaSize < min || va.VmaSize > max {111 t.Fatalf("vma has bad size: %v, want [%v-%v]",112 va.VmaSize, min, max)113 }114 if la.Val < min || la.Val > max {115 t.Fatalf("len has bad value: %v, want [%v-%v]",116 la.Val, min, max)117 }118 }119 check(c.Args[0], c.Args[1], 1*pageSize, 1e5*pageSize)120 check(c.Args[2], c.Args[3], 5*pageSize, 5*pageSize)121 check(c.Args[4], c.Args[5], 7*pageSize, 9*pageSize)122 }123}124// TestCrossTarget ensures that a program serialized for one arch can be125// deserialized for another arch. This happens when managers exchange126// programs via hub.127func TestCrossTarget(t *testing.T) {128 t.Parallel()129 const OS = "linux"130 var archs []string131 for _, target := range AllTargets() {132 if target.OS == OS {133 archs = append(archs, target.Arch)134 }135 }136 for _, arch := range archs {137 target, err := GetTarget(OS, arch)138 if err != nil {139 t.Fatal(err)140 }141 var crossTargets []*Target142 for _, crossArch := range archs {143 if crossArch == arch {144 continue145 }146 crossTarget, err := GetTarget(OS, crossArch)147 if err != nil {148 t.Fatal(err)149 }150 crossTargets = append(crossTargets, crossTarget)151 }152 t.Run(fmt.Sprintf("%v/%v", OS, arch), func(t *testing.T) {153 t.Parallel()154 testCrossTarget(t, target, crossTargets)155 })156 }157}158func testCrossTarget(t *testing.T, target *Target, crossTargets []*Target) {159 ct := target.DefaultChoiceTable()160 rs := randSource(t)161 iters := 100162 if testing.Short() {163 iters /= 10164 }165 for i := 0; i < iters; i++ {166 p := target.Generate(rs, 20, ct)167 testCrossArchProg(t, p, crossTargets)168 p, err := target.Deserialize(p.Serialize(), NonStrict)169 if err != nil {170 t.Fatal(err)171 }172 testCrossArchProg(t, p, crossTargets)173 p.Mutate(rs, 20, ct, nil)174 testCrossArchProg(t, p, crossTargets)175 p, _ = Minimize(p, -1, false, func(*Prog, int) bool {176 return rs.Int63()%2 == 0177 })178 testCrossArchProg(t, p, crossTargets)179 }180}181func testCrossArchProg(t *testing.T, p *Prog, crossTargets []*Target) {182 serialized := p.Serialize()183 for _, crossTarget := range crossTargets {184 _, err := crossTarget.Deserialize(serialized, NonStrict)185 if err == nil || strings.Contains(err.Error(), "unknown syscall") {186 continue187 }188 t.Fatalf("failed to deserialize for %v/%v: %v\n%s",189 crossTarget.OS, crossTarget.Arch, err, serialized)190 }191}192func TestSpecialStructs(t *testing.T) {193 testEachTargetRandom(t, func(t *testing.T, target *Target, rs rand.Source, iters int) {194 _ = target.GenerateAllSyzProg(rs)195 ct := target.DefaultChoiceTable()196 for special, gen := range target.SpecialTypes {197 t.Run(special, func(t *testing.T) {198 var typ Type199 for i := 0; i < len(target.Syscalls) && typ == nil; i++ {200 ForeachCallType(target.Syscalls[i], func(t Type, ctx TypeCtx) {201 if ctx.Dir == DirOut {202 return203 }204 if s, ok := t.(*StructType); ok && s.Name() == special {205 typ = s206 }207 if s, ok := t.(*UnionType); ok && s.Name() == special {208 typ = s209 }210 })211 }212 if typ == nil {213 t.Fatal("can't find struct description")214 }215 g := &Gen{newRand(target, rs), newState(target, ct, nil)}216 for i := 0; i < iters/len(target.SpecialTypes); i++ {217 var arg Arg218 for i := 0; i < 2; i++ {219 arg, _ = gen(g, typ, DirInOut, arg)220 if arg.Dir() != DirInOut {221 t.Fatalf("got wrong arg dir %v", arg.Dir())222 }223 }224 }225 })226 }227 })228}229func TestEscapingPaths(t *testing.T) {230 paths := map[string]bool{231 "/": true,232 "/\x00": true,233 "/file/..": true,234 "/file/../..": true,235 "./..": true,236 "..": true,237 "file/../../file": true,238 "../file": true,239 "./file/../../file/file": true,240 "": false,241 ".": false,242 "file": false,243 "./file": false,244 "./file/..": false,245 }246 for path, want := range paths {247 got := escapingFilename(path)248 if got != want {249 t.Errorf("path %q: got %v, want %v", path, got, want)250 }251 }252}253func TestFallbackSignal(t *testing.T) {254 type desc struct {255 prog string256 info []CallInfo257 }258 tests := []desc{259 // Test restored errno values and that non-executed syscalls don't get fallback signal.260 {261 `262fallback$0()263fallback$0()264fallback$0()265`,266 []CallInfo{267 {268 Flags: CallExecuted,269 Errno: 0,270 Signal: make([]uint32, 1),271 },272 {273 Flags: CallExecuted,274 Errno: 42,275 Signal: make([]uint32, 1),276 },277 {},278 },279 },280 // Test different cases of argument-dependent signal and that unsuccessful calls don't get it.281 {282 `283r0 = fallback$0()284fallback$1(r0)285fallback$1(r0)286fallback$1(0xffffffffffffffff)287fallback$1(0x0)288fallback$1(0x0)289`,290 []CallInfo{291 {292 Flags: CallExecuted,293 Errno: 0,294 Signal: make([]uint32, 1),295 },296 {297 Flags: CallExecuted,298 Errno: 1,299 Signal: make([]uint32, 1),300 },301 {302 Flags: CallExecuted,303 Errno: 0,304 Signal: make([]uint32, 2),305 },306 {307 Flags: CallExecuted,308 Errno: 0,309 Signal: make([]uint32, 1),310 },311 {312 Flags: CallExecuted,313 Errno: 0,314 Signal: make([]uint32, 2),315 },316 {317 Flags: CallExecuted,318 Errno: 2,319 Signal: make([]uint32, 1),320 },321 },322 },323 // Test that calls get no signal after a successful seccomp.324 {325 `326fallback$0()327fallback$0()328breaks_returns()329fallback$0()330breaks_returns()331fallback$0()332fallback$0()333`,334 []CallInfo{335 {336 Flags: CallExecuted,337 Errno: 0,338 Signal: make([]uint32, 1),339 },340 {341 Flags: CallExecuted,342 Errno: 0,343 Signal: make([]uint32, 1),344 },345 {346 Flags: CallExecuted,347 Errno: 1,348 Signal: make([]uint32, 1),349 },350 {351 Flags: CallExecuted,352 Errno: 0,353 },354 {355 Flags: CallExecuted,356 Errno: 0,357 },358 {359 Flags: CallExecuted,360 },361 {362 Flags: CallExecuted,363 },364 },365 },366 {367 `368fallback$0()369breaks_returns()370fallback$0()371breaks_returns()372fallback$0()373`,374 []CallInfo{375 {376 Flags: CallExecuted,377 Errno: 0,378 Signal: make([]uint32, 1),379 },380 {381 Flags: CallExecuted,382 Errno: 1,383 Signal: make([]uint32, 1),384 },385 {386 Flags: CallExecuted,387 Errno: 0,388 },389 {390 Flags: CallExecuted,391 Errno: 0,392 },393 {394 Flags: CallExecuted,395 },396 },397 },398 }399 target, err := GetTarget("test", "64")400 if err != nil {401 t.Fatal(err)402 }403 for i, test := range tests {404 t.Run(fmt.Sprint(i), func(t *testing.T) {405 p, err := target.Deserialize([]byte(test.prog), Strict)406 if err != nil {407 t.Fatal(err)408 }409 if len(p.Calls) != len(test.info) {410 t.Fatalf("call=%v info=%v", len(p.Calls), len(test.info))411 }412 wantSignal := make([]int, len(test.info))413 for i := range test.info {414 wantSignal[i] = len(test.info[i].Signal)415 test.info[i].Signal = nil416 }417 p.FallbackSignal(test.info)418 for i := range test.info {419 if len(test.info[i].Signal) != wantSignal[i] {420 t.Errorf("call %v: signal=%v want=%v", i, len(test.info[i].Signal), wantSignal[i])421 }422 for _, sig := range test.info[i].Signal {423 call, errno := DecodeFallbackSignal(sig)424 if call != p.Calls[i].Meta.ID {425 t.Errorf("call %v: sig=%x id=%v want=%v", i, sig, call, p.Calls[i].Meta.ID)426 }427 if errno != test.info[i].Errno {428 t.Errorf("call %v: sig=%x errno=%v want=%v", i, sig, errno, test.info[i].Errno)429 }430 }431 }432 })433 }434}435func TestSanitizeRandom(t *testing.T) {436 testEachTargetRandom(t, func(t *testing.T, target *Target, rs rand.Source, iters int) {437 ct := target.DefaultChoiceTable()438 for i := 0; i < iters; i++ {439 p := target.Generate(rs, 10, ct)440 s0 := string(p.Serialize())441 p.sanitizeFix()442 s1 := string(p.Serialize())443 if s0 != s1 {444 t.Fatalf("non-sanitized program or non-idempotent sanitize\nwas: %v\ngot: %v", s0, s1)445 }446 }447 })448}...

Full Screen

Full Screen

DefaultChoiceTable

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

DefaultChoiceTable

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Run(`5 var prog = {6 DefaultChoiceTable: function() {7 return "DefaultChoiceTable";8 }9 }10 value, _ := vm.Run(`11 prog.DefaultChoiceTable()12 fmt.Println(value)13}14import (15func main() {16 vm := otto.New()17 vm.Run(`18 var prog = {19 DefaultChoiceTable: function() {20 return "DefaultChoiceTable";21 }22 }23 value, _ := vm.Run(`24 var obj = {};25 obj.name = "John";26 obj.age = 30;27 obj.city = "New York";28 fmt.Println(value)29}30{age: 30, city: "New York", name: "John"}31import (32func main() {33 vm := otto.New()34 vm.Run(`35 var prog = {36 DefaultChoiceTable: function() {37 return "DefaultChoiceTable";38 }39 }

Full Screen

Full Screen

DefaultChoiceTable

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Enter two numbers")4 fmt.Scanf("%d %d", &a, &b)5 fmt.Println("The sum of two numbers is :", a+b)6}7import "fmt"8func main() {9 fmt.Println("Enter two numbers")10 fmt.Scanf("%d %d", &a, &b)11 fmt.Println("The sum of two numbers is :", a+b)12}13import "fmt"14func main() {15 fmt.Println("Enter two numbers")16 fmt.Scanf("%d %d", &a, &b)17 fmt.Println("The sum of two numbers is :", a+b)18}19import "fmt"20func main() {21 fmt.Println("Enter two numbers")22 fmt.Scanf("%d %d", &a, &b)23 fmt.Println("The sum of two numbers is :", a+b)24}25import "fmt"26func main() {27 fmt.Println("Enter two numbers")28 fmt.Scanf("%d %d", &a, &b)29 fmt.Println("The sum of two numbers is :", a+b)30}31import "fmt"32func main() {33 fmt.Println("Enter two numbers")34 fmt.Scanf("%d %d", &a, &b)35 fmt.Println("The sum of two numbers is :", a+b)36}37import "fmt"38func main() {39 fmt.Println("Enter two numbers")40 fmt.Scanf("%d %d", &a, &b)41 fmt.Println("The sum of

Full Screen

Full Screen

DefaultChoiceTable

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 app := cli.NewApp()4 app.Action = func(c *cli.Context) error {5 fmt.Println("Hello friend!")6 }7 app.Run(os.Args)8}9import (10func main() {11 app := cli.NewApp()12 app.Action = func(c *cli.Context) error {13 fmt.Println("Hello friend!")14 }15 app.Run(os.Args)16}17import (18func main() {19 app := cli.NewApp()20 app.Action = func(c *cli.Context) error {21 fmt.Println("Hello friend!")22 }23 app.RunAsSubcommand(os.Args)24}25import (26func main() {27 app := cli.NewApp()28 app.Action = func(c *cli.Context) error {29 fmt.Println("Hello friend!")30 }31 app.RunAndExitOnError(os.Args)32}33import (34func main() {35 app := cli.NewApp()36 app.Action = func(c *cli.Context) error {37 fmt.Println("Hello friend!")38 }39 app.RunAsSubcommand(os.Args)40}41import (

Full Screen

Full Screen

DefaultChoiceTable

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(gol.DefaultChoiceTable(3, 3))4}5import (6func main() {7 fmt.Println(gol.DefaultChoiceTable(3, 3, 1))8}9import (10func main() {11 fmt.Println(gol.DefaultChoiceTable(3, 3, 1, 2))12}13import (14func main() {15 fmt.Println(gol.DefaultChoiceTable(3, 3, 1, 2, 3))16}17import (18func main() {19 fmt.Println(gol.DefaultChoiceTable(3, 3, 1, 2, 3, 4))20}21import (

Full Screen

Full Screen

DefaultChoiceTable

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 myApp := cli.NewApp()4 myApp.Action = func(c *cli.Context) error {5 fmt.Println("Hello friend!")6 }7 myApp.Run(os.Args)8}9import (10func main() {11 myApp := cli.NewApp()12 myApp.Action = func(c *cli.Context) error {13 fmt.Println("Hello friend!")14 }15 myApp.Run(os.Args)16}17import (18func main() {19 myApp := cli.NewApp()20 myApp.Action = func(c *cli.Context) error {21 fmt.Println("Hello friend!")22 }23 myApp.Run(os.Args)24}25import (26func main() {27 myApp := cli.NewApp()28 myApp.Action = func(c *cli.Context) error {29 fmt.Println("Hello friend!")30 }31 myApp.Run(os.Args)32}33import (34func main() {35 myApp := cli.NewApp()36 myApp.Action = func(c *cli.Context) error {37 fmt.Println("Hello friend!")38 }39 myApp.Run(os.Args)40}

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