Skip to content

Commit b9ae51b

Browse files
committed
Add app scoping to the WebExperiment for Frametime
+ Test fixes + some other fixes ! IN PROGRESS
1 parent c83c11b commit b9ae51b

File tree

8 files changed

+40
-20
lines changed

8 files changed

+40
-20
lines changed

AndroidRunner/Device.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ def plug(self):
164164

165165
def current_activity(self):
166166
"""Newer Android 10 does not have mCurrentFocus and mFocusedApp. Different approach to get the current activity"""
167-
recent_activity = Adb.shell(self.id,'dumpsys activity recents | grep "Recent #0" | cut -d "=" -f2 | grep -o -p "[a-z|.]*"')
168-
167+
recent_activity = Adb.shell(self.id,'dumpsys activity recents | grep "Recent #0" | tr " }" "\n" | grep "=" | cut -d "=" -f 2 | sed -E "s/[^a-zA-Z.]+//g"')
168+
169+
"""Recent activities have both a type (home/standard/ect.) as well as a name e.g. com.android.chrome"""
169170
if recent_activity:
170-
result = recent_activity
171+
result = {"type": recent_activity.split("\n")[0], "name": recent_activity.split("\n")[1]}
171172
self.logger.debug('Current activity: %s' % result)
172173
return result
173174
else:

AndroidRunner/WebExperiment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(self, config, progress, restart):
1515
self.browsers = [BrowserFactory.get_browser(b)() for b in config.get('browsers', ['chrome'])]
1616
Tests.check_dependencies(self.devices, [b.package_name for b in self.browsers])
1717
self.duration = Tests.is_integer(config.get('duration', 0)) / 1000
18+
self.config = config
1819

1920
# Browsers have version specific formatting, allows re-creation if needed
2021
def regenerate_browsers(self, device):
@@ -27,7 +28,8 @@ def run(self, device, path, run, browser_name):
2728
if browser_name in browserItem.to_string():
2829
browser = browserItem
2930
kwargs = {
30-
'browser': browser
31+
'browser': browser,
32+
'app': browser.package_name
3133
}
3234
self.before_run(device, path, run, **kwargs)
3335
self.after_launch(device, path, run, **kwargs)
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
from AndroidRunner.Device import Device
2+
from AndroidRunner.Experiment import Experiment
3+
import logging
24

5+
LOGGER = logging.getLogger()
36

4-
# noinspection PyUnusedLocal
57
def main(device: Device, *args: tuple, **kwargs: dict):
6-
pass
8+
LOGGER.debug(args)
9+
LOGGER.debug(kwargs)
10+
11+
experiment: Experiment = args[0]
12+
current_run = experiment.get_experiment()
13+
14+
LOGGER.debug(device.current_activity())
15+
LOGGER.debug(current_run)
16+
17+
print(device.current_activity())
18+
print(current_run)

