Skip to content
This repository was archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
If timeout occurs, also made sure that the Visual Studio process is k…
Browse files Browse the repository at this point in the history
…illed and not just the TcUnit-Runner process.

Added parameter to BAT-file to include timeout.
Made sure that Beckhoff ADS license file is included in the installation of TcUnit-Runner.
  • Loading branch information
sagatowski committed Dec 21, 2020
1 parent 1e1bd61 commit 9fb62f2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
68 changes: 62 additions & 6 deletions TcUnit-Runner/LaunchTcUnit.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ rem If this is not provided, it's assumed that only one task exists in the Tw
rem -a [OPTIONAL] The AMS NetId of the device of where the project and TcUnit should run.
rem If this is not provided, the local AMS NetId is assumed (127.0.0.1.1.1)
rem -w [OPTIONAL] The version of TwinCAT to be used. If this is not provided, the latest TwinCAT version
rem will be used
rem will be used
rem -u [OPTIONAL] Timeout the process with an error after X minutes. If no timeout is provided,
rem the process might run indefinitely in case of error
SET TCUNIT_TASK_NAME=
SET TCUNIT_AMSNETID=
SET TCUNIT_TCVERSION_TO_USE=
SET TCUNIT_TIMEOUT=

CALL :Process_Parameters %1, %2, %3, %4, %5, %6
CALL :Process_Parameters %1, %2, %3, %4, %5, %6, %7, %8

rem Create parameter call to TcUnit-Runner
SET TCUNIT_RUNNER_PARAMETERS=
Expand All @@ -31,7 +34,10 @@ IF DEFINED TCUNIT_AMSNETID (
SET TCUNIT_RUNNER_PARAMETERS=%TCUNIT_RUNNER_PARAMETERS% --AmsNetId=%TCUNIT_AMSNETID%
)
IF DEFINED TCUNIT_TCVERSION_TO_USE (
SET TCUNIT_RUNNER_PARAMETERS=%TCUNIT_RUNNER_PARAMETERS% --TwinCATVersion=%TCUNIT_TCVERSION_TO_USE%
SET TCUNIT_RUNNER_PARAMETERS=%TCUNIT_RUNNER_PARAMETERS% --TcVersion=%TCUNIT_TCVERSION_TO_USE%
)
IF DEFINED TCUNIT_TIMEOUT (
SET TCUNIT_RUNNER_PARAMETERS=%TCUNIT_RUNNER_PARAMETERS% --Timeout=%TCUNIT_TIMEOUT%
)

SET TCUNIT_RUNNER_EXECUTABLE_COMPLETE_PATH=%TCUNIT_RUNNER_INSTALL_DIRECTORY%\TcUnit-Runner.exe
Expand All @@ -43,23 +49,29 @@ IF NOT EXIST "%TCUNIT_RUNNER_EXECUTABLE_COMPLETE_PATH%" (
)

IF NOT DEFINED TCUNIT_TASK_NAME (
echo Task name of the TcUnit task not provided! Assuming only one task in TwinCAT solution
echo Task name of the TcUnit task not provided. Assuming only one task in TwinCAT solution
) ELSE (
echo A TcUnit task name has been provided, using: %TCUNIT_TASK_NAME%
)

IF NOT DEFINED TCUNIT_AMSNETID (
echo AmsNetId to run TwinCAT/TcUnit is not provided! Assuming TwinCAT/TcUnit will run locally '127.0.0.1.1.1'
echo AmsNetId to run TwinCAT/TcUnit is not provided. Assuming TwinCAT/TcUnit will run locally '127.0.0.1.1.1'
) ELSE (
echo An AmsNetId has been provided, using: %TCUNIT_AMSNETID%
)

IF NOT DEFINED TCUNIT_TCVERSION_TO_USE (
echo A TwinCAT version is not provided! Assuming latest TwinCAT version should be used
echo A TwinCAT version is not provided. Assuming latest TwinCAT version should be used
) ELSE (
echo A TwinCAT version has been provided, using: %TCUNIT_TCVERSION_TO_USE%
)

IF NOT DEFINED TCUNIT_TIMEOUT (
echo Timeout not provided.
) ELSE (
echo Timeout has been provided, using [min]: %TCUNIT_TIMEOUT%
)


