1#!/usr/bin/env python3 2# Copyright (C) 2023 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 a 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 16from python.generators.diff_tests.testing import Path, DataPath, Metric 17from python.generators.diff_tests.testing import Csv, Json, TextProto 18from python.generators.diff_tests.testing import DiffTestBlueprint 19from python.generators.diff_tests.testing import TestSuite 20 21 22class PowerVoltageAndScaling(TestSuite): 23 24 def test_dvfs_metric(self): 25 return DiffTestBlueprint( 26 trace=Path('dvfs_metric.textproto'), 27 query=Metric('android_dvfs'), 28 out=Path('dvfs_metric.out')) 29 30 def test_wakesource_wakesource(self): 31 return DiffTestBlueprint( 32 trace=Path('wakesource.textproto'), 33 query=""" 34 SELECT ts, dur, slice.name 35 FROM slice 36 JOIN track ON slice.track_id = track.id 37 WHERE track.name GLOB 'Wakelock*' 38 ORDER BY ts; 39 """, 40 out=Csv(""" 41 "ts","dur","name" 42 34298714043271,7872467,"Wakelock(s2mpw02-power-keys)" 43 34298721846504,42732654,"Wakelock(event0)" 44 34298721915739,16,"Wakelock(s2mpw02-power-keys)" 45 34298764569658,14538,"Wakelock(eventpoll)" 46 """)) 47 48 def test_suspend_resume(self): 49 return DiffTestBlueprint( 50 trace=Path('suspend_resume.textproto'), 51 query=""" 52 SELECT 53 s.ts, 54 s.dur, 55 s.name AS action 56 FROM 57 slice AS s 58 JOIN 59 track AS t 60 ON s.track_id = t.id 61 WHERE 62 t.name = 'Suspend/Resume Latency' 63 ORDER BY s.ts; 64 """, 65 out=Csv(""" 66 "ts","dur","action" 67 10000,5000,"suspend_enter(3)" 68 15000,5000,"suspend_enter(3)" 69 30000,10000,"CPU(0)" 70 50000,10000,"timekeeping_freeze(0)" 71 """)) 72 73 def test_suspend_period(self): 74 return DiffTestBlueprint( 75 trace=Path('suspend_period.textproto'), 76 query=Metric('android_batt'), 77 out=TextProto(r""" 78 android_batt { 79 battery_aggregates { 80 sleep_ns: 20000 81 } 82 suspend_period { 83 timestamp_ns: 30000 84 duration_ns: 10000 85 } 86 suspend_period { 87 timestamp_ns: 50000 88 duration_ns: 10000 89 } 90 } 91 """)) 92