How to use runMutationTests method of prog Package

Best Syzkaller code snippet using prog.runMutationTests

mutation_test.go

Source:mutation_test.go Github

copy

Full Screen

...27 `r0 = mutate_flags3(&(0x7f0000000000)="2e2f66696c653000", 0xddddeeee)`,28 `r0 = mutate_flags3(&(0x7f0000000000)="2e2f66696c653000", 0xaaaaaaaa)`,29 },30 }31 runMutationTests(t, tests, true)32}33func TestChooseCall(t *testing.T) {34 tests := [][2]string{35 // The call with many arguments has a higher mutation probability.36 {37 `mutate0()38mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)39mutate_integer2(0x00, 0x00, 0x20, 0x00, 0x01)`,40 `mutate0()41mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0xffffffff)42mutate_integer2(0x00, 0x00, 0x20, 0x00, 0x01)`,43 },44 // Calls with the same probability.45 {46 `mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)47mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)48mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)49mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)50mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)`,51 `mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)52mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)53mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0xff)54mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)55mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)`,56 },57 // The call with a lower probability can be mutated.58 {59 `mutate7(&(0x7f0000000000)='123', 0x3)60mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)61r0 = mutate_flags(&(0x7f0000000000)="2e2f66696c653000", 0x0, 0x1, 0x1)`,62 `mutate7(&(0x7f0000000000)='123', 0x2)63mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)64r0 = mutate_flags(&(0x7f0000000000)="2e2f66696c653000", 0x0, 0x1, 0x1)`,65 },66 // Complex arguments.67 {68 `test$struct(&(0x7f0000000000)={0x0, {0x0}})69test$array0(&(0x7f0000001000)={0x1, [@f0=0x2, @f1=0x3], 0x4})70mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)`,71 `test$struct(&(0x7f0000000000)={0xff, {0x0}})72test$array0(&(0x7f0000001000)={0x1, [@f0=0x2, @f1=0x3], 0x4})73mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)`,74 },75 }76 runMutationTests(t, tests, true)77}78func TestMutateArgument(t *testing.T) {79 tests := [][2]string{80 // Mutate an integer with a higher priority than the boolean arguments.81 {82 `mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1)`,83 `mutate_integer(0x0, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0xffffffff)`,84 },85 // Mutate a boolean.86 {87 `mutate_integer(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)`,88 `mutate_integer(0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0)`,89 },90 // Mutate flags (bitmask = true).91 {92 `r0 = mutate_flags(&(0x7f0000000000)="2e2f66696c653000", 0x0, 0x1, 0x1)`,93 `r0 = mutate_flags(&(0x7f0000000000)="2e2f66696c653000", 0x20, 0x1, 0x9)`,94 },95 // Mutate an int8 from a set of other arguments with higher priority.96 {97 `mutate_integer2(0x00, 0x00, 0x20, 0x00, 0x01)`,98 `mutate_integer2(0x00, 0x00, 0x20, 0x00, 0x07)`,99 },100 // Mutate an array of structs101 {102 `mutate_array2(&(0x7f0000000000)=[{0x0}, {0x0}, {0x0}, {0x0}, {0x0}])`,103 `mutate_array2(&(0x7f0000000000)=[{0x0}, {0x0}, {0x3}, {0x0}, {0x0}])`,104 },105 // Mutate a non-special union that have more than 1 option106 {107 `mutate_union(&(0x7f0000000000)=@f1=[0x0, 0x1, 0x2, 0x3, 0x0, 0x1, 0x2, 0x3, 0x0, 0x0])`,108 `mutate_union(&(0x7f0000000000)=@f0=0x2)`,109 },110 // Mutate the value of the current option in union111 {112 `mutate_union(&(0x7f0000000000)=@f1=[0x0, 0x1, 0x2, 0x3, 0x0, 0x1, 0x2, 0x3, 0x0, 0x0])`,113 `mutate_union(&(0x7f0000000000)=@f1=[0x0, 0x1, 0xff, 0x3, 0x0, 0x1, 0x2, 0x3, 0x0, 0x0])`,114 },115 }116 target := initTargetTest(t, "test", "64")117 for ti, test := range tests {118 test := test119 t.Run(fmt.Sprint(ti), func(t *testing.T) {120 t.Parallel()121 rs, ct, p, goal, err := buildTestContext(test, target)122 if err != nil {123 t.Fatalf("failed to deserialize the program: %v", err)124 }125 want := goal.Serialize()126 for i := 0; i < 1e5; i++ {127 p1 := p.Clone()128 ctx := &mutator{129 p: p1,130 r: newRand(p1.Target, rs),131 ncalls: 2 * len(p.Calls),132 ct: ct,133 corpus: nil,134 }135 ctx.mutateArg()136 data1 := p1.Serialize()137 if bytes.Equal(want, data1) {138 t.Logf("success on iter %v", i)139 return140 }141 }142 t.Fatalf("failed to achieve goal, original:%s\ngoal:%s", test[0], test[1])143 })144 }145}146func TestSizeMutateArg(t *testing.T) {147 target, rs, iters := initRandomTargetTest(t, "test", "64")148 r := newRand(target, rs)149 ct := target.DefaultChoiceTable()150 for i := 0; i < iters; i++ {151 p := target.Generate(rs, 10, ct)152 for it := 0; it < 10; it++ {153 p1 := p.Clone()154 ctx := &mutator{155 p: p1,156 r: r,157 ncalls: 2 * len(p.Calls),158 ct: ct,159 corpus: nil,160 }161 ctx.mutateArg()162 ForeachArg(p.Calls[0], func(arg Arg, ctx *ArgCtx) {163 if _, ok := arg.Type().(*IntType); !ok {164 return165 }166 bits := arg.Type().TypeBitSize()167 limit := uint64(1<<bits - 1)168 val := arg.(*ConstArg).Val169 if val > limit {170 t.Fatalf("Invalid argument value: %d. (arg size: %d; max value: %d)", val, arg.Size(), limit)171 }172 })173 }174 }175}176func TestClone(t *testing.T) {177 target, rs, iters := initTest(t)178 ct := target.DefaultChoiceTable()179 for i := 0; i < iters; i++ {180 p := target.Generate(rs, 10, ct)181 p1 := p.Clone()182 data := p.Serialize()183 data1 := p1.Serialize()184 if !bytes.Equal(data, data1) {185 t.Fatalf("program changed after clone\noriginal:\n%s\n\nnew:\n%s\n", data, data1)186 }187 }188}189func TestMutateRandom(t *testing.T) {190 testEachTargetRandom(t, func(t *testing.T, target *Target, rs rand.Source, iters int) {191 ct := target.DefaultChoiceTable()192 next:193 for i := 0; i < iters; i++ {194 p := target.Generate(rs, 10, ct)195 data0 := p.Serialize()196 p1 := p.Clone()197 // There is a chance that mutation will produce the same program.198 // So we check that at least 1 out of 20 mutations actually change the program.199 for try := 0; try < 20; try++ {200 p1.Mutate(rs, 10, ct, nil)201 data := p.Serialize()202 if !bytes.Equal(data0, data) {203 t.Fatalf("program changed after mutate\noriginal:\n%s\n\nnew:\n%s\n",204 data0, data)205 }206 data1 := p1.Serialize()207 if bytes.Equal(data, data1) {208 continue209 }210 if _, err := target.Deserialize(data1, NonStrict); err != nil {211 t.Fatalf("Deserialize failed after Mutate: %v\n%s", err, data1)212 }213 continue next214 }215 t.Fatalf("mutation does not change program:\n%s", data0)216 }217 })218}219func TestMutateCorpus(t *testing.T) {220 target, rs, iters := initTest(t)221 ct := target.DefaultChoiceTable()222 var corpus []*Prog223 for i := 0; i < 100; i++ {224 p := target.Generate(rs, 10, ct)225 corpus = append(corpus, p)226 }227 for i := 0; i < iters; i++ {228 p1 := target.Generate(rs, 10, ct)229 p1.Mutate(rs, 10, ct, corpus)230 }231}232func TestMutateTable(t *testing.T) {233 tests := [][2]string{234 // Insert a call.235 {`236mutate0()237mutate2()238`, `239mutate0()240mutate1()241mutate2()242`},243 // Remove calls and update args.244 {`245r0 = mutate5(&(0x7f0000000000)="2e2f66696c653000", 0x0)246mutate0()247mutate6(r0, &(0x7f0000000000)="00", 0x1)248mutate1()249`, `250mutate0()251mutate6(0xffffffffffffffff, &(0x7f0000000000)="00", 0x1)252mutate1()253`},254 // Mutate flags.255 {`256r0 = mutate5(&(0x7f0000000000)="2e2f66696c653000", 0x0)257mutate0()258mutate6(r0, &(0x7f0000000000)="00", 0x1)259mutate1()260`, `261r0 = mutate5(&(0x7f0000000000)="2e2f66696c653000", 0xcdcdcdcd)262mutate0()263mutate6(r0, &(0x7f0000000000)="00", 0x1)264mutate1()265`},266 // Mutate data (delete byte and update size).267 {`268mutate4(&(0x7f0000000000)="11223344", 0x4)269`, `270mutate4(&(0x7f0000000000)="113344", 0x3)271`},272 // Mutate data (insert byte and update size).273 // TODO: this is not working, because Mutate constantly tends274 // update addresses and insert mmap's.275 /*276 {`277 mutate4(&(0x7f0000000000)="1122", 0x2)278 `, `279 mutate4(&(0x7f0000000000)="112200", 0x3)280 `},281 */282 // Mutate data (change byte).283 {`284mutate4(&(0x7f0000000000)="1122", 0x2)285`, `286mutate4(&(0x7f0000000000)="1100", 0x2)287`},288 // Change filename.289 {`290mutate5(&(0x7f0000001000)="2e2f66696c653000", 0x22c0)291mutate5(&(0x7f0000001000)="2e2f66696c653000", 0x22c0)292`, `293mutate5(&(0x7f0000001000)="2e2f66696c653000", 0x22c0)294mutate5(&(0x7f0000001000)="2e2f66696c653100", 0x22c0)295`},296 // Mutate the array.297 {`298mutate_array(0x1, 0x30, &(0x7f0000000000)=[0x1, 0x1, 0x1, 0x1, 0x1])299`, `300mutate_array(0x1, 0x30, &(0x7f0000000000)=[0x1, 0x1, 0x1, 0x1])301`},302 // Extend an array.303 {`304mutate3(&(0x7f0000000000)=[0x1, 0x1], 0x2)305`, `306mutate3(&(0x7f0000000000)=[0x1, 0x1, 0x1], 0x3)307`},308 // Mutate size from it's natural value.309 {`310mutate7(&(0x7f0000000000)='123', 0x3)311`, `312mutate7(&(0x7f0000000000)='123', 0x2)313`},314 // Mutate proc to the special value.315 {`316mutate8(0x2)317`, `318mutate8(0xffffffffffffffff)319`},320 // Increase buffer length321 {`322mutate_buffer(&(0x7f0000000000)=""/100)323`, `324mutate_buffer(&(0x7f0000000000)=""/200)325`},326 // Decrease buffer length327 {`328mutate_buffer(&(0x7f0000000000)=""/800)329`, `330mutate_buffer(&(0x7f0000000000)=""/4)331`},332 // Mutate a ranged buffer333 {`334mutate_rangedbuffer(&(0x7f00000000c0)=""/10)335`, `336mutate_rangedbuffer(&(0x7f00000000c0)=""/7)337`},338 }339 runMutationTests(t, tests, true)340}341func TestNegativeMutations(t *testing.T) {342 tests := [][2]string{343 // Mutate buffer size outside the range limits344 {`345mutate_rangedbuffer(&(0x7f00000000c0)=""/7)346`, `347mutate_rangedbuffer(&(0x7f00000000c0)=""/4)348`},349 {`350mutate_rangedbuffer(&(0x7f00000000c0)=""/7)351`, `352mutate_rangedbuffer(&(0x7f00000000c0)=""/11)353`},354 }355 runMutationTests(t, tests, false)356}357func BenchmarkMutate(b *testing.B) {358 target, cleanup := initBench(b)359 defer cleanup()360 ct := target.DefaultChoiceTable()361 const progLen = 30362 p := target.Generate(rand.NewSource(0), progLen, ct)363 b.ResetTimer()364 b.RunParallel(func(pb *testing.PB) {365 rs := rand.NewSource(0)366 for pb.Next() {367 p.Clone().Mutate(rs, progLen, ct, nil)368 }369 })370}371func BenchmarkGenerate(b *testing.B) {372 target, cleanup := initBench(b)373 defer cleanup()374 ct := target.DefaultChoiceTable()375 const progLen = 30376 b.ResetTimer()377 b.RunParallel(func(pb *testing.PB) {378 rs := rand.NewSource(0)379 for pb.Next() {380 target.Generate(rs, progLen, ct)381 }382 })383}384func runMutationTests(t *testing.T, tests [][2]string, valid bool) {385 target := initTargetTest(t, "test", "64")386 for ti, test := range tests {387 test := test388 t.Run(fmt.Sprint(ti), func(t *testing.T) {389 t.Parallel()390 rs, ct, p, goal, err := buildTestContext(test, target)391 if err != nil {392 t.Fatalf("failed to deserialize the program: %v", err)393 }394 want := goal.Serialize()395 iters := iterCount()396 if valid {397 iters = 1e6 // it will stop after reaching the goal398 }...

Full Screen

Full Screen

runMutationTests

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 prog.RunMutationTests()5}6import (7func RunMutationTests() {8 fmt.Println("RunMutationTests")9}10import (11func TestRunMutationTests(t *testing.T) {12 RunMutationTests()13}14I don’t understand why the RunMutationTests() is not getting called. I am using Go 1.7.3

Full Screen

Full Screen

runMutationTests

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

runMutationTests

Using AI Code Generation

copy

Full Screen

1import (2func runMutationTests(t *testing.T, tests []MutationTest) {3 for _, test := range tests {4 t.Run(test.name, func(t *testing.T) {5 f, err := parser.ParseFile(fset, "src.go", test.src, parser.ParseComments)6 if err != nil {7 t.Fatal(err)8 }9 for _, s := range f.Imports {10 fmt.Println(s.Path.Value)11 }12 ast.Inspect(f, func(n ast.Node) bool {13 switch x := n.(type) {14 fmt.Printf("%s: %s15 }16 })17 info := &types.Info{18 Defs: make(map[*ast.Ident]types.Object),19 }20 config := &types.Config{Importer: importer{t}}21 _, err = config.Check("src.go", fset, []*ast.File{f}, info)22 if err != nil {23 t.Fatal(err)24 }25 for _, expr := range test.exprs {26 if !ok {27 t.Fatalf("no type for expression %s", expr)28 }29 fmt.Printf("%s: %s30 }31 if obj == nil {32 t.Fatal("no object for identifier a")33 }34 fmt.Println("a:", obj.Type())35 })36 }37}38type MutationTest struct {39}40func TestMutation(t *testing.T) {41 tests := []MutationTest{42 {

Full Screen

Full Screen

runMutationTests

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := mutant.Prog{}4 p.RunMutationTests()5 fmt.Println("Hello World!")6}

Full Screen

Full Screen

runMutationTests

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

runMutationTests

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := mutator.NewProg()4 p.AddMutationTest("test1", "test1.go")5 p.AddMutationTest("test2", "test2.go")6 p.AddMutationTest("test3", "test3.go")7 p.AddMutationTest("test4", "test4.go")8 p.AddMutationTest("test5", "test5.go")9 p.AddMutationTest("test6", "test6.go")10 p.AddMutationTest("test7", "test7.go")11 p.AddMutationTest("test8", "test8.go")12 p.AddMutationTest("test9", "test9.go")13 p.AddMutationTest("test10", "test10.go")14 p.AddMutationTest("test11", "test11.go")15 p.AddMutationTest("test12", "test12.go")16 p.AddMutationTest("test13", "test13.go")17 p.AddMutationTest("test14", "test14.go")18 p.AddMutationTest("test15", "test15.go")19 p.AddMutationTest("test16", "test16.go")20 p.AddMutationTest("test17", "test17.go")21 p.AddMutationTest("test18", "test18.go")22 p.AddMutationTest("test19", "test19.go")23 p.AddMutationTest("test20", "test20.go")24 p.AddMutationTest("test21", "test21.go")25 p.AddMutationTest("test22", "test22.go")26 p.AddMutationTest("test23", "test23.go")

Full Screen

Full Screen

runMutationTests

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := prog.NewProg()4 prog.RunMutationTests()5 fmt.Println("Number of mutants killed:", prog.GetNumMutantsKilled())6 fmt.Println("Number of mutants survived:", prog.GetNumMutantsSurvived())7 fmt.Println("Number of mutants timed out:", prog.GetNumMutantsTimedOut())8 fmt.Println("Number of mutants killed by compilation errors:", prog.GetNumMutantsCompileErrors())9}10import (11type Prog struct {12}13func NewProg() *Prog {14 prog := new(Prog)15 prog.mutants = make([]mutant.Mutant, 0)16 prog.tests = make([]test.Test, 0)17}18func (prog *Prog) RunMutationTests() {19 parser := parser.NewParser()

Full Screen

Full Screen

runMutationTests

Using AI Code Generation

copy

Full Screen

1import (2type prog struct {3}4func (p *prog) mutate() {5 for i := 0; i < len(p.array); i++ {6 p.array[i] += rand.Intn(20)7 }8}9func runMutationTests() {10 a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}11 p := prog{array: a}12 results := make([][]int, n)13 for i := 0; i < n; i++ {14 p.mutate()15 }16 fmt.Println(results)17}18func main() {19 rand.Seed(time.Now().UnixNano())20 runMutationTests()21}

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