1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozdevice/sut_tests/test_datachannel.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +import re 1.9 +import socket 1.10 +from time import strptime 1.11 + 1.12 +from dmunit import DeviceManagerTestCase, heartbeat_port 1.13 + 1.14 +class DataChannelTestCase(DeviceManagerTestCase): 1.15 + 1.16 + runs_on_test_device = False 1.17 + 1.18 + def runTest(self): 1.19 + """This tests the heartbeat and the data channel. 1.20 + """ 1.21 + ip = self.dm.host 1.22 + 1.23 + # Let's connect 1.24 + self._datasock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 1.25 + # Assume 60 seconds between heartbeats 1.26 + self._datasock.settimeout(float(60 * 2)) 1.27 + self._datasock.connect((ip, heartbeat_port)) 1.28 + self._connected = True 1.29 + 1.30 + # Let's listen 1.31 + numbeats = 0 1.32 + capturedHeader = False 1.33 + while numbeats < 3: 1.34 + data = self._datasock.recv(1024) 1.35 + print data 1.36 + self.assertNotEqual(len(data), 0) 1.37 + 1.38 + # Check for the header 1.39 + if not capturedHeader: 1.40 + m = re.match(r"(.*?) trace output", data) 1.41 + self.assertNotEqual(m, None, 1.42 + 'trace output line does not match. The line: ' + str(data)) 1.43 + capturedHeader = True 1.44 + 1.45 + # Check for standard heartbeat messsage 1.46 + m = re.match(r"(.*?) Thump thump - (.*)", data) 1.47 + if m == None: 1.48 + # This isn't an error, it usually means we've obtained some 1.49 + # unexpected data from the device 1.50 + continue 1.51 + 1.52 + # Ensure it matches our format 1.53 + mHeartbeatTime = m.group(1) 1.54 + mHeartbeatTime = strptime(mHeartbeatTime, "%Y%m%d-%H:%M:%S") 1.55 + numbeats = numbeats + 1