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 ChromeRailModes(TestSuite): 23 24 def test_combined_rail_modes(self): 25 return DiffTestBlueprint( 26 trace=Path('combined_rail_modes.py'), 27 query=""" 28 SELECT RUN_METRIC('chrome/rail_modes.sql'); 29 SELECT * FROM combined_overall_rail_slices; 30 """, 31 out=Csv(""" 32 "id","ts","dur","rail_mode" 33 1,0,10000,"response" 34 2,10000,25000,"animation" 35 3,35000,10000,"background" 36 """)) 37 38 def test_cpu_time_by_combined_rail_mode(self): 39 return DiffTestBlueprint( 40 trace=Path('cpu_time_by_combined_rail_mode.py'), 41 query=""" 42 SELECT RUN_METRIC('chrome/cpu_time_by_rail_mode.sql'); 43 SELECT * FROM cpu_time_by_rail_mode; 44 """, 45 out=Csv(""" 46 "id","ts","dur","rail_mode","cpu_dur" 47 1,0,10000,"response",26000 48 2,10000,20000,"animation",20000 49 3,30000,5000,"background",8000 50 4,35000,10000,"animation",21000 51 5,45000,10000,"background",1000 52 """)) 53 54 def test_actual_power_by_combined_rail_mode(self): 55 return DiffTestBlueprint( 56 trace=Path('actual_power_by_combined_rail_mode.py'), 57 query=""" 58 SELECT RUN_METRIC('chrome/actual_power_by_rail_mode.sql'); 59 SELECT * FROM real_power_by_rail_mode; 60 """, 61 out=Csv(""" 62 "id","ts","dur","rail_mode","subsystem","joules","drain_w" 63 1,0,10000000,"response","cellular",0.000000,0.000000 64 1,0,10000000,"response","cpu_little",0.000140,0.014000 65 2,10000000,20000000,"animation","cellular",0.000350,0.017500 66 2,10000000,20000000,"animation","cpu_little",0.000140,0.007000 67 3,30000000,5000000,"background","cellular",0.000018,0.003500 68 3,30000000,5000000,"background","cpu_little",0.000007,0.001400 69 4,35000000,10000000,"animation","cellular",0.000021,0.002100 70 4,35000000,10000000,"animation","cpu_little",0.000070,0.007000 71 5,45000000,10000000,"background","cellular",0.000003,0.000350 72 5,45000000,10000000,"background","cpu_little",0.000070,0.007000 73 """)) 74 75 def test_estimated_power_by_combined_rail_mode(self): 76 return DiffTestBlueprint( 77 trace=Path('estimated_power_by_combined_rail_mode.py'), 78 query=""" 79 SELECT RUN_METRIC('chrome/estimated_power_by_rail_mode.sql'); 80 SELECT * FROM power_by_rail_mode; 81 """, 82 out=Csv(""" 83 "id","ts","dur","rail_mode","mas","ma" 84 1,0,10000000,"response",0.554275,55.427500 85 2,10000000,20000000,"animation",0.284850,14.242500 86 3,30000000,5000000,"background",0.076233,15.246667 87 4,35000000,10000000,"animation",0.536850,53.685000 88 5,45000000,10000000,"background",0.071580,7.158000 89 """)) 90 91 def test_modified_rail_modes(self): 92 return DiffTestBlueprint( 93 trace=Path('modified_rail_modes.py'), 94 query=""" 95 SELECT RUN_METRIC('chrome/rail_modes.sql'); 96 SELECT * FROM modified_rail_slices; 97 """, 98 out=Csv(""" 99 "id","ts","dur","mode" 100 2,0,1000000000,"response" 101 3,1000000000,1950000000,"foreground_idle" 102 4,2950000000,333333324,"animation" 103 5,3283333324,216666676,"foreground_idle" 104 6,3500000000,1000000000,"background" 105 """)) 106 107 def test_modified_rail_modes_no_vsyncs(self): 108 return DiffTestBlueprint( 109 trace=Path('modified_rail_modes_no_vsyncs.py'), 110 query=""" 111 SELECT RUN_METRIC('chrome/rail_modes.sql'); 112 SELECT * FROM modified_rail_slices; 113 """, 114 out=Csv(""" 115 "id","ts","dur","mode" 116 2,0,1000000000,"response" 117 3,1000000000,2500000000,"foreground_idle" 118 4,3500000000,1000000000,"background" 119 """)) 120 121 def test_modified_rail_modes_with_input(self): 122 return DiffTestBlueprint( 123 trace=Path('modified_rail_modes_with_input.py'), 124 query=""" 125 SELECT RUN_METRIC('chrome/rail_modes.sql'); 126 SELECT * FROM modified_rail_slices; 127 """, 128 out=Csv(""" 129 "id","ts","dur","mode" 130 2,0,1000000000,"response" 131 3,1000000000,1950000000,"foreground_idle" 132 4,2950000000,50000000,"animation" 133 5,3000000000,66666674,"response" 134 6,3066666674,216666650,"animation" 135 7,3283333324,216666676,"foreground_idle" 136 8,3500000000,1000000000,"background" 137 """)) 138 139 def test_modified_rail_modes_long(self): 140 return DiffTestBlueprint( 141 trace=Path('modified_rail_modes_long.py'), 142 query=""" 143 SELECT RUN_METRIC('chrome/rail_modes.sql'); 144 SELECT * FROM modified_rail_slices; 145 """, 146 out=Csv(""" 147 "id","ts","dur","mode" 148 2,0,1000000000,"response" 149 3,1000000000,1,"background" 150 """)) 151 152 def test_modified_rail_modes_extra_long(self): 153 return DiffTestBlueprint( 154 trace=Path('modified_rail_modes_extra_long.py'), 155 query=""" 156 SELECT RUN_METRIC('chrome/rail_modes.sql'); 157 SELECT * FROM modified_rail_slices; 158 """, 159 out=Csv(""" 160 "id","ts","dur","mode" 161 """)) 162