How to use GenerateBugTable method of main Package

Best Syzkaller code snippet using main.GenerateBugTable

html.go

Source:html.go Github

copy

Full Screen

...147}148func (ctx *TestbedContext) getTableTypes() []uiTableType {149 allTypeList := []uiTableType{150 {HTMLStatsTable, "Statistics", ctx.httpMainStatsTable},151 {HTMLBugsTable, "Bugs", ctx.genSimpleTableController((StatView).GenerateBugTable, true)},152 {HTMLBugCountsTable, "Bug Counts", ctx.genSimpleTableController((StatView).GenerateBugCountsTable, false)},153 {HTMLReprosTable, "Repros", ctx.genSimpleTableController((StatView).GenerateReproSuccessTable, true)},154 {HTMLCReprosTable, "C Repros", ctx.genSimpleTableController((StatView).GenerateCReproSuccessTable, true)},155 {HTMLReproAttemptsTable, "All Repros", ctx.genSimpleTableController((StatView).GenerateReproAttemptsTable, false)},156 {HTMLReproDurationTable, "Duration", ctx.genSimpleTableController((StatView).GenerateReproDurationTable, true)},157 }158 typeList := []uiTableType{}159 for _, t := range allTypeList {160 if ctx.Target.SupportsHTMLView(t.Key) {161 typeList = append(typeList, t)162 }163 }164 return typeList165}...

Full Screen

Full Screen

testbed.go

Source:testbed.go Github

copy

Full Screen

