1/* 2 * Copyright (C) 2024 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 {TraceBuilder} from 'test/unit/trace_builder'; 23import {UserNotifierChecker} from 'test/unit/user_notifier_checker'; 24import {UnitTestUtils} from 'test/unit/utils'; 25import {CoarseVersion} from 'trace/coarse_version'; 26import {CustomQueryType} from 'trace/custom_query'; 27import {Parser} from 'trace/parser'; 28import {TraceType} from 'trace/trace_type'; 29import {PropertyTreeNode} from 'trace/tree_node/property_tree_node'; 30 31describe('TracesParserInput', () => { 32 let parser: Parser<PropertyTreeNode>; 33 let userNotifierChecker: UserNotifierChecker; 34 35 beforeAll(() => { 36 userNotifierChecker = new UserNotifierChecker(); 37 }); 38 39 beforeEach(async () => { 40 jasmine.addCustomEqualityTester(timestampEqualityTester); 41 parser = (await UnitTestUtils.getTracesParser([ 42 'traces/perfetto/input-events.perfetto-trace', 43 ])) as Parser<PropertyTreeNode>; 44 userNotifierChecker.reset(); 45 }); 46 47 it('has expected trace type', () => { 48 expect(parser.getTraceType()).toEqual(TraceType.INPUT_EVENT_MERGED); 49 }); 50 51 it('has expected coarse version', () => { 52 expect(parser.getCoarseVersion()).toEqual(CoarseVersion.LATEST); 53 }); 54 55 it('has expected descriptors', () => { 56 expect(parser.getDescriptors()).toEqual(['input-events.perfetto-trace']); 57 }); 58 59 it('provides timestamps', () => { 60 const timestamps = assertDefined(parser.getTimestamps()); 61 const expected = [ 62 TimestampConverterUtils.makeRealTimestamp(1718386903800330430n), 63 TimestampConverterUtils.makeRealTimestamp(1718386903800330430n), 64 TimestampConverterUtils.makeRealTimestamp(1718386903821511338n), 65 TimestampConverterUtils.makeRealTimestamp(1718386903827304592n), 66 TimestampConverterUtils.makeRealTimestamp(1718386903836681382n), 67 TimestampConverterUtils.makeRealTimestamp(1718386903841727281n), 68 TimestampConverterUtils.makeRealTimestamp(1718386905115026232n), 69 TimestampConverterUtils.makeRealTimestamp(1718386905123057319n), 70 ]; 71 expect(timestamps).toEqual(expected); 72 }); 73 74 it('provides correct entries from individual event traces', async () => { 75 const keyEntry = await parser.getEntry(6); 76 const keyEvent = assertDefined(keyEntry.getChildByName('keyEvent')); 77 expect(keyEvent?.getChildByName('eventId')?.getValue()).toEqual(759309047); 78 79 const motionEntry = await parser.getEntry(0); 80 const motionEvent = assertDefined( 81 motionEntry.getChildByName('motionEvent'), 82 ); 83 expect(motionEvent?.getChildByName('eventId')?.getValue()).toEqual( 84 330184796, 85 ); 86 }); 87 88 it('supports VSYNCID custom query', async () => { 89 const trace = new TraceBuilder() 90 .setType(TraceType.INPUT_EVENT_MERGED) 91 .setParser(parser) 92 .build(); 93 const entries = await trace 94 .sliceEntries(4, 7) 95 .customQuery(CustomQueryType.VSYNCID); 96 const values = entries.map((entry) => entry.getValue()); 97 expect(values).toEqual([89113n, 89113n, 89114n]); 98 userNotifierChecker.expectNone(); 99 }); 100 101 it('supports VSYNCID custom query with missing vsync_ids', async () => { 102 const missingVsyncIdsParser = (await UnitTestUtils.getTracesParser([ 103 'traces/perfetto/input-missing-vsync-ids.perfetto-trace', 104 ])) as Parser<PropertyTreeNode>; 105 const trace = new TraceBuilder() 106 .setType(TraceType.INPUT_EVENT_MERGED) 107 .setParser(missingVsyncIdsParser) 108 .build(); 109 const entries = await trace.customQuery(CustomQueryType.VSYNCID); 110 expect(entries).toHaveSize(missingVsyncIdsParser.getLengthEntries()); 111 }); 112}); 113