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

Commit 9fb62f2

Browse files
committed
If timeout occurs, also made sure that the Visual Studio process is killed 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.
1 parent 1e1bd61 commit 9fb62f2

File tree

3 files changed

+75
-15
lines changed

3 files changed

+75
-15
lines changed

TcUnit-Runner/LaunchTcUnit.bat

+62-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ rem If this is not provided, it's assumed that only one task exists in the Tw
1515
rem -a [OPTIONAL] The AMS NetId of the device of where the project and TcUnit should run.
1616
rem If this is not provided, the local AMS NetId is assumed (127.0.0.1.1.1)
1717
rem -w [OPTIONAL] The version of TwinCAT to be used. If this is not provided, the latest TwinCAT version
18-
rem will be used
18+
rem will be used
19+
rem -u [OPTIONAL] Timeout the process with an error after X minutes. If no timeout is provided,
20+
rem the process might run indefinitely in case of error
1921
SET TCUNIT_TASK_NAME=
2022
SET TCUNIT_AMSNETID=
2123
SET TCUNIT_TCVERSION_TO_USE=
24+
SET TCUNIT_TIMEOUT=
2225

23-
CALL :Process_Parameters %1, %2, %3, %4, %5, %6
26+
CALL :Process_Parameters %1, %2, %3, %4, %5, %6, %7, %8
2427

2528
rem Create parameter call to TcUnit-Runner
2629
SET TCUNIT_RUNNER_PARAMETERS=
@@ -31,7 +34,10 @@ IF DEFINED TCUNIT_AMSNETID (
3134
SET TCUNIT_RUNNER_PARAMETERS=%TCUNIT_RUNNER_PARAMETERS% --AmsNetId=%TCUNIT_AMSNETID%
3235
)
3336
IF DEFINED TCUNIT_TCVERSION_TO_USE (
34-
SET TCUNIT_RUNNER_PARAMETERS=%TCUNIT_RUNNER_PARAMETERS% --TwinCATVersion=%TCUNIT_TCVERSION_TO_USE%
37+
SET TCUNIT_RUNNER_PARAMETERS=%TCUNIT_RUNNER_PARAMETERS% --TcVersion=%TCUNIT_TCVERSION_TO_USE%
38+
)
39+
IF DEFINED TCUNIT_TIMEOUT (
40+
SET TCUNIT_RUNNER_PARAMETERS=%TCUNIT_RUNNER_PARAMETERS% --Timeout=%TCUNIT_TIMEOUT%
3541
)
3642

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

4551
IF NOT DEFINED TCUNIT_TASK_NAME (
46-
echo Task name of the TcUnit task not provided! Assuming only one task in TwinCAT solution
52+
echo Task name of the TcUnit task not provided. Assuming only one task in TwinCAT solution
4753
) ELSE (
4854
echo A TcUnit task name has been provided, using: %TCUNIT_TASK_NAME%
4955
)
5056

5157
IF NOT DEFINED TCUNIT_AMSNETID (
52-
echo AmsNetId to run TwinCAT/TcUnit is not provided! Assuming TwinCAT/TcUnit will run locally '127.0.0.1.1.1'
58+
echo AmsNetId to run TwinCAT/TcUnit is not provided. Assuming TwinCAT/TcUnit will run locally '127.0.0.1.1.1'
5359
) ELSE (
5460
echo An AmsNetId has been provided, using: %TCUNIT_AMSNETID%
5561
)
5662

5763
IF NOT DEFINED TCUNIT_TCVERSION_TO_USE (
58-
echo A TwinCAT version is not provided! Assuming latest TwinCAT version should be used
64+
echo A TwinCAT version is not provided. Assuming latest TwinCAT version should be used
5965
) ELSE (
6066
echo A TwinCAT version has been provided, using: %TCUNIT_TCVERSION_TO_USE%
6167
)
6268

69+
IF NOT DEFINED TCUNIT_TIMEOUT (
70+
echo Timeout not provided.
71+
) ELSE (
72+
echo Timeout has been provided, using [min]: %TCUNIT_TIMEOUT%
73+
)
74+
6375

