cts任务执行

本文详细解析了CommandScheduler中任务的执行流程,包括任务队列的处理方式、设备选择及分配逻辑,以及如何通过InvocationThread启动任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

任务的执行


任务的执行在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方法。放到下一篇文章来讲,因为它很重要,相当于一个调度室的作用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值