• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import {UnitTestUtils} from 'test/unit/utils';
17import {LayerTraceEntry} from 'trace/flickerlib/layers/LayerTraceEntry';
18import {Parser} from 'trace/parser';
19import {Timestamp, TimestampType} from 'trace/timestamp';
20import {TraceType} from 'trace/trace_type';
21
22describe('ParserSurfaceFlingerDump', () => {
23  describe('trace with elapsed + real timestamp', () => {
24    let parser: Parser<LayerTraceEntry>;
25    const DUMP_REAL_TIME = 1659176624505188647n;
26
27    beforeAll(async () => {
28      parser = await UnitTestUtils.getParser(
29        'traces/elapsed_and_real_timestamp/dump_SurfaceFlinger.pb'
30      );
31    });
32
33    it('has expected trace type', () => {
34      expect(parser.getTraceType()).toEqual(TraceType.SURFACE_FLINGER);
35    });
36
37    it('provides elapsed timestamp', () => {
38      const expected = [new Timestamp(TimestampType.ELAPSED, 0n)];
39      expect(parser.getTimestamps(TimestampType.ELAPSED)).toEqual(expected);
40    });
41
42    it('provides real timestamp (always zero)', () => {
43      const expected = [new Timestamp(TimestampType.REAL, 0n)];
44      expect(parser.getTimestamps(TimestampType.REAL)).toEqual(expected);
45    });
46
47    it('retrieves trace entry', async () => {
48      const entry = await parser.getEntry(0, TimestampType.ELAPSED);
49      expect(entry).toBeInstanceOf(LayerTraceEntry);
50      expect(BigInt(entry.timestamp.systemUptimeNanos.toString())).toEqual(0n);
51      expect(BigInt(entry.timestamp.unixNanos.toString())).toEqual(DUMP_REAL_TIME);
52    });
53  });
54
55  describe('trace with elapsed (only) timestamp', () => {
56    let parser: Parser<LayerTraceEntry>;
57
58    beforeAll(async () => {
59      parser = await UnitTestUtils.getParser('traces/elapsed_timestamp/dump_SurfaceFlinger.pb');
60    });
61
62    it('has expected trace type', () => {
63      expect(parser.getTraceType()).toEqual(TraceType.SURFACE_FLINGER);
64    });
65
66    it('provides elapsed timestamp (always zero)', () => {
67      const expected = [new Timestamp(TimestampType.ELAPSED, 0n)];
68      expect(parser.getTimestamps(TimestampType.ELAPSED)).toEqual(expected);
69    });
70
71    it("doesn't provide real timestamp", () => {
72      expect(parser.getTimestamps(TimestampType.REAL)).toEqual(undefined);
73    });
74  });
75});
76