How to use AllTargets method of prog Package

Best Syzkaller code snippet using prog.AllTargets

compile_test.go

Source:compile_test.go Github

copy

Full Screen

...44 Destdir: "obj",45 Options: map[string]bool{"incdeps": true},46 },47 }48 checkTargets(t, expt, desc.AllTargets())49 if len(desc.Objs) == 0 {50 t.Error("No objects")51 }52}53func TestCompileCPic(t *testing.T) {54 desc := (&ProgDesc{LinkDesc: LinkDesc{Picrules: true}}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)55 desc.CompileC("testdir", "src.c", "src")56 expt := map[string]*Target{57 "src.o": {58 Rule: "cc",59 Sources: []string{"src.c"},60 Destdir: "obj",61 Options: map[string]bool{"incdeps": true},62 },63 "src.pic_o": {64 Rule: "cc",65 Sources: []string{"src.c"},66 Destdir: "obj",67 Extraargs: []string{"picflag=-fPIC"},68 Options: map[string]bool{"incdeps": true},69 },70 "src.analyse": {71 Rule: "cc_analyse",72 Sources: []string{"src.c"},73 Destdir: "obj",74 Options: map[string]bool{"incdeps": true},75 },76 }77 checkTargets(t, expt, desc.AllTargets())78}79func TestCompileCXXPic(t *testing.T) {80 desc := (&ProgDesc{LinkDesc: LinkDesc{Picrules: true}}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)81 desc.CompileCXX("testdir", "src.cc", "src")82 expt := map[string]*Target{83 "src.o": {84 Rule: "cxx",85 Sources: []string{"src.cc"},86 Destdir: "obj",87 Options: map[string]bool{"incdeps": true},88 },89 "src.pic_o": {90 Rule: "cxx",91 Sources: []string{"src.cc"},92 Destdir: "obj",93 Extraargs: []string{"picflag=-fPIC"},94 Options: map[string]bool{"incdeps": true},95 },96 "src.analyse": {97 Rule: "cxx_analyse",98 Sources: []string{"src.cc"},99 Destdir: "obj",100 Options: map[string]bool{"incdeps": true},101 },102 }103 checkTargets(t, expt, desc.AllTargets())104 if desc.Link != "linkxx" {105 t.Error("linker wasn't changed")106 }107 if len(desc.Objs) == 0 {108 t.Error("No objects")109 }110}111func TestCompileNoAnalyse(t *testing.T) {112 desc := (&ProgDesc{LinkDesc: LinkDesc{NoAnalyse: true}}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)113 desc.CompileC("testdir", "src.c", "src")114 desc.CompileCXX("testdir", "src2.cc", "src2")115 expt := map[string]*Target{116 "src.o": {117 Rule: "cc",118 Sources: []string{"src.c"},119 Destdir: "obj",120 Options: map[string]bool{"incdeps": true},121 },122 "src2.o": {123 Rule: "cxx",124 Sources: []string{"src2.cc"},125 Destdir: "obj",126 Options: map[string]bool{"incdeps": true},127 },128 }129 checkTargets(t, expt, desc.AllTargets())130 if !desc.DontAnalyse["src"] {131 t.Error("DontAnalyse wasn't set")132 }133 if !desc.DontAnalyse["src2"] {134 t.Error("DontAnalyse wasn't set")135 }136}137func TestCompileYY(t *testing.T) {138 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)139 desc.CompileYY("testdir", "src.yy", "src")140 expt := map[string]*Target{141 "src.cc": {142 Rule: "yaccxx",143 Sources: []string{"src.yy"},144 Destdir: "obj",145 },146 "src.hh": {147 Rule: "phony",148 Sources: []string{"src.cc"},149 Destdir: "obj",150 },151 "src.o": {152 Rule: "cxx",153 Sources: []string{"src.cc"},154 Destdir: "obj",155 Options: map[string]bool{"incdeps": true},156 },157 "src.analyse": {158 Rule: "cxx_analyse",159 Sources: []string{"src.cc"},160 Destdir: "obj",161 Options: map[string]bool{"incdeps": true},162 },163 }164 checkTargets(t, expt, desc.AllTargets())165 if desc.Link != "linkxx" {166 t.Error("linker wasn't changed")167 }168 if !reflect.DeepEqual(desc.Incdeps, []string{"src.hh"}) {169 t.Error("Not added to incdeps")170 }171}172func TestCompileLL(t *testing.T) {173 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)174 desc.CompileLL("testdir", "src.ll", "src")175 expt := map[string]*Target{176 "src.cc": {177 Rule: "flexx",178 Sources: []string{"src.ll"},179 Destdir: "obj",180 },181 "src.o": {182 Rule: "cxx",183 Sources: []string{"src.cc"},184 Destdir: "obj",185 Options: map[string]bool{"incdeps": true},186 },187 "src.analyse": {188 Rule: "cxx_analyse",189 Sources: []string{"src.cc"},190 Destdir: "obj",191 Options: map[string]bool{"incdeps": true},192 },193 }194 checkTargets(t, expt, desc.AllTargets())195 if desc.Link != "linkxx" {196 t.Error("linker wasn't changed")197 }198}199func TestCompileGperf(t *testing.T) {200 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)201 desc.CompileGperf("testdir", "src.gperf", "src")202 expt := map[string]*Target{203 "src.h": {204 Rule: "gperf",205 Sources: []string{"src.gperf"},206 Destdir: "obj",207 },208 }209 checkTargets(t, expt, desc.AllTargets())210 if !reflect.DeepEqual(desc.Incdeps, []string{"src.h"}) {211 t.Error("Not added to incdeps")212 }213}214func TestCompileEnum(t *testing.T) {215 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)216 desc.CompileEnum("testdir", "src.gperf.enum", "src.gperf")217 expt := map[string]*Target{218 "src.gperf": {219 Rule: "gperf_enum",220 Sources: []string{"src.gperf.enum"},221 Destdir: "obj",222 },223 "src.h": {224 Rule: "gperf",225 Sources: []string{"src.gperf"},226 Destdir: "obj",227 },228 }229 checkTargets(t, expt, desc.AllTargets())230 if !reflect.DeepEqual(desc.Incdeps, []string{"src.h"}) {231 t.Error("Not added to incdeps")232 }233 defer func() {234 err := recover()235 if err == nil || err.(*ParseError).Err != EnumWithoutGperf {236 t.Error("Didn't get EnumWithoutGperf error")237 }238 }()239 desc.CompileEnum("testdir", "src.enum", "src")240}241func TestCompileIn(t *testing.T) {242 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)243 desc.CompileIn("testdir", "src.in", "src")244 expt := map[string]*Target{245 "src": {246 Rule: "in",247 Sources: []string{"src.in"},248 Destdir: "obj",249 },250 }251 checkTargets(t, expt, desc.AllTargets())252}253func TestCompileXS(t *testing.T) {254 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)255 desc.CompileXs("testdir", "src.xs", "src")256 expt := map[string]*Target{257 "src.c": {258 Rule: "xs",259 Sources: []string{"src.xs"},260 Destdir: "obj",261 },262 "src.o": {263 Rule: "cc",264 Sources: []string{"src.c"},265 Destdir: "obj",266 Options: map[string]bool{"incdeps": true},267 },268 "src.analyse": {269 Rule: "cc_analyse",270 Sources: []string{"src.c"},271 Destdir: "obj",272 Options: map[string]bool{"incdeps": true},273 },274 }275 checkTargets(t, expt, desc.AllTargets())276 if len(desc.Objs) == 0 {277 t.Error("No objects")278 }279}280func TestCompileGo(t *testing.T) {281 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil).(*ProgDesc)282 desc.CompileGo("testdir", "src.go", "src")283 expt := map[string]*Target{284 "go/src.go": {285 Rule: "copy_go",286 Sources: []string{"src.go"},287 Destdir: "obj",288 },289 }290 checkTargets(t, expt, desc.AllTargets())291 if !reflect.DeepEqual(desc.GoSrc, []string{"$objdir/go/src.go"}) {292 t.Error("GoSrc wasn't set")293 }294}295func TestFindCompilerCC(t *testing.T) {296 vmap := map[string]string{297 "x": "nope",298 "y": "cc version 1.0",299 "gcc": "gcc version 4.7.0",300 "clang": "clang version 3.3.2 (tags/RELEASE_33/dot2-final)",301 "cc": "gcc version 4.8.0",302 }303 var order []string304 notFound := errors.New("Not found")305 defer func() {306 findCompilerRun = (*exec.Cmd).Run307 }()308 findCompilerRun = func(cmd *exec.Cmd) error {309 cc := filepath.Base(cmd.Path)310 order = append(order, cc)311 out, ok := vmap[cc]312 if !ok {313 return notFound314 }315 io.WriteString(cmd.Stdout, out)316 return nil317 }318 ops := NewGlobalOps()319 ops.Config.Compiler = []string{"cc:9.0", "x", "y:2"}320 os.Setenv("CC", "z")321 err := ops.FindCompilerCC()322 if err != nil {323 t.Error("Expected no error, got", err)324 }325 if !reflect.DeepEqual(order, []string{"cc", "x", "y", "z", "gcc", "clang", "cc"}) {326 t.Error("Tested compiler order didn't match expected, got", order)327 }328}329func TestCompileSpecial(t *testing.T) {330 called := false331 PluginSpecialSrcs["test"] = func(desc Descriptor, tname, rule string, srcs []string, destdir, srcdir string, extraargs []string, options map[string]bool) Descriptor {332 called = true333 return desc334 }335 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil)336 desc = CompileSpecial(desc, "testtarget", "test", []string{"src"}, "obj", "testdir", nil, nil)337 if !called {338 t.Error("Expected plugin to be called")339 }340 desc = CompileSpecial(desc, "testtarget2", "test2", []string{"src2"}, "obj", "testdir", nil, nil)341 delete(PluginSpecialSrcs, "test")342 expt := map[string]*Target{343 "testtarget2": {344 Rule: "test2",345 Sources: []string{"src2"},346 Destdir: "obj",347 },348 }349 checkTargets(t, expt, desc.AllTargets())350}351func TestCompileSrc(t *testing.T) {352 called := false353 PluginGeneralExtensions["test"] = func(g *GeneralDesc, srcdir, src, srcbase string) {354 if srcbase != "src" {355 t.Error("srcbase != src")356 }357 called = true358 }359 desc := (&ProgDesc{}).NewFromTemplate("Builddesc", "test", nil)360 CompileSrc(desc, "testdir", "src.test")361 if !called {362 t.Error("Expected plugin to be called")363 }364 CompileSrc(desc, "testdir", "src.in")365 delete(PluginGeneralExtensions, "test")366 expt := map[string]*Target{367 "src": {368 Rule: "in",369 Sources: []string{"src.in"},370 Destdir: "obj",371 },372 }373 checkTargets(t, expt, desc.AllTargets())374}...

