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
|
// Copyright 2016 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package log
import (
"testing"
)
func init() {
EnableLogCaching(4, 20)
}
func TestCaching(t *testing.T) {
tests := []struct{ str, want string }{
{"", ""},
{"a", "a\n"},
{"bb", "a\nbb\n"},
{"ccc", "a\nbb\nccc\n"},
{"dddd", "a\nbb\nccc\ndddd\n"},
{"eeeee", "bb\nccc\ndddd\neeeee\n"},
{"ffffff", "ccc\ndddd\neeeee\nffffff\n"},
{"ggggggg", "eeeee\nffffff\nggggggg\n"},
{"hhhhhhhh", "ggggggg\nhhhhhhhh\n"},
{"jjjjjjjjjjjjjjjjjjjjjjjjj", "jjjjjjjjjjjjjjjjjjjjjjjjj\n"},
}
prependTime = false
for _, test := range tests {
Log(1, test.str)
out := CachedLogOutput()
if out != test.want {
t.Fatalf("wrote: %v\nwant: %v\ngot: %v", test.str, test.want, out)
}
}
}
func TestLazy(t *testing.T) {
// Ensure that the format message is formatted lazily only when logging enabled.
Logf(1e6, "%v", noFormat{t})
}
type noFormat struct{ *testing.T }
func (nf noFormat) String() string {
nf.T.Fatalf("must not be formatted")
return ""
}
|