How to use pollCommits method of main Package

Best Syzkaller code snippet using main.pollCommits

syz-ci.go

Source:syz-ci.go Github

copy

Full Screen

1// Copyright 2017 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-ci is a continuous fuzzing system for syzkaller.4// It runs several syz-manager's, polls and rebuilds images for managers5// and polls and rebuilds syzkaller binaries.6// For usage instructions see: docs/ci.md.7package main8// Implementation details:9//10// 2 main components:11// - SyzUpdater: handles syzkaller updates12// - Manager: handles kernel build and syz-manager process (one per manager)13// Both operate in a similar way and keep 2 builds:14// - latest: latest known good build (i.e. we tested it)15// preserved across restarts/reboots, i.e. we can start fuzzing even when16// current syzkaller/kernel git head is broken, or git is down, or anything else17// - current: currently used build (a copy of one of the latest builds)18// Other important points:19// - syz-ci is always built on the same revision as the rest of syzkaller binaries,20// this allows us to handle e.g. changes in manager config format.21// - consequently, syzkaller binaries are never updated on-the-fly,22// instead we re-exec and then update23// - we understand when the latest build is fresh even after reboot,24// i.e. we store enough information to identify it (git hash, compiler identity, etc),25// so we don't rebuild unnecessary (kernel builds take time)26// - we generally avoid crashing the process and handle all errors gracefully27// (this is a continuous system), except for some severe/user errors during start28// (e.g. bad config file, or can't create necessary dirs)29//30// Directory/file structure:31// syz-ci : current executable32// syzkaller/33// latest/ : latest good syzkaller build34// current/ : syzkaller build currently in use35// managers/36// manager1/ : one dir per manager37// kernel/ : kernel checkout38// workdir/ : manager workdir (never deleted)39// latest/ : latest good kernel image build40// current/ : kernel image currently in use41// jobs/42// linux/ : one dir per target OS43// kernel/ : kernel checkout44// image/ : currently used image45// workdir/ : some temp files46//47// Current executable, syzkaller and kernel builds are marked with tag files.48// Tag files uniquely identify the build (git hash, compiler identity, kernel config, etc).49// For tag files both contents and modification time are important,50// modification time allows us to understand if we need to rebuild after a restart.51import (52 "encoding/json"53 "flag"54 "fmt"55 "net"56 "net/http"57 _ "net/http/pprof"58 "os"59 "path/filepath"60 "regexp"61 "sync"62 "github.com/google/syzkaller/pkg/config"63 "github.com/google/syzkaller/pkg/log"64 "github.com/google/syzkaller/pkg/mgrconfig"65 "github.com/google/syzkaller/pkg/osutil"66)67var (68 flagConfig = flag.String("config", "", "config file")69 flagAutoUpdate = flag.Bool("autoupdate", true, "auto-update the binary (for testing)")70 flagManagers = flag.Bool("managers", true, "start managers (for testing)")71)72type Config struct {73 Name string `json:"name"`74 HTTP string `json:"http"`75 // If manager http address is not specified, give it an address starting from this port. Optional.76 ManagerPort int `json:"manager_port_start"`77 DashboardAddr string `json:"dashboard_addr"` // Optional.78 DashboardClient string `json:"dashboard_client"` // Optional.79 DashboardKey string `json:"dashboard_key"` // Optional.80 HubAddr string `json:"hub_addr"` // Optional.81 HubKey string `json:"hub_key"` // Optional.82 Goroot string `json:"goroot"` // Go 1.8+ toolchain dir.83 SyzkallerRepo string `json:"syzkaller_repo"`84 SyzkallerBranch string `json:"syzkaller_branch"` // Defaults to "master".85 // Dir with additional syscall descriptions (.txt and .const files).86 SyzkallerDescriptions string `json:"syzkaller_descriptions"`87 // GCS path to upload coverage reports from managers (optional).88 CoverUploadPath string `json:"cover_upload_path"`89 BisectBinDir string `json:"bisect_bin_dir"`90 Managers []*ManagerConfig `json:"managers"`91}92type ManagerConfig struct {93 Name string `json:"name"`94 Disabled string `json:"disabled"` // If not empty, don't build/start this manager.95 DashboardClient string `json:"dashboard_client"`96 DashboardKey string `json:"dashboard_key"`97 Repo string `json:"repo"`98 // Short name of the repo (e.g. "linux-next"), used only for reporting.99 RepoAlias string `json:"repo_alias"`100 Branch string `json:"branch"` // Defaults to "master".101 Compiler string `json:"compiler"`102 Userspace string `json:"userspace"`103 KernelConfig string `json:"kernel_config"`104 // File with kernel cmdline values (optional).105 KernelCmdline string `json:"kernel_cmdline"`106 // File with sysctl values (e.g. output of sysctl -a, optional).107 KernelSysctl string `json:"kernel_sysctl"`108 Jobs ManagerJobs `json:"jobs"`109 ManagerConfig json.RawMessage `json:"manager_config"`110 managercfg *mgrconfig.Config111}112type ManagerJobs struct {113 TestPatches bool `json:"test_patches"` // enable patch testing jobs114 PollCommits bool `json:"poll_commits"` // poll info about fix commits115 BisectCause bool `json:"bisect_cause"` // do cause bisection116 BisectFix bool `json:"bisect_fix"` // do fix bisection117}118func main() {119 flag.Parse()120 log.EnableLogCaching(1000, 1<<20)121 cfg, err := loadConfig(*flagConfig)122 if err != nil {123 log.Fatalf("failed to load config: %v", err)124 }125 shutdownPending := make(chan struct{})126 osutil.HandleInterrupts(shutdownPending)127 serveHTTP(cfg)128 os.Unsetenv("GOPATH")129 if cfg.Goroot != "" {130 os.Setenv("GOROOT", cfg.Goroot)131 os.Setenv("PATH", filepath.Join(cfg.Goroot, "bin")+132 string(filepath.ListSeparator)+os.Getenv("PATH"))133 }134 updatePending := make(chan struct{})135 updater := NewSyzUpdater(cfg)136 updater.UpdateOnStart(*flagAutoUpdate, shutdownPending)137 if *flagAutoUpdate {138 go func() {139 updater.WaitForUpdate()140 close(updatePending)141 }()142 }143 var wg sync.WaitGroup144 wg.Add(1)145 stop := make(chan struct{})146 go func() {147 select {148 case <-shutdownPending:149 case <-updatePending:150 }151 kernelBuildSem <- struct{}{} // wait for all current builds152 close(stop)153 wg.Done()154 }()155 var managers []*Manager156 for _, mgrcfg := range cfg.Managers {157 mgr, err := createManager(cfg, mgrcfg, stop)158 if err != nil {159 log.Logf(0, "failed to create manager %v: %v", mgrcfg.Name, err)160 continue161 }162 managers = append(managers, mgr)163 }164 if len(managers) == 0 {165 log.Fatalf("failed to create all managers")166 }167 if *flagManagers {168 for _, mgr := range managers {169 mgr := mgr170 wg.Add(1)171 go func() {172 defer wg.Done()173 mgr.loop()174 }()175 }176 }177 jp := newJobProcessor(cfg, managers, stop, shutdownPending)178 wg.Add(1)179 go func() {180 defer wg.Done()181 jp.loop()182 }()183 // For testing. Racy. Use with care.184 http.HandleFunc("/upload_cover", func(w http.ResponseWriter, r *http.Request) {185 for _, mgr := range managers {186 if err := mgr.uploadCoverReport(); err != nil {187 w.Write([]byte(fmt.Sprintf("failed for %v: %v <br>\n", mgr.name, err)))188 return189 }190 w.Write([]byte(fmt.Sprintf("upload cover for %v <br>\n", mgr.name)))191 }192 })193 wg.Wait()194 select {195 case <-shutdownPending:196 case <-updatePending:197 updater.UpdateAndRestart()198 }199}200func serveHTTP(cfg *Config) {201 ln, err := net.Listen("tcp4", cfg.HTTP)202 if err != nil {203 log.Fatalf("failed to listen on %v: %v", cfg.HTTP, err)204 }205 log.Logf(0, "serving http on http://%v", ln.Addr())206 go func() {207 err := http.Serve(ln, nil)208 log.Fatalf("failed to serve http: %v", err)209 }()210}211func loadConfig(filename string) (*Config, error) {212 cfg := &Config{213 SyzkallerRepo: "https://github.com/google/syzkaller.git",214 SyzkallerBranch: "master",215 ManagerPort: 10000,216 Goroot: os.Getenv("GOROOT"),217 }218 if err := config.LoadFile(filename, cfg); err != nil {219 return nil, err220 }221 if cfg.Name == "" {222 return nil, fmt.Errorf("param 'name' is empty")223 }224 if cfg.HTTP == "" {225 return nil, fmt.Errorf("param 'http' is empty")226 }227 // Manager name must not contain dots because it is used as GCE image name prefix.228 managerNameRe := regexp.MustCompile("^[a-zA-Z0-9-_]{4,64}$")229 var managers []*ManagerConfig230 for i, mgr := range cfg.Managers {231 if mgr.Disabled == "" {232 managers = append(managers, mgr)233 }234 if !managerNameRe.MatchString(mgr.Name) {235 return nil, fmt.Errorf("param 'managers[%v].name' has bad value: %q", i, mgr.Name)236 }237 if mgr.Branch == "" {238 mgr.Branch = "master"239 }240 managercfg, err := mgrconfig.LoadPartialData(mgr.ManagerConfig)241 if err != nil {242 return nil, fmt.Errorf("manager %v: %v", mgr.Name, err)243 }244 if (mgr.Jobs.TestPatches || mgr.Jobs.PollCommits ||245 mgr.Jobs.BisectCause || mgr.Jobs.BisectFix) &&246 (cfg.DashboardAddr == "" || cfg.DashboardClient == "") {247 return nil, fmt.Errorf("manager %v: has jobs but no dashboard info", mgr.Name)248 }249 if mgr.Jobs.PollCommits && (cfg.DashboardAddr == "" || mgr.DashboardClient == "") {250 return nil, fmt.Errorf("manager %v: commit_poll is set but no dashboard info", mgr.Name)251 }252 if (mgr.Jobs.BisectCause || mgr.Jobs.BisectFix) && cfg.BisectBinDir == "" {253 return nil, fmt.Errorf("manager %v: enabled bisection but no bisect_bin_dir", mgr.Name)254 }255 mgr.managercfg = managercfg256 managercfg.Name = cfg.Name + "-" + mgr.Name257 managercfg.Syzkaller = filepath.FromSlash("syzkaller/current")258 if managercfg.HTTP == "" {259 managercfg.HTTP = fmt.Sprintf(":%v", cfg.ManagerPort)260 cfg.ManagerPort++261 }262 }263 cfg.Managers = managers264 if len(cfg.Managers) == 0 {265 return nil, fmt.Errorf("no managers specified")266 }267 return cfg, nil268}...

