Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | |
michael@0 | 5 | import re |
michael@0 | 6 | import socket |
michael@0 | 7 | from time import strptime |
michael@0 | 8 | |
michael@0 | 9 | from dmunit import DeviceManagerTestCase, heartbeat_port |
michael@0 | 10 | |
michael@0 | 11 | class DataChannelTestCase(DeviceManagerTestCase): |
michael@0 | 12 | |
michael@0 | 13 | runs_on_test_device = False |
michael@0 | 14 | |
michael@0 | 15 | def runTest(self): |
michael@0 | 16 | """This tests the heartbeat and the data channel. |
michael@0 | 17 | """ |
michael@0 | 18 | ip = self.dm.host |
michael@0 | 19 | |
michael@0 | 20 | # Let's connect |
michael@0 | 21 | self._datasock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
michael@0 | 22 | # Assume 60 seconds between heartbeats |
michael@0 | 23 | self._datasock.settimeout(float(60 * 2)) |
michael@0 | 24 | self._datasock.connect((ip, heartbeat_port)) |
michael@0 | 25 | self._connected = True |
michael@0 | 26 | |
michael@0 | 27 | # Let's listen |
michael@0 | 28 | numbeats = 0 |
michael@0 | 29 | capturedHeader = False |
michael@0 | 30 | while numbeats < 3: |
michael@0 | 31 | data = self._datasock.recv(1024) |
michael@0 | 32 | print data |
michael@0 | 33 | self.assertNotEqual(len(data), 0) |
michael@0 | 34 | |
michael@0 | 35 | # Check for the header |
michael@0 | 36 | if not capturedHeader: |
michael@0 | 37 | m = re.match(r"(.*?) trace output", data) |
michael@0 | 38 | self.assertNotEqual(m, None, |
michael@0 | 39 | 'trace output line does not match. The line: ' + str(data)) |
michael@0 | 40 | capturedHeader = True |
michael@0 | 41 | |
michael@0 | 42 | # Check for standard heartbeat messsage |
michael@0 | 43 | m = re.match(r"(.*?) Thump thump - (.*)", data) |
michael@0 | 44 | if m == None: |
michael@0 | 45 | # This isn't an error, it usually means we've obtained some |
michael@0 | 46 | # unexpected data from the device |
michael@0 | 47 | continue |
michael@0 | 48 | |
michael@0 | 49 | # Ensure it matches our format |
michael@0 | 50 | mHeartbeatTime = m.group(1) |
michael@0 | 51 | mHeartbeatTime = strptime(mHeartbeatTime, "%Y%m%d-%H:%M:%S") |
michael@0 | 52 | numbeats = numbeats + 1 |