• 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, BinaryProto
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20from google.protobuf import text_format
21
22
23class Timestamps(TestSuite):
24
25  def test_ns(self):
26    return DiffTestBlueprint(
27        trace=TextProto(""),
28        query="""
29        INCLUDE PERFETTO MODULE common.timestamps;
30        SELECT ns(4) as result;
31      """,
32        out=Csv("""
33        "result"
34        4
35      """))
36
37  def test_us(self):
38    return DiffTestBlueprint(
39        trace=TextProto(""),
40        query="""
41        INCLUDE PERFETTO MODULE common.timestamps;
42        SELECT us(4) as result;
43      """,
44        out=Csv("""
45        "result"
46        4000
47      """))
48
49  def test_ms(self):
50    return DiffTestBlueprint(
51        trace=TextProto(""),
52        query="""
53        INCLUDE PERFETTO MODULE common.timestamps;
54        SELECT ms(4) as result;
55      """,
56        out=Csv("""
57        "result"
58        4000000
59      """))
60
61  def test_seconds(self):
62    return DiffTestBlueprint(
63        trace=TextProto(""),
64        query="""
65        INCLUDE PERFETTO MODULE common.timestamps;
66        SELECT seconds(4) as result;
67      """,
68        out=Csv("""
69        "result"
70        4000000000
71      """))
72
73  def test_minutes(self):
74    return DiffTestBlueprint(
75        trace=TextProto(""),
76        query="""
77        INCLUDE PERFETTO MODULE common.timestamps;
78        SELECT minutes(1) as result;
79      """,
80        out=Csv("""
81        "result"
82        60000000000
83      """))
84
85  def test_hours(self):
86    return DiffTestBlueprint(
87        trace=TextProto(""),
88        query="""
89        INCLUDE PERFETTO MODULE common.timestamps;
90        SELECT hours(1) as result;
91      """,
92        out=Csv("""
93        "result"
94        3600000000000
95      """))
96
97  def test_days(self):
98    return DiffTestBlueprint(
99        trace=TextProto(""),
100        query="""
101        INCLUDE PERFETTO MODULE common.timestamps;
102        SELECT days(1) as result;
103      """,
104        out=Csv("""
105        "result"
106        86400000000000
107      """))
108