blob: 16d6a208ff2cd91cb3d8d636e75d5c294399effd [file] [log] [blame]
Patrice Arruda958b89c2020-07-13 18:21:14 +00001// 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) {
Colin Cross323dc602020-09-18 14:25:31 -070025 t.Parallel()
Patrice Arruda958b89c2020-07-13 18:21:14 +000026 startTime := time.Date(2020, time.July, 13, 13, 0, 0, 0, time.UTC)
27 dur := time.Nanosecond * 10
28 initialNow := _now
29 _now = func() time.Time { return startTime.Add(dur) }
30 defer func() { _now = initialNow }()
31
32 timeTracer := &timeTracerImpl{}
33 timeTracer.activeEvents = append(timeTracer.activeEvents, timeEvent{
34 desc: "test",
35 name: "test",
36 start: startTime,
37 })
38
39 perf := timeTracer.End(tracer.Thread(0))
40 if perf.GetRealTime() != uint64(dur.Nanoseconds()) {
41 t.Errorf("got %d, want %d nanoseconds for event duration", perf.GetRealTime(), dur.Nanoseconds())
42 }
43}