-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathphonetest.py
More file actions
98 lines (90 loc) · 3.68 KB
/
phonetest.py
File metadata and controls
98 lines (90 loc) · 3.68 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import Queue
import logging
from datetime import datetime
class PhoneTest:
"""
The initialization function. It takes and stores all the information
related to contacting this phone.
Params:
phoneid = ID of phone, to be used in log messages and reporting
serial = serial number for adb style interfaces
ip = phone's IP address (where sutagent running if it is running)
sutcmdport = cmd port of sutagent if it is running
sutdataport = data port of sutagent if it is running
machinetype = pretty name of machine type - i.e. galaxy_nexus, droid_pro etc
osver = version string of phone OS
TODO: Add in connection data here for programmable power so we can add a
powercycle method to this class.
"""
def __init__(self,
phoneid=None,
serial=None,
ip=None,
sutcmdport=None,
sutdataport=None,
machinetype = None,
osver=None):
print "This is the initialization function"
self._jobs = Queue.Queue()
self._phoneid = phoneid
self._serial = serial
self._ip = ip
self._sutcmdport = sutcmdport
self._sutdataport = sutdataport
self._machinetype = machinetype
self._osver = osver
self._logger = logging.getLogger('phonetest')
self._status = {'timestamp': datetime.now().isoformat(),
'online': True, 'msg': 'Initialized'}
"""
add job - Add a job to the list of things the phone should do
Params:
job dict - the job is the main unit of communication with the test.
A job is a dict of the following information:
* buildurl - url of bundle to download and install before running test
* revisionID - changeset ID associated with that build
* branch - branch of build (for reporting)
* builddate - date of build (for reporting)
This can be called both once the phone has started testing as well as
prior to phone start.
"""
def add_job(self, job=None):
# TODO: Enforce the abstract class?
self._logger.warning("Base class adding job %s" % job)
if job:
self._jobs.put_nowait(job)
"""
start Test - starts the testing process.
This will walk the job queue and run all the jobs. If stop is True then it
will stop the message loop once it completes the list of jobs, otherwise
the phone will wait for more jobs to be added to the queue.
"""
def start_test(self, stop=False):
# TODO: Enforce abstract class here
print "TODO: Enforce abstract class"
"""
get status - will return some kind of status to the daemon master.
The child object is expected to set a status message, this function
will ensure that the master will obtain a properly formatted message.
The returned message will have the following form:
YYYYMMDDTHH:MM:SS.uuu|<True/False>|<msg>
where the timestamp is the stamp the last status message was set
the True/False is the phone's current belief as to its online state
and the message is the last message set in the status block
"""
def get_status(self):
statusline = "%s|%s|%s" % (self._status["timestamp"],
self._status["online"], self._status["msg"])
self._logger.debug("Getting status: %s" % statusline)
return statusline
"""
sets the status
Params:
online = boolean True of False
msg = the message of status
"""
def _set_status(self, online=True, msg=None):
self._logger.debug("creating status")
self._status["timestamp"] = datetime.now().isoformat()
self._status["online"] = online
self._status["msg"] = msg