summaryrefslogtreecommitdiff
path: root/startop/scripts/trace_analyzer/trace_analyzer_test.py
blob: 579529c6f6d5492df35fb443675d32daa6a94757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
#
# Copyright 2019, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""
Unit tests for trace_analyzer module.

Install:
  $> sudo apt-get install python3-pytest   ##  OR
  $> pip install -U pytest
See also https://docs.pytest.org/en/latest/getting-started.html

Usage:
  $> pytest trace_analyzer_test.py

See also https://docs.pytest.org/en/latest/usage.html
"""

# global imports
import os
import sys

DIR = os.path.abspath(os.path.dirname(__file__))

sys.path.append(os.path.dirname(DIR))
import lib.cmd_utils as cmd_utils

def test_trace_analyzer(tmpdir):
  # Setup
  bin = os.path.join(DIR, 'trace_analyzer')
  systrace = os.path.join(DIR, 'test_fixtures/common_systrace')
  db_file = tmpdir.mkdir('trace_analyzer').join('test.db')

  # Act
  passed, output = cmd_utils.execute_arbitrary_command([bin, systrace,
                                                        str(db_file)],
                                                       timeout=300,
                                                       shell=False,
                                                       simulate=False)

  # Assert
  assert passed
  assert output == """\
'blocked_iowait_duration_ms',\
'process_name',\
'launching_duration_ms',\
'launching_started_timestamp_ms',\
'launching_finished_timestamp_ms'
81.697999999960302375,\
'com.google.android.dialer',\
594.99400000095192808,\
14594219.85600000061,\
14594814.85000000149"""