=== modified file 'lava_dispatcher/actions/lava-android-test.py'
--- lava_dispatcher/actions/lava-android-test.py	2012-04-26 07:44:18 +0000
+++ lava_dispatcher/actions/lava-android-test.py	2012-06-07 10:49:44 +0000
@@ -23,7 +23,7 @@
 import subprocess
 import logging
 from lava_dispatcher.actions import BaseAction
-from lava_dispatcher.client.base import OperationFailed
+from lava_dispatcher.client.base import OperationFailed, TimeoutError
 from lava_dispatcher.utils import generate_bundle_file_name
 
 
@@ -62,9 +62,17 @@
                                              bundle_name)]
             if option is not None:
                 cmds.extend(['-O', option])
+            if timeout != -1:
+                cmds.insert(0, 'timeout')
+                cmds.insert(1, '%ss' % timeout)
+
             logging.info("Execute command on host: %s" % (' '.join(cmds)))
             rc = subprocess.call(cmds)
-            if rc != 0:
+            if rc == 124:
+                raise TimeoutError(
+                           "The test case(%s) on device(%s) times out" % (
+                                                test_name, session.dev_name))
+            elif rc != 0:
                 raise OperationFailed(
                     "Failed to run test case(%s) on device(%s) with return "
                     "value: %s" % (test_name, session.dev_name, rc))
@@ -116,9 +124,17 @@
                                                bundle_name)])
                 if parser is not None:
                     cmds.extend(['-p', parser])
+
+                if timeout != -1:
+                    cmds.insert(0, 'timeout')
+                    cmds.insert(1, '%ss' % timeout)
                 logging.info("Execute command on host: %s" % (' '.join(cmds)))
                 rc = subprocess.call(cmds)
