-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconsole.py
65 lines (49 loc) · 2.24 KB
/
console.py
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
from __future__ import absolute_import
import click
import sys
from probe.android.adb import adb
from probe.probe import Probe
from probe.helpers.logger import logger, setup_logging
from probe.tricorder import Tricorder
from probe.measurers.probe import *
from probe.measurers.collector import *
# from time import sleep
__author__ = 'rotem'
@click.command()
@click.option('--package', default='', help='Package name to run Probe on')
@click.option('--activity', default='=', help='Activity to restart within that package')
@click.option('--apk-path', default=None, help='Path to installed APK')
@click.option('--repeat-count', default=8, help='Times to repeat the test')
@click.option('--timeout', default=15, help='probe will stop when logcat output is silent for that duration')
@click.option('--device-id', default=None, help='device_id to send commands to')
def main(package, activity, repeat_count, apk_path, timeout, device_id):
setup_logging()
tricorder = Tricorder(package)
adb.set_apk_path(apk_path)
for x in range(repeat_count):
# adb.logcat_clean()
probe = Probe(tricorder, package, activity, device_id)
logger.info('\ninstance no %s' % x)
probe.start(timeout)
normalized_result = tricorder.dump()
previous_results = tricorder.get_previous_runs(normalized_result)
# compare results with previous results (from db)
build_successful, error_log = tricorder.compare_with_previous_results(previous_results, normalized_result)
# Fail if results are above the defined threshold
if build_successful:
logger.info('Probe: run OK. All measurements from current in instance are within threshold bounds')
else:
logger.error('Probe: run failed! Summarizing failed tests:')
logger.error('\n' + error_log)
sys.exit(0 if build_successful else 1)
# trico = Tricorder(package, 'test')
# adb.logcat_clean()
# probe = Probe(trico, package, activity, device_id)
#
# thread = Thread(target=probe.start)
# thread.start()
#
# sleep(2)
# probe.stop()
if __name__ == "__main__":
main()