コード例 #1
0
 def __init__(self, device, package, seed=11, number=10):
     self.device = device
     self.seed = seed
     self.number = number
     self.package = package
     self.logcat = LogcatAgent(self.device)
     #TODO add orientation and other events
     self.specialEvents = ['wifi', 'data']
     random.seed(self.seed)
コード例 #2
0
 def __init__(self, device, package, seed=11, number=10):
     self.device = device
     self.seed = seed
     self.number = number
     self.package = package
     self.logcat = LogcatAgent(self.device)
     #TODO add orientation and other events
     self.specialEvents = ['wifi', 'data']
     random.seed(self.seed)
コード例 #3
0
def main():
    """ This example dumps all error messages in logcat and then clear it.
    After 5 seconds, it dumps all messages and finishes.
    Note that logcat encodes its output with utf-8
    """
    device = EMonkeyDevice()
    agent = LogcatAgent(device)
    print agent.dump(fmt=None, filterTuples=[('*', 'E')])
    agent.clear()
    print 'Waiting for 5 seconds...'
    time.sleep(5)
    print agent.dump()
コード例 #4
0
def main():
    """ This example dumps all error messages in logcat and then clear it.
    After 5 seconds, it dumps all messages and finishes.
    Note that logcat encodes its output with utf-8
    """
    device = EMonkeyDevice()
    agent = LogcatAgent(device)
    print agent.dump(fmt=None, filterTuples=[('*', 'E')])
    agent.clear()
    print 'Waiting for 5 seconds...'
    time.sleep(5)
    print agent.dump()
コード例 #5
0
def main():
    """ This test launches a series of apps (with given package and main activity names)
    and repeats this for a given number of times. After that, the scripts dumps the error
    messages printed to logcat during the test.
    """
    # constants
    APP_CLOCK = 'com.android.deskclock/com.android.deskclock.DeskClock'
    APP_SETTINGS = 'com.android.settings/com.android.settings.Settings'
    # configurations
    packages = [APP_SETTINGS, APP_CLOCK]
    sleep_interval = 2
    repeats = 2
    app_tag = 'ActivityManager'
    device = DeviceManager.getDevice()
    agent = LogcatAgent(device)
    agent.clear()
    print 'Start launching stress test'
    for _ in range(repeats):
        for p in packages:
            device.startActivity(component=p)
            time.sleep(sleep_interval)
    err = agent.dump(fmt=None, filterTuples=[(app_tag, 'E'), ('*', 'S')])
    print 'Finishing test, dumping error messages:'
    print err
コード例 #6
0
def main():
    """ This test launches a series of apps (with given package and main activity names)
    and repeats this for a given number of times. After that, the scripts dumps the error
    messages printed to logcat during the test.
    """
    # constants
    APP_HOME = 'com.android.launcher/com.android.launcher2.Launcher'
    APP_CLOCK = 'com.google.android.deskclock/com.android.deskclock.DeskClock'
    # configurations
    packages = [APP_CLOCK, APP_HOME]
    sleep_interval = 2
    repeats = 2
    app_tag = 'ActivityManager'
    device = EMonkeyDevice()
    agent = LogcatAgent(device)
    agent.clear()
    print 'Start launching stress test'
    for _ in range(repeats):
        for p in packages:
            device.startActivity(component=p)
            time.sleep(sleep_interval)
    err = agent.dump(fmt=None, filterTuples=[(app_tag, 'E'), ('*', 'S')])
    print 'Finishing test, dumping error messages:'
    print err
