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