rem Find the visual studio solution file.
FOR /r %%i IN (*.sln) DO (
Expand Down Expand Up @@ -105,6 +117,12 @@ IF "%~1" == "-w" (
IF "%~1" == "-W" (
SET TCUNIT_TCVERSION_TO_USE=%2
)
IF "%~1" == "-u" (
SET TCUNIT_TIMEOUT=%2
)
IF "%~1" == "-U" (
SET TCUNIT_TIMEOUT=%2
)

rem Second parameter
IF "%~3" == "-t" (
Expand All @@ -125,6 +143,12 @@ IF "%~3" == "-w" (
IF "%~3" == "-W" (
SET TCUNIT_TCVERSION_TO_USE=%4
)
IF "%~3" == "-u" (
SET TCUNIT_TIMEOUT=%4
)
IF "%~3" == "-U" (
SET TCUNIT_TIMEOUT=%4
)

rem Third parameter
IF "%~5" == "-t" (
Expand All @@ -145,6 +169,38 @@ IF "%~5" == "-w" (
IF "%~5" == "-W" (
SET TCUNIT_TCVERSION_TO_USE=%6
)
IF "%~5" == "-u" (
SET TCUNIT_TIMEOUT=%6
)
IF "%~5" == "-U" (
SET TCUNIT_TIMEOUT=%6
)

rem Fourth parameter
IF "%~7" == "-t" (
SET TCUNIT_TASK_NAME=%8
)
IF "%~7" == "-T" (
SET TCUNIT_TASK_NAME=%8
)
IF "%~7" == "-a" (
SET TCUNIT_AMSNETID=%8
)
IF "%~7" == "-A" (
SET TCUNIT_AMSNETID=%8
)
IF "%~7" == "-w" (
SET TCUNIT_TCVERSION_TO_USE=%8
)
IF "%~7" == "-W" (
SET TCUNIT_TCVERSION_TO_USE=%8
)
IF "%~7" == "-u" (
SET TCUNIT_TIMEOUT=%8
)
IF "%~7" == "-U" (
SET TCUNIT_TIMEOUT=%8
)


GOTO:EOF
Expand Down
19 changes: 10 additions & 9 deletions TcUnit-Runner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static void Main(string[] args)
.Add("v=|VisualStudioSolutionFilePath=", "The full path to the TwinCAT project (sln-file)", v => VisualStudioSolutionFilePath = v)
.Add("t=|TcUnitTaskName=", "[OPTIONAL] The name of the task running TcUnit defined under \"Tasks\"", t => TcUnitTaskName = t)
.Add("a=|AmsNetId=", "[OPTIONAL] The AMS NetId of the device of where the project and TcUnit should run", a => AmsNetId = a)
.Add("w=|TcVersion=", "[OPTIONAL] The TwinCAT version to be used to load the TwinCAT project", w => ForceToThisTwinCATVersion = w)
.Add("u=|Timeout=", "[OPTIONAL] Timeout the process with an error after X minutes", u => Timeout = u)
.Add("w=|TwinCATVersion=", "[OPTIONAL] The TwinCAT version to be used to load the TwinCAT project", w => ForceToThisTwinCATVersion = w)
.Add("?|h|help", h => showHelp = h != null);
try
{
Expand Down Expand Up @@ -98,18 +98,19 @@ static void Main(string[] args)
Environment.Exit(Constants.RETURN_VISUAL_STUDIO_SOLUTION_PATH_NOT_FOUND);
}

/* Start a timeout for the process if the user asked for it
LogBasicInfo();

/* Start a timeout for the process(es) if the user asked for it
*/
if (Timeout != null)
{
log.Info($"Timeout enabled - process times out after {Timeout} minutes");
log.Info("Timeout enabled - process(es) timesout after " +Timeout +" minute(s)");
System.Timers.Timer timeout = new System.Timers.Timer(Int32.Parse(Timeout) * 1000 * 60);
timeout.Elapsed += KillProcess;
timeout.AutoReset = false;
timeout.Start();
}

LogBasicInfo();
MessageFilter.Register();

TwinCATProjectFilePath = TcFileUtilities.FindTwinCATProjectFile(VisualStudioSolutionFilePath);
Expand Down Expand Up @@ -342,10 +343,9 @@ static void Main(string[] args)
AdsState adsState = tcAdsClient.ReadState().AdsState;
if (adsState != AdsState.Run)
{
log.Error($"ERROR: invalid AdsState {adsState} <> {AdsState.Run}. This could indicate a PLC Exception, terminating ...");
log.Error("ERROR: invalid AdsState "+adsState +"<>" +AdsState.Run +". This could indicate a PLC Exception, terminating ...");
Environment.Exit(Constants.RETURN_INVALID_ADSSTATE);
}
log.Debug($"DEBUG: AdsState={adsState}");
}
}
catch (Exception ex)
Expand Down Expand Up @@ -398,6 +398,7 @@ static void DisplayHelp(OptionSet p)
Console.WriteLine("Example #2: TcUnit-Runner -v \"C:\\Jenkins\\workspace\\TcProject\\TcProject.sln\" -t \"UnitTestTask\"");
Console.WriteLine("Example #3: TcUnit-Runner -v \"C:\\Jenkins\\workspace\\TcProject\\TcProject.sln\" -t \"UnitTestTask\" -a 192.168.4.221.1.1");
Console.WriteLine("Example #4: TcUnit-Runner -v \"C:\\Jenkins\\workspace\\TcProject\\TcProject.sln\" -w \"3.1.4024.11\"");
Console.WriteLine("Example #5: TcUnit-Runner -v \"C:\\Jenkins\\workspace\\TcProject\\TcProject.sln\" -u 5");
Console.WriteLine();
Console.WriteLine("Options:");
p.WriteOptionDescriptions(Console.Out);
Expand All @@ -407,12 +408,12 @@ static void DisplayHelp(OptionSet p)
/// Using the Timeout option the user may specify the longest time that the process
/// of this application is allowed to run. Sometimes (on low RAM machines), the
/// DTE build process will hang and the only way to get out of this situation is
/// to kill the process.
/// to kill this process and any eventual Visual Studio process.
/// </summary>
static private void KillProcess(Object source, System.Timers.ElapsedEventArgs e)
{
log.Error ("ERROR: timeout occured, killing process ...");
Environment.Exit(Constants.RETURN_TWINCAT_VERSION_NOT_FOUND);
log.Error ("ERROR: timeout occured, killing process(es) ...");
CleanUpAndExitApplication(Constants.RETURN_TIMEOUT);
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions TcUnit-Runner/TcUnit-Runner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<Content Include="LaunchTcUnit.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Beckhoff.TwinCAT.Ads_LICENSE">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 9fb62f2

Please sign in to comment.