1#!/usr/bin/env python3
2#
3# Copyright 2019, The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18"""
19Unit tests for trace_analyzer module.
20
21Install:
22  $> sudo apt-get install python3-pytest   ##  OR
23  $> pip install -U pytest
24See also https://docs.pytest.org/en/latest/getting-started.html
25
26Usage:
27  $> pytest trace_analyzer_test.py
28
29See also https://docs.pytest.org/en/latest/usage.html
30"""
31
32# global imports
33import os
34import sys
35
36DIR = os.path.abspath(os.path.dirname(__file__))
37
38sys.path.append(os.path.dirname(DIR))
39import lib.cmd_utils as cmd_utils
40
41def test_trace_analyzer(tmpdir):
42  # Setup
43  bin = os.path.join(DIR, 'trace_analyzer')
44  systrace = os.path.join(DIR, 'test_fixtures/common_systrace')
45  db_file = tmpdir.mkdir('trace_analyzer').join('test.db')
46
47  # Act
48  passed, output = cmd_utils.execute_arbitrary_command([bin, systrace,
49                                                        str(db_file)],
50                                                       timeout=300,
51                                                       shell=False,
52                                                       simulate=False)
53
54  # Assert
55  assert passed
56  assert output == """\
57'blocked_iowait_duration_ms',\
58'process_name',\
59'launching_duration_ms',\
60'launching_started_timestamp_ms',\
61'launching_finished_timestamp_ms'
6281.697999999960302375,\
63'com.google.android.dialer',\
64594.99400000095192808,\
6514594219.85600000061,\
6614594814.85000000149"""
67