1// Copyright (C) 2024 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {FullTraceMetricData} from './metricUtils'; 16import {pinFullTraceJankInstance} from './fullTraceJankMetricHandler'; 17 18const validMetricsTest: { 19 inputMetric: string; 20 expectedOutput: FullTraceMetricData; 21}[] = [ 22 { 23 inputMetric: 'perfetto_ft_launcher-missed_app_frames-mean', 24 expectedOutput: { 25 process: 'com.google.android.apps.nexuslauncher', 26 jankType: 'app_frames', 27 }, 28 }, 29 { 30 inputMetric: 'perfetto_ft_systemui-missed_sf_frames-mean', 31 expectedOutput: { 32 process: 'com.android.systemui', 33 jankType: 'sf_frames', 34 }, 35 }, 36 { 37 inputMetric: 'perfetto_ft_systemui-missed_app_frames-mean', 38 expectedOutput: { 39 process: 'com.android.systemui', 40 jankType: 'app_frames', 41 }, 42 }, 43]; 44 45const invalidMetricsTest: string[] = [ 46 'perfetto_cuj_launcher-RECENTS_SCROLLING-counter_metrics-missed_sf_frames-mean', 47 'perfetto_android_blocking_call-cuj-name-com.google.android.apps.nexuslauncher-name-TASKBAR_EXPAND-blocking_calls-name-animation-total_dur_ms-mean', 48]; 49 50const tester = pinFullTraceJankInstance; 51 52describe('testMetricParser_match', () => { 53 it('parses metrics and returns expected data', () => { 54 for (const testCase of validMetricsTest) { 55 const parsedData = tester.match(testCase.inputMetric); 56 // without this explicit check, undefined also passes the test 57 expect(parsedData).toBeDefined(); 58 if (parsedData) { 59 expect(parsedData).toEqual(testCase.expectedOutput); 60 } 61 } 62 }); 63 it('parses metrics and returns undefined', () => { 64 for (const testCase of invalidMetricsTest) { 65 const parsedData = tester.match(testCase); 66 67 expect(parsedData).toBeUndefined(); 68 } 69 }); 70}); 71