6476
rem Find the visual studio solution file.
6577
FOR /r %%i IN (*.sln) DO (
@@ -105,6 +117,12 @@ IF "%~1" == "-w" (
105117
IF "%~1" == "-W" (
106118
SET TCUNIT_TCVERSION_TO_USE=%2
107119
)
120+
IF "%~1" == "-u" (
121+
SET TCUNIT_TIMEOUT=%2
122+
)
123+
IF "%~1" == "-U" (
124+
SET TCUNIT_TIMEOUT=%2
125+
)
108126

109127
rem Second parameter
110128
IF "%~3" == "-t" (
@@ -125,6 +143,12 @@ IF "%~3" == "-w" (
125143
IF "%~3" == "-W" (
126144
SET TCUNIT_TCVERSION_TO_USE=%4
127145
)
146+
IF "%~3" == "-u" (
147+
SET TCUNIT_TIMEOUT=%4
148+
)
149+
IF "%~3" == "-U" (
150+
SET TCUNIT_TIMEOUT=%4
151+
)
128152

129153
rem Third parameter
130154
IF "%~5" == "-t" (
@@ -145,6 +169,38 @@ IF "%~5" == "-w" (
145169
IF "%~5" == "-W" (
146170
SET TCUNIT_TCVERSION_TO_USE=%6
147171
)
172+
IF "%~5" == "-u" (
173+
SET TCUNIT_TIMEOUT=%6
174+
)
175+
IF "%~5" == "-U" (
176+
SET TCUNIT_TIMEOUT=%6
177+
)
178+
179+
rem Fourth parameter
180+
IF "%~7" == "-t" (
181+
SET TCUNIT_TASK_NAME=%8
182+
)
183+
IF "%~7" == "-T" (
184+
SET TCUNIT_TASK_NAME=%8
185+
)
186+
IF "%~7" == "-a" (
187+
SET TCUNIT_AMSNETID=%8
188+
)
189+
IF "%~7" == "-A" (
190+
SET TCUNIT_AMSNETID=%8
191+
)
192+
IF "%~7" == "-w" (
193+
SET TCUNIT_TCVERSION_TO_USE=%8
194+
)
195+
IF "%~7" == "-W" (
196+
SET TCUNIT_TCVERSION_TO_USE=%8
197+
)
198+
IF "%~7" == "-u" (
199+
SET TCUNIT_TIMEOUT=%8
200+
)
201+
IF "%~7" == "-U" (
202+
SET TCUNIT_TIMEOUT=%8
203+
)
148204

149205

150206
GOTO:EOF

TcUnit-Runner/Program.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ static void Main(string[] args)
6262
.Add("v=|VisualStudioSolutionFilePath=", "The full path to the TwinCAT project (sln-file)", v => VisualStudioSolutionFilePath = v)
6363
.Add("t=|TcUnitTaskName=", "[OPTIONAL] The name of the task running TcUnit defined under \"Tasks\"", t => TcUnitTaskName = t)
6464
.Add("a=|AmsNetId=", "[OPTIONAL] The AMS NetId of the device of where the project and TcUnit should run", a => AmsNetId = a)
65+
.Add("w=|TcVersion=", "[OPTIONAL] The TwinCAT version to be used to load the TwinCAT project", w => ForceToThisTwinCATVersion = w)
6566
.Add("u=|Timeout=", "[OPTIONAL] Timeout the process with an error after X minutes", u => Timeout = u)
66-
.Add("w=|TwinCATVersion=", "[OPTIONAL] The TwinCAT version to be used to load the TwinCAT project", w => ForceToThisTwinCATVersion = w)
6767
.Add("?|h|help", h => showHelp = h != null);
6868
try
6969
{
@@ -98,18 +98,19 @@ static void Main(string[] args)
9898
Environment.Exit(Constants.RETURN_VISUAL_STUDIO_SOLUTION_PATH_NOT_FOUND);
9999
}
100100

101-
/* Start a timeout for the process if the user asked for it
101+
LogBasicInfo();
102+
103+
/* Start a timeout for the process(es) if the user asked for it
102104
*/
103105
if (Timeout != null)
104106
{
105-
log.Info($"Timeout enabled - process times out after {Timeout} minutes");
107+
log.Info("Timeout enabled - process(es) timesout after " +Timeout +" minute(s)");
106108
System.Timers.Timer timeout = new System.Timers.Timer(Int32.Parse(Timeout) * 1000 * 60);
107109
timeout.Elapsed += KillProcess;
108110
timeout.AutoReset = false;
109111
timeout.Start();
110112
}
111113

112-
LogBasicInfo();
113114
MessageFilter.Register();
114115

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

418419
/// <summary>

TcUnit-Runner/TcUnit-Runner.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
<Content Include="LaunchTcUnit.bat">
125125
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
126126
</Content>
127+
<Content Include="Beckhoff.TwinCAT.Ads_LICENSE">
128+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
129+
</Content>
127130
<None Include="packages.config" />
128131
</ItemGroup>
129132
<ItemGroup>

0 commit comments

Comments
 (0)