Adding Conditions to Control When Tests Run
There can be times when you want a test or a group of tests to only run when certain criteria are met. As an example, you may want to set a condition that will bypass the memory programming step if any of the preceding tests failed.
Conditions are represented in the test list by a question-mark as shown in Figure 16. The condition is evaluated just before the group or test is due to be executed, and the tests are only performed if the condition evaluates to TRUE.

Figure 16: Conditions that Control When Tests Run
In the example above, the nested conditions Verify Programmed Data and Full Program Required will only be evaluated if the Program Flash condition at the top of the hierarchy is TRUE.
To set a condition:
- Go to the XJRunner Setup screen
- Select the test or test group from the test list (see Figure 17)
- Click Add Condition... to open the Add Condition dialog box
- Enter a condition as described below
- Click OK in the Add Condition dialog box
- Save the project

Figure 17: Adding a Condition for When a Test Runs
Entering a Condition
The condition is created in the Add Condition dialog by a mix of typing and inserting global functions and/or the results of previous tests:

Figure 18: Creating a Condition
Creating Expressions Based on the Result of a Previous Test
Functions related to the result of a previous test can be inserted into the condition by clicking Insert Test Function. This opens the dialog box shown in Figure 19. For example, to insert HAS_PASSED("XJDemo.IC11.IIC_CheckPresent") into the condition, select the test IC11.IIC_CheckPresent from the list, select the Pass radio button, and click OK.

Figure 19: Using the Result from a Previous Test in a Condition
However, it is important to ensure you do not attempt to evaluate the result of a previous test if that previous test did not run; otherwise, a runtime error would occur. It is therefore good practice only to use the result of another test in conjunction with a function that ensures the test executed, such as HAS_RUN(). This can be done by combining the two expressions using a Boolean operator as described next.
The most commonly used Boolean operator is a short-circuiting logical AND, represented by &&?. If the first part of the expression evaluates to FALSE, the second part is not evaluated.
Short circuiting operators are useful when combining functions such as HAS_PASSED() with HAS_RUN() because they can avoid both halves of the expression being evaluated. For example, the condition:
HAS_RUN(test) &&? HAS_PASSED(test)
does not attempt to evaluate HAS_PASSED(test) if the test has not run (i.e. if HAS_RUN(test) returns FALSE). This prevents a runtime error.
The HAS_PASSED() operator can also be used to avoid running a test that it is already known will fail. Consider an example from the test list above (Figure 17): the test group that functionally checks an I2C ADC includes a test to confirm it responds to its address on the I2C bus and another that takes a reading from one of its ADC channels. Because there is no point in attempting to read a value from the device if it is not responding, it is sensible to add a condition to the second test that ensures it only runs if the bus check passed. This is done using the following expression:
HAS_RUN("XJDemo.IC11.IIC_CheckPresent") &&? HAS_PASSED("XJDemo.IC11.IIC_CheckPresent")
- All the operators that can be used are listed in the XJTAG Help system.
- The Boolean AND and OR operators && and || should not be used when setting up conditions because they are not short-circuiting in XJEase and therefore carry the risk of causing run-time errors.
Creating Expressions with Global Variables
Global variables (both built-in and those from circuit code files) can also be used in a condition. They are inserted using the Insert Global button (Figure 18 above).
XJEase has a built-in global called TEST_FAIL_COUNT that is updated after every test is run and is only zero if all tests have passed. It can be used, for instance, to avoid trying to program firmware if any of the preceding tests have failed. In that example, the condition used for the programming test would be: TEST_FAIL_COUNT = 0.
Continuing After a Test Failure
By default, if a test fails, XJRunner is set to stop at that point rather than continuing through the test list. However, if you are using conditions that will stop tests executing that you wouldn't want to run on a faulty board (e.g. to stop a failing board from being programmed), it is recommended that you override the default. Allowing testing to continue after a failure in this situation can be beneficial because the additional testing might provide useful insights into the cause of the failure, and the conditions will prevent unwanted tests from running. When a condition is added, you will therefore be asked if you would like to override the default setting by enabling Continue on Test Failure.
XJTAG v4.1.101