xref: /aosp_15_r20/development/tools/winscope/src/parsers/events/parser_eventlog_test.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1/*
2 * Copyright (C) 2023 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 */
16
17import {assertDefined} from 'common/assert_utils';
18import {PropertyTreeBuilder} from 'test/unit/property_tree_builder';
19import {TimestampConverterUtils} from 'test/unit/timestamp_converter_utils';
20import {UnitTestUtils} from 'test/unit/utils';
21import {CoarseVersion} from 'trace/coarse_version';
22import {Parser} from 'trace/parser';
23import {TraceType} from 'trace/trace_type';
24import {PropertyTreeNode} from 'trace/tree_node/property_tree_node';
25import {EventTag} from './event_tag';
26
27describe('ParserEventLog', () => {
28  describe('trace with monotonically increasing timestamps', () => {
29    let parser: Parser<PropertyTreeNode>;
30
31    beforeAll(async () => {
32      jasmine.addCustomEqualityTester(UnitTestUtils.timestampEqualityTester);
33      parser = assertDefined(
34        await UnitTestUtils.getParser('traces/eventlog.winscope'),
35      ) as Parser<PropertyTreeNode>;
36    });
37
38    it('has expected trace type', () => {
39      expect(parser.getTraceType()).toEqual(TraceType.EVENT_LOG);
40    });
41
42    it('has expected coarse version', () => {
43      expect(parser.getCoarseVersion()).toEqual(CoarseVersion.LEGACY);
44    });
45
46    it('has expected timestamps', () => {
47      const timestamps = assertDefined(parser.getTimestamps());
48
49      expect(timestamps.length).toEqual(184);
50
51      const expected = [
52        TimestampConverterUtils.makeRealTimestamp(1681207047981157174n),
53        TimestampConverterUtils.makeRealTimestamp(1681207047991161039n),
54        TimestampConverterUtils.makeRealTimestamp(1681207047991310494n),
55      ];
56      expect(timestamps.slice(0, 3)).toEqual(expected);
57    });
58
59    it('contains parsed jank CUJ events', async () => {
60      const entry = await parser.getEntry(18);
61
62      const expected = new PropertyTreeBuilder()
63        .setRootId('EventLogTrace')
64        .setName('event')
65        .setIsRoot(true)
66        .setChildren([
67          {name: 'eventTimestamp', value: 1681207048025596830n},
68          {name: 'pid', value: 2806},
69          {name: 'uid', value: 10227},
70          {name: 'tid', value: 3604},
71          {name: 'tag', value: EventTag.JANK_CUJ_BEGIN_TAG},
72          {
73            name: 'eventData',
74            value: '[66,1681207048025580000,2661012903966,2661012904007,]',
75          },
76        ])
77        .build();
78
79      expect(entry).toEqual(expected);
80    });
81  });
82
83  describe('trace with timestamps not monotonically increasing', () => {
84    let parser: Parser<PropertyTreeNode>;
85
86    beforeAll(async () => {
87      jasmine.addCustomEqualityTester(UnitTestUtils.timestampEqualityTester);
88      parser = assertDefined(
89        await UnitTestUtils.getParser(
90          'traces/eventlog_timestamps_not_monotonically_increasing.winscope',
91        ),
92      ) as Parser<PropertyTreeNode>;
93    });
94
95    it('sorts entries to make timestamps monotonically increasing', () => {
96      const timestamps = assertDefined(parser.getTimestamps());
97
98      expect(timestamps.length).toEqual(3);
99
100      const expected = [
101        TimestampConverterUtils.makeRealTimestamp(1681207047981157174n),
102        TimestampConverterUtils.makeRealTimestamp(1681207047991161039n),
103        TimestampConverterUtils.makeRealTimestamp(1681207047991310494n),
104      ];
105      expect(timestamps).toEqual(expected);
106    });
107
108    it('contains parsed events', async () => {
109      const entry = await parser.getEntry(0);
110
111      const expected = new PropertyTreeBuilder()
112        .setRootId('EventLogTrace')
113        .setName('event')
114        .setIsRoot(true)
115        .setChildren([
116          {name: 'eventTimestamp', value: 1681207047981157174n},
117          {name: 'pid', value: 1654},
118          {name: 'uid', value: 1000},
119          {name: 'tid', value: 1821},
120          {name: 'tag', value: 'input_interaction'},
121          {name: 'eventData', value: 'Interaction with'},
122        ])
123        .build();
124
125      expect(entry).toEqual(expected);
126    });
127  });
128});
129