aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs/testos.go
blob: 2fd4dd151fff0e22356a0ff4e6054c7b2b7b1827 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2019 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package vcs

import (
	"fmt"

	"github.com/google/syzkaller/pkg/debugtracer"
	"github.com/google/syzkaller/pkg/report/crash"
	"github.com/google/syzkaller/sys/targets"
)

type testos struct {
	*gitRepo
}

var _ ConfigMinimizer = new(testos)

func newTestos(dir string, opts []RepoOpt) *testos {
	return &testos{
		gitRepo: newGitRepo(dir, nil, opts),
	}
}

func (ctx *testos) PreviousReleaseTags(commit, compilerType string) ([]string, error) {
	return ctx.gitRepo.previousReleaseTags(commit, false, false, false)
}

func (ctx *testos) EnvForCommit(
	defaultCompiler, compilerType, binDir, commit string, kernelConfig []byte,
	backports []BackportCommit,
) (*BisectEnv, error) {
	return &BisectEnv{KernelConfig: kernelConfig}, nil
}

func (ctx *testos) Minimize(target *targets.Target, original, baseline []byte, types []crash.Type,
	dt debugtracer.DebugTracer, pred func(test []byte) (BisectResult, error)) ([]byte, error) {
	if len(baseline) == 0 {
		return original, nil
	}
	if res, err := pred(baseline); err != nil {
		return nil, err
	} else if res == BisectBad {
		return baseline, nil
	}
	switch string(baseline) {
	case "minimize-fails":
		return nil, fmt.Errorf("minimization failure")
	case "minimize-succeeds":
		config := []byte("new-minimized-config")
		pred(config)
		return config, nil
	default:
		return original, nil
	}
}

func (ctx *testos) PrepareBisect() error {
	return nil
}