Windows WML tests: Add WindowsTimeout project

As the --timeout option for Wesnoth can stall the process, we replace it
by an encapsulation comparable to the Unix timeout function.

WindowsTimeout isn't limited to Wesnoth, it can in fact set a timeout for
any executable called through it.

An example on the use of these WinAPI functions can be found on
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682512.aspx
This commit is contained in:
aquileia 2014-05-29 02:06:53 +02:00
parent 472c0cda45
commit 4832724565
3 changed files with 388 additions and 0 deletions

View file

@ -0,0 +1,58 @@
/*
Copyright (C) 2014 by Sebastian Koelle <sk.aquileia@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* @file
* Execute another executable:
* - wait for the process to quit, then pass through the error code
* - terminate it after a timeout of "t" microseconds, then return 2
*/
#if _WIN32_WINNT < 0x0602 //Windows version before Win8
#include <windows.h>
#else
#include <Processthreadsapi.h>
#endif
// #define WIN32_LEAN_AND_MEAN
#include <stdlib.h>
#include <iostream>
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cout << "WindowsTimeout: Error USAGE1: " << argv[0] << " \"command [--options]\" t";
return -1;
}
PROCESS_INFORMATION pi;
STARTUPINFO info = { sizeof(info) };
HANDLE hStdErr = GetStdHandle(STD_ERROR_HANDLE);
info.hStdError = hStdErr;
if (!CreateProcess(NULL, argv[1], NULL, NULL, TRUE, 0, NULL, NULL, &info, &pi))
return -1;
DWORD dwExitCode;
if (::WaitForSingleObject(pi.hProcess, atoi(argv[2])) == WAIT_OBJECT_0) {
GetExitCodeProcess(pi.hProcess, &dwExitCode);
}
else {
TerminateProcess(pi.hProcess, 2);
dwExitCode = 2;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(hStdErr);
return dwExitCode;
}

View file

@ -0,0 +1,319 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="WindowsTimeout"
ProjectGUID="{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}"
RootNamespace="wesnoth"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\WindowsTimeout"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="4"
DisableSpecificWarnings="4127;4512"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
LinkIncremental="2"
OutputFile="$(OutDir)\WindowsTimeout.exe"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)\..\.."
IntermediateDirectory="$(ConfigurationName)\WindowsTimeout"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
LinkTimeCodeGeneration="1"
OutputFile="$(OutDir)\WindowsTimeout.exe"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug_with_VLD|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\WindowsTimeout"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
WarningLevel="4"
DebugInformationFormat="4"
DisableSpecificWarnings="4127;4512"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
LinkTimeCodeGeneration="1"
OutputFile="$(OutDir)\WindowsTimeout.exe"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="ReleaseDEBUG|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)\WindowsTimeout"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="false"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
LinkIncremental="2"
OutputFile="$(OutDir)\WindowsTimeout.exe"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath="WindowsTimeout.cpp"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -4,6 +4,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wesnoth", "wesnoth.vcproj",
ProjectSection(ProjectDependencies) = postProject
{01AE7104-A4B1-428E-BA7C-460FE656AE5C} = {01AE7104-A4B1-428E-BA7C-460FE656AE5C}
{4A16638B-127B-4AE8-8E0B-4B211B96F976} = {4A16638B-127B-4AE8-8E0B-4B211B96F976}
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C} = {06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wesnothd", "wesnothd.vcproj", "{72F28A4A-A6A2-4C49-8141-7CD0DFA9ECCE}"
@ -20,6 +21,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "schema_generator", "schema_
{4A16638B-127B-4AE8-8E0B-4B211B96F976} = {4A16638B-127B-4AE8-8E0B-4B211B96F976}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WindowsTimeout", "WindowsTimeout.vcproj", "{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_with_VLD|Win32 = Debug_with_VLD|Win32
@ -64,6 +67,14 @@ Global
{9FDDFD0B-C23F-47DB-97F7-7BDCA3E754D9}.Debug|Win32.ActiveCfg = Debug|Win32
{9FDDFD0B-C23F-47DB-97F7-7BDCA3E754D9}.Release|Win32.ActiveCfg = Release|Win32
{9FDDFD0B-C23F-47DB-97F7-7BDCA3E754D9}.ReleaseDEBUG|Win32.ActiveCfg = ReleaseDEBUG|Win32
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}.Debug_with_VLD|Win32.ActiveCfg = Debug_with_VLD|Win32
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}.Debug_with_VLD|Win32.Build.0 = Debug_with_VLD|Win32
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}.Debug|Win32.ActiveCfg = Debug|Win32
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}.Debug|Win32.Build.0 = Debug|Win32
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}.Release|Win32.ActiveCfg = Release|Win32
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}.Release|Win32.Build.0 = Release|Win32
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}.ReleaseDEBUG|Win32.ActiveCfg = ReleaseDEBUG|Win32
{06CDDAD5-8638-46F0-88F5-1B458B7FBE0C}.ReleaseDEBUG|Win32.Build.0 = ReleaseDEBUG|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE