summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozdevice/sut_tests/test_datachannel.py
blob: 99b71a584d5621b3ac664e8f77510c9838e5c4bc (plain)
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import re
import socket
from time import strptime

from dmunit import DeviceManagerTestCase, heartbeat_port


class DataChannelTestCase(DeviceManagerTestCase):

    runs_on_test_device = False

    def runTest(self):
        """This tests the heartbeat and the data channel.
        """
        ip = self.dm.host

        # Let's connect
        self._datasock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # Assume 60 seconds between heartbeats
        self._datasock.settimeout(float(60 * 2))
        self._datasock.connect((ip, heartbeat_port))
        self._connected = True

        # Let's listen
        numbeats = 0
        capturedHeader = False
        while numbeats < 3:
            data = self._datasock.recv(1024)
            print data
            self.assertNotEqual(len(data), 0)

            # Check for the header
            if not capturedHeader:
                m = re.match(r"(.*?) trace output", data)
                self.assertNotEqual(m, None,
                                    'trace output line does not match. The line: ' + str(data))
                capturedHeader = True

            # Check for standard heartbeat messsage
            m = re.match(r"(.*?) Thump thump - (.*)", data)
            if m is None:
                # This isn't an error, it usually means we've obtained some
                # unexpected data from the device
                continue

            # Ensure it matches our format
            mHeartbeatTime = m.group(1)
            mHeartbeatTime = strptime(mHeartbeatTime, "%Y%m%d-%H:%M:%S")
            numbeats = numbeats + 1