Skip to content

Commit

Permalink
Merge pull request #78 from odmnk/build_fixes
Browse files Browse the repository at this point in the history
Build fixes
  • Loading branch information
iivanoo authored May 31, 2021
2 parents b6c0344 + d3d3d4c commit 13ca4f2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ omit = */old tests*
*BatterystatsParser*
*/python3.6/*
*/pytest-*
*/venv/*
*/.venv/*

30 changes: 28 additions & 2 deletions tests/unit/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from AndroidRunner.Plugins.Profiler import ProfilerException
from AndroidRunner.Plugins.trepn.Trepn import Trepn
from AndroidRunner.Plugins.perfetto.Perfetto import Perfetto
import AndroidRunner.util as util

class TestPluginTemplate(object):
@pytest.fixture()
Expand Down Expand Up @@ -832,12 +833,23 @@ def test_init(self, load_json_mock, super_mock):
def test_dependencies(self, perfetto_plugin):
assert perfetto_plugin.dependencies() == []

def test_load(self, perfetto_plugin, mock_device):
def test_load(self, perfetto_plugin, mock_device, tmpdir):
config_file = tmpdir.mkdir("config_files").join("perfetto_config.pbtx")
config_file.write("Perfetto config file")
perfetto_plugin.perfetto_config_file_local_path = str(config_file)
perfetto_plugin.load(mock_device)

assert perfetto_plugin.perfetto_config_file_device_path == op.join(perfetto_plugin.PERFETTO_CONFIG_DEVICE_PATH, "perfetto_config.pbtx")
mock_device.push.assert_called_with(perfetto_plugin.perfetto_config_file_local_path, perfetto_plugin.perfetto_config_file_device_path)


def test_load_file_not_found(self, perfetto_plugin, mock_device):
perfetto_plugin.perfetto_config_file_local_path = "/home/user/no_file.pbtx"

with pytest.raises(util.ConfigError) as except_result:
perfetto_plugin.load(mock_device)

assert "Config file not found on host. Is /home/user/no_file.pbtx the correct path?" in str(except_result)

def test_set_output(self, perfetto_plugin, tmpdir):
test_output_dir = str(tmpdir)

Expand Down Expand Up @@ -881,6 +893,8 @@ def test_start_profiling_binary_config(self, datetime_mock, subprocess_mock, per
subprocess_mock.assert_called_with(["adb", "-s", mock_device.id, "shell", f"cat {perfetto_plugin.perfetto_config_file_device_path} | perfetto --background {empty_string} -c - -o {perfetto_plugin.perfetto_trace_file_device_path}"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)



@patch("AndroidRunner.Plugins.perfetto.Perfetto.subprocess.Popen")
def test_start_profiling_error(self, subprocess_mock, perfetto_plugin, mock_device):
perfetto_plugin.perfetto_config_file_format = "binary"
Expand All @@ -905,6 +919,18 @@ def test_start_profiling_error_no_pid(self, subprocess_mock, perfetto_plugin, mo
assert perfetto_plugin.perfetto_device_pid == "22"
mock_device.shell.assert_called_once_with("ps -A | grep perfetto | awk '{print $2}'")

@patch("AndroidRunner.Plugins.perfetto.Perfetto.subprocess.Popen")
def test_start_profiling_error_no_pid_ProfilerException(self, subprocess_mock, perfetto_plugin, mock_device):
perfetto_plugin.perfetto_config_file_format = "binary"
popen_mock = Mock()
popen_mock.communicate.return_value = (b"", b"")
mock_device.id = 20
mock_device.shell.return_value = "22 23 24"
subprocess_mock.return_value = popen_mock

with pytest.raises(ProfilerException):
perfetto_plugin.start_profiling(mock_device)

def test_stop_profiling(self, mock_device, perfetto_plugin):
perfetto_plugin.perfetto_device_pid = "42"
perfetto_plugin.stop_profiling(mock_device)
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def script_path(self, tmpdir):
temp_file = tmpdir.join("script.py")
temp_file.write('\n'.join(['from time import sleep',
'def main(device_id):\n',
' sleep(2.5)\n'
' sleep(0.5)\n'
' return "succes"']))
return str(temp_file)

Expand Down Expand Up @@ -259,7 +259,7 @@ def test_script_run_normal(self, script_path):

def test_script_run_timeout(self, script_path):
fake_device = Mock()
assert Python3(script_path, timeout=1).run(fake_device) == 'timeout'
assert Python3(script_path, timeout=10).run(fake_device) == 'timeout'

def test_script_run_logcat(self, script_path):
fake_device = Mock()
Expand Down Expand Up @@ -298,4 +298,3 @@ def test_mp_logcat_regex_one_iteration(self, sleep, script_path):

sleep.assert_called_once_with(1)
test_queue.put.assert_called_once_with("logcat")
assert 'script' in str(test_queue.put.call_args_list[1][0])

0 comments on commit 13ca4f2

Please sign in to comment.