4
4
"bytes"
5
5
"errors"
6
6
"fmt"
7
- "github.com/chermehdi/egor/config"
8
- "github.com/fatih/color"
9
- "github.com/jedib0t/go-pretty/table"
10
7
"io/ioutil"
11
8
"os"
12
9
"os/exec"
@@ -15,6 +12,10 @@ import (
15
12
"strings"
16
13
"time"
17
14
15
+ "github.com/chermehdi/egor/config"
16
+ "github.com/fatih/color"
17
+ "github.com/jedib0t/go-pretty/table"
18
+
18
19
"github.com/urfave/cli/v2"
19
20
)
20
21
39
40
)
40
41
41
42
const WorkDir = "work"
43
+ const TimeOutDelta float64 = 25.0
42
44
43
45
// Checks the output of a given testcase against it's expected output
44
46
type Checker interface {
@@ -93,6 +95,7 @@ type CaseStatus struct {
93
95
Status int8
94
96
CheckerError error
95
97
Stderr string
98
+ Duration time.Duration
96
99
}
97
100
98
101
// Implementation must be able to prepare the working environment to compile and execute testscases,
@@ -168,7 +171,7 @@ func getStderrDisplay(stderr string) string {
168
171
func (c * ConsoleJudgeReport ) Display () {
169
172
t := table .NewWriter ()
170
173
t .SetOutputMirror (os .Stdout )
171
- t .AppendHeader (table.Row {"#" , "Test Name" , "Status" , "Custom" , "Additional infos" , "Stderr" })
174
+ t .AppendHeader (table.Row {"#" , "Test Name" , "Status" , "Custom" , "Additional infos" , "Stderr" , "Execution Time" })
172
175
for i , stat := range c .Stats {
173
176
output := "None"
174
177
if stat .CheckerError != nil {
@@ -181,6 +184,7 @@ func (c *ConsoleJudgeReport) Display() {
181
184
c .Descs [i ].CustomCase ,
182
185
output ,
183
186
getStderrDisplay (stat .Stderr ),
187
+ stat .Duration
184
188
})
185
189
}
186
190
t .SetStyle (table .StyleLight )
@@ -191,7 +195,8 @@ func newJudgeReport() JudgeReport {
191
195
return & ConsoleJudgeReport {Stats : []CaseStatus {}}
192
196
}
193
197
194
- func timedExecution (cmd * exec.Cmd , timeOut float64 ) (int8 , error ) {
198
+ func timedExecution (cmd * exec.Cmd , timeOut float64 ) (int8 , time.Duration , error ) {
199
+ start := time .Now ()
195
200
cmd .Start ()
196
201
done := make (chan error )
197
202
go func () { done <- cmd .Wait () }()
@@ -200,9 +205,11 @@ func timedExecution(cmd *exec.Cmd, timeOut float64) (int8, error) {
200
205
select {
201
206
case <- timeout :
202
207
cmd .Process .Kill ()
203
- return TO , nil
208
+ elapsed := time .Since (start )
209
+ return TO , elapsed , nil
204
210
case err := <- done :
205
- return OK , err
211
+ elapsed := time .Since (start )
212
+ return OK , elapsed , err
206
213
}
207
214
}
208
215
@@ -234,12 +241,13 @@ func execute(judge Judge, desc CaseDescription, command string, args ...string)
234
241
cmd .Stdout = outputFile
235
242
cmd .Stderr = & stderrBuffer
236
243
237
- status , err := timedExecution (cmd , desc .TimeLimit )
244
+ status , duration , err := timedExecution (cmd , desc .TimeLimit + TimeOutDelta )
238
245
if status == TO {
239
246
return CaseStatus {
240
247
Status : TL ,
241
248
CheckerError : nil ,
242
249
Stderr : stderrBuffer .String (),
250
+ Duration : duration ,
243
251
}, nil
244
252
}
245
253
@@ -248,6 +256,7 @@ func execute(judge Judge, desc CaseDescription, command string, args ...string)
248
256
Status : RE ,
249
257
CheckerError : nil ,
250
258
Stderr : stderrBuffer .String (),
259
+ Duration : duration ,
251
260
}, err
252
261
}
253
262
@@ -256,6 +265,7 @@ func execute(judge Judge, desc CaseDescription, command string, args ...string)
256
265
return CaseStatus {
257
266
Status : RE ,
258
267
CheckerError : nil ,
268
+ Duration : duration ,
259
269
}, err
260
270
}
261
271
output , err := ioutil .ReadFile (desc .WorkFile )
@@ -264,6 +274,7 @@ func execute(judge Judge, desc CaseDescription, command string, args ...string)
264
274
return CaseStatus {
265
275
Status : RE ,
266
276
CheckerError : nil ,
277
+ Duration : duration ,
267
278
}, err
268
279
}
269
280
err = judge .Checker ().Check (string (output ), string (expectedOutput ))
@@ -272,12 +283,14 @@ func execute(judge Judge, desc CaseDescription, command string, args ...string)
272
283
Status : WA ,
273
284
CheckerError : err ,
274
285
Stderr : stderrBuffer .String (),
286
+ Duration : duration ,
275
287
}, err
276
288
}
277
289
return CaseStatus {
278
290
Status : AC ,
279
291
CheckerError : nil ,
280
292
Stderr : stderrBuffer .String (),
293
+ Duration : duration ,
281
294
}, err
282
295
}
283
296
0 commit comments