• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2020 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 at
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
16import os
17import unittest
18
19from trace_processor.api import TraceProcessor
20
21
22class TestApi(unittest.TestCase):
23
24  def test_trace_file(self):
25    # Get path to trace_processor_shell and construct TraceProcessor
26    tp = TraceProcessor(
27        file_path=os.path.join(os.environ["ROOT_DIR"], 'test', 'data',
28                               'example_android_trace_30s.pb'),
29        bin_path=os.environ["SHELL_PATH"])
30    qr_iterator = tp.query('select * from slice limit 10')
31    dur_result = [
32        178646, 119740, 58073, 155000, 173177, 20209377, 3589167, 90104, 275312,
33        65313
34    ]
35
36    for num, row in enumerate(qr_iterator):
37      self.assertEqual(row.type, 'internal_slice')
38      self.assertEqual(row.dur, dur_result[num])
39
40    # Test the batching logic by issuing a large query and ensuring we receive
41    # all rows, not just a truncated subset.
42    qr_iterator = tp.query('select count(*) as cnt from slice')
43    expected_count = next(qr_iterator).cnt
44    self.assertGreater(expected_count, 0)
45
46    qr_iterator = tp.query('select * from slice')
47    count = sum(1 for _ in qr_iterator)
48    self.assertEqual(count, expected_count)
49
50    tp.close()
51