Programmatically Abort Execution upon Step Failure

Updated Jun 12, 2023

Environment

Software

  • TestStand

I want to programmatically abort an execution after a test step fails. This is necessary if the test is a critical measurement, or is somehow related to the safe running of the manufacturing line. How do I programmatically abort execution upon a step failure?

How do I change what step a sequence goes to after it fails?


There are two approaches to this problem that can be implemented quickly on any development machine. 

Option 1: Using a PostStep Callback (TestStand 1.0.3 or older):
  1. Open the sequence file for the test that needs the abort behavior and go to Edit»Sequence File Callbacks.
  2. Select the SequenceFilePostStep callback from the list and press the Add button to include the callback in the file. Click OK to return to your sequence file. 
Note: The SequenceFilePostStep callback sequence will be run by TestStand once after every step in the client sequence. If you implement the callback in the process model, substitute the SequenceFilePostStep callback for the ProcessModelPostStepcallback for best results. For more information about this and other callbacks, please see the TestStand Help.
  1. ​Open the callback sequence by selecting it from the View ring control and select ActiveX Automation Adapter from the step adapter ring control. 
  2. Add an Action step to your callback sequence. Right-Click on the new step and select Properties from the context menu.
  3. Select Preconditions from the step properties window. In the Preconditions dialog choose Insert New Expression.
  4. Enter the expression StrComp(RunState.Caller.PreviousStep.Result.Status, "Failed")==0 into the Edit/View Expression box either by typing it in directly or using the Browse button to access Functions and Properties. This will force the step to execute only when the last executed test step reports a failure. Click OK to return to the step properties window and select Specify Module to open up the Edit Automation Call dialog. 
  5. Configure the ActiveX Reference field to look at RunState.Execution either by typing it in, or by using the Browse button to navigate through the RunState properties.
  6. Use the Automation Server ring control and select the TestStand API.
  7. Use the Object Class ring control and select the Execution class.
  8. Uncheck the Create Object checkbox.
  9. Under the Call Method or Access Property heading, use the Action ring control to select Call Method and use the Method ring control to select the method Abort. Click the OK button to save the step settings. Now whenever the SequenceFilePostStep callback is executed and a failure is detected, the sequence will abort.
Option 2: PostStepFailure Callback (TestStand 2.0 and newer): 
  1. Open the sequence file for the test that needs the abort behavior and go to Edit»Sequence File Callbacks.
  2. Select the SequenceFilePostStepFailure callback from the list and click the Add button to include the callback in the file. Click OK to return to your sequence file. 
Note: The SequenceFilePostStepFailure callback sequence will be run by TestStand only after a step fails in your test sequence. If you implement the callback in the process model, substitute the SequenceFilePostStepFailure callback for the ProcessModelPostStepFailure callback for best results. For more information about this and other callbacks, please see the TestStand Help.
  1. ​Open the callback sequence by selecting it from the View ring control and select ActiveX/COM Adapter from the step adapter ring control. 
  2. Add an Action step to your callback sequence. Right-Click on the new step and select Properties from the context menu. Choose Specify Module from the new window to edit the step.
  3. Configure the ActiveX Reference field to look at RunState.Execution either by typing it in, or using the Browse button to navigate through the RunState properties.
  4. Use the Automation Server ring control to select the TestStand API.
  5. Use the Object Class ring control to select the Execution class.
  6. Uncheck the Create Object checkbox.
  7. Under the Call Method or Access Property heading, use the Action ring control to select Call Method and use the Method ring control to select the function Abort. Click the OK button to save the step settings. Now whenever the SequenceFilePostStepFailurecallback is executed, the sequence will abort.

Additional Information

For both solutions, an easy modification would be to have the execution's abortion dependent upon some user input. For example, consider including a message popup step before the ActiveX call where the user chooses whether to accept the failure or abort the sequence. The result of this message popup could then be used as an additional precondition on the action step. Another modification would be to choose some action aside from Abort. Check the user manual for the differences between AbortTerminate, and Break to see which behavior is the best for your sequence.