CTS framework resolution (7)-scheduling room for task execution

Source: Internet
Author: User
Testinvocation


/*** {@ Inheritdoc} */@ overridepublic void invoke (itestdevice device, iconfiguration config, irescheduler rescheduler) throws devicenotavailableexception, throwable {try {mstatus = "fetching build"; config. getlogoutput (). init (); getlogregistry (). registerlogger (config. getlogoutput (); ibuildinfo = NULL; If (config. getbuildprovider () instanceof idevicebuildprovider) {info = (idevicebuildprovider) c Onfig. getbuildprovider ()). getbuild (device);} else if (config. getbuildprovider () instanceof ideviceconfigbuildprovider) {// call config to obtain CTS. the class corresponding to the <build_provider> label in the XML file, and then get the ibuildinfo object info = (ideviceconfigbuildprovider) config by calling getbuild. getbuildprovider ()). getbuild (device, config);} else {info = config. getbuildprovider (). getbuild () ;}if (info! = NULL) {// system. out. println (string. format ("setup: % s teardown: % s", // config. getcommandoptions (). isneedprepare (), // config. getcommandoptions (). isneedteardown (); clog. loganddisplay (loglevel. info, String. format ("setup: % s teardown: % s", config. getcommandoptions (). isneedprepare (), config. getcommandoptions (). isneedteardown (); // obtain the test options in the <Test> configuration item and inject them into injectbuild (Info, config. gettests (); If (shardconfig (config, info, rescheduler) {clog. I ("invocation for % s has been sharded, rescheduling", device. getserialnumber ();} else {Device. setrecovery (config. getdevicerecovery (); // prepare for flash and start caseperforminvocation (config, device, info, reschedation); // exit here, depend on your minvocation to deregister // loggerreturn ;}} else {mstatus = "(no build to test)"; clog. D ("no build to test"); rescheduletest (config, reschedtest);} catch (buildretrievalerror e) {clog. E (E);/** because this is buildretrievalerror, so do not generate test * result/report an empty invocation, so this error is sent to * listeners startinvocation (config, device, E. getbuildinfo (); // * don't want to use # reportfailure, since that will call * buildnottested for (itestinvocationlistener listener: * config. gettestinvocationlisteners () {* listener. invocationfailed (E);} reportlogs (device, * config. gettestinvocationlisteners (), config. getlogoutput (); * invocationsummaryhelper. reportinvocationended (* config. gettestinvocationlisteners (), 0); return; */} catch (ioexception e) {clog. E (E);} // save current log contents to global loggetlogregistry (). dumptogloballog (config. getlogoutput (); getlogregistry (). unregisterlogger (); config. getlogoutput (). closelog ();}


The scheduling room is called the scheduling room because it is the component that runs the nine components step by step. The component and the component do not know the other component's existence, but testinvocation knows it. Instead of creating an object through the reflection mechanism, it calls the interface method to get what it wants and then passes it to the next component. The above method shows that it first obtains the buildprovider object. Call the getbuild object to obtain the ibuildinfo object. In our program, we actually call the getbuild method of ctsbuildprovider.

If Info is not null: inject ibuildinfo to the test task to determine whether the task can be split. If not, register the device Recovery class and jump to the performinvocation method.

If Info is null: No executable build is displayed, call irescheduler. reschedulecommand () to retry.


/*** Performs the invocation ** @ Param config * The {@ link iconfiguration} * @ Param device * The {@ link itestdevice} to use. may be <code> null </code> * @ Param info * The {@ link ibuildinfo} */private void implements minvocation (iconfiguration config, itestdevice device, ibuildinfo info, irescheduler rescheduler) throws throwable {Boolean resumed = false; long starttime = system. currenttimemillis (); long Elapsedtime =-1; info. setdeviceserial (device. getserialnumber (); startinvocation (config, device, Info); try {Device. setoptions (config. getdeviceoptions (); // prepare to build and run caseprepareandrun (config, device, info, reschedrun);} catch (builderror e) {clog. W ("build % s failed on device % S. reason: % s ", info. getbuildid (), device. getserialnumber (), E. tostring (); takebugreport (device, config. gettestinvocationlis Teners (), build_error_bugreport_name); reportfailure (E, config. gettestinvocationlisteners (), config, info, rescheduler);} catch (targetsetuperror e) {clog. E ("caught exception while running invocation"); clog. E (E); reportfailure (E, config. gettestinvocationlisteners (), config, info, rescheduler); // maybe test device if offline, check itdevice. waitfordeviceonline ();} catch (devicenotavailableexception E) {// Log a warning here so its captured before reportlogs is calledclog. W ("invocation did not complete due to device % s becoming not available. "+" Reason: % s ", device. getserialnumber (), E. getmessage (); If (E instanceof deviceunresponsiveexception) & testdevicestate. online. equals (device. getdevicestate () {// under certain cases it might still be possible to grab a // bugreporttakebugreport (Dev Ice, config. gettestinvocationlisteners (), device_unresponsive_bugreport_name);} resumed = resume (config, info, rescheduler, system. currenttimemillis ()-starttime); If (! Resumed) {reportfailure (E, config. gettestinvocationlisteners (), config, info, rescheduler);} else {clog. I ("rescheduled failed invocation for resume");} Throw E;} catch (runtimeexception e) {// log a warning here so its captured before reportlogs is calledclog. W ("unexpected exception when running invocation: % s", E. tostring (); reportfailure (E, config. gettestinvocationlisteners (), config, info, resche Dashes); throw E;} catch (assertionerror e) {clog. W ("caught assertionerror while running invocation:", E. tostring (); reportfailure (E, config. gettestinvocationlisteners (), config, info, rescheduler);} finally {mstatus = "done running tests"; try {// reportlogs (device, config. gettestinvocationlisteners (), config. getlogoutput (); elapsedtime = system. currenttimemillis ()-starttime; If (! Resumed) {// send the report invocationsummaryhelper. reportinvocationended (config. gettestinvocationlisteners (), elapsedtime);} finally {config. getbuildprovider (). Cleanup (Info );}}}

Start the start method of all listeners to start a notification.


/** * Starts the invocation. * <p/> * Starts logging, and informs listeners that invocation has been started. *  * @param config * @param device * @param info */private void startInvocation(IConfiguration config, ITestDevice device, IBuildInfo info) {logStartInvocation(info, device);for (ITestInvocationListener listener : config.getTestInvocationListeners()) {try {listener.invocationStarted(info);} catch (RuntimeException e) {// don't let one listener leave the invocation in a bad stateCLog.e("Caught runtime exception from ITestInvocationListener");CLog.e(e);}}}

Then obtain the device_options object and set it to itestdevice. Call the prepareandrun (config, device, info, rescheduler); method.


Private void prepareandrun (iconfiguration config, itestdevice device, ibuildinfo info, irescheduler reschedable) throws throwable {// use the junit3 logic for handling exceptions when running teststhrowable exception = NULL; try {// If (config. getcommandoptions (). isneedprepare ()&&! Isrepeat) {dosetup (config, device, Info); // The isrepeat = true;} else {clog. loganddisplay (loglevel. debug, String. format ("No need to flash, derect to run case");} // run caseruntests (device, info, config, reschedsts);} catch (throwable running) {exception = running;} finally {try {If (config. getcommandoptions (). isneedteardown () {doteardown (config, device, info, exception) ;}} catch (throwable tea Ringdown) {If (exception = NULL) {exception = tearingdown ;}} if (exception! = NULL) {Throw exception ;}}

In this method, first obtain whether prepare is required according to performance_options. If necessary, call the target_prepare class to prepare for the work. If not, call the runtests method directly.


private void runTests(ITestDevice device, IBuildInfo buildInfo, IConfiguration config, IRescheduler rescheduler) throws DeviceNotAvailableException {List<ITestInvocationListener> listeners = config.getTestInvocationListeners();for (IRemoteTest test : config.getTests()) {if (test instanceof IDeviceTest) {((IDeviceTest) test).setDevice(device);}test.run(new ResultForwarder(listeners));}}

The above method calls the class configured by tests to catch up with the run method in the call to start the test. After the test is completed, perform teardown.







CTS framework resolution (7)-scheduling room for task execution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.