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"`
|
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,
|
func (cmd KernelAutogenCmd) Run(kernelCmd *KernelCmd, g *Globals) (err error) {
|
||||||
commands []config.DockerCommand,
|
|
||||||
max int64, host, download bool) (err error) {
|
|
||||||
return errors.New("MEH")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cmd *KernelAutogenCmd) Run(kernelCmd *KernelCmd, g *Globals) (err error) {
|
|
||||||
ka, err := config.ReadArtifactConfig(g.WorkDir + "/.out-of-tree.toml")
|
ka, err := config.ReadArtifactConfig(g.WorkDir + "/.out-of-tree.toml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
60
pack.go
60
pack.go
@ -8,42 +8,27 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.dumpstack.io/tools/out-of-tree/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PackCmd struct {
|
type PackCmd struct {
|
||||||
Autogen bool `help:"kernel autogeneration"`
|
Autogen bool `help:"kernel autogeneration"`
|
||||||
|
UseHost bool `help:"also use host kernels"`
|
||||||
NoDownload bool `help:"do not download qemu image while kernel generation"`
|
NoDownload bool `help:"do not download qemu image while kernel generation"`
|
||||||
ExploitRuns int64 `default:"4" help:"amount of runs of each exploit"`
|
ExploitRuns int64 `default:"4" help:"amount of runs of each exploit"`
|
||||||
KernelRuns int64 `default:"1" help:"amount of runs of each kernel"`
|
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"`
|
Tag string `help:"filter tag"`
|
||||||
|
|
||||||
Timeout time.Duration `help:"timeout after tool will not spawn new tests"`
|
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) {
|
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())
|
tag := fmt.Sprintf("pack_run_%d", time.Now().Unix())
|
||||||
log.Println("Tag:", tag)
|
log.Println("Tag:", tag)
|
||||||
|
|
||||||
@ -60,11 +45,16 @@ func (cmd *PackCmd) Run(g *Globals) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cmd.Autogen {
|
if cmd.Autogen {
|
||||||
var perRegex int64 = 1
|
err = KernelAutogenCmd{Max: cmd.Max}.Run(
|
||||||
err = kernelAutogenHandler(workPath,
|
&KernelCmd{
|
||||||
g.Config.Docker.Registry,
|
NoDownload: cmd.NoDownload,
|
||||||
g.Config.Docker.Commands,
|
UseHost: cmd.UseHost,
|
||||||
perRegex, false, !cmd.NoDownload)
|
},
|
||||||
|
&Globals{
|
||||||
|
Config: g.Config,
|
||||||
|
WorkDir: workPath,
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -72,11 +62,19 @@ func (cmd *PackCmd) Run(g *Globals) (err error) {
|
|||||||
|
|
||||||
log.Println(f.Name())
|
log.Println(f.Name())
|
||||||
|
|
||||||
pewHandler(kcfg, workPath, "", "", "", false, stop,
|
PewCmd{
|
||||||
g.Config.Docker.Timeout.Duration,
|
Max: cmd.KernelRuns,
|
||||||
g.Config.Qemu.Timeout.Duration,
|
Runs: cmd.ExploitRuns,
|
||||||
cmd.KernelRuns, cmd.ExploitRuns, pathDevNull,
|
Threads: cmd.Threads,
|
||||||
tag, threads, db, false)
|
Tag: tag,
|
||||||
|
Timeout: cmd.Timeout,
|
||||||
|
QemuTimeout: cmd.QemuTimeout,
|
||||||
|
DockerTimeout: cmd.DockerTimeout,
|
||||||
|
Dist: pathDevNull,
|
||||||
|
}.Run(&Globals{
|
||||||
|
Config: g.Config,
|
||||||
|
WorkDir: workPath,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
102
pew.go
102
pew.go
@ -34,13 +34,16 @@ type PewCmd struct {
|
|||||||
Binary string `help:"use binary, do not build"`
|
Binary string `help:"use binary, do not build"`
|
||||||
Test string `help:"override path for test"`
|
Test string `help:"override path for test"`
|
||||||
Dist string `help:"build result path" default:"/dev/null"`
|
Dist string `help:"build result path" default:"/dev/null"`
|
||||||
Threads int `help:"threads"`
|
Threads int `help:"threads" default:"1"`
|
||||||
Tag string `help:"log tagging"`
|
Tag string `help:"log tagging"`
|
||||||
Verbose bool `help:"show more information"`
|
Verbose bool `help:"show more information"`
|
||||||
Timeout time.Duration `help:"timeout after tool will not spawn new tests"`
|
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)
|
kcfg, err := config.ReadKernelConfig(g.Config.Kernels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -57,13 +60,51 @@ func (cmd *PewCmd) Run(g *Globals) (err error) {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
return pewHandler(
|
ka, err := config.ReadArtifactConfig(g.WorkDir + "/.out-of-tree.toml")
|
||||||
kcfg, g.WorkDir, cmd.Kernel, cmd.Binary, cmd.Test,
|
if err != nil {
|
||||||
cmd.Guess, stop, g.Config.Qemu.Timeout.Duration,
|
return
|
||||||
g.Config.Docker.Timeout.Duration,
|
}
|
||||||
cmd.Max, cmd.Runs, cmd.Dist, cmd.Tag, cmd.Threads,
|
|
||||||
db, cmd.Verbose,
|
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 {
|
type runstate struct {
|
||||||
@ -543,46 +584,3 @@ func genAllKernels() (sk []config.KernelMask, err error) {
|
|||||||
}
|
}
|
||||||
return
|
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