• 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 {Parser} from 'trace/parser';
18import {LogMessage} from 'trace/protolog';
19import {Timestamp, TimestampType} from 'trace/timestamp';
20import {TraceType} from 'trace/trace_type';
21
22describe('ParserProtoLog', () => {
23  let parser: Parser<LogMessage>;
24
25  const expectedFirstLogMessageElapsed = {
26    text: 'InsetsSource updateVisibility for ITYPE_IME, serverVisible: false clientVisible: false',
27    time: '14m10s746ms266486ns',
28    tag: 'WindowManager',
29    level: 'DEBUG',
30    at: 'com/android/server/wm/InsetsSourceProvider.java',
31    timestamp: 850746266486n,
32  };
33
34  const expectedFirstLogMessageReal = {
35    text: 'InsetsSource updateVisibility for ITYPE_IME, serverVisible: false clientVisible: false',
36    time: '2022-06-20T12:12:05.377266486',
37    tag: 'WindowManager',
38    level: 'DEBUG',
39    at: 'com/android/server/wm/InsetsSourceProvider.java',
40    timestamp: 1655727125377266486n,
41  };
42
43  beforeAll(async () => {
44    parser = (await UnitTestUtils.getParser(
45      'traces/elapsed_and_real_timestamp/ProtoLog.pb'
46    )) as Parser<LogMessage>;
47  });
48
49  it('has expected trace type', () => {
50    expect(parser.getTraceType()).toEqual(TraceType.PROTO_LOG);
51  });
52
53  it('has expected length', () => {
54    expect(parser.getLengthEntries()).toEqual(50);
55  });
56
57  it('provides elapsed timestamps', () => {
58    const timestamps = parser.getTimestamps(TimestampType.ELAPSED)!;
59    expect(timestamps.length).toEqual(50);
60
61    const expected = [
62      new Timestamp(TimestampType.ELAPSED, 850746266486n),
63      new Timestamp(TimestampType.ELAPSED, 850746336718n),
64      new Timestamp(TimestampType.ELAPSED, 850746350430n),
65    ];
66    expect(timestamps.slice(0, 3)).toEqual(expected);
67  });
68
69  it('provides real timestamps', () => {
70    const timestamps = parser.getTimestamps(TimestampType.REAL)!;
71    expect(timestamps.length).toEqual(50);
72
73    const expected = [
74      new Timestamp(TimestampType.REAL, 1655727125377266486n),
75      new Timestamp(TimestampType.REAL, 1655727125377336718n),
76      new Timestamp(TimestampType.REAL, 1655727125377350430n),
77    ];
78    expect(timestamps.slice(0, 3)).toEqual(expected);
79  });
80
81  it('reconstructs human-readable log message (ELAPSED time)', async () => {
82    const message = await parser.getEntry(0, TimestampType.ELAPSED);
83
84    expect(Object.assign({}, message)).toEqual(expectedFirstLogMessageElapsed);
85    expect(message).toBeInstanceOf(LogMessage);
86  });
87
88  it('reconstructs human-readable log message (REAL time)', async () => {
89    const message = await parser.getEntry(0, TimestampType.REAL);
90
91    expect(Object.assign({}, message)).toEqual(expectedFirstLogMessageReal);
92  });
93});
94