cts任务执行

来源:互联网 发布:matlab算矩阵乘法 编辑:程序博客网 时间:2024/06/01 09:15

任务的执行


任务的执行在CommandScheduler的run方法中,所以删除所有的断点,在run方法中打上断点,重启启动debug:




先看while循环下面的第一行代码


[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. ExecutableCommand cmd = dequeueConfigCommand();  

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. private ExecutableCommand dequeueConfigCommand() {  
  2.         try {  
  3.             // poll for a command, rather than block indefinitely, to handle shutdown case  
  4.             return mCommandQueue.poll(getCommandPollTimeMs(), TimeUnit.MILLISECONDS);  
  5.         } catch (InterruptedException e) {  
  6.             CLog.i("Waiting for command interrupted");  
  7.         }  
  8.         return null;  
  9.     }  

从队列中取出第一个对象。如果队列中没有元素那就返回null。返回后,while中会判断如果为null的话,就会结束再次调用


[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. ExecutableCommand cmd = dequeueConfigCommand();  


直到cmd不为null。所以在


[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. IDeviceSelection options = cmd.getConfiguration().getDeviceRequirements();  


打上断点,按F8,程序会在cmd不为null时进入到上面的代码,停下来。




首先得到系统设备要求,根据该要求,判断是否有满足要求的设备并分配该设备。



原生的 要求就一个S/N号,ddms会根据该SN号分配一个IDevice,然后cts根据IDevice包装成ITestDevice对象返回。然后根据ITestDevice,IDeviceManager和ExecutableCommand开始真正的启动任务。我们先不急于讨论执行的过程,而是继续向下看:


[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. addInvocationThread(invThread);  
  2. if (cmd.isLoopMode()) {  
  3.     addNewExecCommandToQueue(cmd.getCommandTracker());  
  4. }  

先将正在执行的线程存到set中,然后将该命令再次放入任务队列中,这样的目的是为了能循环执行该任务。如果根据sn号没有分配成功ITestDevice,则会再次尝试一次,如果在规定时间内还没找到设备则放弃。最后做一些tearDown操作,然后将case运行过程中的log保存到文件。就算执行完了。


现在回头看一下执行任务的线程中是如何操作的:


[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. private InvocationThread startInvocation(IDeviceManager manager, ITestDevice device,  
  2.             ExecutableCommand cmd) {  
  3.         final String invocationName = String.format("Invocation-%s", device.getSerialNumber());  
  4.         InvocationThread invocationThread = new InvocationThread(invocationName, manager, device,  
  5.                 cmd);  
  6.         invocationThread.start();  
  7.         return invocationThread;  
  8.     }  

InvocationThread为CommandScheduler私有内部类,继承与线程,这就属于线程里启动线程。所以直接看InvocationThread的run方法就ok了。在run方法里调用了ITestInvocation的invoke方法:




传入的对象分别为ITestDevice、IConfiguration、IRescheduler。前两个已经涉及到,最后一个IRescheduler是什么?自己看吧,也没啥意义。这样任务的前期的工作都已经搞定了,程序转到了TestInvocation的invoke方法。放到下一篇文章来讲,因为它很重要,相当于一个调度室的作用。

0 0
原创粉丝点击