• 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 Csv, Json
17from python.generators.diff_tests.testing import DiffTestBlueprint
18from python.generators.diff_tests.testing import TestSuite
19
20
21class JsonTests(TestSuite):
22
23  def test_string_pid_tid(self):
24    return DiffTestBlueprint(
25        trace=Json('''
26          {
27            "traceEvents": [{
28              "pid": "foo",
29              "tid": "bar",
30              "ts": 5.1,
31              "dur": 500.1,
32              "name": "name.exec",
33              "ph": "XXX",
34              "cat": "aaa"
35            }]
36          }
37        '''),
38        query="""
39          SELECT
40            slice.ts,
41            slice.dur,
42            slice.name,
43            process.name as process_name,
44            thread.name as thread_name
45          FROM slice
46          LEFT JOIN thread_track ON slice.track_id = thread_track.id
47          LEFT JOIN thread USING (utid)
48          LEFT JOIN process USING (upid)
49        """,
50        out=Csv("""
51          "ts","dur","name","process_name","thread_name"
52          5100,500100,"name.exec","foo","bar"
53        """))
54