11-22-2011 04:06 AM
Hi there.
How do I reset the Teststand engine?
I want to execute quite an amount of tests. One test job is divided into the Teststand Test execution and the later reporting of the TS report into our DB.
Therefore I implemented a dll in C#.
In it the Teststand Execution is encapsulated in an class (TSExecTask.cs). In it's constructor the TS engine is created.
ts_Engine=newEngine ();
and the testsequence is loaded
ts_SeqFile=this.ts_Engine.GetSequenceFileEx ( SeqFilePath,
GetSeqFileOptions.GetSeqFile_DoNotRunLoadCallback,
TypeConflictHandlerTypes.ConflictHandler_Error );
and later in the Execute methode of my class the test will be executed.
After the execution I am polling for the UIMessages in a loop and exiting it when I get a EndExecution on ts_Execution.
ts_Execution=ts_Engine.NewExecution ( this.ts_SeqFile,
"Single Pass",
ts_Engine.GetStationModelSequenceFile ( outstrTemp ),
false,
ExecutionTypeMask.ExecTypeMask_CloseWindowWhenDone,
null, null, null );
Then the class needs to unload execution and sequence in the overrides IDispose method.
ts_Execution=null;
ts_SeqFile.UnloadModules ();
bool unloaded=ts_Engine.ReleaseSequenceFileEx ( ts_SeqFile, 0);
ts_SeqFile=null;
//ts_ProcessModelFile.UnloadModules ();
//unloaded=ts_Engine.ReleaseSequenceFileEx ( ts_ProcessModelFile, 0 );
ts_Engine.UnloadAllModules ();
ts_Engine.UnloadTypePaletteFiles ();
ts_Engine=null;
And there is my Problem.
The Execution is not unloaded. Although returning true the SequenceFile is not gone and on executing the next test. Teststand tells me that
I want to basically reset the Engine for every test I am to execute. Thereby freeing the memory by calling the GC.Collect on the calling TSExecTask class.
Is there a way to releasing all sequence files and unloading all executions of an engine WITHOUT using the annoying ApplicationManager?
11-22-2011 04:13 AM
I tried to shutdown the engine.
ts_Engine.ShutDown ( false);
bool engineGone=false;
UIMessage uimsg=null;
bool firstPassed=false;
while ( !engineGone )
{
if ( !ts_Engine.IsUIMessageQueueEmpty )
{
uimsg=ts_Engine.GetUIMessage ();
if ( uimsg.Event==UIMessageCodes.UIMsg_ShutDownComplete )
{
if( firstPassed )
engineGone=true;
firstPassed=true;
ts_engine.Shutdown(true);
}
uimsg.Acknowledge ();
System.Threading.Thread.Sleep ( 100);
}
}
But then the Engine cannot be instanciated.
11-28-2011 04:28 AM
Hello Marcos,
I tried to reproduce the error you are seeing but haven't had any luck so far. I have a few questions to better understand your problem.
1. Could you please give some more information on what this Sequence does? It seems to be a process model.
2. Why do you call the UnloadModules() and UnloadAllModules() methods?
3. It looks like the Sequence you load keeps running in the background when you unload. Do you want it to abort that sequence? Should it come to an end by itself? Use the function WaitForEndEx() to help better understand when the sequence stops so you can unload it.
Regards,
Joseph Tagg
11-28-2011 06:55 AM
1. ...The Sequence is a individual testing sequence nothing extraordinary . Quite basic actually.
Why should it be a processmodel?2. ...
I am calling the unload methods to ensure that dependecies are released ( dlls, vi, and stuff)
3. ...
After I am starting the execution - the way i mentioned - i am entering a while loop, in which i am checking the ui messages.
(Terminating the while loop when a EndExecution event happed that contains my execution.
I used to wait for the execution with that method until i read this in the documentation
WaitForEndEx Method
Syntax
Execution.WaitForEndEx ( millisecondTimeOut, processWindowsMsgs = True, [stepToStoreResultsIn], [callingSequenceContext])
Remarks
This method is not meant to be used by a user interface or sequence editor, as it does not process UIMessages. Instead, use this method from a step to synchronize with another execution
Also i wanted to avoid to handle the ui messages in a separate thread.
The basic question is how to uninit/ unload the engine properly.Or how to find out which execution are still running an which sequence files are still loaded. WITHOUT the ApplicationMgr?
12-05-2011 08:10 AM
Hi Marcos,
in your case it looks like you'll have to use the application manager to do what you want.
Regards,
Joseph
12-05-2011 04:56 PM
Hi Marcos,
I notice that you are polling the UI message queue to check for the shutdown event. Usually, the best way to handle UI messages is to create an event callback for the engine object (the UIMessageEvent event). With this implementation, you could simply call the final shutdown call in the callback, something like:
private void UImessageEvent(object sender, eventArgs e) { if (e.uiMsg.Event == UIMessageCodes.UIMsg_ShutDownComplete) ts_engine.Shutdown(true); }
If you do want to use the polling, make sure that you enable autopolling, as described in the help:
Engine.UIMessagePollingEnabled
You may also want to try calling engine.terminateall() if you are still seeing open executions.
Hope this helps!