1// Copyright 2020 Google Inc. All Rights Reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package metrics 16 17import ( 18 "testing" 19 "time" 20 21 "android/soong/ui/tracer" 22) 23 24func TestEnd(t *testing.T) { 25 startTime := time.Date(2020, time.July, 13, 13, 0, 0, 0, time.UTC) 26 dur := time.Nanosecond * 10 27 initialNow := _now 28 _now = func() time.Time { return startTime.Add(dur) } 29 defer func() { _now = initialNow }() 30 31 et := &EventTracer{} 32 et.push(&event{ 33 desc: "test", 34 name: "test", 35 start: startTime, 36 }) 37 38 perf := et.End(tracer.Thread(0)) 39 if perf.GetRealTime() != uint64(dur.Nanoseconds()) { 40 t.Errorf("got %d, want %d nanoseconds for event duration", perf.GetRealTime(), dur.Nanoseconds()) 41 } 42} 43