From d152c952b25b9508a734205a2ac69f274b811f6d Mon Sep 17 00:00:00 2001 From: Jakob Sagatowski Date: Wed, 30 Dec 2020 15:03:45 +0100 Subject: [PATCH] Implemented new way of execute tests RUN_IN_SEQUENCE(). 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. --- README.md | 2 +- .../TcUnitVerifier/Test/PRG_TEST.TcPOU | 9 ++- .../POUs/FB_AdsAssertMessageFormatter.TcPOU | 2 +- .../FB_AdsLogStringMessageFifoQueue.TcPOU | 2 +- .../POUs/FB_AssertArrayResultStatic.TcPOU | 4 +- .../TcUnit/POUs/FB_AssertResultStatic.TcPOU | 4 +- TcUnit/TcUnit/POUs/FB_FileControl.TcPOU | 6 +- TcUnit/TcUnit/POUs/FB_TcUnitRunner.TcPOU | 62 ++++++++++++++++++- TcUnit/TcUnit/POUs/FB_Test.TcPOU | 28 ++++----- TcUnit/TcUnit/POUs/FB_TestSuite.TcPOU | 44 ++++++++----- TcUnit/TcUnit/POUs/Functions/RUN.TcPOU | 1 + .../POUs/Functions/RUN_IN_SEQUENCE.TcPOU | 13 ++++ TcUnit/TcUnit/TcUnit.plcproj | 5 +- TcUnit/TcUnit/Version/Global_Version.TcGVL | 2 +- TcUnit/_Config/PLC/TcUnit.xti | 4 +- 15 files changed, 142 insertions(+), 46 deletions(-) create mode 100644 TcUnit/TcUnit/POUs/Functions/RUN_IN_SEQUENCE.TcPOU diff --git a/README.md b/README.md index 9b83b0a..ba8afdb 100644 --- a/README.md +++ b/README.md @@ -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). \ No newline at end of file +For general ideas/discussions, use the [discussions](https://github.com/tcunit/TcUnit/discussions). \ No newline at end of file diff --git a/TcUnit-Verifier/TcUnit-Verifier_TwinCAT/TcUnit-Verifier_TwinCAT/TcUnitVerifier/Test/PRG_TEST.TcPOU b/TcUnit-Verifier/TcUnit-Verifier_TwinCAT/TcUnit-Verifier_TwinCAT/TcUnitVerifier/Test/PRG_TEST.TcPOU index 9580c07..d3fd92f 100644 --- a/TcUnit-Verifier/TcUnit-Verifier_TwinCAT/TcUnit-Verifier_TwinCAT/TcUnitVerifier/Test/PRG_TEST.TcPOU +++ b/TcUnit-Verifier/TcUnit-Verifier_TwinCAT/TcUnit-Verifier_TwinCAT/TcUnitVerifier/Test/PRG_TEST.TcPOU @@ -35,7 +35,14 @@ VAR //TestFinishedNamedDoesNotExist : FB_TestFinishedNamedDoesNotExist; END_VAR]]> - + \ No newline at end of file diff --git a/TcUnit/TcUnit/POUs/FB_AdsAssertMessageFormatter.TcPOU b/TcUnit/TcUnit/POUs/FB_AdsAssertMessageFormatter.TcPOU index 5801398..2a2cc87 100644 --- a/TcUnit/TcUnit/POUs/FB_AdsAssertMessageFormatter.TcPOU +++ b/TcUnit/TcUnit/POUs/FB_AdsAssertMessageFormatter.TcPOU @@ -11,7 +11,7 @@ FUNCTION_BLOCK FB_AdsAssertMessageFormatter IMPLEMENTS I_AssertMessageFormatter] - - 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; diff --git a/TcUnit/TcUnit/POUs/FB_AssertResultStatic.TcPOU b/TcUnit/TcUnit/POUs/FB_AssertResultStatic.TcPOU index f2760e7..7fd7212 100644 --- a/TcUnit/TcUnit/POUs/FB_AssertResultStatic.TcPOU +++ b/TcUnit/TcUnit/POUs/FB_AssertResultStatic.TcPOU @@ -161,7 +161,7 @@ END_FOR]]> - 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; diff --git a/TcUnit/TcUnit/POUs/FB_FileControl.TcPOU b/TcUnit/TcUnit/POUs/FB_FileControl.TcPOU index b4138dc..ff90b1c 100644 --- a/TcUnit/TcUnit/POUs/FB_FileControl.TcPOU +++ b/TcUnit/TcUnit/POUs/FB_FileControl.TcPOU @@ -14,7 +14,7 @@ END_VAR]]> @@ -57,7 +57,7 @@ END_VAR]]> +METHOD INTERNAL AbortRunningTestSuiteTests]]> - + + + + + + 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();]]> diff --git a/TcUnit/TcUnit/POUs/FB_Test.TcPOU b/TcUnit/TcUnit/POUs/FB_Test.TcPOU index bdbfe6b..0599d03 100644 --- a/TcUnit/TcUnit/POUs/FB_Test.TcPOU +++ b/TcUnit/TcUnit/POUs/FB_Test.TcPOU @@ -20,50 +20,50 @@ END_VAR]]> - + - + - + - + - + - + - + @@ -75,7 +75,7 @@ END_IF]]> @@ -86,19 +86,19 @@ END_IF]]> - + - + - @@ -107,7 +107,7 @@ END_VAR]]> - @@ -117,7 +117,7 @@ END_VAR]]> +METHOD INTERNAL SetSkipped]]> diff --git a/TcUnit/TcUnit/POUs/FB_TestSuite.TcPOU b/TcUnit/TcUnit/POUs/FB_TestSuite.TcPOU index b0546d0..e78e9cf 100644 --- a/TcUnit/TcUnit/POUs/FB_TestSuite.TcPOU +++ b/TcUnit/TcUnit/POUs/FB_TestSuite.TcPOU @@ -36,12 +36,15 @@ VAR This assert formatter can be replaced with something else than ADS *) AdsAssertMessageFormatter : FB_AdsAssertMessageFormatter; AssertMessageFormatter : I_AssertMessageFormatter := AdsAssertMessageFormatter; + + (* Indication whether this test suite has started running its tests *) + HasStartedRunning : BOOL; END_VAR]]> - - - @@ -150,9 +152,9 @@ IF NumberOfTests > 0 THEN END_IF (* If we have been running at least one cycle and no tests are registered it means that this testsuite is empty - and doesn't contain any test cases. In that case, add a warning message and ignore this testsuite. *) + and doesn't contain any test cases. In that case, ignore this testsuite. *) GetCurTaskIndex(); -IF NumberOfTests = 0 AND NOT TwinCAT_SystemInfoVarList._TaskInfo[GetCurTaskIndex.index].FirstCycle THEN +IF NumberOfTests = 0 AND NOT TwinCAT_SystemInfoVarList._TaskInfo[GetCurTaskIndex.index].FirstCycle AND HasStartedRunning THEN AreAllTestsFinished := TRUE; END_IF]]> @@ -3576,7 +3578,7 @@ END_VAR]]> - + + + + + + - - - - + - + @@ -3690,7 +3698,7 @@ END_VAR]]> - 0 THEN END_IF]]> + + + + + + diff --git a/TcUnit/TcUnit/POUs/Functions/RUN_IN_SEQUENCE.TcPOU b/TcUnit/TcUnit/POUs/Functions/RUN_IN_SEQUENCE.TcPOU new file mode 100644 index 0000000..2e89805 --- /dev/null +++ b/TcUnit/TcUnit/POUs/Functions/RUN_IN_SEQUENCE.TcPOU @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/TcUnit/TcUnit/TcUnit.plcproj b/TcUnit/TcUnit/TcUnit.plcproj index a11152d..b16a115 100644 --- a/TcUnit/TcUnit/TcUnit.plcproj +++ b/TcUnit/TcUnit/TcUnit.plcproj @@ -32,7 +32,7 @@ Documentation and examples are available at www.tcunit.org www.tcunit.org Jakob Sagatowski and contributors - 1.1.0.0 + 1.2.0.0 @@ -163,6 +163,9 @@ Documentation and examples are available at www.tcunit.org Code + + Code + Code diff --git a/TcUnit/TcUnit/Version/Global_Version.TcGVL b/TcUnit/TcUnit/Version/Global_Version.TcGVL index 53c0953..acbed66 100644 --- a/TcUnit/TcUnit/Version/Global_Version.TcGVL +++ b/TcUnit/TcUnit/Version/Global_Version.TcGVL @@ -7,7 +7,7 @@ // This function has been automatically generated from the project information. VAR_GLOBAL CONSTANT {attribute 'const_non_replaced'} - stLibVersion_TcUnit : ST_LibVersion := (iMajor := 1, iMinor := 1, iBuild := 0, iRevision := 0, sVersion := '1.1.0.0'); + stLibVersion_TcUnit : ST_LibVersion := (iMajor := 1, iMinor := 2, iBuild := 0, iRevision := 0, sVersion := '1.2.0.0'); END_VAR ]]> diff --git a/TcUnit/_Config/PLC/TcUnit.xti b/TcUnit/_Config/PLC/TcUnit.xti index ae2318b..d1f2e81 100644 --- a/TcUnit/_Config/PLC/TcUnit.xti +++ b/TcUnit/_Config/PLC/TcUnit.xti @@ -1,7 +1,7 @@ - + - + TcUnit Instance {08500001-0000-0000-F000-000000000064}