1// Copyright 2021 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3// syz-testbed automatically checks out, builds and sets up a number of syzkaller instances.4// This might be very helpful e.g. when gauging the effect of new changes on the total syzkaller5// performance.6// For details see docs/syz_testbed.md.7package main8import (9 "encoding/json"10 "flag"11 "fmt"12 "log"13 "net"14 "os"15 "path/filepath"16 "regexp"17 "strconv"18 "time"19 "github.com/google/syzkaller/pkg/config"20 syz_instance "github.com/google/syzkaller/pkg/instance"21 "github.com/google/syzkaller/pkg/mgrconfig"22 "github.com/google/syzkaller/pkg/osutil"23 "github.com/google/syzkaller/pkg/tool"24 "github.com/google/syzkaller/pkg/vcs"25)26var (27 flagConfig = flag.String("config", "", "config file")28 flagCleanup = flag.Bool("cleanup", false, "remove existing work directories")29)30type TestbedConfig struct {31 Corpus string `json:"corpus"` // path to the corpus file32 Workdir string `json:"workdir"` // instances will be checked out there33 ManagerConfig json.RawMessage `json:"manager_config"` // base manager config34 Checkouts []TestbedCheckout `json:"checkouts"`35}36type TestbedCheckout struct {37 Name string `json:"name"`38 Repo string `json:"repo"`39 Branch string `json:"branch"`40 Count int `json:"count"`41}42type CheckoutInfo struct {43 Path string44 Name string45 Instances []InstanceInfo46}47// The essential information about an already prepared instance.48type InstanceInfo struct {49 Name string50 Workdir string51 BenchFile string52 LogFile string53 HTTP string54 ExecCommand string55 ExecCommandArgs []string56}57func main() {58 flag.Parse()59 cfg := &TestbedConfig{}60 err := config.LoadFile(*flagConfig, &cfg)61 if err != nil {62 tool.Failf("failed to read config: %s", err)63 }64 err = checkConfig(cfg)65 if err != nil {66 tool.Failf("invalid config: %s", err)67 }68 managerCfg, err := mgrconfig.LoadPartialData(cfg.ManagerConfig)69 if err != nil {70 tool.Failf("failed to parse manager config: %s", err)71 }72 if managerCfg.HTTP == "" {73 managerCfg.HTTP = ":50000"74 }75 checkouts := []*CheckoutInfo{}76 for _, co := range cfg.Checkouts {77 checkouts = append(checkouts, newCheckout(co, cfg, managerCfg))78 }79 log.Printf("------------------")80 for _, co := range checkouts {81 for _, instance := range co.Instances {82 go runInstance(instance)83 }84 }85 go collectStats(cfg, checkouts)86 // Block the execution indefinitely.87 // Either the process will be killed or it will exit itself if one of the instances fails.88 select {}89}90func collectStats(cfg *TestbedConfig, checkouts []*CheckoutInfo) {91 const period = 90 * time.Second92 benchFolder := filepath.Join(cfg.Workdir, "benches")93 err := osutil.MkdirAll(benchFolder)94 if err != nil {95 tool.Failf("failed to create bench folder: %s", err)96 }97 tableStats := map[string]func(checkouts []*CheckoutInfo) ([][]string, error){98 "bugs.csv": generateBugTable,99 "checkout_stats.csv": checkoutStatsTable,100 "instance_stats.csv": instanceStatsTable,101 }102 for {103 time.Sleep(period)104 for fileName, genFunc := range tableStats {105 table, err := genFunc(checkouts)106 if err == nil {107 saveTableAsCsv(table, filepath.Join(cfg.Workdir, fileName))108 }109 }110 for _, checkout := range checkouts {111 fileName := fmt.Sprintf("avg_%v.txt", checkout.Name)112 saveAvgBenchFile(checkout, filepath.Join(benchFolder, fileName))113 }114 }115}116func runInstance(info InstanceInfo) {117 logfile, err := os.Create(info.LogFile)118 if err != nil {119 tool.Failf("[%s] failed to create logfile: %s", info.Name, err)120 }121 cmd := osutil.GraciousCommand(info.ExecCommand, info.ExecCommandArgs...)122 cmd.Stdout = logfile123 cmd.Stderr = logfile124 err = cmd.Start()125 if err != nil {126 tool.Failf("[%s] failed to start instance: %s", info.Name, err)127 }128 log.Printf("[%s] Instance started. Listening on %s", info.Name, info.HTTP)129 logfile.Close()130 err = cmd.Wait()131 tool.Failf("[%s] Instance exited: %s", info.Name, err)132}133func newCheckout(co TestbedCheckout, cfg *TestbedConfig, managerCfg *mgrconfig.Config) *CheckoutInfo {134 log.Printf("[%s] Checking out", co.Name)135 path := filepath.Join(cfg.Workdir, "checkouts", co.Name)136 if osutil.IsExist(path) {137 if !*flagCleanup {138 tool.Failf("path %s already exists", path)139 }140 osutil.RemoveAll(path)141 }142 repo := vcs.NewSyzkallerRepo(path)143 commit, err := repo.Poll(co.Repo, co.Branch)144 if err != nil {145 tool.Failf("failed to checkout %s (%s): %s", co.Repo, co.Branch, err)146 }147 log.Printf("[%s] Done. Latest commit: %s", co.Name, commit)148 log.Printf("[%s] Building", co.Name)149 if _, err := osutil.RunCmd(time.Hour, path, syz_instance.MakeBin); err != nil {150 tool.Failf("[%s] Make failed: %s", co.Name, err)151 }152 checkoutInfo := CheckoutInfo{153 Name: co.Name,154 Path: path,155 }156 for i := 1; i <= co.Count; i++ {157 name := fmt.Sprintf("%v-%d", co.Name, i)158 log.Printf("[%s] Generating workdir", name)159 workdir := filepath.Join(path, fmt.Sprintf("workdir_%d", i))160 err = osutil.MkdirAll(workdir)161 if err != nil {162 tool.Failf("failed to create dir %s", workdir)163 }164 if cfg.Corpus != "" {165 corpusPath := filepath.Join(workdir, "corpus.db")166 err = osutil.CopyFile(cfg.Corpus, corpusPath)167 if err != nil {168 tool.Failf("failed to copy corpus from %s: %s", cfg.Corpus, err)169 }170 }171 log.Printf("[%s] Generating syz-manager config", name)172 managerCfg.Name = name173 managerCfg.Workdir = workdir174 managerCfg.Syzkaller = path175 managerCfgPath := filepath.Join(path, fmt.Sprintf("syz_%d.cnf", i))176 err = config.SaveFile(managerCfgPath, managerCfg)177 if err != nil {178 tool.Failf("failed to save manager config to %s: %s", managerCfgPath, err)179 }180 bench := filepath.Join(path, fmt.Sprintf("bench_%d.txt", i))181 log := filepath.Join(path, fmt.Sprintf("log_%d.txt", i))182 checkoutInfo.Instances = append(checkoutInfo.Instances, InstanceInfo{183 Name: managerCfg.Name,184 Workdir: workdir,185 BenchFile: bench,186 LogFile: log,187 HTTP: managerCfg.HTTP,188 ExecCommand: filepath.Join(path, "bin", "syz-manager"),189 ExecCommandArgs: []string{"-config", managerCfgPath, "-bench", bench},190 })191 managerCfg.HTTP, err = increasePort(managerCfg.HTTP)192 if err != nil {193 tool.Failf("failed to inrease port number: %s", err)194 }195 }196 return &checkoutInfo197}198func increasePort(http string) (string, error) {199 host, portStr, err := net.SplitHostPort(http)200 if err != nil {201 return "", fmt.Errorf("invalid http value: %s", http)202 }203 port, err := strconv.Atoi(portStr)204 if err != nil {205 return "", err206 }207 return net.JoinHostPort(host, fmt.Sprintf("%d", port+1)), nil208}209func checkConfig(cfg *TestbedConfig) error {210 if cfg.Workdir == "" {211 return fmt.Errorf("workdir is empty")212 }213 cfg.Workdir = osutil.Abs(cfg.Workdir)214 err := osutil.MkdirAll(cfg.Workdir)215 if err != nil {216 return err217 }218 if cfg.Corpus != "" && !osutil.IsExist(cfg.Corpus) {219 return fmt.Errorf("corpus %v does not exist", cfg.Corpus)220 }221 cfg.Corpus = osutil.Abs(cfg.Corpus)222 instanceNameRe := regexp.MustCompile(`^[0-9a-z\-]{1,20}$`)223 names := make(map[string]bool)224 for idx := range cfg.Checkouts {225 co := &cfg.Checkouts[idx]226 if !vcs.CheckRepoAddress(co.Repo) {227 return fmt.Errorf("invalid repo: %s", co.Repo)228 }229 if co.Branch == "" {230 co.Branch = "master"231 } else if !vcs.CheckBranch(co.Branch) {232 return fmt.Errorf("invalid branch: %s", co.Branch)233 }234 if co.Count < 0 {235 return fmt.Errorf("count cannot be negative")236 } else if co.Count == 0 {237 // The default value.238 co.Count = 1239 }240 if !instanceNameRe.MatchString(co.Name) {241 return fmt.Errorf("invalid instance name: %v", co.Name)242 }243 if names[co.Name] {244 return fmt.Errorf("duplicate instance name: %v", co.Name)245 }246 names[co.Name] = true247 }248 return nil249}...

