xref: /aosp_15_r20/external/perfetto/test/trace_processor/diff_tests/parser/zip/tests.py (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 Csv, Path, DataPath
17from python.generators.diff_tests.testing import DiffTestBlueprint
18from python.generators.diff_tests.testing import TestSuite
19
20
21class Zip(TestSuite):
22
23  def test_perf_proto_sym(self):
24    return DiffTestBlueprint(
25        trace=DataPath('zip/perf_track_sym.zip'),
26        query=Path('../simpleperf/stacks_test.sql'),
27        out=Csv('''
28        "name"
29        "main,A"
30        "main,A,B"
31        "main,A,B,C"
32        "main,A,B,C,D"
33        "main,A,B,C,D,E"
34        "main,A,B,C,E"
35        "main,A,B,D"
36        "main,A,B,D,E"
37        "main,A,B,E"
38        "main,A,C"
39        "main,A,C,D"
40        "main,A,C,D,E"
41        "main,A,C,E"
42        "main,A,D"
43        "main,A,D,E"
44        "main,A,E"
45        "main,B"
46        "main,B,C"
47        "main,B,C,D"
48        "main,B,C,D,E"
49        "main,B,C,E"
50        "main,B,D"
51        "main,B,D,E"
52        "main,B,E"
53        "main,C"
54        "main,C,D"
55        "main,C,D,E"
56        "main,C,E"
57        "main,D"
58        "main,D,E"
59        "main,E"
60        '''))
61
62  def test_zip_tokenization_order(self):
63    return DiffTestBlueprint(
64        trace=DataPath('zip/perf_track_sym.zip'),
65        query='''
66        SELECT *
67        FROM __intrinsic_trace_file
68        ORDER BY processing_order
69        ''',
70        out=Csv('''
71        "id","type","parent_id","name","size","trace_type","processing_order"
72        0,"__intrinsic_trace_file","[NULL]","[NULL]",94651,"zip",0
73        3,"__intrinsic_trace_file",0,"c.trace.pb",379760,"proto",1
74        1,"__intrinsic_trace_file",0,"b.simpleperf.data",554911,"perf",2
75        2,"__intrinsic_trace_file",0,"a.symbols.pb",186149,"symbols",3
76        '''))
77
78  def test_tar_gz_tokenization_order(self):
79    return DiffTestBlueprint(
80        trace=DataPath('perf_track_sym.tar.gz'),
81        query='''
82        SELECT *
83        FROM __intrinsic_trace_file
84        ORDER BY processing_order
85        ''',
86        out=Csv('''
87        "id","type","parent_id","name","size","trace_type","processing_order"
88        0,"__intrinsic_trace_file","[NULL]","[NULL]",94091,"gzip",0
89        1,"__intrinsic_trace_file",0,"",1126400,"tar",1
90        4,"__intrinsic_trace_file",1,"/c.trace.pb",379760,"proto",2
91        3,"__intrinsic_trace_file",1,"/b.simpleperf.data",554911,"perf",3
92        2,"__intrinsic_trace_file",1,"/a.symbols.pb",186149,"symbols",4
93        '''))
94
95  # Make sure the logcat timestamps are correctly converted to trace ts. All
96  # logcat events in the trace were emitted while a perfetto trace collection
97  # was active. Thus their timestamps should be between the min and max ts of
98  # all track events.
99  # The device where the trace was collected had a timezone setting of UTC+1
100  def test_logcat_and_proto(self):
101    return DiffTestBlueprint(
102        trace=DataPath('zip/logcat_and_proto.zip'),
103        query='''
104        WITH
105          INTERVAL AS (
106            SELECT
107              (SELECT MIN(ts) FROM slice) AS min_ts,
108              (SELECT MAX(ts) FROM slice) AS max_ts
109          )
110        SELECT COUNT(*) AS count
111        FROM android_logs, INTERVAL
112        WHERE ts BETWEEN min_ts AND max_ts;
113        ''',
114        out=Csv('''
115        "count"
116        58
117        '''))
118