Full Screen

Full Screen

email.go

Source:email.go Github

copy

Full Screen

...137 latestHash.s = hashes[0]138 latestHash.Unlock()139 http.HandleFunc("/latesthash", latestHashHandler)140 for {141 pollCommits(dir)142 // Poll every minute or whenever we're forced with the143 // /mailnow handler.144 select {145 case <-time.After(1 * time.Minute):146 case <-fetchc:147 log.Printf("Polling git due to explicit trigger.")148 }149 }150}151func pollCommits(dir string) {152 cmd := exec.Command("git", "fetch", "origin")153 cmd.Dir = dir154 out, err := cmd.CombinedOutput()155 if err != nil {156 log.Printf("Error running git fetch origin master in %s: %v\n%s", dir, err, out)157 return158 }159 log.Printf("Ran git fetch.")160 // TODO: see if .git/refs/remotes/origin/master changed. quicker.161 hashes, err := recentCommits(dir)162 if err != nil {163 log.Print(err)164 return165 }...

Full Screen

Full Screen

pollCommits

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := pollCommits()4 if err != nil {5 fmt.Println(err)6 }7}8func pollCommits() error {9 progressReader := progressreader.New(progressreader.Config{10 Formatter: streamformatter.NewStreamFormatter(),11 })12 pool := pools.NewResourcePool(func() (pools.Resource, error) {13 return os.Open("1.go")14 }, 1, 1, true)15 progressReader2 := progressreader.New(progressreader.Config{16 Formatter: streamformatter.NewStreamFormatter(),17 })18 pool2 := pools.NewResourcePool(func() (pools.Resource, error) {19 return os.Open("2.go")20 }, 1, 1, true)21 progressReader3 := progressreader.New(progressreader.Config{22 Formatter: streamformatter.NewStreamFormatter(),23 })

Full Screen

Full Screen

pollCommits

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

pollCommits

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 commitDetails := pollCommits()4 commitDetailsJson := golxml.Xml2Json(commitDetails)5 commitDetailsXml := golxml.Json2Xml(commitDetailsJson)6 commitDetailsYaml := golxml.Json2Yaml(commitDetailsJson)7 golpath.WriteFile("commitDetails.json", commitDetailsJson)8 golpath.WriteFile("commitDetails.xml", commitDetailsXml)9 golpath.WriteFile("commitDetails.yaml", commitDetailsYaml)10}11func pollCommits() (commitDetails string) {12 githubUsername := golenv.Get("GITHUB_USERNAME")13 githubPassword := golenv.Get("GITHUB_PASSWORD")14 githubRepository := golenv.Get("GITHUB_REPOSITORY")15 githubRepositoryBranch := golenv.Get("GITHUB_REPOSITORY_BRANCH")16 githubRepositoryPath := golenv.Get("GITHUB_REPOSITORY_PATH")

Full Screen

Full Screen

pollCommits

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := commit.Commit{}4 for _, v := range c.Commits {5 fmt.Println(v)6 }7}

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