Skip to content

Commit ad2f335

Browse files
simulation: test new log behavior
1 parent fb82171 commit ad2f335

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

internal/prettylog/prettylog.go

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package prettylog
2525

2626
import (
2727
"bytes"
28+
"encoding/base64"
2829
"encoding/json"
2930
"fmt"
3031
"io"
@@ -225,6 +226,12 @@ func (w Writer) writeFields(evt map[string]interface{}, buf *bytes.Buffer) {
225226

226227
switch value := evt[field].(type) {
227228
case string:
229+
if strings.HasPrefix(value, "base64:") {
230+
bytes, err := base64.StdEncoding.AppendDecode(nil, []byte(value[len("base64:"):]))
231+
if err == nil {
232+
value = string(bytes)
233+
}
234+
}
228235
if needsQuote(value) {
229236
buf.WriteString(w.formatter.fieldValue(field, strconv.Quote(value)))
230237
} else {

internal/simulation/os_linux.go

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err sysc
169169
panic("syscall should have been rewritten somewhere")
170170
}
171171

172-
// TODO: test this
173172
logf("unsupported syscall %s (%d) %d %d %d %d %d %d", SyscallName(trap), trap, a1, a2, a3, a4, a5, a6)
174173

175174
return 0, 0, syscall.ENOSYS

internal/tests/behavior/log_meta_test.go

+24-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package behavior_test
55
import (
66
"bytes"
77
"encoding/json"
8+
"fmt"
89
"strings"
910
"testing"
1011

@@ -124,6 +125,19 @@ func TestLogDuringInit(t *testing.T) {
124125
}
125126
}
126127

128+
func formatLogsWithExtra(logs []*gosimlog.Log) []string {
129+
// TODO: share this code with prettylog somehow?
130+
var lines []string
131+
for _, log := range logs {
132+
line := fmt.Sprintf("%d %s/%d %s %s", log.Step, log.Machine, log.Goroutine, log.Level, log.Msg)
133+
for _, kv := range log.Unknown {
134+
line += fmt.Sprintf(" %s=%s", kv.Key, kv.Value)
135+
}
136+
lines = append(lines, line)
137+
}
138+
return lines
139+
}
140+
127141
func TestLogTraceSyscall(t *testing.T) {
128142
if race.Enabled {
129143
// TODO: repair, which will need a reasonable plan for printing data
@@ -155,20 +169,17 @@ func TestLogTraceSyscall(t *testing.T) {
155169
t.Fatal(err)
156170
}
157171

158-
// TODO: make sure we check traceKind?
159172
// TODO: support snapshotting these logs?
160-
// TODO: include machine etc.?
161-
if diff := cmp.Diff(metatesting.SimplifyParsedLog(metatesting.ParseLog(run.LogOutput)), []string{
162-
"INFO unsupported syscall unknown (9999) 0 0 0 0 0 0",
163-
// TODO: check flags
164-
"INFO call SysOpenat",
165-
"INFO ret SysOpenat",
166-
"INFO call SysFcntl",
167-
"INFO ret SysFcntl",
168-
"INFO call SysWrite",
169-
"INFO ret SysWrite",
170-
"INFO call SysClose",
171-
"INFO ret SysClose",
173+
if diff := cmp.Diff(formatLogsWithExtra(gosimlog.ParseLog(run.LogOutput)), []string{
174+
"1 main/4 INFO unsupported syscall unknown (9999) 0 0 0 0 0 0",
175+
`2 main/4 INFO call SysOpenat dirfd="AT_FDCWD" path="hello" flags="O_WRONLY|O_TRUNC|O_CREAT|O_CLOEXEC" mode="0o644"`,
176+
"3 main/4 INFO ret SysOpenat fd=5 err=null",
177+
"4 main/4 INFO call SysFcntl",
178+
"5 main/4 INFO ret SysFcntl",
179+
`6 main/4 INFO call SysWrite fd=5 p="world"`,
180+
"7 main/4 INFO ret SysWrite n=5 err=null",
181+
"8 main/4 INFO call SysClose fd=5",
182+
"9 main/4 INFO ret SysClose err=null",
172183
}); diff != "" {
173184
t.Error("diff", diff)
174185
}

internal/tests/behavior/log_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func TestLogDuringInit(t *testing.T) {
9292

9393
func TestLogTraceSyscall(t *testing.T) {
9494
// should print ENOSYS
95+
// TODO: test this with a known number and make it work both on arm64 and amd64
9596
syscall.Syscall(9999, 0, 0, 0)
9697

9798
// should print open, write, close

0 commit comments

Comments
 (0)