testing/mozbase/mozdevice/tests/sut_basic.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozdevice/tests/sut_basic.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +from sut import MockAgent
     1.5 +import mozdevice
     1.6 +import mozlog
     1.7 +import unittest
     1.8 +
     1.9 +class BasicTest(unittest.TestCase):
    1.10 +
    1.11 +    def test_init(self):
    1.12 +        """Tests DeviceManager initialization."""
    1.13 +        a = MockAgent(self)
    1.14 +
    1.15 +        d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG)
    1.16 +        # all testing done in device's constructor
    1.17 +        a.wait()
    1.18 +
    1.19 +    def test_init_err(self):
    1.20 +        """Tests error handling during initialization."""
    1.21 +        cmds = [("testroot", "/mnt/sdcard"),
    1.22 +                ("isdir /mnt/sdcard/tests", "/mnt/sdcard/tests: No such file or directory\n"),
    1.23 +                ("isdir /mnt/sdcard/tests", "/mnt/sdcard/tests: No such file or directory\n"),
    1.24 +                ("mkdr /mnt/sdcard/tests", "/mnt/sdcard/tests successfully created"),
    1.25 +                ("ver", "SUTAgentAndroid Version 1.14")]
    1.26 +        a = MockAgent(self, start_commands = cmds)
    1.27 +        dm = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG)
    1.28 +        a.wait()
    1.29 +
    1.30 +    def test_timeout_normal(self):
    1.31 +        """Tests DeviceManager timeout, normal case."""
    1.32 +        a = MockAgent(self, commands = [("isdir /mnt/sdcard/tests", "TRUE"),
    1.33 +                                        ("cd /mnt/sdcard/tests", ""),
    1.34 +                                        ("ls", "test.txt"),
    1.35 +                                        ("rm /mnt/sdcard/tests/test.txt",
    1.36 +                                         "Removed the file")])
    1.37 +        d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG)
    1.38 +        ret = d.removeFile('/mnt/sdcard/tests/test.txt')
    1.39 +        self.assertEqual(ret, None) # if we didn't throw an exception, we're ok
    1.40 +        a.wait()
    1.41 +
    1.42 +    def test_timeout_timeout(self):
    1.43 +        """Tests DeviceManager timeout, timeout case."""
    1.44 +        a = MockAgent(self, commands = [("isdir /mnt/sdcard/tests", "TRUE"),
    1.45 +                                        ("cd /mnt/sdcard/tests", ""),
    1.46 +                                        ("ls", "test.txt"),
    1.47 +                                        ("rm /mnt/sdcard/tests/test.txt", 0)])
    1.48 +        d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=mozlog.DEBUG)
    1.49 +        d.default_timeout = 1
    1.50 +        exceptionThrown = False
    1.51 +        try:
    1.52 +            d.removeFile('/mnt/sdcard/tests/test.txt')
    1.53 +        except mozdevice.DMError:
    1.54 +            exceptionThrown = True
    1.55 +        self.assertEqual(exceptionThrown, True)
    1.56 +        a.should_stop = True
    1.57 +        a.wait()
    1.58 +
    1.59 +    def test_shell(self):
    1.60 +        """Tests shell command"""
    1.61 +        for cmd in [ ("exec foobar", False), ("execsu foobar", True) ]:
    1.62 +            for retcode in [ 1, 2 ]:
    1.63 +                a = MockAgent(self, commands=[(cmd[0],
    1.64 +                                               "\nreturn code [%s]" % retcode)])
    1.65 +                d = mozdevice.DroidSUT("127.0.0.1", port=a.port)
    1.66 +                exceptionThrown = False
    1.67 +                try:
    1.68 +                    d.shellCheckOutput(["foobar"], root=cmd[1])
    1.69 +                except mozdevice.DMError:
    1.70 +                    exceptionThrown = True
    1.71 +                expectedException = (retcode != 0)
    1.72 +                self.assertEqual(exceptionThrown, expectedException)
    1.73 +
    1.74 +                a.wait()
    1.75 +
    1.76 +if __name__ == '__main__':
    1.77 +    unittest.main()

mercurial