Home | History | Annotate | Download | only in log
      1 // Copyright 2016 syzkaller project authors. All rights reserved.
      2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
      3 
      4 package log
      5 
      6 import (
      7 	"testing"
      8 )
      9 
     10 func init() {
     11 	EnableLogCaching(4, 20)
     12 }
     13 
     14 func TestCaching(t *testing.T) {
     15 	tests := []struct{ str, want string }{
     16 		{"", ""},
     17 		{"a", "a\n"},
     18 		{"bb", "a\nbb\n"},
     19 		{"ccc", "a\nbb\nccc\n"},
     20 		{"dddd", "a\nbb\nccc\ndddd\n"},
     21 		{"eeeee", "bb\nccc\ndddd\neeeee\n"},
     22 		{"ffffff", "ccc\ndddd\neeeee\nffffff\n"},
     23 		{"ggggggg", "eeeee\nffffff\nggggggg\n"},
     24 		{"hhhhhhhh", "ggggggg\nhhhhhhhh\n"},
     25 		{"jjjjjjjjjjjjjjjjjjjjjjjjj", "jjjjjjjjjjjjjjjjjjjjjjjjj\n"},
     26 	}
     27 	prependTime = false
     28 	for _, test := range tests {
     29 		Logf(1, test.str)
     30 		out := CachedLogOutput()
     31 		if out != test.want {
     32 			t.Fatalf("wrote: %v\nwant: %v\ngot: %v", test.str, test.want, out)
     33 		}
     34 	}
     35 }
     36