blob: 043450bdd3781c56e66bd8d564fdbe15b818a82a [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) {
Patrice Arruda958b89c2020-07-13 18:21:14 +000025 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
Patrice Arruda8a44a372020-12-14 20:55:23 +000031 et := &EventTracer{}
32 et.push(&event{
Patrice Arruda958b89c2020-07-13 18:21:14 +000033 desc: "test",
34 name: "test",
35 start: startTime,
36 })
37
Patrice Arruda8a44a372020-12-14 20:55:23 +000038 perf := et.End(tracer.Thread(0))
Patrice Arruda958b89c2020-07-13 18:21:14 +000039 if perf.GetRealTime() != uint64(dur.Nanoseconds()) {
40 t.Errorf("got %d, want %d nanoseconds for event duration", perf.GetRealTime(), dur.Nanoseconds())
41 }
42}