forked from timmyyuan/gobench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goker_dingo_hunter.go
91 lines (73 loc) · 2.07 KB
/
goker_dingo_hunter.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gobench
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
)
type DingoHunterExecuter struct {
*BatchRunResult
FileMigo string
Source string
TestFn string
cntrCtx *CntrContext
}
func newDingoHunterExecuter(config ExecBugConfig) *DingoHunterExecuter {
g := &DingoHunterExecuter{
BatchRunResult: &BatchRunResult{
ExecBugConfig: config,
},
}
project, id := SplitBugID(g.Bug.ID)
testfile := filepath.Join(g.SourceDir, fmt.Sprintf("%s%s_test.go", project, id))
g.Source, g.TestFn = filepath.Join(g.SourceDir, "main.go"), "main.go"
g.FileMigo = filepath.Join(g.SourceDir, "deadlock.migo")
InstrumentMainFunc(testfile)
if err := os.Rename(testfile, g.Source); err != nil {
panic(err)
}
return g
}
func (g *DingoHunterExecuter) TestEntryAndFunc() (string, string) {
return g.Source, g.TestFn
}
func (g *DingoHunterExecuter) Build() {}
func (g *DingoHunterExecuter) Run() *SingleRunResult {
stage1 := fmt.Sprintf("/go/bin/dingo-hunter migo %v --output %v", g.Source, g.FileMigo)
stage2 := fmt.Sprintf("Gong -A %v", g.FileMigo)
result := g.next()
result.Command = stage1 + "\n\t" + stage2
result.process(func() {
var err error
var output1, output2 []byte
args := strings.Split(stage1, " ")
output1, err = exec.Command(args[0], args[1:]...).CombinedOutput()
if err != nil {
result.Logs = []byte(fmt.Sprintf("StageOne Error:\n%s\n", output1))
result.ExitCode = 1
return
}
args = strings.Split(stage2, " ")
output2, err = exec.Command(args[0], args[1:]...).CombinedOutput()
if err != nil {
result.Logs = []byte(fmt.Sprintf("StageOne:\n%s\nStageTwo Error:\n%s\n", output1, output2))
result.ExitCode = 1
return
}
result.Logs = []byte(fmt.Sprintf("StageOne:\n%s\nStageTwo:\n%s\n", output1, output2))
return
})
return result
}
func (g *DingoHunterExecuter) Done() {
fulllog := g.log()
backup := filepath.Join(g.OutputDir, "full.log")
if err := ioutil.WriteFile(backup, []byte(fulllog), 0644); err != nil {
panic(err)
}
}
func (g *DingoHunterExecuter) GetResult() *BatchRunResult {
return g.BatchRunResult
}