blob: 324a9587a15313a97ae1646065438035ca1c2021 [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package log_test
import (
"bytes"
"testing"
"android.googlesource.com/platform/tools/gpu/framework/log"
)
const TraceExpected = `Info:Lemon
Info:L1:Bananna
Info:L1->L2:Melon
Info:L1->L2->L3:Mango
Info:R1:Apple
`
func TestTrace(t *testing.T) {
buf := &bytes.Buffer{}
base := log.Background().
PreFilter(log.Limit(log.DebugLevel)).
Filter(log.Pass).
Handler(log.Writer(log.Normal, buf))
l1 := base.Enter("L1")
l2 := l1.Enter("L2")
l3 := l2.Enter("L3")
r1 := base.Enter("R1")
base.Print("Lemon")
l1.Print("Bananna")
l2.Print("Melon")
l3.Print("Mango")
r1.Print("Apple")
got := buf.String()
if got != TraceExpected {
t.Errorf("Got %q expected %q", got, TraceExpected)
}
}