Function under Test - Manual - AxUnit - AxUnit - AxUnit,

AxUnit (legacy) CLI Tool (test)

Portfolio
SIMATIC AX
Product
AxUnit
Software version
2.0.9
Edition
08/2025
Language
English (original)
Package Name
@ax/axunit-docs

Let us consider rect_sig function generating rectangle signal defined by the current system time and given period.

/**
* Generates rectangle signal of given period
* 1     -----   -----
*       |   |   |   |   |
* 0 -----   -----   -----
* ----------|--------------------> t
*         period
*/
FUNCTION rect_sig : int
    VAR_INPUT
        period: TIME;
    END_VAR
    VAR_TEMP
        current: LTIME;
        half_of_period: TIME;
        elapsed_in_period: TIME;
    END_VAR

    current := Siemens.Simatic.S71500.Clocks.GetOperatingTime(); // system function to be mocked

    half_of_period := period / 2;
    elapsed_in_period := TO_TIME(TO_LINT(current) MOD TO_LINT(period));

    if (elapsed_in_period > half_of_period ) then
        rect_sig := 1;
        return;
    end_if;

    rect_sig := 0;
END_FUNCTION

This function internally calls Siemens.Simatic.S71500.Clocks.GetOperatingTime function. In order to test all execution paths of rect_sig there is a need to control the value returned by Siemens.Simatic.S71500.Clocks.GetOperatingTime.