forked from nicolasdilley/Gomela
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
executable file
·283 lines (237 loc) · 7.49 KB
/
main_test.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"testing"
)
const (
test_projects = "test_projects.csv"
gl_test_filename = "testmodels/gl_test.csv"
)
type Model struct {
Name string
commit string
numParams int
glScore string
SendScore string
CloseScore string
NegCounterScore string
}
func TestMain(t *testing.T) {
fmt.Println("Parsing GL models")
// Go through each of the 141 GL model and test them individually
data, _ := ioutil.ReadFile(gl_test_filename)
projects := make(map[string][]Model) // map of projects and their
lines := strings.Split(string(data), "\n")
for _, line := range lines[:len(lines)-1] {
splitted := strings.Split(line, ",")
model_line := splitted[0]
project := strings.ReplaceAll(strings.Split(model_line, ":")[0], AUTHOR_PROJECT_SEP, "/")
num_params, _ := strconv.Atoi(splitted[2])
send_score := truncate(splitted[3])
close_score := truncate(splitted[4])
neg_counter_score := truncate(splitted[5])
gl_score := truncate(strings.Split(splitted[6], "\r")[0])
model := Model{
Name: strings.Split(splitted[0], ":")[1],
commit: splitted[1],
numParams: num_params,
glScore: gl_score,
SendScore: send_score,
CloseScore: close_score,
NegCounterScore: neg_counter_score,
}
projects[project] = append(projects[project], model)
}
// remove all results2021* results
fmt.Println("Removing result20* folders")
filepath.Walk(".", func(path string, file os.FileInfo, err error) error {
if file.IsDir() {
if strings.Contains(file.Name(), "result20") {
os.RemoveAll(path)
}
if file.Name() != "." {
return filepath.SkipDir
}
} else {
if strings.Contains(file.Name(), ".trail") {
os.Remove(path)
}
}
return nil
})
projects_list := ""
for p, m := range projects {
projects_list += p + "," + m[0].commit + "\n"
}
ioutil.WriteFile(test_projects, []byte(projects_list), 0766)
fmt.Println("Building gomela")
building := exec.Command("go", "build")
building.Stderr = os.Stdout
building.Stdout = os.Stdout
building.Run()
fmt.Println("Starting the modelling phase")
modelling := exec.Command("./gomela", "-l", test_projects)
modelling.Stderr = os.Stdout
modelling.Stdout = os.Stdout
err := modelling.Run()
if err != nil {
fmt.Println("there was an error while modelling the projects: ", err)
}
result_folder_path := ""
fmt.Println("Looking for the result folder")
filepath.Walk(".", func(path string, file os.FileInfo, err error) error {
if file.IsDir() {
if strings.Contains(file.Name(), "result20") {
result_folder_path = path
}
if file.Name() != "." {
return filepath.SkipDir
}
}
return nil
})
if result_folder_path == "" {
t.Errorf("Could not find result folder")
t.Fail()
}
RESULTS_FOLDER = result_folder_path
folders, err := ioutil.ReadDir(result_folder_path)
if err != nil {
t.Errorf("Could not look at the number of file in %s", result_folder_path)
t.Fail()
}
if len(folders)-2 != len(projects) {
t.Errorf("The number of projects modelled is not equal to number of input project! Inputted %d projects and got %d back", len(projects), len(folders)-2)
not_found := []string{}
for p, _ := range projects {
found := false
for _, m := range folders {
if strings.ReplaceAll(p, "/", AUTHOR_PROJECT_SEP) == m.Name() {
found = true
break
}
if !found {
not_found = append(not_found, p)
}
}
// fmt.Println("The projects not found are :")
// for _, s := range not_found {
// fmt.Println(s)
// }
}
}
fmt.Println("Removing uneeded models")
projects_to_verify := make(map[string][]os.FileInfo)
filepath.Walk(result_folder_path, func(dir_path string, dir_file os.FileInfo, err error) error {
if dir_file.IsDir() && dir_file.Name() != result_folder_path {
filepath.Walk(dir_path, func(path string, file os.FileInfo, err error) error {
if !file.IsDir() {
found := false
if models, ok := projects[strings.ReplaceAll(dir_file.Name(), AUTHOR_PROJECT_SEP, "/")]; ok {
for _, m := range models {
if file.Name() == m.Name {
found = true
break
}
}
} else {
t.Errorf("Could not find project %s", strings.ReplaceAll(dir_file.Name(), AUTHOR_PROJECT_SEP, "/"))
}
if !found {
os.Remove(path)
}
}
return nil
})
models, err1 := ioutil.ReadDir(dir_path)
if err1 != nil {
t.Errorf("Could not read dir %s ", dir_path)
}
projects_to_verify[dir_file.Name()] = models
return filepath.SkipDir
}
return nil
})
fmt.Println("Verifying all models")
for p, models := range projects_to_verify {
VerifyModels(models, p, make([]interface{}, 0))
}
fmt.Println("Testing that all models are reported as deadlocks")
folder, _ := filepath.Abs(RESULTS_FOLDER)
survey_parser := exec.Command("./survey_parser/survey_parser", folder+"/log.csv", "./projects.txt", folder+"/verification.csv")
survey_parser.Run()
scores, err2 := ioutil.ReadFile("./scores.csv")
if err2 != nil {
t.Fatal("could not open scores.csv")
}
result_projects := make(map[string][]Model)
score_lines := strings.Split(string(scores), "\n")
for _, line := range score_lines[:len(score_lines)-1] {
splitted := strings.Split(line, ",")
model_line := splitted[0]
project := strings.ReplaceAll(strings.Split(model_line, ":")[0], AUTHOR_PROJECT_SEP, "/")
num_params, _ := strconv.Atoi(splitted[2])
send_score := truncate(splitted[3])
close_score := truncate(splitted[4])
neg_counter_score := truncate(splitted[5])
gl_score := truncate(strings.Split(splitted[6], "\r")[0])
model := Model{
Name: strings.Split(splitted[0], ":")[1],
commit: splitted[1],
numParams: num_params,
glScore: gl_score,
SendScore: send_score,
CloseScore: close_score,
NegCounterScore: neg_counter_score,
}
result_projects[project] = append(result_projects[project], model)
}
for p, models := range projects {
if result_models, ok := result_projects[p]; ok {
for _, model := range models {
var result *Model
for _, result_model := range result_models {
if model.Name == result_model.Name {
result = &result_model
break
}
}
if result == nil {
t.Errorf("Could not find model %s in project %s ", model.Name, p)
t.Fail()
} else {
if result.numParams != model.numParams {
t.Errorf("Model %s was expected to have %d parameters but had %d", model.Name, model.numParams, result.numParams)
}
if result.glScore != model.glScore {
t.Errorf("Model %s was expected to have a GL score of %s but had a score of %s", model.Name, model.glScore, result.glScore)
}
if result.SendScore != model.SendScore {
t.Errorf("Model %s was expected to have a send score of %s but had a score of %s", model.Name, model.SendScore, result.SendScore)
}
if result.CloseScore != model.CloseScore {
t.Errorf("Model %s was expected to have a close score of %s but had a score of %s", model.Name, model.CloseScore, result.CloseScore)
}
if result.NegCounterScore != model.NegCounterScore {
t.Errorf("Model %s was expected to have a neg counter score of %s but had a score of %s", model.Name, model.NegCounterScore, result.NegCounterScore)
}
}
}
} else {
t.Errorf("Project " + p + "did not generate any models.")
}
}
}
func truncate(s string) string {
new_s := s
if len(s) > 4 {
new_s = s[:4]
}
return new_s
}