-
Notifications
You must be signed in to change notification settings - Fork 9
/
logger.go
53 lines (46 loc) · 1.75 KB
/
logger.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
package test161
import (
"github.com/ops-class/test161/expect"
"regexp"
"time"
)
// Recv processes new sys161 output and restarts the progress timer
func (t *Test) Recv(receivedTime time.Time, received []byte) {
// This is a slightly hacky way to ensure that getStats isn't started until
// sys161 has began to run. (Starting it too early causes the unix socket
// connect to fail.) statStarted is only used once and doesn't need to be
// protected.
if !t.statStarted {
go t.getStats()
t.statStarted = true
}
// Parse some new incoming data. Frequently just a single byte but sometimes
// more.
t.L.Lock()
defer t.L.Unlock()
// Mark progress for the progress timeout.
t.progressTime = float64(t.SimTime)
for _, b := range received {
// Add timestamps to the beginning of each line.
if t.currentOutput.WallTime == 0.0 {
t.currentOutput.WallTime = t.getWallTime()
t.currentOutput.SimTime = t.SimTime
}
t.currentOutput.Buffer.WriteByte(b)
if b == '\n' {
t.currentOutput.Line = t.currentOutput.Buffer.String()
t.outputLineComplete()
t.currentCommand.Output = append(t.currentCommand.Output, t.currentOutput)
t.env.notifyAndLogErr("Update Command Output", t.currentCommand, MSG_PERSIST_UPDATE, MSG_FIELD_OUTPUT)
t.currentOutput = &OutputLine{}
}
}
}
// Unused parts of the expect.Logger interface
func (t *Test) Send(time.Time, []byte) {}
func (t *Test) SendMasked(time.Time, []byte) {}
func (t *Test) RecvNet(time.Time, []byte) {}
func (t *Test) RecvEOF(time.Time) {}
func (t *Test) ExpectCall(time.Time, *regexp.Regexp) {}
func (t *Test) ExpectReturn(time.Time, expect.Match, error) {}
func (t *Test) Close(time.Time) {}