Full Screen

Full Screen

csource_test.go

Source:csource_test.go Github

copy

Full Screen

...19)20func TestGenerate(t *testing.T) {21 t.Parallel()22 checked := make(map[string]bool)23 for _, target := range prog.AllTargets() {24 target := target25 sysTarget := targets.Get(target.OS, target.Arch)26 if runtime.GOOS != sysTarget.BuildOS {27 continue28 }29 t.Run(target.OS+"/"+target.Arch, func(t *testing.T) {30 if target.OS == "linux" && target.Arch == "arm64" {31 // Episodically fails on travis with:32 // collect2: error: ld terminated with signal 11 [Segmentation fault]33 t.Skip("broken")34 }35 if target.OS == "test" && target.PtrSize == 4 {36 // The same reason as linux/32.37 t.Skip("broken")38 }39 if _, err := exec.LookPath(sysTarget.CCompiler); err != nil {40 t.Skipf("no target compiler %v", sysTarget.CCompiler)41 }42 full := !checked[target.OS]43 checked[target.OS] = true44 t.Parallel()45 testTarget(t, target, full)46 })47 }48}49// This is the main configuration used by executor, so we want to test it as well.50var executorOpts = Options{51 Threaded: true,52 Collide: true,53 Repeat: true,54 Procs: 2,55 Sandbox: "none",56 Repro: true,57 UseTmpDir: true,58}59func testTarget(t *testing.T, target *prog.Target, full bool) {60 seed := time.Now().UnixNano()61 if os.Getenv("TRAVIS") != "" {62 seed = 0 // required for deterministic coverage reports63 }64 rs := rand.NewSource(seed)65 t.Logf("seed=%v", seed)66 p := target.Generate(rs, 10, nil)67 // Turns out that fully minimized program can trigger new interesting warnings,68 // e.g. about NULL arguments for functions that require non-NULL arguments in syz_ functions.69 // We could append both AllSyzProg as-is and a minimized version of it,70 // but this makes the NULL argument warnings go away (they showed up in ".constprop" versions).71 // Testing 2 programs takes too long since we have lots of options permutations and OS/arch.72 // So we use the as-is in short tests and minimized version in full tests.73 syzProg := target.GenerateAllSyzProg(rs)74 var opts []Options75 if !full || testing.Short() {76 p.Calls = append(p.Calls, syzProg.Calls...)77 opts = allOptionsSingle(target.OS)78 opts = append(opts, executorOpts)79 } else {80 minimized, _ := prog.Minimize(syzProg, -1, false, func(p *prog.Prog, call int) bool {81 return len(p.Calls) == len(syzProg.Calls)82 })83 p.Calls = append(p.Calls, minimized.Calls...)84 opts = allOptionsPermutations(target.OS)85 }86 for opti, opts := range opts {87 opts := opts88 t.Run(fmt.Sprintf("%v", opti), func(t *testing.T) {89 t.Parallel()90 testOne(t, p, opts)91 })92 }93}94func testOne(t *testing.T, p *prog.Prog, opts Options) {95 src, err := Write(p, opts)96 if err != nil {97 t.Logf("opts: %+v\nprogram:\n%s\n", opts, p.Serialize())98 t.Fatalf("%v", err)99 }100 bin, err := Build(p.Target, src)101 if err != nil {102 t.Logf("opts: %+v\nprogram:\n%s\n", opts, p.Serialize())103 t.Fatalf("%v", err)104 }105 defer os.Remove(bin)106}107func TestSysTests(t *testing.T) {108 t.Parallel()109 for _, target := range prog.AllTargets() {110 target := target111 sysTarget := targets.Get(target.OS, target.Arch)112 if runtime.GOOS != sysTarget.BuildOS {113 continue // we need at least preprocessor binary to generate sources114 }115 t.Run(target.OS+"/"+target.Arch, func(t *testing.T) {116 t.Parallel()117 dir := filepath.Join("..", "..", "sys", target.OS, "test")118 if !osutil.IsExist(dir) {119 return120 }121 files, err := ioutil.ReadDir(dir)122 if err != nil {123 t.Fatalf("failed to read %v: %v", dir, err)...

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 targets := prog.AllTargets()4 for _, target := range targets {5 fmt.Println(target.OS, target.Arch)6 }7}

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2var (3func main() {4 flag.Parse()5 if handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout); err != nil {6 log.Fatal(err)7 }8 defer handle.Close()9 err = handle.SetBPFFilter(filter)10 if err != nil {11 log.Fatal(err)12 }13 fmt.Println("Only capturing TCP port 80 packets.")14 packetSource := gopacket.NewPacketSource(handle, handle.LinkType())15 for packet := range packetSource.Packets() {

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 handle, err := pcap.OpenLive("wlan0", 1600, true, pcap.BlockForever)4 if err != nil {5 log.Fatal(err)6 }7 defer handle.Close()8 err = handle.SetBPFFilter(filter)9 if err != nil {10 log.Fatal(err)11 }12 fmt.Println("Only capturing TCP port 80 packets.")13 packetSource := gopacket.NewPacketSource(handle, handle.LinkType())14 for packet := range packetSource.Packets() {15 fmt.Println(packet)16 time.Sleep(1 * time.Second)17 }18}192017/07/22 11:36:45.617095 layers.go:1373: Ethernet {Contents=[..14..] Payload=[..54..] SrcMAC=00:0c:29:5b:5b:3b DstMAC=00:0c:29:5b:5b:3c EthernetType=IPv4 Length=0}202017/07/22 11:36:45.617122 layers.go:1373: IPv4 {Contents=[..20..] Payload=[..34..] Version=4 IHL=5 TOS=0 Length=54 Id=3679 Flags=DF FragOffset=0 TTL=128 Protocol=TCP Checksum=56025 SrcIP=

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 devices, _ := pcap.FindAllDevs()4 for _, device := range devices {5 for _, address := range device.Addresses {6 fmt.Println(address.IP)7 }8 }9}

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 handle, err := pcap.OpenLive("wlp2s0", 1600, true, pcap.BlockForever)4 if err != nil {5 log.Fatal(err)6 }7 defer handle.Close()8 err = handle.SetBPFFilter(filter)9 if err != nil {10 log.Fatal(err)11 }12 fmt.Println("Only capturing TCP port 80 packets.")13 packetSource := gopacket.NewPacketSource(handle, handle.LinkType())14 for packet := range packetSource.Packets() {15 fmt.Println(packet)16 }17}

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 target, err := prog.GetTarget(sys.OS_LINUX, "amd64")4 if err != nil {5 panic(err)6 }7 p := prog.Gen(target, 10, nil)8 for i, t := range p.Calls {9 fmt.Println(i, t.Meta.Name)10 }11}

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var (4 handle, err = pcap.OpenLive(device, snapshot_len, promiscuous, timeout)5 if err != nil {6 log.Fatal(err)7 }8 defer handle.Close()9 err = handle.SetBPFFilter(filter)10 if err != nil {11 log.Fatal(err)12 }13 fmt.Println("Only capturing TCP port 80 packets.")14 packetSource := gopacket.NewPacketSource(handle, handle.LinkType())15 for packet := range packetSource.Packets() {16 if tcpLayer := packet.Layer(layers.LayerTypeTCP); tcpLayer != nil {17 fmt.Println("This is a TCP packet!")18 tcp, _ := tcpLayer.(*layers.TCP)19 fmt.Printf("From src port %d to dst port %d20 for _, layer := range packet.Layers() {21 fmt.Println("PACKET LAYER:", layer.LayerType())22 }23 for _, layer := range packet.Layers() {24 fmt.Println("PACKET DECODED LAYER:", layer.LayerType())25 }26 if appLayer := packet.ApplicationLayer(); appLayer != nil {27 fmt.Println("Application layer/Payload found.")28 if strings.Contains(string(appLayer.Payload()), "HTTP") {29 fmt.Println("HTTP found!")30 }31 }32 }33 }34}35import (

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := gas.NewProgram()4 prog.AddRules(rules.NewG103())5 prog.AddRules(rules.NewG104())6 prog.AddRules(rules.NewG105())7 prog.AddRules(rules.NewG106())8 prog.AddRules(rules.NewG107())9 prog.AddRules(rules.NewG108())10 prog.AddRules(rules.NewG109())11 prog.AddRules(rules.NewG110())12 prog.AddRules(rules.NewG111())13 prog.AddRules(rules.NewG201())14 prog.AddRules(rules.NewG202())15 prog.AddRules(rules.NewG203())16 prog.AddRules(rules.NewG204())17 prog.AddRules(rules.NewG301())18 prog.AddRules(rules.NewG302())19 prog.AddRules(rules.NewG401())20 prog.AddRules(rules.NewG402())21 prog.AddRules(rules.NewG403())22 prog.AddRules(rules.NewG404())23 prog.AddRules(rules.NewG501())24 prog.AddRules(rules.NewG502())25 prog.AddRules(rules.NewG503())26 prog.AddRules(rules.NewG504())27 prog.AddRules(rules.NewG505())28 prog.AddRules(rules.NewG506())29 prog.AddRules(rules.NewG601())30 prog.AddRules(rules.NewG602())31 prog.AddRules(rules.NewG603())32 prog.AddRules(rules.NewG604())33 prog.AddRules(rules.NewG605())34 prog.AddRules(rules.NewG606())35 prog.AddRules(rules.NewG607())36 prog.AddRules(rules.NewG608())37 prog.AddRules(rules.NewG609())38 prog.AddRules(rules.NewG610())39 prog.AddRules(rules.NewG611())40 prog.AddRules(rules.NewG612())41 prog.AddRules(rules.NewG613())42 prog.AddRules(rules.NewG614())43 prog.AddRules(rules.NewG615())44 prog.AddRules(rules.NewG616())45 prog.AddRules(rules.NewG617())46 prog.AddRules(rules.NewG618())47 prog.AddRules(rules.NewG619())48 prog.AddRules(rules.NewG620())49 prog.AddRules(rules.NewG621())

Full Screen

Full Screen

AllTargets

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := prog.MakeTarget(64, prog.DefaultChoiceTable(), "test", "test", nil)4 for i := range iter.N(100) {5 fmt.Printf("target %v: %v6", i, p.AllTargets()[i])7 }8}

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