NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to synchronize for-loop in batch testplan?

Hello,

i am running a batch model with 4 testsockets.

In my testplan there is a for loop with 10 loops.

Currently when running the testplan it happens that the four testsockets just execute the forloop as fast as possible and dont care about the other three testsockets.

How can i change the for loop so that for each loop the test sockets must wait for all testsockets are finished with the last loop before starting the next loop?

Current idea is to create an array with size = number of testsocks.

This array is initialized with 0s

After the for loop is ended i set the variable to 1

before next loop i check if all four are set to 1

 

Somethig like:

 

Clear StationGlobals.Finished[ ] = 0,0,0,0

for

   #Wait for StationGlobals.Finished[0..3] == 1 (if yes then clear them and continue)

   Execute Test

   #Set StationGlobals.Finished[TestSockets.MyIndex] = 1)

end loop

 

How can this be done better?

 

Thx

0 Kudos
Message 1 of 9
(4,129 Views)

There are likely several approaches that you could implement that would utilize built-in TestStand features to accomplish your stated goal. One such approach (attached) would be to use a Rendezvous step to ensure all TestSockets must rendezvous at the end of the loop before continuing.

 

Please let us know if this covers your stated goals.

 

-Jeff

Message 2 of 9
(4,119 Views)

Use a rendezvous step right before end loop.  Easy peasy.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 3 of 9
(4,116 Views)

I don't think a rendezvous would be the first choice in this case.

 

If you are running in batch, you can just set Step Properties>>Synchronization>>Batch Synchronization to Parallel (or Serial) to force a rendezvous at any step. No need to create an actual Rendezvous and it should still work even if a socket is disabled, errors out, or is terminated.

0 Kudos
Message 4 of 9
(4,109 Views)

Thanks you. This works.

What if i want to use a second Rendevouz?

Do i have to execute another "Create Rendevouz" with a new Name OR can i just put a second "Operation: Rendevouz" teststep with the already created Name at another position?

 

##########################

Create Rendevouz "Loop"

 

forloop1

do something

Rendevouz1

end

 

forloop2

do something

Rendevouz2

end

##########################

0 Kudos
Message 5 of 9
(4,082 Views)

you could try to surround the loops with Batch Synchronization 

CLAD, CTD
0 Kudos
Message 6 of 9
(4,067 Views)

I changed my mind and am siding with James on this one.  I wouldn't use the rendezvous step.  Batch Synchronization is much safer.  Why?  Because you are using the existing batch threads and you don't need to explicitly create a rendezvous.  Here is a screenshot on how to set the synchronization for a step.  Just do it on your For step.  Check out the attachment.  NOTE: this only works if you are using the Batch Model.

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 7 of 9
(4,066 Views)

As jiggawax  said paralell will work  but you may have another option.

 

do you want to do those loops in parallel on each test socket... or do you rather have Test socket  1 do all the loops.. then Test socket 2 do all the loops as a sequence. Testand will wait to all test sockets to finish looping to continue..

 

you can use the batch synchronization and use "

 

 

  • Serial (One Thread at a Time)—Ensures that each thread in a batch executes the section sequentially and in the order you specify when you create the batch. When all threads in a batch arrive at their respective instances of the Enter step, TestStand releases one thread at a time in ascending order according to the order number you assigned to the threads when you added them to the batch with the Batch Specification step type. As each thread executes the Exit step for the section, the next thread in the batch proceeds from the Enter step. After all threads in the batch arrive at the Exit step, they exit the section together.

 

Depending on you application  you have many options now on the table...

CLAD, CTD
0 Kudos
Message 8 of 9
(4,062 Views)

You do not need to execute a second "Create Rendezvous" to ensure that your scenario will work; you can simply use a second "Operation: Rendezvous" step in the second loop that references the originally created Rendezvous. However, after testing the general Rendezvous approach further, it is not immune to the following corner cases: when a test socket is disabled, errors out, or is terminated (as stated above by James_Grey). Because the "Create Rendezvous" requires a 'Number of Threads Per Rendezvous' expression, the above mentioned scenarios can cause a deadlock (if your Rendezvous does not use a timeout).

 

The approach mentioned by James_Grey is likely a better approach because Batch Syncronization is more immune to the above stated corner cases. Attached is an example of this approach.

 

-Jeff

0 Kudos
Message 9 of 9
(4,061 Views)