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 {CujScopedMetricData} from './metricUtils'; 16import {pinCujScopedJankInstance} from './pinCujScoped'; 17 18const validMetricsTest: { 19 inputMetric: string; 20 expectedOutput: CujScopedMetricData; 21}[] = [ 22 { 23 inputMetric: 24 'perfetto_cuj_systemui-NOTIFICATION_SHADE_EXPAND_COLLAPSE::Expand-timeline_metrics-missed_app_frames-mean', 25 expectedOutput: { 26 process: 'com.android.systemui', 27 cujName: 'NOTIFICATION_SHADE_EXPAND_COLLAPSE::Expand', 28 jankType: 'app_frames', 29 }, 30 }, 31 { 32 inputMetric: 33 'perfetto_cuj_systemui-SHADE_DIALOG_OPEN::internet-timeline_metrics-missed_sf_frames-mean', 34 expectedOutput: { 35 process: 'com.android.systemui', 36 cujName: 'SHADE_DIALOG_OPEN::internet', 37 jankType: 'sf_frames', 38 }, 39 }, 40 { 41 inputMetric: 42 'perfetto_cuj_launcher-RECENTS_SCROLLING-counter_metrics-missed_sf_frames-mean', 43 expectedOutput: { 44 process: 'com.google.android.apps.nexuslauncher', 45 cujName: 'RECENTS_SCROLLING', 46 jankType: 'sf_frames', 47 }, 48 }, 49]; 50 51const invalidMetricsTest: string[] = [ 52 'perfetto_ft_launcher-missed_sf_frames-mean', 53 'perfetto_android_blocking_call-cuj-name-com.google.android.apps.nexuslauncher-name-TASKBAR_EXPAND-blocking_calls-name-animation-total_dur_ms-mean', 54]; 55 56const tester = pinCujScopedJankInstance; 57 58describe('testMetricParser_match', () => { 59 it('parses metrics and returns expected data', () => { 60 for (const testCase of validMetricsTest) { 61 const parsedData = tester.match(testCase.inputMetric); 62 // without this explicit check, undefined also passes the test 63 expect(parsedData).toBeDefined(); 64 if (parsedData) { 65 expect(parsedData).toEqual(testCase.expectedOutput); 66 } 67 } 68 }); 69 it('parses metrics and returns undefined', () => { 70 for (const testCase of invalidMetricsTest) { 71 const parsedData = tester.match(testCase); 72 73 expect(parsedData).toBeUndefined(); 74 } 75 }); 76}); 77