How to use checkConfig method of bisect Package

Best Syzkaller code snippet using bisect.checkConfig

bisect.go

Source:bisect.go Github

copy

Full Screen

...61// - if the crash still happens on the oldest release/HEAD (for cause/fix bisection correspondingly),62// no commits and the crash report on the oldest release/HEAD63// - if the crash is not reproduced on the start commit, an error64func Run(cfg *Config) ([]*vcs.Commit, *report.Report, error) {65 if err := checkConfig(cfg); err != nil {66 return nil, nil, err67 }68 cfg.Manager.Cover = false // it's not supported somewhere back in time69 repo, err := vcs.NewRepo(cfg.Manager.TargetOS, cfg.Manager.Type, cfg.Manager.KernelSrc)70 if err != nil {71 return nil, nil, err72 }73 bisecter, ok := repo.(vcs.Bisecter)74 if !ok {75 return nil, nil, fmt.Errorf("bisection is not implemented for %v", cfg.Manager.TargetOS)76 }77 env := &env{78 cfg: cfg,79 repo: repo,80 bisecter: bisecter,81 }82 if cfg.Fix {83 env.log("bisecting fixing commit since %v", cfg.Kernel.Commit)84 } else {85 env.log("bisecting cause commit starting from %v", cfg.Kernel.Commit)86 }87 start := time.Now()88 commits, rep, err := env.bisect()89 env.log("revisions tested: %v, total time: %v (build: %v, test: %v)",90 env.numTests, time.Since(start), env.buildTime, env.testTime)91 if err != nil {92 env.log("error: %v", err)93 return nil, nil, err94 }95 if len(commits) == 0 {96 if cfg.Fix {97 env.log("the crash still happens on HEAD")98 } else {99 env.log("the crash already happened on the oldest tested release")100 }101 env.log("crash: %v\n%s", rep.Title, rep.Report)102 return nil, rep, nil103 }104 what := "bad"105 if cfg.Fix {106 what = "good"107 }108 if len(commits) > 1 {109 env.log("bisection is inconclusive, the first %v commit could be any of:", what)110 for _, com := range commits {111 env.log("%v", com.Hash)112 }113 return commits, nil, nil114 }115 com := commits[0]116 env.log("first %v commit: %v %v", what, com.Hash, com.Title)117 env.log("cc: %q", com.CC)118 if rep != nil {119 env.log("crash: %v\n%s", rep.Title, rep.Report)120 }121 return commits, rep, nil122}123func (env *env) bisect() ([]*vcs.Commit, *report.Report, error) {124 cfg := env.cfg125 var err error126 if env.inst, err = instance.NewEnv(&cfg.Manager); err != nil {127 return nil, nil, err128 }129 if env.head, err = env.repo.CheckoutBranch(cfg.Kernel.Repo, cfg.Kernel.Branch); err != nil {130 return nil, nil, err131 }132 if err := build.Clean(cfg.Manager.TargetOS, cfg.Manager.TargetVMArch,133 cfg.Manager.Type, cfg.Manager.KernelSrc); err != nil {134 return nil, nil, fmt.Errorf("kernel clean failed: %v", err)135 }136 env.log("building syzkaller on %v", cfg.Syzkaller.Commit)137 if err := env.inst.BuildSyzkaller(cfg.Syzkaller.Repo, cfg.Syzkaller.Commit); err != nil {138 return nil, nil, err139 }140 if _, err := env.repo.CheckoutCommit(cfg.Kernel.Repo, cfg.Kernel.Commit); err != nil {141 return nil, nil, err142 }143 res, _, rep0, err := env.test()144 if err != nil {145 return nil, nil, err146 } else if res != vcs.BisectBad {147 return nil, nil, fmt.Errorf("the crash wasn't reproduced on the original commit")148 }149 bad, good, rep1, err := env.commitRange()150 if err != nil {151 return nil, nil, err152 }153 if good == "" {154 return nil, rep1, nil // still not fixed/happens on the oldest release155 }156 reports := make(map[string]*report.Report)157 reports[cfg.Kernel.Commit] = rep0158 commits, err := env.bisecter.Bisect(bad, good, cfg.Trace, func() (vcs.BisectResult, error) {159 res, com, rep, err := env.test()160 reports[com.Hash] = rep161 if cfg.Fix {162 if res == vcs.BisectBad {163 res = vcs.BisectGood164 } else if res == vcs.BisectGood {165 res = vcs.BisectBad166 }167 }168 return res, err169 })170 var rep *report.Report171 if len(commits) == 1 {172 rep = reports[commits[0].Hash]173 }174 return commits, rep, err175}176func (env *env) commitRange() (string, string, *report.Report, error) {177 if env.cfg.Fix {178 return env.commitRangeForFix()179 }180 return env.commitRangeForBug()181}182func (env *env) commitRangeForFix() (string, string, *report.Report, error) {183 env.log("testing current HEAD %v", env.head.Hash)184 if _, err := env.repo.SwitchCommit(env.head.Hash); err != nil {185 return "", "", nil, err186 }187 res, _, rep, err := env.test()188 if err != nil {189 return "", "", nil, err190 }191 if res != vcs.BisectGood {192 return "", "", rep, nil193 }194 return env.head.Hash, env.cfg.Kernel.Commit, nil, nil195}196func (env *env) commitRangeForBug() (string, string, *report.Report, error) {197 cfg := env.cfg198 tags, err := env.bisecter.PreviousReleaseTags(cfg.Kernel.Commit)199 if err != nil {200 return "", "", nil, err201 }202 if len(tags) == 0 {203 return "", "", nil, fmt.Errorf("no release tags before this commit")204 }205 lastBad := cfg.Kernel.Commit206 var lastRep *report.Report207 for _, tag := range tags {208 env.log("testing release %v", tag)209 if _, err := env.repo.SwitchCommit(tag); err != nil {210 return "", "", nil, err211 }212 res, _, rep, err := env.test()213 if err != nil {214 return "", "", nil, err215 }216 if res == vcs.BisectGood {217 return lastBad, tag, nil, nil218 }219 if res == vcs.BisectBad {220 lastBad = tag221 lastRep = rep222 }223 }224 return "", "", lastRep, nil225}226func (env *env) test() (vcs.BisectResult, *vcs.Commit, *report.Report, error) {227 cfg := env.cfg228 env.numTests++229 current, err := env.repo.HeadCommit()230 if err != nil {231 return 0, nil, nil, err232 }233 bisectEnv, err := env.bisecter.EnvForCommit(current.Hash, cfg.Kernel.Config)234 if err != nil {235 return 0, nil, nil, err236 }237 compiler := filepath.Join(cfg.BinDir, bisectEnv.Compiler, "bin", "gcc")238 compilerID, err := build.CompilerIdentity(compiler)239 if err != nil {240 return 0, nil, nil, err241 }242 env.log("testing commit %v with %v", current.Hash, compilerID)243 buildStart := time.Now()244 if err := build.Clean(cfg.Manager.TargetOS, cfg.Manager.TargetVMArch,245 cfg.Manager.Type, cfg.Manager.KernelSrc); err != nil {246 return 0, nil, nil, fmt.Errorf("kernel clean failed: %v", err)247 }248 err = env.inst.BuildKernel(compiler, cfg.Kernel.Userspace,249 cfg.Kernel.Cmdline, cfg.Kernel.Sysctl, bisectEnv.KernelConfig)250 env.buildTime += time.Since(buildStart)251 if err != nil {252 if verr, ok := err.(*osutil.VerboseError); ok {253 env.log("%v", verr.Title)254 env.saveDebugFile(current.Hash, 0, verr.Output)255 } else if verr, ok := err.(build.KernelBuildError); ok {256 env.log("%v", verr.Title)257 env.saveDebugFile(current.Hash, 0, verr.Output)258 } else {259 env.log("%v", err)260 }261 return vcs.BisectSkip, current, nil, nil262 }263 testStart := time.Now()264 const numTests = 10265 results, err := env.inst.Test(numTests, cfg.Repro.Syz, cfg.Repro.Opts, cfg.Repro.C)266 env.testTime += time.Since(testStart)267 if err != nil {268 env.log("failed: %v", err)269 return vcs.BisectSkip, current, nil, nil270 }271 bad, good, rep := env.processResults(current, results)272 res := vcs.BisectSkip273 if bad != 0 {274 res = vcs.BisectBad275 } else if numTests-good-bad > numTests/3*2 {276 // More than 2/3 of instances failed with infrastructure error,277 // can't reliably tell that the commit is good.278 res = vcs.BisectSkip279 } else if good != 0 {280 res = vcs.BisectGood281 }282 return res, current, rep, nil283}284func (env *env) processResults(current *vcs.Commit, results []error) (bad, good int, rep *report.Report) {285 var verdicts []string286 for i, res := range results {287 if res == nil {288 good++289 verdicts = append(verdicts, "OK")290 continue291 }292 switch err := res.(type) {293 case *instance.TestError:294 if err.Boot {295 verdicts = append(verdicts, fmt.Sprintf("boot failed: %v", err))296 } else {297 verdicts = append(verdicts, fmt.Sprintf("basic kernel testing failed: %v", err))298 }299 output := err.Output300 if err.Report != nil {301 output = err.Report.Output302 }303 env.saveDebugFile(current.Hash, i, output)304 case *instance.CrashError:305 bad++306 rep = err.Report307 verdicts = append(verdicts, fmt.Sprintf("crashed: %v", err))308 output := err.Report.Report309 if len(output) == 0 {310 output = err.Report.Output311 }312 env.saveDebugFile(current.Hash, i, output)313 default:314 verdicts = append(verdicts, fmt.Sprintf("failed: %v", err))315 }316 }317 unique := make(map[string]bool)318 for _, verdict := range verdicts {319 unique[verdict] = true320 }321 if len(unique) == 1 {322 env.log("all runs: %v", verdicts[0])323 } else {324 for i, verdict := range verdicts {325 env.log("run #%v: %v", i, verdict)326 }327 }328 return329}330func (env *env) saveDebugFile(hash string, idx int, data []byte) {331 if env.cfg.DebugDir == "" || len(data) == 0 {332 return333 }334 osutil.MkdirAll(env.cfg.DebugDir)335 osutil.WriteFile(filepath.Join(env.cfg.DebugDir, fmt.Sprintf("%v.%v", hash, idx)), data)336}337func checkConfig(cfg *Config) error {338 if !osutil.IsExist(cfg.BinDir) {339 return fmt.Errorf("bin dir %v does not exist", cfg.BinDir)340 }341 if cfg.Kernel.Userspace != "" && !osutil.IsExist(cfg.Kernel.Userspace) {342 return fmt.Errorf("userspace dir %v does not exist", cfg.Kernel.Userspace)343 }344 if cfg.Kernel.Sysctl != "" && !osutil.IsExist(cfg.Kernel.Sysctl) {345 return fmt.Errorf("sysctl file %v does not exist", cfg.Kernel.Sysctl)346 }347 if cfg.Kernel.Cmdline != "" && !osutil.IsExist(cfg.Kernel.Cmdline) {348 return fmt.Errorf("cmdline file %v does not exist", cfg.Kernel.Cmdline)349 }350 return nil351}...

