Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TcoElements scaffold, testing framework additions, template script fix #38

Merged
merged 5 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
382 changes: 321 additions & 61 deletions TcOpen.sln

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions notices.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,31 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

# TcUnit

https://github.com/tcunit/TcUnit

MIT License

Copyright (c) 2018 Jakob Sagatowski and contributors
For a complete list of contributors, see https://github.com/tcunit/TcUnit/graphs/contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions src/TcoCore/src/TcoCoreConnector/pex/_internals_/ITestContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TcoCore.Testing
{
public interface ITestContext
{
bool ContextOpen();
bool ContextClose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;

namespace TcoCore.Testing
{
/// <summary>
/// Series of extension method for execution action within a `TcoContext`.
/// </summary>
public static class TcoContextTestRunners
{
/// <summary>
/// [Call from external environment] Runs the remote action once.
/// </summary>
/// <param name="context">Context</param>
/// <param name="action">Action to run.</param>
public static void Run(this ITestContext context, Action action)
{
context.ContextOpen();
action();
context.ContextClose();
}

/// <summary>
/// [Call from external environment] Runs with cycle with open-action-close context.
/// </summary>
/// <param name="context">Context</param>
/// <param name="action">Acton to run</param>
/// <param name="endCondition">End condition. When `true` cycle stops.</param>
public static void Run(this ITestContext context, Action action, Func<bool> endCondition)
{
while (!endCondition())
{
context.ContextOpen();
action();
context.ContextClose();
}
}

/// <summary>
/// [Call from external environment] Runs with cycle with open-action-close context.
/// </summary>
/// <param name="context">Context</param>
/// <param name="action">Action to run, when returns `true` cycle stops.</param>
public static void Run(this ITestContext context, Func<bool> action)
{
bool actionDone = false;
while (!actionDone)
{
context.ContextOpen();
actionDone = action();
context.ContextClose();
}
}

/// <summary>
/// [Executes call on PLC task] Executes with cycle with open-action-close context.
/// Make sure you call `_internals_TcoContext_.ProbeRun` instead of `Run` method in your PLC program. (<seealso cref="_internals_TcoContext.ExecuteProbeRun(ulong, ulong)"/>)
/// </summary>
/// <param name="context">Context</param>
/// <param name="action">Action to run, when returns `true` cycle stops.</param>
public static void Run(this _internals_TcoContext context, ulong numberOfCycles = 1, ulong testId = 0)
{
context.ExecuteProbeRun(numberOfCycles, testId);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Threading.Tasks;

namespace TcoCore
{
/// <summary>
/// Partial class exposes Open and Close context methods for testing purposes.
/// </summary>
public partial class _internals_TcoContext : Testing.ITestContext
{
/// <summary>
/// Opens the context from testing application.
/// </summary>
/// <returns></returns>
public bool ContextOpen()
{
this._Open();
return true;
}

/// <summary>
/// Closes the context form testing application.
/// </summary>
/// <returns></returns>
public bool ContextClose()
{
this._Close();
return true;
}

/// <summary>
/// Executes context cycle given number of times. Optionally can provide <see cref="_testId"/> for test code isolation.
/// In the plc you must ensure cyclical call of <see cref="TcoCore.TcoContext.PlcTcoContext.ProbeRun"/> method.
/// </summary>
/// <param name="counts">Number of time the context cycle executes</param>
/// <param name="testId">Test Id</param>
public void ExecuteProbeRun(ulong counts, ulong testId)
{
_probeCurrentCycleCount.Synchron = ulong.MaxValue;
_testId.Synchron = testId;
_probeRunRequiredCycles.Synchron = counts;
_probeCurrentCycleCount.Synchron = 0;

Task.Run(() => { while (_probeCurrentCycleCount.Synchron < _probeRunRequiredCycles.Synchron) ; }).Wait();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.6">
<DUT Name="F_AnyToUnionValue" Id="{19e9788e-e223-0e11-3cca-450663879b34}">
<Declaration><![CDATA[// credits Jakob Sagatowski https://github.com/sagatowski & contributors https://github.com/tcunit/TcUnit

TYPE F_AnyToUnionValue :
UNION
_bool : BOOL;
_bit : BIT;
_byte : BYTE;
_dword : DWORD;
_lword : LWORD;
_string :STRING(255);
_udint : UDINT;
_uint : UINT;
_usint : USINT;
_sint : SINT;
_int : INT;
_word : WORD;
_dint : DINT;
_lint : LINT;
_ulint : ULINT;
_real : REAL;
_lreal : LREAL;
_wstring : WSTRING(255);
_time : TIME;
_ltime : LTIME;
_date : DATE;
_dateandtime : DATE_AND_TIME;
_timeofday : TIME_OF_DAY;
END_UNION
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>
Loading