Triggering code when tests complete

In Version 3.0.2 and later an additional Settings tab has been added to the XJRunner Setup screen in XJDeveloper.  This tab, labelled “Functions”, includes the options of having a function which gets run after every test function completes (a post-function function), as well as a function that gets run after all testing completes (a post-testing function).

Post-function Function

The post-function function is run after each selected test function in the list no matter how the function completes or is terminated. The selected function must be a function with two input arguments and no outputs:

PostFunction( INT stopMode, INT result )()

The stopMode indicates the reason why the test ended. For example this could be because the function returned, or it could be because the user pressed the stop button. The result indicates the return value from the completed test function.

This can be useful when a custom log file is required. For example, the following code will append a line to a CSV file with the result from each test as it completes:

PostFunction(INT stopMode, INT result)()
// Write to custom log
FILE log;

FOPEN("customlog.csv", "a")(log);
IF FERROR() THEN
PRINT("Unable to open customlog.csv");
EXIT(RESULT_FAIL);
END;

FWRITE(log, CURRENT_TEST_GROUP + "," + CURRENT_TEST_FUNCTION + "," + FORMAT(result, "%i") + "n");
IF FERROR() THEN
PRINT("An error occurred when writing to customlog.csv");
EXIT(RESULT_FAIL);
END;

FCLOSE(log);
END;

Post-testing Function

The post-testing function is run once after all selected test functions have been completed. The selected function must be a function with two input arguments and no outputs:

PostTesting( INT stopMode, INT failureCount )()

The stopMode indicates how the tests terminated overall. For example this could be because all the functions completed normally (although some tests may have failed), or it could be because the user pressed the stop button. The failureCount indicates how many test functions failed.

This can be useful when particular actions need to occur to complete the testing. This can include resetting or powering-down the board being tested, or appending an entry to a summary log file keeping track of the final result for each board tested.

On the Functions tab there is also a check box “Run after log file has been written”. When this is not selected, any text printed to the screen during the post-testing function will also be added to the active log file. In this mode, the contents of the log file should not be manipulated from within the post-testing function. If the post-testing function needs to use the contents of the log file then this check box should be enabled. In this mode, the post-testing function can still print to the screen but this text will not be added to the active log file. This then enables the log file to be used in various ways. For example it can be copied to a server:

CONST STRING LogFileDest := "\\server\share\logs";

PostTesting(INT stopMode, INT failureCount)()
INT result;

IF WIDTHOF(LOG_FILE_PATH) = 0 THEN
PRINT("Log file cannot be accessed.n");
PRINT("Check that logging has been enabled and the post-testing function ");
PRINT("has been set to run after the log file has been writtenn");
RETURN;
ELSIF !FEXISTS(LOG_FILE_PATH) THEN
PRINT("Unable to copy log file - file "", LOG_FILE_PATH, "" does not existn");
RETURN;
END;

// Copy log file to server share
PRINT("Copying log file from ", LOG_FILE_PATH, " to ", LogFileDest, "n");
SYSTEM("copy /y "" + LOG_FILE_PATH + "" "" + LogFileDest + """)(result);
END;

Alternatively, the log file can be printed:

CONST STRING PRINTER_NAME := "PrinterName";

PostTesting(INT stopMode, INT failureCount)()
INT result;

IF WIDTHOF(LOG_FILE_PATH) = 0 THEN
PRINT("Log file cannot be accessed.n");
PRINT("Check that logging has been enabled and the post-testing function ");
PRINT("has been set to run after the log file has been writtenn");
RETURN;
ELSIF !FEXISTS(LOG_FILE_PATH) THEN
PRINT("Unable to print log file - file "", LOG_FILE_PATH, "" does not existn");
RETURN;
END;

SYSTEM("notepad.exe /PT "" + LOG_FILE_PATH + "" "" + PRINTER_NAME + """)(result);
END;

This uses Notepad to print the log file, so the font used can be altered by running Notepad and changing the font on the Format menu. Close Notepad and then the same font will be used to print all log files in the future.

Note: by default connection test is set to the most verbose level of error detail. If many connection errors are detected then this can produce a long log file. To avoid creating such long files, the Error Detail Level can be changed to provide less detailed information.


Ready to get started? Try XJTAG

computer

See XJTAG in action.

Our experts will be happy to show you how the XJTAG tools can help you diagnose faults on your board as well as cutting test development and repair time.

Ask for a Demo

telephone

Questions? We'll call you back.

We're here to help. Enter your contact details and one of our test specialists will call you back shortly.


workstation

Get a free test setup.

Evaluate the XJTAG system with full functionality for 30 days and get the first test project set up for your board – for free. No obligation to purchase.

Get started now

Join world leading companies using XJTAG Boundary Scan