1
0

Implements parameter "--max=X" for pew

This commit is contained in:
dump_stack() 2019-08-12 23:21:38 +00:00
parent 5dbbb33297
commit caee1b5756
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 24 additions and 5 deletions

View File

@ -105,6 +105,8 @@ func main() {
dockerTimeoutFlag := app.Flag("docker-timeout", "Timeout for docker")
dockerTimeout := dockerTimeoutFlag.Default("1m").Duration()
pewCommand := app.Command("pew", "Build, run and test module/exploit")
pewMax := pewCommand.Flag("max", "Test no more than X kernels").
PlaceHolder("X").Default(fmt.Sprint(KERNELS_ALL)).Int64()
pewKernelFlag := pewCommand.Flag("kernel", "Override kernel regex")
pewKernel := pewKernelFlag.String()
@ -205,7 +207,8 @@ func main() {
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case pewCommand.FullCommand():
err = pewHandler(kcfg, *path, *pewKernel, *pewBinary,
*pewTest, *pewGuess, *qemuTimeout, *dockerTimeout)
*pewTest, *pewGuess, *qemuTimeout, *dockerTimeout,
*pewMax)
case kernelListCommand.FullCommand():
err = kernelListHandler(kcfg)
case kernelAutogenCommand.FullCommand():

24
pew.go
View File

@ -285,13 +285,27 @@ func whatever(swg *sizedwaitgroup.SizedWaitGroup, ka config.Artifact,
}
}
func shuffleKernels(a []config.KernelInfo) []config.KernelInfo {
// FisherYates shuffle
for i := len(a) - 1; i > 0; i-- {
j := rand.Intn(i + 1)
a[i], a[j] = a[j], a[i]
}
return a
}
func performCI(ka config.Artifact, kcfg config.KernelConfig, binaryPath,
testPath string, qemuTimeout, dockerTimeout time.Duration) (err error) {
testPath string, qemuTimeout, dockerTimeout time.Duration,
max int64) (err error) {
found := false
swg := sizedwaitgroup.New(runtime.NumCPU())
for _, kernel := range kcfg.Kernels {
for _, kernel := range shuffleKernels(kcfg.Kernels) {
if max <= 0 {
break
}
var supported bool
supported, err = ka.Supported(kernel)
if err != nil {
@ -300,6 +314,7 @@ func performCI(ka config.Artifact, kcfg config.KernelConfig, binaryPath,
if supported {
found = true
max -= 1
swg.Add()
go whatever(&swg, ka, kernel, binaryPath, testPath,
qemuTimeout, dockerTimeout)
@ -355,7 +370,8 @@ func genAllKernels() (sk []config.KernelMask, err error) {
func pewHandler(kcfg config.KernelConfig,
workPath, ovrrdKrnl, binary, test string, guess bool,
qemuTimeout, dockerTimeout time.Duration) (err error) {
qemuTimeout, dockerTimeout time.Duration,
max int64) (err error) {
ka, err := config.ReadArtifactConfig(workPath + "/.out-of-tree.toml")
if err != nil {
@ -383,7 +399,7 @@ func pewHandler(kcfg config.KernelConfig,
}
}
err = performCI(ka, kcfg, binary, test, qemuTimeout, dockerTimeout)
err = performCI(ka, kcfg, binary, test, qemuTimeout, dockerTimeout, max)
if err != nil {
return
}