• 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 {WindowManagerState} from 'trace/flickerlib/windows/WindowManagerState';
18import {Parser} from 'trace/parser';
19import {Timestamp, TimestampType} from 'trace/timestamp';
20import {TraceType} from 'trace/trace_type';
21
22describe('ParserWindowManager', () => {
23  describe('trace with elapsed + real timestamp', () => {
24    let parser: Parser<WindowManagerState>;
25
26    beforeAll(async () => {
27      parser = await UnitTestUtils.getParser('traces/elapsed_and_real_timestamp/WindowManager.pb');
28    });
29
30    it('has expected trace type', () => {
31      expect(parser.getTraceType()).toEqual(TraceType.WINDOW_MANAGER);
32    });
33
34    it('provides elapsed timestamps', () => {
35      const expected = [
36        new Timestamp(TimestampType.ELAPSED, 14474594000n),
37        new Timestamp(TimestampType.ELAPSED, 15398076788n),
38        new Timestamp(TimestampType.ELAPSED, 15409222011n),
39      ];
40      expect(parser.getTimestamps(TimestampType.ELAPSED)!.slice(0, 3)).toEqual(expected);
41    });
42
43    it('provides real timestamps', () => {
44      const expected = [
45        new Timestamp(TimestampType.REAL, 1659107089075566202n),
46        new Timestamp(TimestampType.REAL, 1659107089999048990n),
47        new Timestamp(TimestampType.REAL, 1659107090010194213n),
48      ];
49      expect(parser.getTimestamps(TimestampType.REAL)!.slice(0, 3)).toEqual(expected);
50    });
51
52    it('retrieves trace entry', async () => {
53      const entry = await parser.getEntry(1, TimestampType.REAL);
54      expect(entry).toBeInstanceOf(WindowManagerState);
55      expect(BigInt(entry.timestamp.elapsedNanos.toString())).toEqual(15398076788n);
56      expect(BigInt(entry.timestamp.unixNanos.toString())).toEqual(1659107089999048990n);
57    });
58
59    it('formats entry timestamps', async () => {
60      const entry = await parser.getEntry(1, TimestampType.REAL);
61      expect(entry.name).toEqual('2022-07-29T15:04:49.999048960');
62    });
63  });
64
65  describe('trace elapsed (only) timestamp', () => {
66    let parser: Parser<WindowManagerState>;
67
68    beforeAll(async () => {
69      parser = await UnitTestUtils.getParser('traces/elapsed_timestamp/WindowManager.pb');
70    });
71
72    it('has expected trace type', () => {
73      expect(parser.getTraceType()).toEqual(TraceType.WINDOW_MANAGER);
74    });
75
76    it('provides timestamps', () => {
77      const expected = [
78        new Timestamp(TimestampType.ELAPSED, 850254319343n),
79        new Timestamp(TimestampType.ELAPSED, 850763506110n),
80        new Timestamp(TimestampType.ELAPSED, 850782750048n),
81      ];
82      expect(parser.getTimestamps(TimestampType.ELAPSED)).toEqual(expected);
83    });
84
85    it('retrieves trace entry', async () => {
86      const entry = await parser.getEntry(0, TimestampType.ELAPSED);
87      expect(entry).toBeInstanceOf(WindowManagerState);
88      expect(BigInt(entry.timestamp.elapsedNanos.toString())).toEqual(850254319343n);
89    });
90
91    it('formats entry timestamps', async () => {
92      const entry = await parser.getEntry(0, TimestampType.ELAPSED);
93      expect(entry.name).toEqual('14m10s254ms319343ns');
94    });
95  });
96});
97