コード例 #7
0
class HeisenbugTester:
    """ Deprecated
    """
    def __init__(self, device, package, seed=11, number=10):
        self.device = device
        self.seed = seed
        self.number = number
        self.package = package
        self.logcat = LogcatAgent(self.device)
        #TODO add orientation and other events
        self.specialEvents = ['wifi', 'data']
        random.seed(self.seed)

    def generateSpecialEventSequence(self):
        length = len(self.specialEvents)
        seq = self.specialEvents * (self.number / length + 1)
        seq = random.sample(seq, self.number)
        return seq

    def processSpecialEvents(self, specialEvent):
        if specialEvent == 'wifi':
            WifiAgent(self.device).changeWifiStatus()
        elif specialEvent == 'data':
            CellularAgent(self.device).toggleCellularDataStatus()

    def runnerMixEvents(self):
        """run self.number pieces of random special events
           and self.number pieces of random simple events in between of any two continuous special events
        """
        try:
            specialSeq = self.generateSpecialEventSequence()
            for i in specialSeq:
                self.processSpecialEvents(i)
                self.device.shell('monkey -p ' + self.package + ' -vvv ' +
                                  str(self.number))
            return True
        except:
            return False

    def runnerSimpleEvents(self):
        """run self.number random simple events
        """
        try:
            self.device.shell('monkey -p ' + self.package + ' -vvv ' +
                              str(self.number))
            return True
        except:
            return False

    def runnerSpecialEvents(self):
        """run self.number pieces of random special events
        """
        try:
            specialSeq = self.generateSpecialEventSequence()
            for i in specialSeq:
                self.processSpecialEvents(i)
            return True
        except:
            return False

    def dumpLog(self):
        log = self.logcat.dump(filterTuples=[('*', 'W')])
        log = log.split('\n')
        result = []
        for line in log:
            if self.package in line:
                result.append(line)
        return result
        #self.device.shell('logcat *:W | grep '+self.activity)

    def clearLog(self):
        return self.logcat.clear()

    def runner(self, mode='mix'):
        #log=open('HeissenbugTesterlog.txt', 'w')
        #logcat=subprocess.Popen(['adb','logcat', '*:W', '|', 'grep', self.package], stdout=log)
        self.clearLog()
        if mode == 'mix':
            result = self.runnerMixEvents()
        elif mode == 'special':
            result = self.runnerSpecialEvents()
        elif mode == 'simple':
            result = self.runnerSimpleEvents()
        return result, self.dumpLog()
コード例 #8
0
class HeisenbugTester:
    """ Deprecated
    """
    def __init__(self, device, package, seed=11, number=10):
        self.device = device
        self.seed = seed
        self.number = number
        self.package = package
        self.logcat = LogcatAgent(self.device)
        #TODO add orientation and other events
        self.specialEvents = ['wifi', 'data']
        random.seed(self.seed)

    def generateSpecialEventSequence(self):
        length = len(self.specialEvents)
        seq = self.specialEvents * (self.number/length+1)
        seq = random.sample(seq, self.number)
        return seq

    def processSpecialEvents(self, specialEvent):
        if specialEvent == 'wifi':
            WifiAgent(self.device).changeWifiStatus()
        elif specialEvent == 'data':
            CellularAgent(self.device).toggleCellularDataStatus()


    def runnerMixEvents(self):
        """run self.number pieces of random special events
           and self.number pieces of random simple events in between of any two continuous special events
        """
        try:
            specialSeq = self.generateSpecialEventSequence()
            for i in specialSeq:
                self.processSpecialEvents(i)
                self.device.shell('monkey -p ' + self.package + ' -vvv ' + str(self.number))
            return True
        except:
            return False

    def runnerSimpleEvents(self):
        """run self.number random simple events
        """
        try:
            self.device.shell('monkey -p ' + self.package + ' -vvv ' + str(self.number))
            return True
        except:
            return False

    def runnerSpecialEvents(self):
        """run self.number pieces of random special events
        """
        try:
            specialSeq = self.generateSpecialEventSequence()
            for i in specialSeq:
                self.processSpecialEvents(i)
            return True
        except:
            return False

    def dumpLog(self):
        log = self.logcat.dump(filterTuples=[('*', 'W')])
        log = log.split('\n')
        result = []
        for line in log:
            if self.package in line:
                result.append(line)
        return result
        #self.device.shell('logcat *:W | grep '+self.activity)

    def clearLog(self):
        return self.logcat.clear()

    def runner(self, mode='mix'):
        #log=open('HeissenbugTesterlog.txt', 'w')
        #logcat=subprocess.Popen(['adb','logcat', '*:W', '|', 'grep', self.package], stdout=log)
        self.clearLog()
        if mode == 'mix':
            result = self.runnerMixEvents()
        elif mode == 'special':
            result = self.runnerSpecialEvents()
        elif mode == 'simple':
            result = self.runnerSimpleEvents()
        return result, self.dumpLog()