Full Screen

Full Screen

stats.go

Source:stats.go Github

copy

Full Screen

1// Copyright 2021 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3package main4import (5 "encoding/csv"6 "encoding/json"7 "fmt"8 "io/ioutil"9 "os"10 "path/filepath"11 "strings"12 "github.com/google/syzkaller/pkg/osutil"13)14type BugInfo struct {15 Title string16}17// TODO: we're implementing this functionaity at least the 3rd time (see syz-manager/html18// and tools/reporter). Create a more generic implementation and put it into a globally19// visible package.20func collectBugs(workdir string) ([]BugInfo, error) {21 crashdir := filepath.Join(workdir, "crashes")22 dirs, err := osutil.ListDir(crashdir)23 if err != nil {24 return nil, err25 }26 bugs := []BugInfo{}27 for _, dir := range dirs {28 titleBytes, err := ioutil.ReadFile(filepath.Join(crashdir, dir, "description"))29 if err != nil {30 return nil, err31 }32 title := strings.TrimSpace(string(titleBytes))33 bugs = append(bugs, BugInfo{title})34 }35 return bugs, nil36}37func readBenches(benchFile string) ([]map[string]uint64, error) {38 f, err := os.Open(benchFile)39 if err != nil {40 return nil, err41 }42 defer f.Close()43 dec := json.NewDecoder(f)44 ret := []map[string]uint64{}45 for dec.More() {46 curr := make(map[string]uint64)47 if err := dec.Decode(&curr); err == nil {48 ret = append(ret, curr)49 }50 }51 return ret, nil52}53func avgStats(infos []map[string]uint64) map[string]uint64 {54 ret := make(map[string]uint64)55 if len(infos) == 0 {56 return ret57 }58 for _, stat := range infos {59 for key, value := range stat {60 ret[key] += value61 }62 }63 for key, value := range ret {64 ret[key] = value / uint64(len(infos))65 }66 return ret67}68type BugSummary struct {69 title string70 found map[*CheckoutInfo]bool71}72// If there are several instances belonging to a single checkout, we're interested in the73// set of bugs found by at least one of those instances.74func summarizeBugs(checkouts []*CheckoutInfo) ([]*BugSummary, error) {75 bugsMap := make(map[string]*BugSummary)76 for _, checkout := range checkouts {77 for _, instance := range checkout.Instances {78 bugs, err := collectBugs(instance.Workdir)79 if err != nil {80 return nil, err81 }82 for _, bug := range bugs {83 summary := bugsMap[bug.Title]84 if summary == nil {85 summary = &BugSummary{86 title: bug.Title,87 found: make(map[*CheckoutInfo]bool),88 }89 bugsMap[bug.Title] = summary90 }91 summary.found[checkout] = true92 }93 }94 }95 summaries := []*BugSummary{}96 for _, value := range bugsMap {97 summaries = append(summaries, value)98 }99 return summaries, nil100}101// For each checkout, take the union of sets of bugs found by each instance.102// Then output these unions as a single table.103func generateBugTable(checkouts []*CheckoutInfo) ([][]string, error) {104 table := [][]string{}105 titles := []string{""}106 for _, checkout := range checkouts {107 titles = append(titles, checkout.Name)108 }109 summaries, err := summarizeBugs(checkouts)110 if err != nil {111 return nil, err112 }113 table = append(table, titles)114 for _, bug := range summaries {115 row := []string{bug.title}116 for _, checkout := range checkouts {117 val := ""118 if bug.found[checkout] {119 val = "YES"120 }121 row = append(row, val)122 }123 table = append(table, row)124 }125 return table, nil126}127type StatGroup struct {128 Name string129 Instances []InstanceInfo130}131func genericStatsTable(groups []StatGroup) ([][]string, error) {132 // Map: stats key x group name -> value.133 cells := make(map[string]map[string]string)134 for _, group := range groups {135 infos := []map[string]uint64{}136 for _, instance := range group.Instances {137 records, err := readBenches(instance.BenchFile)138 if err != nil {139 return nil, err140 }141 if len(records) > 0 {142 infos = append(infos, records[len(records)-1])143 }144 }145 for key, value := range avgStats(infos) {146 if _, ok := cells[key]; !ok {147 cells[key] = make(map[string]string)148 }149 cells[key][group.Name] = fmt.Sprintf("%d", value)150 }151 }152 title := []string{""}153 for _, group := range groups {154 title = append(title, group.Name)155 }156 table := [][]string{title}157 for key, valuesMap := range cells {158 row := []string{key}159 for _, group := range groups {160 row = append(row, valuesMap[group.Name])161 }162 table = append(table, row)163 }164 return table, nil165}166func checkoutStatsTable(checkouts []*CheckoutInfo) ([][]string, error) {167 groups := []StatGroup{}168 for _, checkout := range checkouts {169 groups = append(groups, StatGroup{170 Name: checkout.Name,171 Instances: checkout.Instances,172 })173 }174 return genericStatsTable(groups)175}176func instanceStatsTable(checkouts []*CheckoutInfo) ([][]string, error) {177 groups := []StatGroup{}178 for _, checkout := range checkouts {179 for _, instance := range checkout.Instances {180 groups = append(groups, StatGroup{181 Name: instance.Name,182 Instances: []InstanceInfo{instance},183 })184 }185 }186 return genericStatsTable(groups)187}188// Average bench files of several instances into a single bench file.189func saveAvgBenchFile(checkout *CheckoutInfo, fileName string) error {190 allRecords := [][]map[string]uint64{}191 for _, instance := range checkout.Instances {192 records, err := readBenches(instance.BenchFile)193 if err != nil {194 return err195 }196 allRecords = append(allRecords, records)197 }198 f, err := os.Create(fileName)199 if err != nil {200 return err201 }202 defer f.Close()203 for i := 0; ; i++ {204 toAvg := []map[string]uint64{}205 for _, records := range allRecords {206 if i < len(records) {207 toAvg = append(toAvg, records[i])208 }209 }210 if len(toAvg) != len(allRecords) {211 break212 }213 averaged := avgStats(toAvg)214 data, err := json.MarshalIndent(averaged, "", " ")215 if err != nil {216 return err217 }218 if _, err := f.Write(append(data, '\n')); err != nil {219 return err220 }221 }222 return nil223}224func saveTableAsCsv(table [][]string, fileName string) error {225 f, err := os.Create(fileName)226 if err != nil {227 return err228 }229 defer f.Close()230 return csv.NewWriter(f).WriteAll(table)231}...

