diff --git a/CHANGELOG.md b/CHANGELOG.md index 6110fc3..b4d82b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ - Support for (distro-specific) custom docker commands that will be executed before the base template. +- Parameter for setting up a reliability threshold for exit code. + +- Parameter for setting up global timeout, after which no new tasks + will be started. + ### Fixed - Spelling in output. diff --git a/main.go b/main.go index b138447..f8f8135 100644 --- a/main.go +++ b/main.go @@ -111,6 +111,9 @@ func main() { userKcfgPathEnv := userKcfgPathFlag.Envar("OUT_OF_TREE_KCFG") userKcfgPath := userKcfgPathEnv.Default(conf.UserKernels).String() + timeoutFlag := app.Flag("timeout", "Timeout after tool will not spawn new tests") + timeout := timeoutFlag.Duration() + qemuTimeoutFlag := app.Flag("qemu-timeout", "Timeout for qemu") qemuTimeout := qemuTimeoutFlag.Default(conf.Qemu.Timeout).Duration() @@ -287,10 +290,15 @@ func main() { } defer db.Close() + stop := time.Time{} // never stop + if *timeout != 0 { + stop = time.Now().Add(*timeout) + } + switch kingpin.MustParse(app.Parse(os.Args[1:])) { case pewCommand.FullCommand(): err = pewHandler(kcfg, *path, *pewKernel, *pewBinary, - *pewTest, *pewGuess, *qemuTimeout, *dockerTimeout, + *pewTest, *pewGuess, stop, *qemuTimeout, *dockerTimeout, *pewMax, *pewRuns, *pewDist, *pewTag, *pewThreads, db) case kernelListCommand.FullCommand(): err = kernelListHandler(kcfg) @@ -326,7 +334,7 @@ func main() { case logMarkdownCommand.FullCommand(): err = logMarkdownHandler(db, *path, *logMarkdownTag) case packCommand.FullCommand(): - err = packHandler(db, *path, *dockerRegistry, + err = packHandler(db, *path, *dockerRegistry, stop, conf.Docker.Commands, kcfg, *packAutogen, !*packNoDownload, *packExploitRuns, *packKernelRuns) } diff --git a/pack.go b/pack.go index d1c58da..104e897 100644 --- a/pack.go +++ b/pack.go @@ -15,7 +15,7 @@ import ( "code.dumpstack.io/tools/out-of-tree/config" ) -func packHandler(db *sql.DB, path, registry string, +func packHandler(db *sql.DB, path, registry string, stop time.Time, commands []config.DockerCommand, kcfg config.KernelConfig, autogen, download bool, exploitRuns, kernelRuns int64) (err error) { @@ -50,7 +50,7 @@ func packHandler(db *sql.DB, path, registry string, log.Println(f.Name()) pewHandler(kcfg, workPath, "", "", "", false, - dockerTimeout, qemuTimeout, + stop, dockerTimeout, qemuTimeout, kernelRuns, exploitRuns, pathDevNull, tag, threads, db) } diff --git a/pew.go b/pew.go index dd70802..1f18a63 100644 --- a/pew.go +++ b/pew.go @@ -391,7 +391,8 @@ func shuffleKernels(a []config.KernelInfo) []config.KernelInfo { } func performCI(ka config.Artifact, kcfg config.KernelConfig, binaryPath, - testPath string, qemuTimeout, dockerTimeout time.Duration, + testPath string, stop time.Time, + qemuTimeout, dockerTimeout time.Duration, max, runs int64, dist, tag string, threads int, db *sql.DB) (err error) { @@ -413,6 +414,9 @@ func performCI(ka config.Artifact, kcfg config.KernelConfig, binaryPath, found = true max-- for i := int64(0); i < runs; i++ { + if !stop.IsZero() && time.Now().After(stop) { + break + } swg.Add() go whatever(&swg, ka, kernel, binaryPath, testPath, qemuTimeout, dockerTimeout, @@ -468,9 +472,10 @@ func genAllKernels() (sk []config.KernelMask, err error) { return } +// TODO: Now too many parameters, move all of them to some structure func pewHandler(kcfg config.KernelConfig, workPath, ovrrdKrnl, binary, test string, guess bool, - qemuTimeout, dockerTimeout time.Duration, + stop time.Time, qemuTimeout, dockerTimeout time.Duration, max, runs int64, dist, tag string, threads int, db *sql.DB) (err error) { @@ -500,7 +505,8 @@ func pewHandler(kcfg config.KernelConfig, } } - err = performCI(ka, kcfg, binary, test, qemuTimeout, dockerTimeout, + err = performCI(ka, kcfg, binary, test, + stop, qemuTimeout, dockerTimeout, max, runs, dist, tag, threads, db) if err != nil { return