CTS Framework Parsing (7)-Control room of task execution

Source: Internet
Author: User
Tags config prepare throw exception throwable
testinvocation


/** * {@inheritDoc} */@Override public void Invoke (Itestdevice device, iconfiguration config, Irescheduler reschedu
			Ler) throws Devicenotavailableexception, Throwable {try {mstatus = "fetching build";
			Config.getlogoutput (). Init ();
			Getlogregistry (). Registerlogger (Config.getlogoutput ());
			Ibuildinfo info = null; if (Config.getbuildprovider () instanceof idevicebuildprovider) {info = ((idevicebuildprovider) config.getbuildprovide
			R ()). Getbuild (device); } else if (Config.getbuildprovider () instanceof Ideviceconfigbuildprovider) {//call config to get <build_provid in Cts.xml file The corresponding class in the er> tag is then obtained by calling Getbuild Ibuildinfo Object info = ((ideviceconfigbuildprovider) Config.getbuildprovider ()).
			Getbuild (device, config);
			} else {info = Config.getbuildprovider (). Getbuild (); if (info! = NULL) {//System.out.println ("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 ());
				Get the test options in the <test> configuration item and inject it into info injectbuild (info, config.gettests ()); if (shardconfig (config, info, rescheduler)) {clog.i ("invocation for%s have been sharded, rescheduling", Device.getse
				Rialnumber ());
					} else {device.setrecovery (config.getdevicerecovery ());
					Prepare the brush machine, start case performinvocation (config, device, info, rescheduler);
				Exit here, depend on performinvocation to deregister//logger return;
				}} else {mstatus = "(no build to test)";
				CLOG.D ("No Build to test");
			Rescheduletest (config, rescheduler);
			}} catch (Buildretrievalerror e) {CLOG.E (e); /* * Because this was buildretrievalerror, so does not generate test * result//Report an empty invocation Error is sent to * listeners Startinvocation (config,Device, E.getbuildinfo ());  * don ' t want to use #reportFailure, since that'll call * buildnottested for (Itestinvocationlistener listener : * Config.gettestinvocationlisteners ()) {* listener.invocationfailed (e);} reportlogs (Device, * Config.gett
			 Estinvocationlisteners (), Config.getlogoutput ()); * invocationsummaryhelper.reportinvocationended (* config.gettestinvocationlisteners (), 0);
			 Return
		*/} catch (IOException e) {CLOG.E (e);
		}//Save current log contents to global log getlogregistry (). Dumptogloballog (Config.getlogoutput ());
		Getlogregistry (). Unregisterlogger ();
	Config.getlogoutput (). Closelog (); }


It is called control room because it is the remaining component of the 9 component that is going step-by-step, and the components and components do not know each other's existence, only testinvocation know. It gets the object through the reflection mechanism, creates the object separately, and then invokes the interface method in it to get what it wants and then pass it to the next component. The above method can be seen, it first get BuildProvider object. Call the Getbuild object to get the Ibuildinfo object. In this program, we are actually calling the Getbuild method of Ctsbuildprovider.

If info is not null: then inject ibuildinfo into the test task, determine if the task can be split, if not, register the device recovery class, and then jump to the Performinvocation method.

If info is null: Prompt for no executable build, call Irescheduler.reschedulecommand () to retry.


/** * Performs the invocation * * @param config * The {@link iconfiguration} * @param device * The {@link Itestdevice} to use. May is <code>null</code> * @param info * The {@link ibuildinfo} */private void PERFORMINVOC ation (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 build and run case Prepareandrun (config, device, info, rescheduler); } catch (Builderror e) {CLOG.W ("Build%s failed on device%s. Reason:%s", Info.getbuildid (), Device.getserialnumber ()
			, e.tostring ());
			Takebugreport (device, Config.gettestinvocationlisteners (), 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 it device.waitfordeviceonline (); } catch (Devicenotavailableexception e) {//Log a warning here's captured before Reportlogs is called CLOG.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//bugreport Takebugreport (device, Config.gettestinvoca
			Tionlisteners (), 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's captured before Reportlogs is called CLOG.W ("unexpected
			Exception when running invocation:%s ", e.tostring ());
			Reportfailure (E, config.gettestinvocationlisteners (), config, info, rescheduler);
		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 report invocationsummaryhelper.reportinvocationended (Config.gettestinvocationlisteners (), Elaps
				Edtime); }} finally {Config.getbuildprovider ().CleanUp (info); }
		}
	}

Start all listeners first, starting with a notification function.


/**
	 * Starts the invocation.
	 * <p/>
	 * starts logging, and informs listeners that invocation have 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 of a bad state
				clog.e ("Caught Runtim E exception from Itestinvocationlistener ");
				CLOG.E (e);}}
	

Then get the Device_options object, set to Itestdevice. Then call Prepareandrun (config, device, info, rescheduler);


private void Prepareandrun (iconfiguration config, itestdevice device, Ibuildinfo info, Irescheduler rescheduler) throws T hrowable {
		//Use the JUNIT3 logic for handling exceptions when running tests throwable
		exception = null;

		try {
			//
			if (Config.getcommandoptions (). Isneedprepare () &&!isrepeat) {
				dosetup (config, device, info);
				The next time you start, no longer brush the machine
				isrepeat = true;
			} else{
				Clog.loganddisplay (Loglevel.debug, String.Format ("No need to Flash,derect to run case");
			}
			Run case
			runtests (device, Info, config, rescheduler),
		} catch (Throwable running) {
			exception = running;< c15/>} finally {
			try {
				if (config.getcommandoptions (). Isneedteardown ()) {
					doteardown (config, device, info, exception);
				}
			} catch (Throwable tearingdown) {
				if (exception = = null) {
					exception = Tearingdown;
				}}
		}
		if (Exception! = null) {
			throw exception;
		}
	}

In this method, we first get the need prepare according to cmd_options, if necessary, call the Target_prepare class to do the preparation, if not needed, call the Runtests method directly


private void Runtests (Itestdevice device, ibuildinfo buildinfo, iconfiguration config, Irescheduler rescheduler) throws D evicenotavailableexception {
		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 invokes the tests configured class to chase the Run method inside the call to start the test. After the test is done, do teardown work.

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.