Skip to content

Commit

Permalink
Implemented new way of execute tests RUN_IN_SEQUENCE().
Browse files Browse the repository at this point in the history
This executes the test suites one after the other (as opposed to RUN() which executes all test suites in parallel).
For more details, see #95.

Also changed method access modifiers for all methods in TcUnit so that none is left with the default (PUBLIC).
Incremented version of TcUnit to 1.2.0.0.
  • Loading branch information
sagatowski committed Dec 30, 2020
1 parent c4cd949 commit d152c95
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ That's fantastic! But please read the [CONTRIBUTING](CONTRIBUTING.md) first.
**Found a bug or want to discuss an idea?**
Check the [open](https://github.com/tcunit/TcUnit/issues) and [closed](https://github.com/tcunit/TcUnit/issues?q=is%3Aissue+is%3Aclosed) issues.
If your issue does not already exist, create a [new](https://github.com/tcunit/TcUnit/issues/new).
For general idea/discussions, use the [discussions](https://github.com/tcunit/TcUnit/discussions).
For general ideas/discussions, use the [discussions](https://github.com/tcunit/TcUnit/discussions).
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ VAR
//TestFinishedNamedDoesNotExist : FB_TestFinishedNamedDoesNotExist;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TcUnit.RUN();]]></ST>
<ST><![CDATA[(* There are two ways to run TcUnit test suites:
1. The RUN() will run all the test suites in parallel
2. The RUN_IN_SEQUENCE() will run the test suites in sequence (one-by-one, next one doesn't start until the previous one is finished)
Only use one of them at a time
*)
TcUnit.RUN();
//TcUnit.RUN_IN_SEQUENCE();]]></ST>
</Implementation>
</POU>
</TcPlcObject>
2 changes: 1 addition & 1 deletion TcUnit/TcUnit/POUs/FB_AdsAssertMessageFormatter.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FUNCTION_BLOCK FB_AdsAssertMessageFormatter IMPLEMENTS I_AssertMessageFormatter]
<ST><![CDATA[]]></ST>
</Implementation>
<Method Name="LogAssertFailure" Id="{48cbc6b0-5380-44b8-a045-57b6ad9f189d}">
<Declaration><![CDATA[METHOD LogAssertFailure
<Declaration><![CDATA[METHOD PUBLIC LogAssertFailure
VAR_INPUT
Expected : Tc2_System.T_MaxString;
Actual : Tc2_System.T_MaxString;
Expand Down
2 changes: 1 addition & 1 deletion TcUnit/TcUnit/POUs/FB_AdsLogStringMessageFifoQueue.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Error := NOT MemRingBuffer.bOk;]]></ST>
</Method>
<Method Name="WriteLog" Id="{4ca4d063-d389-4869-8fdb-ce7017f310dc}">
<Declaration><![CDATA[(* Writes a new data set into the ring buffer *)
METHOD PUBLIC WriteLog
METHOD INTERNAL WriteLog
VAR_INPUT
MsgCtrlMask : DWORD;
MsgFmtStr : Tc2_System.T_MaxString;
Expand Down
4 changes: 2 additions & 2 deletions TcUnit/TcUnit/POUs/FB_AssertArrayResultStatic.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ END_FOR]]></ST>
</Implementation>
</Method>
<Method Name="GetNumberOfArrayAssertsForTest" Id="{73e503e0-e1d1-4f6d-bdbf-ae50167481e7}">
<Declaration><![CDATA[METHOD PUBLIC GetNumberOfArrayAssertsForTest : UINT
<Declaration><![CDATA[METHOD INTERNAL GetNumberOfArrayAssertsForTest : UINT
VAR_INPUT
CompleteTestInstancePath : Tc2_System.T_MaxString;
END_VAR
Expand Down Expand Up @@ -202,7 +202,7 @@ GetNumberOfArrayAssertsForTest := NumberOfArrayAsserts;]]></ST>
the stored detection-count for this combination, create a new report and add +1 to the storage of
the detection-count.
*)
METHOD PUBLIC ReportResult
METHOD INTERNAL ReportResult
VAR_INPUT
ExpectedsSize : UDINT;
ExpectedsTypeClass : IBaseLibrary.TypeClass;
Expand Down
4 changes: 2 additions & 2 deletions TcUnit/TcUnit/POUs/FB_AssertResultStatic.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ END_FOR]]></ST>
</Implementation>
</Method>
<Method Name="GetNumberOfAssertsForTest" Id="{a073fba3-9c9c-44bc-b792-f90e25f50f64}">
<Declaration><![CDATA[METHOD PUBLIC GetNumberOfAssertsForTest : UINT
<Declaration><![CDATA[METHOD INTERNAL GetNumberOfAssertsForTest : UINT
VAR_INPUT
CompleteTestInstancePath : Tc2_System.T_MaxString;
END_VAR
Expand Down Expand Up @@ -209,7 +209,7 @@ GetNumberOfAssertsForTest := NumberOfAsserts;]]></ST>
the stored detection-count for this combination, create a new report and add +1 to the storage of
the detection-count.
*)
METHOD PUBLIC ReportResult
METHOD INTERNAL ReportResult
VAR_INPUT
ExpectedSize : UDINT;
ExpectedTypeClass : IBaseLibrary.TypeClass;
Expand Down
6 changes: 3 additions & 3 deletions TcUnit/TcUnit/POUs/FB_FileControl.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ END_VAR]]></Declaration>
</Implementation>
<Method Name="Close" Id="{519e9011-283c-40b1-afd4-31686c5b81fe}">
<Declaration><![CDATA[(*
Closes the current opened file.
Closes the currently opened file.
*)
METHOD PUBLIC Close : SysFile.SysTypes.RTS_IEC_RESULT;]]></Declaration>
<Implementation>
Expand Down Expand Up @@ -57,7 +57,7 @@ END_VAR]]></Declaration>
<Declaration><![CDATA[(*
Reads a file from disk into the buffer
*)
METHOD Read : SysFile.SysTypes.RTS_IEC_RESULT;
METHOD PUBLIC Read : SysFile.SysTypes.RTS_IEC_RESULT;
VAR_INPUT
BufferPointer : POINTER TO BYTE; // Call with ADR();
Size : UDINT; // Call with SIZEOF();
Expand All @@ -80,7 +80,7 @@ END_IF]]></ST>
<Declaration><![CDATA[(*
Writes the contents of the buffer into a file.
*)
METHOD Write : SysFile.SysTypes.RTS_IEC_RESULT;
METHOD PUBLIC Write : SysFile.SysTypes.RTS_IEC_RESULT;
VAR_INPUT
BufferPointer : POINTER TO BYTE; // Call with ADR();
Size : UDINT; // Call with SIZEOF();
Expand Down
62 changes: 60 additions & 2 deletions TcUnit/TcUnit/POUs/FB_TcUnitRunner.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ END_VAR]]></Declaration>
<Method Name="AbortRunningTestSuiteTests" Id="{3fcbd569-749a-493c-a697-2c976fa6e96a}">
<Declaration><![CDATA[(* This function sets a flag which makes the runner stop running the tests
in the test suites *)
METHOD PUBLIC AbortRunningTestSuiteTests]]></Declaration>
METHOD INTERNAL AbortRunningTestSuiteTests]]></Declaration>
<Implementation>
<ST><![CDATA[AbortRunningTestSuites := TRUE;]]></ST>
</Implementation>
</Method>
<Method Name="RunTestSuiteTests" Id="{d333e6c4-a1da-4b5b-91b3-4b4808e6c299}">
<Declaration><![CDATA[METHOD RunTestSuiteTests
<Declaration><![CDATA[(* This runs all the test suites in parallel *)
METHOD INTERNAL RunTestSuiteTests
VAR
Counter : UINT := 0;
BusyPrinting : BOOL;
Expand All @@ -58,6 +59,7 @@ IF NOT AllTestSuitesFinished THEN
NumberOfTestSuitesFinished := NumberOfTestSuitesFinished + 1;
ELSE
GVL_TcUnit.CurrentTestSuiteBeingCalled := GVL_TcUnit.TestSuiteAddresses[Counter];
GVL_TcUnit.CurrentTestSuiteBeingCalled^.SetHasStartedRunning();
GVL_TcUnit.CurrentTestSuiteBeingCalled^();
END_IF
END_FOR
Expand All @@ -81,6 +83,62 @@ TestResultLogger.LogTestSuiteResults();
(* publish the xUnit Xml file once if enabled *)
XmlTestResultPublisher.LogTestSuiteResults();
(* Run the buffered ADS logger *)
GVL_TcUnit.AdsMessageQueue();]]></ST>
</Implementation>
</Method>
<Method Name="RunTestSuiteTestsInSequence" Id="{01bbc2d3-b1c5-4bce-a3f3-fa46a50fd167}">
<Declaration><![CDATA[(* This runs all the test suites in sequence (one after the other) *)
METHOD INTERNAL RunTestSuiteTestsInSequence
VAR
BusyPrinting : BOOL;
(* We need to hold a temporary state of the statistics
as we don't consider the tests to be completely finished until all test suites have executed completely.
The reason we want to do it this way is because a test suite can run over several cycles. Only once all tests
are finished (which might take many cycles), do we gather correct statistics *)
NumberOfTestSuitesFinished : UINT := 0;
END_VAR
VAR_INST
(* This variable holds which current test suite is being called, as we are running
each one in a sequence (one by one) *)
CurrentlyRunningTestSuite : UINT := 1;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[(* Run TcUnit test suites *)
IF NOT AllTestSuitesFinished THEN
IF GVL_TcUnit.NumberOfInitializedTestSuites = 0 THEN
AllTestSuitesFinished := TRUE;
ELSIF GVL_TcUnit.NumberOfInitializedTestSuites > 0 THEN
IF GVL_TcUnit.TestSuiteAddresses[CurrentlyRunningTestSuite]^.AreAllTestsFinished() THEN
IF CurrentlyRunningTestSuite <> GVL_TcUnit.NumberOfInitializedTestSuites THEN
NumberOfTestSuitesFinished := NumberOfTestSuitesFinished + 1;
CurrentlyRunningTestSuite := CurrentlyRunningTestSuite + 1;
END_IF
ELSE
GVL_TcUnit.CurrentTestSuiteBeingCalled := GVL_TcUnit.TestSuiteAddresses[CurrentlyRunningTestSuite];
GVL_TcUnit.CurrentTestSuiteBeingCalled^.SetHasStartedRunning();
GVL_TcUnit.CurrentTestSuiteBeingCalled^();
END_IF
(* Check if some event triggered an abortion of running the tests, in that case abort it now.
This can be accomplished by setting the result of the test suites run to finished. *)
IF AbortRunningTestSuites THEN
NumberOfTestSuitesFinished := GVL_TcUnit.NumberOfInitializedTestSuites;
END_IF
IF NumberOfTestSuitesFinished = GVL_TcUnit.NumberOfInitializedTestSuites THEN
AllTestSuitesFinished := TRUE;
END_IF
END_IF
END_IF
(* Store test suite results continuously *)
TestResults();
(* Log test suite results continuously *)
TestResultLogger.LogTestSuiteResults();
(* publish the xUnit Xml file once if enabled *)
XmlTestResultPublisher.LogTestSuiteResults();
(* Run the buffered ADS logger *)
GVL_TcUnit.AdsMessageQueue();]]></ST>
</Implementation>
Expand Down
28 changes: 14 additions & 14 deletions TcUnit/TcUnit/POUs/FB_Test.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,50 @@ END_VAR]]></Declaration>
<ST><![CDATA[]]></ST>
</Implementation>
<Method Name="GetAssertionMessage" Id="{273c4e89-faee-43b5-803d-428cdf75ac48}">
<Declaration><![CDATA[METHOD PUBLIC GetAssertionMessage : Tc2_System.T_MaxString]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL GetAssertionMessage : Tc2_System.T_MaxString]]></Declaration>
<Implementation>
<ST><![CDATA[GetAssertionMessage := AssertionMessage;]]></ST>
</Implementation>
</Method>
<Method Name="GetAssertionType" Id="{cd1419c3-7b07-4183-b487-40bdbb0bbce3}">
<Declaration><![CDATA[METHOD PUBLIC GetAssertionType : E_AssertionType]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL GetAssertionType : E_AssertionType]]></Declaration>
<Implementation>
<ST><![CDATA[GetAssertionType := AssertionType;]]></ST>
</Implementation>
</Method>
<Method Name="GetName" Id="{94757f0e-9979-49d0-ad9f-e35c823175d4}">
<Declaration><![CDATA[METHOD PUBLIC GetName : Tc2_System.T_MaxString;]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL GetName : Tc2_System.T_MaxString;]]></Declaration>
<Implementation>
<ST><![CDATA[GetName := TestName;]]></ST>
</Implementation>
</Method>
<Method Name="GetNumberOfAssertions" Id="{0cfa1f03-0295-4f8f-bfd9-24d7b7f17e37}">
<Declaration><![CDATA[METHOD PUBLIC GetNumberOfAssertions : UINT]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL GetNumberOfAssertions : UINT]]></Declaration>
<Implementation>
<ST><![CDATA[GetNumberOfAssertions := NumberOfAssertions;]]></ST>
</Implementation>
</Method>
<Method Name="IsFailed" Id="{e42409e3-251f-4133-8b14-3630785983d6}">
<Declaration><![CDATA[METHOD PUBLIC IsFailed : BOOL]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL IsFailed : BOOL]]></Declaration>
<Implementation>
<ST><![CDATA[IsFailed := TestIsFailed;]]></ST>
</Implementation>
</Method>
<Method Name="IsFinished" Id="{813a9067-b864-4739-9c14-830160e0eabc}">
<Declaration><![CDATA[METHOD PUBLIC IsFinished : BOOL]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL IsFinished : BOOL]]></Declaration>
<Implementation>
<ST><![CDATA[IsFinished := TestIsFinished;]]></ST>
</Implementation>
</Method>
<Method Name="IsSkipped" Id="{ff97feb1-1a4a-4f36-ba1d-f8483e588d4f}">
<Declaration><![CDATA[METHOD PUBLIC IsSkipped : BOOL]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL IsSkipped : BOOL]]></Declaration>
<Implementation>
<ST><![CDATA[IsSkipped := TestIsSkipped;]]></ST>
</Implementation>
</Method>
<Method Name="SetAssertionMessage" Id="{05091715-93d7-47f7-9b6c-cb2511f88eb7}">
<Declaration><![CDATA[(* Sets the assertion message. If one already exists, it's not overwritten as we keep the first assertion in the test *)
METHOD PUBLIC SetAssertionMessage
METHOD INTERNAL SetAssertionMessage
VAR_INPUT
AssertMessage : Tc2_System.T_MaxString;
END_VAR]]></Declaration>
Expand All @@ -75,7 +75,7 @@ END_IF]]></ST>
</Method>
<Method Name="SetAssertionType" Id="{f885f3cc-c862-4d38-9dbb-f44d7639f6a8}">
<Declaration><![CDATA[(* Sets the assertion type. If one already exists, it's not overwritten as we keep the first assertion in the test *)
METHOD PUBLIC SetAssertionType
METHOD INTERNAL SetAssertionType
VAR_INPUT
AssertType : E_AssertionType;
END_VAR]]></Declaration>
Expand All @@ -86,19 +86,19 @@ END_IF]]></ST>
</Implementation>
</Method>
<Method Name="SetFailed" Id="{b840b41b-4045-4fd9-b97d-0bf226c46fb3}">
<Declaration><![CDATA[METHOD PUBLIC SetFailed]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL SetFailed]]></Declaration>
<Implementation>
<ST><![CDATA[TestIsFailed := TRUE;]]></ST>
</Implementation>
</Method>
<Method Name="SetFinished" Id="{e1245d1c-be22-4d60-bc91-fe0262827234}">
<Declaration><![CDATA[METHOD SetFinished : BOOL]]></Declaration>
<Declaration><![CDATA[METHOD INTERNAL SetFinished : BOOL]]></Declaration>
<Implementation>
<ST><![CDATA[TestIsFinished := TRUE;]]></ST>
</Implementation>
</Method>
<Method Name="SetName" Id="{4c12f6eb-bbe4-4872-ac89-4411e2e81414}">
<Declaration><![CDATA[METHOD PUBLIC SetName
<Declaration><![CDATA[METHOD INTERNAL SetName
VAR_INPUT
Name : Tc2_System.T_MaxString;
END_VAR]]></Declaration>
Expand All @@ -107,7 +107,7 @@ END_VAR]]></Declaration>
</Implementation>
</Method>
<Method Name="SetNumberOfAssertions" Id="{94c630e9-29b9-45f4-8716-809aab6fb076}">
<Declaration><![CDATA[METHOD PUBLIC SetNumberOfAssertions
<Declaration><![CDATA[METHOD INTERNAL SetNumberOfAssertions
VAR_INPUT
NoOfAssertions : UINT;
END_VAR]]></Declaration>
Expand All @@ -117,7 +117,7 @@ END_VAR]]></Declaration>
</Method>
<Method Name="SetSkipped" Id="{e9a94cad-c60d-4460-92bf-2b70cf2f46b2}">
<Declaration><![CDATA[(* Sets the test case to skipped *)
METHOD PUBLIC SetSkipped]]></Declaration>
METHOD INTERNAL SetSkipped]]></Declaration>
<Implementation>
<ST><![CDATA[TestIsSkipped := TRUE;]]></ST>
</Implementation>
Expand Down
Loading

0 comments on commit d152c95

Please sign in to comment.