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 AndroidBugreport(TestSuite): 23 def test_android_bugreport_battery_stats(self): 24 return DiffTestBlueprint( 25 trace=DataPath('bugreport-crosshatch-SPB5.zip'), 26 query=""" 27 WITH first_100_events AS ( 28 SELECT ts, slice.name, dur 29 FROM slice 30 JOIN track on slice.track_id = track.id 31 WHERE track.name LIKE 'battery_stats.%' 32 ORDER BY 1, 2, 3 ASC 33 LIMIT 100 34 ), 35 first_100_states AS ( 36 SELECT ts, name, value 37 FROM counter 38 JOIN counter_track on counter.track_id = counter_track.id 39 WHERE name LIKE 'battery_stats.%' 40 ORDER BY 1, 2, 3 ASC 41 LIMIT 100 42 ) 43 SELECT * FROM first_100_events 44 UNION ALL 45 SELECT * FROM first_100_states; 46 """, 47 out=Path('android_bugreport_battery_stats_test.out')) 48 49 def test_android_bugreport_battery_stats_counts(self): 50 return DiffTestBlueprint( 51 trace=DataPath('bugreport-crosshatch-SPB5.zip'), 52 query=""" 53 WITH event_counts(type, count) AS ( VALUES 54 ('battery_stats_history_events', ( 55 SELECT 56 COUNT(1) 57 FROM slice 58 JOIN track 59 ON slice.track_id = track.id 60 WHERE 61 track.name LIKE 'battery_stats.%' 62 ) 63 ), 64 ('battery_stats_history_states', ( 65 SELECT 66 COUNT(1) 67 FROM counter 68 JOIN counter_track 69 ON counter.track_id = counter_track.id 70 WHERE 71 name LIKE 'battery_stats.%' 72 ) 73 ) 74 ) 75 SELECT * FROM event_counts 76 """, 77 out=Csv(""" 78 "type","count" 79 "battery_stats_history_events",4237 80 "battery_stats_history_states",12245 81 """)) 82 83 def test_android_bugreport_logs(self): 84 return DiffTestBlueprint( 85 trace=DataPath('bugreport-crosshatch-SPB5.zip'), 86 query=""" 87 WITH 88 initial AS (SELECT 89 (SELECT count(*) FROM android_logs) AS cnt, 90 ts, prio, tag, msg FROM android_logs 91 ORDER BY ts ASC 92 LIMIT 100 93 ), 94 latest AS (SELECT 95 (SELECT count(*) FROM android_logs) AS cnt, 96 ts, prio, tag, msg FROM android_logs 97 ORDER BY ts DESC 98 LIMIT 100 99 ) 100 SELECT * FROM initial UNION ALL SELECT * FROM latest; 101 """, 102 out=Path('android_bugreport_logs_test.out')) 103 104 def test_android_bugreport_dumpstate(self): 105 return DiffTestBlueprint( 106 trace=DataPath('bugreport-crosshatch-SPB5.zip'), 107 query=""" 108 SELECT section, service, count(line) AS linecount FROM android_dumpstate 109 GROUP BY section, service; 110 """, 111 out=Path('android_bugreport_dumpstate_test.out')) 112 113 def test_android_bugreport_dumpsys(self): 114 return DiffTestBlueprint( 115 trace=DataPath('bugreport-crosshatch-SPB5.zip'), 116 query=""" 117 SELECT section, service, line FROM android_dumpstate 118 WHERE service = 'color_display'; 119 """, 120 out=Path('android_bugreport_dumpsys_test.out')) 121 122 def test_android_bugreport_parse_order(self): 123 return DiffTestBlueprint( 124 trace=DataPath('bugreport-crosshatch-SPB5.zip'), 125 query=""" 126 SELECT id, parent_id, name, size, trace_type, processing_order 127 FROM __intrinsic_trace_file 128 WHERE trace_type <> "unknown" 129 ORDER BY processing_order 130 """, 131 out=Csv(""" 132 "id","parent_id","name","size","trace_type","processing_order" 133 0,"[NULL]","[NULL]",6220586,"zip",0 134 1,0,"bugreport-crosshatch-SPB5.210812.002-2021-08-24-23-35-40.txt",43132864,"android_dumpstate",1 135 16,0,"FS/data/misc/logd/logcat.01",2169697,"android_logcat",2 136 15,0,"FS/data/misc/logd/logcat",2152073,"android_logcat",3 137 """)) 138 139 def test_android_bugreport_trace_types(self): 140 return DiffTestBlueprint( 141 trace=DataPath('bugreport-crosshatch-SPB5.zip'), 142 query=""" 143 SELECT trace_type, count(*) AS cnt, sum(size) AS total_size 144 FROM __intrinsic_trace_file 145 GROUP BY trace_type 146 ORDER BY trace_type 147 """, 148 out=Csv(""" 149 "trace_type","cnt","total_size" 150 "android_dumpstate",1,43132864 151 "android_logcat",2,4321770 152 "unknown",2452,626115 153 "zip",1,6220586 154 """)) 155 156 def test_android_bugreport_trace_types(self): 157 return DiffTestBlueprint( 158 trace=DataPath('bugreport-crosshatch-SPB5.zip'), 159 query=""" 160 INCLUDE PERFETTO MODULE android.dumpsys.show_map; 161 SELECT * FROM android_dumpsys_show_map 162 ORDER BY rss_kb DESC 163 LIMIT 10; 164 """, 165 out=Csv(""" 166 "process_name","pid","vss_kb","rss_kb","pss_kb","shared_clean_kb","shared_dirty_kb","private_clean_kb","private_dirty_kb","swap_kb","swap_pss_kb","anon_huge_pages_kb","shmem_pmd_mapped_kb","file_pmd_mapped_kb","shared_huge_tlb_kb","private_hugetlb_kb","locked_kb","mapping_count","mapped_object" 167 "(system_server)",1835,1048576,28068,28068,0,0,0,28068,0,0,0,0,0,0,0,1,0,"space" 168 "(com.android.systemui)",2281,524288,8836,8836,0,0,0,8836,0,0,0,0,0,0,0,1,0,"space" 169 "(system_server)",1835,7180,7180,1469,0,5832,0,1348,0,0,0,0,0,0,0,1,0,"space]" 170 "(com.android.bluetooth)",2261,7180,7180,677,0,6644,0,536,0,0,0,0,0,0,0,1,0,"space]" 171 "(com.android.systemui)",2281,7180,7180,1133,0,6176,0,1004,0,0,0,0,0,0,0,1,0,"space]" 172 "(com.breel.wallpapers18)",2385,7180,7180,564,0,6760,0,420,0,0,0,0,0,0,0,1,0,"space]" 173 "(com.android.networkstack.process)",2407,7180,7180,762,0,6556,0,624,0,0,0,0,0,0,0,1,0,"space]" 174 "(.dataservices)",2436,7180,7180,614,0,6708,0,472,0,0,0,0,0,0,0,1,0,"space]" 175 "(com.qualcomm.qti.telephonyservice)",2502,7180,7180,553,0,6772,0,408,0,0,0,0,0,0,0,1,0,"space]" 176 "(com.google.android.grilservice)",2503,7180,7180,553,0,6772,0,408,0,0,0,0,0,0,0,1,0,"space]" 177 """)) 178