Full Screen

Full Screen

checkConfig

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

checkConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if len(os.Args) != 3 {4 fmt.Println("Invalid number of arguments")5 os.Exit(1)6 }7 if os.Args[1] != "good" && os.Args[1] != "bad" {8 fmt.Println("Invalid arguments")9 os.Exit(1)10 }11 if os.Args[2] != "good" && os.Args[2] != "bad" {12 fmt.Println("Invalid arguments")13 os.Exit(1)14 }15 bisect.checkConfig(os.Args[1], os.Args[2])16}

Full Screen

Full Screen

checkConfig

Using AI Code Generation

copy

Full Screen

1import (2import (3func main() {4 var (5 if bisect.CheckConfig(config) {6 fmt.Println("Config looks good.")7 } else {8 fmt.Println("Config looks bad.")9 }10}11import (12import (13func main() {14 var (15 bisect.Bisect(config)16 fmt.Println("Bisecting done.")17}

Full Screen

Full Screen

checkConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 b := bisect.NewBisect()4 b.CheckConfig()5 fmt.Println(b.Result)6}

Full Screen

Full Screen

checkConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("enter the number of elements")4 fmt.Scanln(&n)5 fmt.Println("enter the elements")6 for i := 0; i < n; i++ {7 fmt.Scanln(&temp)8 arr = append(arr, temp)9 }10 fmt.Println("enter the key to be searched")11 fmt.Scanln(&key)12 a.SetArray(arr)13 a.SetKey(key)14 result = a.CheckConfig()15 if result == 1 {16 fmt.Println("key found")17 } else {18 fmt.Println("key not found")19 }20 os.Exit(0)21}

Full Screen

Full Screen

checkConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 reader := bufio.NewReader(os.Stdin)4 fmt.Println("Enter the name of the file containing the config details")5 filename, _ := reader.ReadString('\n')6 filename = strings.Replace(filename, "\n", "", -1)7 fmt.Println("Enter the name of the file containing the test cases")8 testcasefile, _ := reader.ReadString('\n')9 testcasefile = strings.Replace(testcasefile, "\n", "", -1)10 bisect := Bisect{}11 bisect.checkConfig(filename, testcasefile)12}

Full Screen

Full Screen

checkConfig

Using AI Code Generation

copy

Full Screen

1import (2type bisect struct {3}4func (b *bisect) checkConfig() {5 fmt.Println("Checking Config file")6}7func main() {8 b := bisect{}9 b.checkConfig()10 fmt.Println("File Path: ", os.Args[1])11}

Full Screen

Full Screen

checkConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 b = bisect.Bisect{}4 b.SetConfiguration("config.json")5 b.CheckConfiguration()6 fmt.Println(b)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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful