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 {Timestamp, TimestampType} from 'trace/timestamp'; 19import {TraceType} from 'trace/trace_type'; 20 21describe('ParserInputMethodService', () => { 22 describe('trace with elapsed + real timestamp', () => { 23 let parser: Parser<any>; 24 25 beforeAll(async () => { 26 parser = await UnitTestUtils.getParser( 27 'traces/elapsed_and_real_timestamp/InputMethodService.pb' 28 ); 29 }); 30 31 it('has expected trace type', () => { 32 expect(parser.getTraceType()).toEqual(TraceType.INPUT_METHOD_SERVICE); 33 }); 34 35 it('provides elapsed timestamps', () => { 36 const expected = [new Timestamp(TimestampType.ELAPSED, 16578752896n)]; 37 expect(parser.getTimestamps(TimestampType.ELAPSED)).toEqual(expected); 38 }); 39 40 it('provides real timestamps', () => { 41 const expected = [new Timestamp(TimestampType.REAL, 1659107091180519857n)]; 42 expect(parser.getTimestamps(TimestampType.REAL)).toEqual(expected); 43 }); 44 45 it('retrieves trace entry', async () => { 46 const entry = await parser.getEntry(0, TimestampType.REAL); 47 expect(BigInt(entry.elapsedRealtimeNanos)).toEqual(16578752896n); 48 }); 49 }); 50 51 describe('trace with elapsed (only) timestamp', () => { 52 let parser: Parser<any>; 53 54 beforeAll(async () => { 55 parser = await UnitTestUtils.getParser('traces/elapsed_timestamp/InputMethodService.pb'); 56 }); 57 58 it('has expected trace type', () => { 59 expect(parser.getTraceType()).toEqual(TraceType.INPUT_METHOD_SERVICE); 60 }); 61 62 it('provides elapsed timestamps', () => { 63 expect(parser.getTimestamps(TimestampType.ELAPSED)![0]).toEqual( 64 new Timestamp(TimestampType.ELAPSED, 1149230019887n) 65 ); 66 }); 67 68 it("doesn't provide real timestamps", () => { 69 expect(parser.getTimestamps(TimestampType.REAL)).toEqual(undefined); 70 }); 71 72 it('retrieves trace entry', async () => { 73 const entry = await parser.getEntry(0, TimestampType.ELAPSED); 74 expect(BigInt(entry.elapsedRealtimeNanos)).toEqual(1149230019887n); 75 }); 76 }); 77}); 78