• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 StdlibCommon(TestSuite):
23
24  def test_thread_state_summary(self):
25    return DiffTestBlueprint(
26        trace=Path('../../common/synth_1.py'),
27        query="""
28        INCLUDE PERFETTO MODULE deprecated.v42.common.thread_states;
29
30        SELECT
31          state,
32          cpu,
33          dur
34        FROM thread_state_summary_for_interval(
35          25,
36          75,
37          (
38            SELECT utid
39            FROM thread
40            WHERE name = 'init'
41          )
42        )
43        """,
44        out=Csv("""
45        "state","cpu","dur"
46        "Running",1,50
47        "Runnable","[NULL]",25
48        """))
49
50  def test_spans_overlapping_dur_intersect_edge(self):
51    return DiffTestBlueprint(
52        trace=TextProto(r"""
53
54        """),
55        query="""
56        INCLUDE PERFETTO MODULE common.timestamps;
57        SELECT SPANS_OVERLAPPING_DUR(0, 2, 1, 2) AS dur
58        """,
59        out=Csv("""
60        "dur"
61        1
62        """))
63
64  def test_spans_overlapping_dur_intersect_edge_reversed(self):
65    return DiffTestBlueprint(
66        trace=TextProto(r"""
67
68        """),
69        query="""
70        INCLUDE PERFETTO MODULE common.timestamps;
71        SELECT SPANS_OVERLAPPING_DUR(1, 2, 0, 2) AS dur
72        """,
73        out=Csv("""
74        "dur"
75        1
76        """))
77
78  def test_spans_overlapping_dur_intersect_all(self):
79    return DiffTestBlueprint(
80        trace=TextProto(r"""
81
82        """),
83        query="""
84        INCLUDE PERFETTO MODULE common.timestamps;
85        SELECT SPANS_OVERLAPPING_DUR(0, 3, 1, 1) AS dur
86        """,
87        out=Csv("""
88        "dur"
89        1
90        """))
91
92  def test_spans_overlapping_dur_intersect_all_reversed(self):
93    return DiffTestBlueprint(
94        trace=TextProto(r"""
95
96        """),
97        query="""
98        INCLUDE PERFETTO MODULE common.timestamps;
99        SELECT SPANS_OVERLAPPING_DUR(1, 1, 0, 3) AS dur
100        """,
101        out=Csv("""
102        "dur"
103        1
104        """))
105
106  def test_spans_overlapping_dur_no_intersect(self):
107    return DiffTestBlueprint(
108        trace=TextProto(r"""
109
110        """),
111        query="""
112        INCLUDE PERFETTO MODULE common.timestamps;
113        SELECT SPANS_OVERLAPPING_DUR(0, 1, 2, 1) AS dur
114        """,
115        out=Csv("""
116        "dur"
117        0
118        """))
119
120  def test_spans_overlapping_dur_no_intersect_reversed(self):
121    return DiffTestBlueprint(
122        trace=TextProto(r"""
123
124        """),
125        query="""
126        INCLUDE PERFETTO MODULE common.timestamps;
127        SELECT SPANS_OVERLAPPING_DUR(2, 1, 0, 1) AS dur
128        """,
129        out=Csv("""
130        "dur"
131        0
132        """))
133
134  def test_spans_overlapping_dur_negative_dur(self):
135    return DiffTestBlueprint(
136        trace=TextProto(r"""
137
138        """),
139        query="""
140        INCLUDE PERFETTO MODULE common.timestamps;
141        SELECT SPANS_OVERLAPPING_DUR(0, -1, 0, 1) AS dur
142        """,
143        out=Csv("""
144        "dur"
145        0
146        """))
147
148  def test_spans_overlapping_dur_negative_dur_reversed(self):
149    return DiffTestBlueprint(
150        trace=TextProto(r"""
151
152        """),
153        query="""
154        INCLUDE PERFETTO MODULE common.timestamps;
155        SELECT SPANS_OVERLAPPING_DUR(0, 1, 0, -1) AS dur
156        """,
157        out=Csv("""
158        "dur"
159        0
160        """))
161