testing/mozbase/mozdevice/tests/sut_logcat.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozdevice/tests/sut_logcat.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +import mozdevice
     1.7 +import mozlog
     1.8 +import unittest
     1.9 +from sut import MockAgent
    1.10 +
    1.11 +
    1.12 +class TestLogCat(unittest.TestCase):
    1.13 +    """ Class to test methods assosiated with logcat """
    1.14 +
    1.15 +    def test_getLogcat(self):
    1.16 +
    1.17 +        logcat_output = ("07-17 00:51:10.377 I/SUTAgentAndroid( 2933): onCreate\n\r"
    1.18 +        "07-17 00:51:10.457 D/dalvikvm( 2933): GC_CONCURRENT freed 351K, 17% free 2523K/3008K, paused 5ms+2ms, total 38ms\n\r"
    1.19 +        "07-17 00:51:10.497 I/SUTAgentAndroid( 2933): Caught exception creating file in /data/local/tmp: open failed: EACCES (Permission denied)\n\r"
    1.20 +        "07-17 00:51:10.507 E/SUTAgentAndroid( 2933): ERROR: Cannot access world writeable test root\n\r"
    1.21 +        "07-17 00:51:10.547 D/GeckoHealthRec( 3253): Initializing profile cache.\n\r"
    1.22 +        "07-17 00:51:10.607 D/GeckoHealthRec( 3253): Looking for /data/data/org.mozilla.fennec/files/mozilla/c09kfhne.default/times.json\n\r"
    1.23 +        "07-17 00:51:10.637 D/GeckoHealthRec( 3253): Using times.json for profile creation time.\n\r"
    1.24 +        "07-17 00:51:10.707 D/GeckoHealthRec( 3253): Incorporating environment: times.json profile creation = 1374026758604\n\r"
    1.25 +        "07-17 00:51:10.507 D/GeckoHealthRec( 3253): Requested prefs.\n\r"
    1.26 +        "07-17 06:50:54.907 I/SUTAgentAndroid( 3876): \n\r"
    1.27 +        "07-17 06:50:54.907 I/SUTAgentAndroid( 3876): Total Private Dirty Memory         3176 kb\n\r"
    1.28 +        "07-17 06:50:54.907 I/SUTAgentAndroid( 3876): Total Proportional Set Size Memory 5679 kb\n\r"
    1.29 +        "07-17 06:50:54.907 I/SUTAgentAndroid( 3876): Total Shared Dirty Memory          9216 kb\n\r"
    1.30 +        "07-17 06:55:21.627 I/SUTAgentAndroid( 3876): 127.0.0.1 : execsu /system/bin/logcat -v time -d dalvikvm:I "
    1.31 +        "ConnectivityService:S WifiMonitor:S WifiStateTracker:S wpa_supplicant:S NetworkStateTracker:S\n\r"
    1.32 +        "07-17 06:55:21.827 I/dalvikvm-heap( 3876): Grow heap (frag case) to 3.019MB for 102496-byte allocation\n\r"
    1.33 +        "return code [0]")
    1.34 +
    1.35 +        inp = ("execsu /system/bin/logcat -v time -d "
    1.36 +        "dalvikvm:I ConnectivityService:S WifiMonitor:S "
    1.37 +        "WifiStateTracker:S wpa_supplicant:S NetworkStateTracker:S")
    1.38 +
    1.39 +        commands = [(inp, logcat_output)]
    1.40 +        m = MockAgent(self, commands=commands)
    1.41 +        d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG)
    1.42 +        self.assertEqual(logcat_output[:-17].split('\r'), d.getLogcat())
    1.43 +
    1.44 +    def test_recordLogcat(self):
    1.45 +
    1.46 +        commands = [("execsu /system/bin/logcat -c", "return code [0]")]
    1.47 +
    1.48 +        m = MockAgent(self, commands=commands)
    1.49 +        d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG)
    1.50 +        # No error raised means success
    1.51 +        self.assertEqual(None, d.recordLogcat())
    1.52 +
    1.53 +if __name__ == '__main__':
    1.54 +    unittest.main()

mercurial