Add missing flags, refactor
This commit is contained in:
parent
abd8e69186
commit
ce7794ce84
@ -57,13 +57,7 @@ type KernelAutogenCmd struct {
|
||||
Max int64 `help:"download random kernels from set defined by regex in release_mask, but no more than X for each of release_mask" default:"100500"`
|
||||
}
|
||||
|
||||
func kernelAutogenHandler(workPath, registry string,
|
||||
commands []config.DockerCommand,
|
||||
max int64, host, download bool) (err error) {
|
||||
return errors.New("MEH")
|
||||
}
|
||||
|
||||
func (cmd *KernelAutogenCmd) Run(kernelCmd *KernelCmd, g *Globals) (err error) {
|
||||
func (cmd KernelAutogenCmd) Run(kernelCmd *KernelCmd, g *Globals) (err error) {
|
||||
ka, err := config.ReadArtifactConfig(g.WorkDir + "/.out-of-tree.toml")
|
||||
if err != nil {
|
||||
return
|
||||
|
60
pack.go
60
pack.go
@ -8,42 +8,27 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/config"
|
||||
)
|
||||
|
||||
type PackCmd struct {
|
||||
Autogen bool `help:"kernel autogeneration"`
|
||||
UseHost bool `help:"also use host kernels"`
|
||||
NoDownload bool `help:"do not download qemu image while kernel generation"`
|
||||
ExploitRuns int64 `default:"4" help:"amount of runs of each exploit"`
|
||||
KernelRuns int64 `default:"1" help:"amount of runs of each kernel"`
|
||||
Max int64 `help:"download random kernels from set defined by regex in release_mask, but no more than X for each of release_mask" default:"1"`
|
||||
|
||||
Threads int `help:"threads" default:"4"`
|
||||
|
||||
Tag string `help:"filter tag"`
|
||||
|
||||
Timeout time.Duration `help:"timeout after tool will not spawn new tests"`
|
||||
QemuTimeout time.Duration `help:"timeout for qemu"`
|
||||
DockerTimeout time.Duration `help:"timeout for docker"`
|
||||
}
|
||||
|
||||
func (cmd *PackCmd) Run(g *Globals) (err error) {
|
||||
kcfg, err := config.ReadKernelConfig(g.Config.Kernels)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
db, err := openDatabase(g.Config.Database)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
stop := time.Time{} // never stop
|
||||
if cmd.Timeout != 0 {
|
||||
stop = time.Now().Add(cmd.Timeout)
|
||||
}
|
||||
|
||||
threads := runtime.NumCPU()
|
||||
|
||||
tag := fmt.Sprintf("pack_run_%d", time.Now().Unix())
|
||||
log.Println("Tag:", tag)
|
||||
|
||||
@ -60,11 +45,16 @@ func (cmd *PackCmd) Run(g *Globals) (err error) {
|
||||
}
|
||||
|
||||
if cmd.Autogen {
|
||||
var perRegex int64 = 1
|
||||
err = kernelAutogenHandler(workPath,
|
||||
g.Config.Docker.Registry,
|
||||
g.Config.Docker.Commands,
|
||||
perRegex, false, !cmd.NoDownload)
|
||||
err = KernelAutogenCmd{Max: cmd.Max}.Run(
|
||||
&KernelCmd{
|
||||
NoDownload: cmd.NoDownload,
|
||||
UseHost: cmd.UseHost,
|
||||
},
|
||||
&Globals{
|
||||
Config: g.Config,
|
||||
WorkDir: workPath,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -72,11 +62,19 @@ func (cmd *PackCmd) Run(g *Globals) (err error) {
|
||||
|
||||
log.Println(f.Name())
|
||||
|
||||
pewHandler(kcfg, workPath, "", "", "", false, stop,
|
||||
g.Config.Docker.Timeout.Duration,
|
||||
g.Config.Qemu.Timeout.Duration,
|
||||
cmd.KernelRuns, cmd.ExploitRuns, pathDevNull,
|
||||
tag, threads, db, false)
|
||||
PewCmd{
|
||||
Max: cmd.KernelRuns,
|
||||
Runs: cmd.ExploitRuns,
|
||||
Threads: cmd.Threads,
|
||||
Tag: tag,
|
||||
Timeout: cmd.Timeout,
|
||||
QemuTimeout: cmd.QemuTimeout,
|
||||
DockerTimeout: cmd.DockerTimeout,
|
||||
Dist: pathDevNull,
|
||||
}.Run(&Globals{
|
||||
Config: g.Config,
|
||||
WorkDir: workPath,
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
|
102
pew.go
102
pew.go
@ -34,13 +34,16 @@ type PewCmd struct {
|
||||
Binary string `help:"use binary, do not build"`
|
||||
Test string `help:"override path for test"`
|
||||
Dist string `help:"build result path" default:"/dev/null"`
|
||||
Threads int `help:"threads"`
|
||||
Threads int `help:"threads" default:"1"`
|
||||
Tag string `help:"log tagging"`
|
||||
Verbose bool `help:"show more information"`
|
||||
Timeout time.Duration `help:"timeout after tool will not spawn new tests"`
|
||||
|
||||
QemuTimeout time.Duration `help:"timeout for qemu"`
|
||||
DockerTimeout time.Duration `help:"timeout for docker"`
|
||||
}
|
||||
|
||||
func (cmd *PewCmd) Run(g *Globals) (err error) {
|
||||
func (cmd PewCmd) Run(g *Globals) (err error) {
|
||||
kcfg, err := config.ReadKernelConfig(g.Config.Kernels)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@ -57,13 +60,51 @@ func (cmd *PewCmd) Run(g *Globals) (err error) {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
return pewHandler(
|
||||
kcfg, g.WorkDir, cmd.Kernel, cmd.Binary, cmd.Test,
|
||||
cmd.Guess, stop, g.Config.Qemu.Timeout.Duration,
|
||||
g.Config.Docker.Timeout.Duration,
|
||||
cmd.Max, cmd.Runs, cmd.Dist, cmd.Tag, cmd.Threads,
|
||||
db, cmd.Verbose,
|
||||
)
|
||||
ka, err := config.ReadArtifactConfig(g.WorkDir + "/.out-of-tree.toml")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if ka.SourcePath == "" {
|
||||
ka.SourcePath = g.WorkDir
|
||||
}
|
||||
|
||||
if cmd.Kernel != "" {
|
||||
var km config.KernelMask
|
||||
km, err = kernelMask(cmd.Kernel)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ka.SupportedKernels = []config.KernelMask{km}
|
||||
}
|
||||
|
||||
if cmd.Guess {
|
||||
ka.SupportedKernels, err = genAllKernels()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
qemuTimeout := g.Config.Qemu.Timeout.Duration
|
||||
if cmd.QemuTimeout != 0 {
|
||||
qemuTimeout = cmd.QemuTimeout
|
||||
}
|
||||
|
||||
dockerTimeout := g.Config.Docker.Timeout.Duration
|
||||
if cmd.DockerTimeout != 0 {
|
||||
dockerTimeout = cmd.DockerTimeout
|
||||
}
|
||||
|
||||
err = performCI(ka, kcfg, cmd.Binary, cmd.Test, stop,
|
||||
qemuTimeout, dockerTimeout,
|
||||
cmd.Max, cmd.Runs, cmd.Dist, cmd.Tag,
|
||||
cmd.Threads, db, cmd.Verbose)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type runstate struct {
|
||||
@ -543,46 +584,3 @@ 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,
|
||||
stop time.Time, qemuTimeout, dockerTimeout time.Duration,
|
||||
max, runs int64, dist, tag string, threads int,
|
||||
db *sql.DB, verbose bool) (err error) {
|
||||
|
||||
ka, err := config.ReadArtifactConfig(workPath + "/.out-of-tree.toml")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if ka.SourcePath == "" {
|
||||
ka.SourcePath = workPath
|
||||
}
|
||||
|
||||
if ovrrdKrnl != "" {
|
||||
var km config.KernelMask
|
||||
km, err = kernelMask(ovrrdKrnl)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ka.SupportedKernels = []config.KernelMask{km}
|
||||
}
|
||||
|
||||
if guess {
|
||||
ka.SupportedKernels, err = genAllKernels()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = performCI(ka, kcfg, binary, test,
|
||||
stop, qemuTimeout, dockerTimeout,
|
||||
max, runs, dist, tag, threads, db, verbose)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user