Full Screen

Full Screen

GenerateBugTable

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

GenerateBugTable

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var bugTable = GenerateBugTable()4 for i := 0; i < len(bugTable); i++ {5 fmt.Println(bugTable[i])6 }7}8import (9func GenerateBugTable() []int {10 var bugTable = make([]int, 0)11 for i := 0; i < math.MaxUint32; i++ {12 bugTable = append(bugTable, i)13 }14}

Full Screen

Full Screen

GenerateBugTable

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var bugTable = BugTable{}4 bugTable.GenerateBugTable(x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w)5 fmt.Println(bugTable)6}7import "fmt"8func main() {

Full Screen

Full Screen

GenerateBugTable

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

GenerateBugTable

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 bugTable := GenerateBugTable()5 for _, bug := range bugTable {6 fmt.Println(bug)7 }8}9{1 1 1 1 1 1 1 1}10{2 2 2 2 2 2 2 2}11{3 3 3 3 3 3 3 3}12{4 4 4 4 4 4 4 4}13{5 5 5 5 5 5 5 5}14{6 6 6 6 6 6 6 6}15{7 7 7 7 7 7 7 7}16{8 8 8 8 8 8 8 8}17{9 9 9 9 9 9 9 9}18{10 10 10 10 10 10 10 10}19{11 11 11 11 11 11 11 11}20{12 12 12 12 12 12 12 12}21{13 13 13 13 13 13 13 13}22{14 14 14 14 14 14 14 14}23{15 15 15 15 15 15 15 15}24{16 16 16 16 16 16 16 16}25{17 17 17 17 17 17 17 17}26{18 18 18 18 18 18 18 18}27{19 19 19 19 19 19 19 19}28{20 20 20 20 20 20 20 20}29{21 21 21 21 21 21 21 21}30{22 22 22 22 22 22 22 22}31{23 23 23 23 23 23 23 23}32{24 24 24 24 24 24 24 24}33{25 25 25 25 25 25 25 25}34{26 26 26 26 26 26 26 26}35{27 27

Full Screen

Full Screen

GenerateBugTable

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3 bugTable = GenerateBugTable()4 bugTable.PrintBugTable()5}6import "fmt"7type BugTable struct{8}9func GenerateBugTable() *BugTable{10 bugTable = new(BugTable)11 bugTable.bugTable = [][]int{{1,2,3},{4,5,6},{7,8,9}}12}13func (bugTable *BugTable) PrintBugTable(){14 for i := 0; i < len(bugTable.bugTable); i++ {15 for j := 0; j < len(bugTable.bugTable[i]); j++ {16 fmt.Print(bugTable.bugTable[i][j])17 }18 fmt.Println()19 }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