examples/android/config_web.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
"cpu",
2020
"mem"
2121
]
22+
},
23+
"Frametimes": {
24+
"subject_aggregation" : "default",
25+
"sample_interval": 1000
2226
}
2327
},
2428
"scripts": {

examples/performance/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "native",
33
"devices": {
4-
"nexus6p": {}
4+
"Pixel 6": {}
55
},
66
"repetitions": 2,
77
"apps": [

tests/unit/fixtures/FakeDevice.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
class FakeDevice(object):
33
def __init__(self, device_id):
44
self.id = device_id
5-
6-
def current_activity(self):
7-
return 'fake.activity'
5+
6+
@staticmethod
7+
def current_activity():
8+
return {"type": "standard", "name": 'fake.activity'}
89

910
def logcat_regex(self, regex):
1011
return regex

tests/unit/test_devices.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from AndroidRunner.Device import Device
88
from AndroidRunner.Devices import Devices
99
from AndroidRunner.util import ConfigError
10-
10+
from tests.unit.fixtures.FakeDevice import FakeDevice
1111

1212
class TestDevice(object):
1313

@@ -372,8 +372,8 @@ def test_su_plug(self, adb_shell_su, device_root):
372372

373373
@patch('AndroidRunner.Adb.shell')
374374
def test_current_activity_success(self, adb_shell, device):
375-
adb_shell.return_value = "com.android.chrome"
376-
assert device.current_activity() == "com.android.chrome"
375+
adb_shell.return_value = 'test\norg.activity'
376+
assert device.current_activity() == {'type': 'test', 'name': 'org.activity'}
377377

378378
@patch('AndroidRunner.Adb.shell')
379379
def test_current_activity_error(self, adb_shell, device):

tests/unit/test_experiment.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from AndroidRunner.util import ConfigError, makedirs
2222
from tests.PluginTests import PluginTests
2323
from AndroidRunner.PrematureStoppableRun import PrematureStoppableRun
24-
24+
from tests.unit.fixtures.FakeDevice import FakeDevice
2525

2626
# noinspection PyUnusedLocal
2727
class TestExperiment(object):
@@ -498,7 +498,7 @@ def test_after_launch(self, script_run, default_experiment):
498498
kwargs = {'arg1': 1, 'arg2': 2}
499499
mock_device = Mock()
500500
mock_device.id = 123
501-
current_activity = 'Working on theses'
501+
current_activity = FakeDevice.current_activity()
502502
mock_device.current_activity.return_value = current_activity
503503
path = 'test/path'
504504
run = 1234566789
@@ -549,7 +549,7 @@ def test_before_close(self, script_run, default_experiment):
549549
kwargs = {'arg1': 1, 'arg2': 2}
550550
mock_device = Mock()
551551
mock_device.id = 123
552-
current_activity = 'Working on theses'
552+
current_activity = FakeDevice.current_activity()
553553
mock_device.current_activity.return_value = current_activity
554554
path = 'test/path'
555555
run = 1234566789
@@ -1090,7 +1090,7 @@ def test_before_run(self, before_run, sleep, web_experiment):
10901090
kwargs = {'arg1': 1, 'arg2': 2, 'browser': mock_browser}
10911091
mock_device = Mock()
10921092
mock_device.id = 'id'
1093-
current_activity = "playing euro truck simulator 2"
1093+
current_activity = FakeDevice.current_activity()
10941094
mock_device.current_activity.return_value = current_activity
10951095
path = 'test/path'
10961096
run = 123456789
@@ -1136,7 +1136,7 @@ def test_after_run(self, after_run, sleep, web_experiment):
11361136
kwargs = {'arg1': 1, 'arg2': 2, 'browser': mock_browser}
11371137
mock_device = Mock()
11381138
mock_device.id = 'id'
1139-
current_activity = "playing euro truck simulator 2"
1139+
current_activity = FakeDevice.current_activity()
11401140
mock_device.current_activity.return_value = current_activity
11411141
path = 'test/path'
11421142
run = 123456789
@@ -1335,7 +1335,7 @@ def test_before_run(self, before_run, after_launch, native_experiment):
13351335
kwargs = {'arg1': 1, 'arg2': 2}
13361336
mock_device = Mock()
13371337
mock_device.id = 'id'
1338-
current_activity = "playing euro truck simulator 2"
1338+
current_activity = FakeDevice.current_activity()
13391339
mock_device.current_activity.return_value = current_activity
13401340
path = 'test/path'
13411341
run = 123456789
@@ -1377,7 +1377,7 @@ def test_after_run(self, after_run, native_experiment):
13771377
kwargs = {'arg1': 1, 'arg2': 2}
13781378
mock_device = Mock()
13791379
mock_device.id = 'id'
1380-
current_activity = "playing euro truck simulator 2"
1380+
current_activity = FakeDevice.current_activity()
13811381
mock_device.current_activity.return_value = current_activity
13821382
path = 'test/path'
13831383
run = 123456789

0 commit comments

Comments
 (0)