FB_TestDurationMeasurement Function Block
Extends TcUnit.FB_TestSuite
This testsuite tests that durations are calculated correctly by different types of test cases Tests are considered passing if the duration returned is reasonablly close to the expected value.
Methods
TestOrderedTest30msDurationMeasuredCorrectly
PRIVATE
Implementation
IF TEST_ORDERED('TestOrderedTest30msDurationMeasuredCorrectly') THEN
DelayTimer(IN := TRUE, PT := T#30ms);
IF delayTimer.Q THEN
// Write the approximate duration through an assert message for use by the verifier
AssertEquals_LREAL(0, 0.03, 0, 'Duration');
TEST_FINISHED();
END_IF
END_IF
TestRegularTestDurationMeasuredCorrectly
Implementation
TEST('TestRegularTestDurationMeasuredCorrectly');
IF NOT TestExecuted THEN
// Introduce a delay and store the time it takes for evaluation by the test
// use an assert statement as the delay because it takes quite a bit of time
// double the value to account for the second assert which will print the message
TestStartedAt := F_GetCpuCounterAs64bit(GVL_TcUnit.GetCpuCounter);
AssertEquals_LREAL(0, 10, 0, 'Duration for calculation');
TestDuration := LWORD_TO_LREAL(F_GetCpuCounterAs64bit(GVL_TcUnit.GetCpuCounter) - TestStartedAt) * GVL_TcUnit.HundredNanosecondToSecond * 2.0;
TestExecuted := TRUE;
END_IF
// Write the duration through an assert message for use by the verifier
AssertEquals_LREAL(0, TestDuration, 0, 'Duration');
TEST_FINISHED();
TestNamedTest20msDurationMeasuredCorrectly
Implementation
TEST('TestNamedTest20msDurationMeasuredCorrectly');
delayTimer(IN := TRUE, PT := T#20ms);
IF delayTimer.Q THEN
// Write the approximate duration through an assert message for use by the verifier
AssertEquals_LREAL(0, 0.02, 0, 'Duration');
TEST_FINISHED_NAMED('TestNamedTest20msDurationMeasuredCorrectly');
END_IF
Used by
Declaration source
(* This testsuite tests that durations are calculated correctly by different types of test cases
Tests are considered passing if the duration returned is reasonablly close to the expected value.
*)
FUNCTION_BLOCK FB_TestDurationMeasurement EXTENDS TcUnit.FB_TestSuite