FB_Test  Function Block

This function block holds all data that defines a test.


Variables

Name Type Description
TestName T_MaxString
TestIsFinished BOOL
TestIsSkipped BOOL This is set to true, if test is disabled (by putting the string "disabled_" in front of the test name
NumberOfAssertions UINT
TestOrderNumber UINT(0..GVL_Param_TcUnit.MaxNumberOfTestsForEachTestSuite)
TestIsFailed BOOL Indication of whether this test has at least one failed assert
AssertionMessage T_MaxString Assertion message for the first assertion in this test
AssertionType E_AssertionType Assertion type for the first assertion in this test
StartedAt LWORD Temporary variable to calculate the actual duration of the test, the value holds the cpu cycle counter when a test is started in 100ns precision
Duration LREAL Duration of the test in seconds

Methods

GetAssertionMessage INTERNAL
Implementation
GetAssertionMessage := AssertionMessage;
GetAssertionType INTERNAL
Implementation
GetAssertionType := AssertionType;
GetDuration INTERNAL
Implementation
GetDuration := Duration;
GetName INTERNAL
Implementation
GetName := TestName;
GetNumberOfAssertions INTERNAL
Implementation
GetNumberOfAssertions := NumberOfAssertions;
GetTestOrder INTERNAL

Gets in which order/sequence relative to the order tests should this test be executed/evaluated.

Implementation
GetTestOrder := TestOrderNumber;
IsFailed INTERNAL
Implementation
IsFailed := TestIsFailed;
IsFinished INTERNAL
Implementation
IsFinished := TestIsFinished;
IsSkipped INTERNAL
Implementation
IsSkipped := TestIsSkipped;
SetAssertionMessage INTERNAL

Sets the assertion message. If one already exists, it's not overwritten as we keep the first assertion in the test

Parameters

Name Type Description
AssertMessage T_MaxString
Implementation
IF LEN(STR := AssertionMessage) = 0 THEN
    AssertionMessage := AssertMessage;
END_IF
SetAssertionType INTERNAL

Sets the assertion type. If one already exists, it's not overwritten as we keep the first assertion in the test

Parameters

Name Type Description
AssertType E_AssertionType
Implementation
IF AssertionType = E_AssertionType.Type_UNDEFINED THEN
    AssertionType := AssertType;
END_IF
SetFailed INTERNAL
Implementation
TestIsFailed := TRUE;
SetFinishedAndDuration INTERNAL

Parameters

Name Type Description
FinishedAt LWORD CPU cycle counter with 100ns precision
Implementation
TestIsFinished := TRUE;
Duration := LWORD_TO_LREAL(FinishedAt - StartedAt) * GVL_TcUnit.HundredNanosecondToSecond; // Seconds
SetName INTERNAL

Parameters

Name Type Description
Name T_MaxString
Implementation
TestName := Name;
SetNumberOfAssertions INTERNAL

Parameters

Name Type Description
NoOfAssertions UINT
Implementation
NumberOfAssertions := NoOfAssertions;
SetSkipped INTERNAL

Sets the test case to skipped

Implementation
TestIsSkipped := TRUE;
SetStartedAtIfNotSet INTERNAL

Parameters

Name Type Description
Timestamp LWORD CPU cycle counter with 100ns precision
Implementation
IF StartedAt = 0 THEN
    StartedAt := Timestamp;
END_IF
SetTestOrder INTERNAL

Sets in which order/sequence relative to the order tests should this test be executed/evaluated.

Parameters

Name Type Description
OrderNumber UINT(0..GVL_Param_TcUnit.MaxNumberOfTestsForEachTestSuite)
Implementation
TestOrderNumber := OrderNumber;

Used by

Declaration source
// This function block holds all data that defines a test.
FUNCTION_BLOCK FB_Test
VAR
    TestName : T_MaxString;
    TestIsFinished : BOOL;
    TestIsSkipped : BOOL; // This is set to true, if test is disabled (by putting the string "disabled_" in front of the test name
    NumberOfAssertions : UINT;

    (* In which order/sequence relative to the order tests should this test be executed/evaluated.
       A value of 0 means it is not defined by TEST_ORDERED() but by un-ordered test (TEST()).
       A value <> 0 tells in which order this test will be executed/evaluated. The lower the number, the earlier it will execute. *)
    TestOrderNumber : UINT(0..GVL_Param_TcUnit.MaxNumberOfTestsForEachTestSuite); 

    // Failure parameters. If TestIsFailed is TRUE, the other parameters will hold values as well
    TestIsFailed : BOOL; // Indication of whether this test has at least one failed assert
    AssertionMessage : T_MaxString; // Assertion message for the first assertion in this test
    AssertionType : E_AssertionType; // Assertion type for the first assertion in this test

    StartedAt : LWORD; // Temporary variable to calculate the actual duration of the test, the value holds the cpu cycle counter when a test is started in 100ns precision
    Duration : LREAL; // Duration of the test in seconds
END_VAR