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 PerfettoInclude(TestSuite): 23 24 def test_import(self): 25 return DiffTestBlueprint( 26 trace=TextProto(r""" 27 packet { 28 ftrace_events { 29 cpu: 1 30 event { 31 timestamp: 1000 32 pid: 1 33 print { 34 buf: "C|1000|battery_stats.data_conn|13\n" 35 } 36 } 37 event { 38 timestamp: 4000 39 pid: 1 40 print { 41 buf: "C|1000|battery_stats.data_conn|20\n" 42 } 43 } 44 event { 45 timestamp: 1000 46 pid: 1 47 print { 48 buf: "C|1000|battery_stats.audio|1\n" 49 } 50 } 51 } 52 } 53 """), 54 query=""" 55 SELECT IMPORT('common.timestamps'); 56 57 SELECT TRACE_START(); 58 """, 59 out=Csv(""" 60 "TRACE_START()" 61 1000 62 """)) 63 64 def test_include_perfetto_module(self): 65 return DiffTestBlueprint( 66 trace=TextProto(r""" 67 packet { 68 ftrace_events { 69 cpu: 1 70 event { 71 timestamp: 1000 72 pid: 1 73 print { 74 buf: "C|1000|battery_stats.data_conn|13\n" 75 } 76 } 77 event { 78 timestamp: 4000 79 pid: 1 80 print { 81 buf: "C|1000|battery_stats.data_conn|20\n" 82 } 83 } 84 event { 85 timestamp: 1000 86 pid: 1 87 print { 88 buf: "C|1000|battery_stats.audio|1\n" 89 } 90 } 91 } 92 } 93 """), 94 query=""" 95 INCLUDE PERFETTO MODULE common.timestamps; 96 97 SELECT TRACE_START(); 98 """, 99 out=Csv(""" 100 "TRACE_START()" 101 1000 102 """)) 103 104 def test_include_and_import(self): 105 return DiffTestBlueprint( 106 trace=TextProto(r""" 107 packet { 108 ftrace_events { 109 cpu: 1 110 event { 111 timestamp: 1000 112 pid: 1 113 print { 114 buf: "C|1000|battery_stats.data_conn|13\n" 115 } 116 } 117 event { 118 timestamp: 4000 119 pid: 1 120 print { 121 buf: "C|1000|battery_stats.data_conn|20\n" 122 } 123 } 124 event { 125 timestamp: 1000 126 pid: 1 127 print { 128 buf: "C|1000|battery_stats.audio|1\n" 129 } 130 } 131 } 132 } 133 """), 134 query=""" 135 SELECT IMPORT('common.timestamps'); 136 INCLUDE PERFETTO MODULE common.timestamps; 137 138 SELECT TRACE_START(); 139 """, 140 out=Csv(""" 141 "TRACE_START()" 142 1000 143 """)) 144