-                if rc != 0:
+                if rc == 124:
+                    raise TimeoutError(
+                               "The test (%s) on device(%s) times out." % (
+                                            ' '.join(cmds), session.dev_name))
+                elif rc != 0:
                     raise OperationFailed(
                         "Failed to run test custom case[%s] on device(%s)"
                         " with return value: %s" % (' '.join(cmds),
@@ -156,9 +172,17 @@
             cmds.extend(['-s', session.dev_name, '-o',
                          '%s/%s.bundle' % (self.context.host_result_dir,
                                            bundle_name)])
+            if timeout != -1:
+                cmds.insert(0, 'timeout')
+                cmds.insert(1, '%ss' % timeout)
+
             logging.info("Execute command on host: %s" % (' '.join(cmds)))
             rc = subprocess.call(cmds)
-            if rc != 0:
+            if rc == 124:
+                raise TimeoutError(
+                       "Failed to run monkeyrunner test url[%s] "
+                       "on device(%s)" % (url, session.dev_name))
+            elif rc != 0:
                 raise OperationFailed(
                     "Failed to run monkeyrunner test url[%s] on device(%s)"
                     " with return value: %s" % (url, session.dev_name, rc))
@@ -188,9 +212,17 @@
                         '-s', session.dev_name]
                 if option is not None:
                     cmds.extend(['-o', option])
+                if timeout != -1:
+                    cmds.insert(0, 'timeout')
+                    cmds.insert(1, '%ss' % timeout)
                 logging.info("Execute command on host: %s" % (' '.join(cmds)))
                 rc = subprocess.call(cmds)
-                if rc != 0:
+                if rc == 124:
+                    raise OperationFailed(
+                        "The installation of test case(%s)"
+                        " on device(%s) times out" % (test,
+                                                     session.dev_name))
+                elif rc != 0:
                     raise OperationFailed(
                         "Failed to install test case(%s) on device(%s) with "
                         "return value: %s" % (test, session.dev_name, rc))

=== modified file 'lava_dispatcher/client/base.py'
--- lava_dispatcher/client/base.py	2012-05-31 10:43:31 +0000
+++ lava_dispatcher/client/base.py	2012-06-13 07:35:23 +0000
@@ -513,6 +513,12 @@
     """
 
 
+class TimeoutError(DispatcherError):
+    """
+    The timeout error
+    """
+
+
 class CriticalError(DispatcherError):
     """
     The critical error

=== modified file 'lava_dispatcher/client/master.py'
--- lava_dispatcher/client/master.py	2012-06-11 19:54:52 +0000
+++ lava_dispatcher/client/master.py	2012-06-13 07:35:23 +0000
@@ -813,10 +813,10 @@
             self.proc.sendline("reboot")
         # Looking for reboot messages or if they are missing, the U-Boot message will also indicate the
         # reboot is done.
-        id = self.proc.expect(
+        match_id = self.proc.expect(
             ['Restarting system.', 'The system is going down for reboot NOW',
                 'Will now restart', 'U-Boot', pexpect.TIMEOUT], timeout=120)
-        if id not in [0, 1, 2, 3]:
+        if match_id not in [0, 1, 2, 3]:
             raise Exception("Soft reboot failed")
 
     def hard_reboot(self):
@@ -839,7 +839,8 @@
 
     def _enter_uboot(self):
         interrupt_boot_prompt = self.device_option('interrupt_boot_prompt')
-        self.proc.expect(interrupt_boot_prompt)
+        if self.proc.expect(interrupt_boot_prompt) != 0:
+            raise Exception("Faile to enter uboot")
 
         interrupt_boot_command = self.device_option('interrupt_boot_command')
         self.proc.sendline(interrupt_boot_command)

=== modified file 'lava_dispatcher/job.py'
--- lava_dispatcher/job.py	2012-05-29 02:10:58 +0000
+++ lava_dispatcher/job.py	2012-06-13 07:35:23 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2011 Linaro Limited
+# Copyright (C) 2011-2012 Linaro Limited
 #
 # Author: Paul Larson <paul.larson@linaro.org>
 #
@@ -21,14 +21,17 @@
 import json
 import logging
 import pexpect
+import time
 import traceback
 
 from json_schema_validator.schema import Schema
 from json_schema_validator.validator import Validator
 
 from lava_dispatcher.actions import get_all_cmds
-from lava_dispatcher.client.base import CriticalError, GeneralError
 from lava_dispatcher.context import LavaContext
+from lava_dispatcher.client.base import CriticalError, \
+                                        TimeoutError, \
+                                        GeneralError
 
 
 job_schema = {
@@ -123,7 +126,7 @@
     def logging_level(self):
         try:
             return self.job_data['logging_level']
-        except :
+        except:
             return None
 
     def run(self):
@@ -131,7 +134,8 @@
         self._set_logging_level()
         lava_commands = get_all_cmds()
 
-        if self.job_data['actions'][-1]['command'].startswith("submit_results"):
+        if self.job_data['actions'][-1]['command'].startswith(
+            "submit_results"):
             submit_results = self.job_data['actions'].pop(-1)
         else:
             submit_results = None
@@ -147,15 +151,43 @@
         self.context.test_data.add_tags(self.tags)
 
         try:
+            job_length = len(self.job_data['actions'])
+            job_num = 0
             for cmd in self.job_data['actions']:
+                job_num = job_num + 1
                 params = cmd.get('parameters', {})
-                logging.info("[ACTION-B] %s is started with %s" % (cmd['command'], params))
+                if cmd.get('command').startswith('lava_android_test'):
+                    if not params.get('timeout') and \
+                       self.job_data.get('timeout'):
+                        params['timeout'] = self.job_data['timeout']
+                logging.info("[ACTION-B] %s is started with %s" % (
+                                            cmd['command'], params))
                 metadata = cmd.get('metadata', {})
                 self.context.test_data.add_metadata(metadata)
                 action = lava_commands[cmd['command']](self.context)
                 try:
                     status = 'fail'
                     action.run(**params)
+                except TimeoutError as err:
+                    if cmd.get('command').startswith('lava_android_test'):
+                        logging.warning("[ACTION-E] %s times out." % (
+                                                cmd['command']))
+                        if job_num == job_length:
+                            ## not reboot the android image for
+                            ## the last test action
+                            pass
+                        else:
+                            ## clear the session on the serial and wait a while
+                            ## and not put the following 3 sentences into the
+                            ## boot_linaro_android_image method just for
+                            ## avoiding effects when the method being called
+                            ## in other places
+                            logging.warning(
+                                "Now the android image will be rebooted")
+                            self.context.client.proc.sendcontrol("c")
+                            self.context.client.proc.sendline("")
+                            time.sleep(5)
+                            self.context.client.boot_linaro_android_image()
                 except CriticalError as err:
                     raise
                 except (pexpect.TIMEOUT, GeneralError) as err:
@@ -167,23 +199,29 @@
                 finally:
                     err_msg = ""
                     if status == 'fail':
-                        logging.warning("[ACTION-E] %s is finished with error (%s)." %(cmd['command'], err))
-                        err_msg = "Lava failed at action %s with error: %s\n" %\
-                                  (cmd['command'], unicode(str(err), 'ascii', 'replace'))
+                        logging.warning(
+                            "[ACTION-E] %s is finished with error (%s)." % (
+                                    cmd['command'], err))
+                        err_msg = ("Lava failed at action %s with error:"
+                                   "%s\n") % (cmd['command'],
+                                              unicode(str(err),
+                                                      'ascii', 'replace'))
                         if cmd['command'] == 'lava_test_run':
-                            err_msg += "Lava failed on test: %s" %\
+                            err_msg += "Lava failed on test: %s" % \
                                        params.get('test_name', "Unknown")
                         err_msg = err_msg + traceback.format_exc()
                         # output to both serial log and logfile
                         self.context.client.sio.write(err_msg)
                     else:
-                        logging.info("[ACTION-E] %s is finished successfully." %cmd['command'])
+                        logging.info(
+                            "[ACTION-E] %s is finished successfully." % (
+                                                        cmd['command']))
                         err_msg = ""
                     self.context.test_data.add_result(
                         action.test_name(**params), status, err_msg)
         except:
             #Capture all user-defined and non-user-defined critical errors
-            self.context.test_data.job_status='fail'
+            self.context.test_data.job_status = 'fail'
             raise
         finally:
             if submit_results:
@@ -213,4 +251,6 @@
             elif level == 'CRITICAL':
                 logging.root.setLevel(logging.CRITICAL)
             else:
-                logging.warning("Unknown logging level in the job '%s'. Allow level are : CRITICAL, ERROR, WARNING, INFO or DEBUG" %level)
+                logging.warning("Unknown logging level in the job '%s'. "
+                                "Allow level are : CRITICAL, ERROR, "
+                                "WARNING, INFO or DEBUG" % level)

