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 {assertDefined} from 'common/assert_utils'; 17import { 18 TimestampConverterUtils, 19 timestampEqualityTester, 20} from 'common/time/test_utils'; 21import {TraceBuilder} from 'test/unit/trace_builder'; 22import {UnitTestUtils} from 'test/unit/utils'; 23import {CoarseVersion} from 'trace/coarse_version'; 24import {CustomQueryType} from 'trace/custom_query'; 25import {Parser} from 'trace/parser'; 26import {TraceType} from 'trace/trace_type'; 27import {PropertyTreeNode} from 'trace/tree_node/property_tree_node'; 28 29describe('ParserTransactions', () => { 30 describe('trace with real timestamps', () => { 31 let parser: Parser<PropertyTreeNode>; 32 33 beforeAll(async () => { 34 jasmine.addCustomEqualityTester(timestampEqualityTester); 35 parser = (await UnitTestUtils.getParser( 36 'traces/elapsed_and_real_timestamp/Transactions.pb', 37 )) as Parser<PropertyTreeNode>; 38 }); 39 40 it('has expected trace type', () => { 41 expect(parser.getTraceType()).toEqual(TraceType.TRANSACTIONS); 42 }); 43 44 it('has expected coarse version', () => { 45 expect(parser.getCoarseVersion()).toEqual(CoarseVersion.LEGACY); 46 }); 47 48 it('provides timestamps', () => { 49 const timestamps = assertDefined(parser.getTimestamps()); 50 51 expect(timestamps.length).toEqual(712); 52 53 const expected = [ 54 TimestampConverterUtils.makeRealTimestamp(1659507541051480997n), 55 TimestampConverterUtils.makeRealTimestamp(1659507541118452067n), 56 TimestampConverterUtils.makeRealTimestamp(1659507542621651001n), 57 ]; 58 expect(timestamps.slice(0, 3)).toEqual(expected); 59 }); 60 61 it('retrieves trace entry from timestamp', async () => { 62 const entry = await parser.getEntry(1); 63 expect(entry.id).toEqual('TransactionsTraceEntry entry'); 64 }); 65 66 it("decodes 'what' field in proto", async () => { 67 { 68 const entry = await parser.getEntry(0); 69 const transactions = assertDefined( 70 entry.getChildByName('transactions'), 71 ); 72 73 expect( 74 transactions 75 .getChildByName('0') 76 ?.getChildByName('layerChanges') 77 ?.getChildByName('0') 78 ?.getChildByName('what') 79 ?.formattedValue(), 80 ).toEqual('eLayerChanged'); 81 82 expect( 83 transactions 84 .getChildByName('1') 85 ?.getChildByName('layerChanges') 86 ?.getChildByName('0') 87 ?.getChildByName('what') 88 ?.formattedValue(), 89 ).toEqual('eFlagsChanged | eDestinationFrameChanged'); 90 } 91 { 92 const entry = await parser.getEntry(222); 93 const transactions = assertDefined( 94 entry.getChildByName('transactions'), 95 ); 96 97 expect( 98 transactions 99 .getChildByName('1') 100 ?.getChildByName('displayChanges') 101 ?.getChildByName('0') 102 ?.getChildByName('what') 103 ?.formattedValue(), 104 ).toEqual( 105 'eLayerStackChanged | eDisplayProjectionChanged | eFlagsChanged', 106 ); 107 } 108 }); 109 110 it('supports VSYNCID custom query', async () => { 111 const trace = new TraceBuilder() 112 .setType(TraceType.TRANSACTIONS) 113 .setParser(parser) 114 .build(); 115 const entries = await trace 116 .sliceEntries(0, 3) 117 .customQuery(CustomQueryType.VSYNCID); 118 const values = entries.map((entry) => entry.getValue()); 119 expect(values).toEqual([1n, 2n, 3n]); 120 }); 121 }); 122 123 describe('trace with only elapsed timestamps', () => { 124 let parser: Parser<PropertyTreeNode>; 125 126 beforeAll(async () => { 127 parser = (await UnitTestUtils.getParser( 128 'traces/elapsed_timestamp/Transactions.pb', 129 )) as Parser<PropertyTreeNode>; 130 }); 131 132 it('has expected trace type', () => { 133 expect(parser.getTraceType()).toEqual(TraceType.TRANSACTIONS); 134 }); 135 136 it('provides timestamps', () => { 137 const timestamps = assertDefined(parser.getTimestamps()); 138 139 expect(timestamps.length).toEqual(4997); 140 141 const expected = [ 142 TimestampConverterUtils.makeElapsedTimestamp(14862317023n), 143 TimestampConverterUtils.makeElapsedTimestamp(14873423549n), 144 TimestampConverterUtils.makeElapsedTimestamp(14884850511n), 145 ]; 146 expect(timestamps.slice(0, 3)).toEqual(expected); 147 }); 148 }); 149}); 150