1#!/usr/bin/env python3 2# Copyright (C) 2024 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 17from python.generators.diff_tests.testing import Csv, TextProto 18from python.generators.diff_tests.testing import DiffTestBlueprint 19from python.generators.diff_tests.testing import TestSuite 20 21 22class CpuClusters(TestSuite): 23 24 def test_android_cpu_cluster_type_one_core(self): 25 return DiffTestBlueprint( 26 trace=TextProto(r""" 27 packet { 28 cpu_info { 29 cpus { 30 processor: "unknown" 31 capacity: 1024 32 frequencies: 100000 33 frequencies: 200000 34 } 35 } 36 } 37 """), 38 query=""" 39 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 40 41 SELECT 42 ucpu, 43 cpu, 44 cluster_type 45 FROM 46 android_cpu_cluster_mapping; 47 """, 48 out=Csv(""" 49 "ucpu","cpu","cluster_type" 50 0,0,"[NULL]" 51 """)) 52 53 def test_android_cpu_cluster_type_two_core(self): 54 return DiffTestBlueprint( 55 trace=TextProto(r""" 56 packet { 57 cpu_info { 58 cpus { 59 processor: "unknown" 60 capacity: 158 61 frequencies: 100000 62 frequencies: 200000 63 } 64 cpus { 65 processor: "unknown" 66 capacity: 1024 67 frequencies: 500000 68 frequencies: 574000 69 } 70 } 71 } 72 """), 73 query=""" 74 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 75 76 SELECT 77 ucpu, 78 cpu, 79 cluster_type 80 FROM 81 android_cpu_cluster_mapping; 82 """, 83 out=Csv(""" 84 "ucpu","cpu","cluster_type" 85 0,0,"little" 86 1,1,"big" 87 """)) 88 89 def test_android_cpu_cluster_type_three_core(self): 90 return DiffTestBlueprint( 91 trace=TextProto(r""" 92 packet { 93 cpu_info { 94 cpus { 95 processor: "unknown" 96 capacity: 158 97 frequencies: 100000 98 frequencies: 200000 99 } 100 cpus { 101 processor: "unknown" 102 capacity: 550 103 frequencies: 300000 104 frequencies: 400000 105 } 106 cpus { 107 processor: "unknown" 108 capacity: 1024 109 frequencies: 500000 110 frequencies: 574000 111 } 112 } 113 } 114 """), 115 query=""" 116 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 117 118 SELECT 119 ucpu, 120 cpu, 121 cluster_type 122 FROM 123 android_cpu_cluster_mapping; 124 """, 125 out=Csv(""" 126 "ucpu","cpu","cluster_type" 127 0,0,"little" 128 1,1,"medium" 129 2,2,"big" 130 """)) 131 132 def test_android_cpu_cluster_type_four_core(self): 133 return DiffTestBlueprint( 134 trace=TextProto(r""" 135 packet { 136 cpu_info { 137 cpus { 138 processor: "unknown" 139 capacity: 158 140 frequencies: 100000 141 frequencies: 200000 142 } 143 cpus { 144 processor: "unknown" 145 capacity: 550 146 frequencies: 300000 147 frequencies: 400000 148 } 149 cpus { 150 processor: "unknown" 151 capacity: 700 152 frequencies: 400000 153 frequencies: 500000 154 } 155 cpus { 156 processor: "unknown" 157 capacity: 1024 158 frequencies: 500000 159 frequencies: 574000 160 } 161 } 162 } 163 """), 164 query=""" 165 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 166 167 SELECT 168 ucpu, 169 cpu, 170 cluster_type 171 FROM 172 android_cpu_cluster_mapping; 173 """, 174 out=Csv(""" 175 "ucpu","cpu","cluster_type" 176 0,0,"little" 177 1,1,"medium" 178 2,2,"medium" 179 3,3,"big" 180 """)) 181 182 def test_android_cpu_cluster_type_five_core(self): 183 return DiffTestBlueprint( 184 trace=TextProto(r""" 185 packet { 186 cpu_info { 187 cpus { 188 processor: "unknown" 189 capacity: 158 190 frequencies: 100000 191 frequencies: 200000 192 } 193 cpus { 194 processor: "unknown" 195 capacity: 550 196 frequencies: 300000 197 frequencies: 400000 198 } 199 cpus { 200 processor: "unknown" 201 capacity: 700 202 frequencies: 400000 203 frequencies: 500000 204 } 205 cpus { 206 processor: "unknown" 207 capacity: 800 208 frequencies: 500000 209 frequencies: 520000 210 } 211 cpus { 212 processor: "unknown" 213 capacity: 1024 214 frequencies: 500000 215 frequencies: 574000 216 } 217 } 218 } 219 """), 220 query=""" 221 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 222 223 SELECT 224 ucpu, 225 cpu, 226 cluster_type 227 FROM 228 android_cpu_cluster_mapping; 229 """, 230 out=Csv(""" 231 "ucpu","cpu","cluster_type" 232 0,0,"[NULL]" 233 1,1,"[NULL]" 234 2,2,"[NULL]" 235 3,3,"[NULL]" 236 4,4,"[NULL]" 237 """)) 238 239 def test_android_cpu_cluster_type_capacity_not_present(self): 240 return DiffTestBlueprint( 241 trace=TextProto(r""" 242 packet { 243 cpu_info { 244 cpus { 245 processor: "unknown" 246 frequencies: 100000 247 frequencies: 200000 248 } 249 cpus { 250 processor: "unknown" 251 frequencies: 300000 252 frequencies: 400000 253 } 254 cpus { 255 processor: "unknown" 256 frequencies: 500000 257 frequencies: 574000 258 } 259 } 260 } 261 """), 262 query=""" 263 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 264 265 SELECT 266 ucpu, 267 cpu, 268 cluster_type 269 FROM 270 android_cpu_cluster_mapping; 271 """, 272 out=Csv(""" 273 "ucpu","cpu","cluster_type" 274 0,0,"little" 275 1,1,"medium" 276 2,2,"big" 277 """)) 278 279 def test_android_cpu_cluster_type_insufficient_data_to_calculate(self): 280 return DiffTestBlueprint( 281 trace=TextProto(r""" 282 packet { 283 cpu_info { 284 cpus { 285 processor: "unknown" 286 frequencies: 10000 287 } 288 cpus { 289 processor: "unknown" 290 frequencies: 10000 291 } 292 cpus { 293 processor: "unknown" 294 frequencies: 10000 295 } 296 } 297 } 298 """), 299 query=""" 300 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 301 302 SELECT 303 ucpu, 304 cpu, 305 cluster_type 306 FROM 307 android_cpu_cluster_mapping; 308 """, 309 out=Csv(""" 310 "ucpu","cpu","cluster_type" 311 0,0,"[NULL]" 312 1,1,"[NULL]" 313 2,2,"[NULL]" 314 """)) 315 316 def test_android_cpu_cluster_type_no_frequencies(self): 317 return DiffTestBlueprint( 318 trace=TextProto(r""" 319 packet { 320 cpu_info { 321 cpus { 322 processor: "unknown" 323 } 324 cpus { 325 processor: "unknown" 326 } 327 cpus { 328 processor: "unknown" 329 } 330 } 331 } 332 """), 333 query=""" 334 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 335 336 SELECT 337 ucpu, 338 cpu, 339 cluster_type 340 FROM 341 android_cpu_cluster_mapping; 342 """, 343 out=Csv(""" 344 "ucpu","cpu","cluster_type" 345 0,0,"[NULL]" 346 1,1,"[NULL]" 347 2,2,"[NULL]" 348 """)) 349