From 94f0869d876f07858b69355dbbada4601d551497 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Tue, 2 Aug 2016 19:30:24 +0900 Subject: [PATCH] Regression test using MSBuild. --- test/runsuite.c | 7 +- winbuild/.gitignore | 4 + winbuild/MSBuild-Get.psm1 | 148 ++++++++++++++++++++++++ winbuild/regress.ps1 | 210 +++++++++++++++++++++++++++++++++++ winbuild/regress_one.vcxproj | 171 ++++++++++++++++++++++++++++ 5 files changed, 538 insertions(+), 2 deletions(-) create mode 100644 winbuild/.gitignore create mode 100644 winbuild/MSBuild-Get.psm1 create mode 100644 winbuild/regress.ps1 create mode 100755 winbuild/regress_one.vcxproj diff --git a/test/runsuite.c b/test/runsuite.c index 8d31b2f..4dfe9ab 100644 --- a/test/runsuite.c +++ b/test/runsuite.c @@ -201,6 +201,9 @@ rundiff(const char *testname, const char *inputdir) size_t result_len; #ifdef WIN32 static int diff_call = 1, first_call = 1; + const char *expected_dir = "\\expected\\"; +#else + const char *expected_dir = "/expected/"; #endif int diff_rtn; int i, j; @@ -217,9 +220,9 @@ rundiff(const char *testname, const char *inputdir) size_t expected_len; if (outputno == 0) - snprintf(filename, sizeof(filename), "%s/expected/%s.out", inputdir, testname); + snprintf(filename, sizeof(filename), "%s%s%s.out", inputdir, expected_dir, testname); else - snprintf(filename, sizeof(filename), "%s/expected/%s_%d.out", inputdir, testname, outputno); + snprintf(filename, sizeof(filename), "%s%s%s_%d.out", inputdir, expected_dir, testname, outputno); expected = slurpfile(filename, &expected_len); if (expected == NULL) { diff --git a/winbuild/.gitignore b/winbuild/.gitignore new file mode 100644 index 0000000..eb5dbd6 --- /dev/null +++ b/winbuild/.gitignore @@ -0,0 +1,4 @@ +# +generated_regress.vcxproj +/test_x86 +/test_x64 diff --git a/winbuild/MSBuild-Get.psm1 b/winbuild/MSBuild-Get.psm1 new file mode 100644 index 0000000..df24a5f --- /dev/null +++ b/winbuild/MSBuild-Get.psm1 @@ -0,0 +1,148 @@ +function Get-MSBuild([ref]$VCVersion, [ref]$MSToolsVersion, [ref]$Toolset, $configInfo) +{ + $path_save = ${env:PATH} + + $VisualStudioVersion=$VCVersion.Value + $MSToolsVersionv=$MSToolsVersion.Value + $Toolsetv=$Toolset.Value + + $WSDK71Set="Windows7.1SDK" + $refnum="" + Write-Debug "VCVersion=$VCVersionv $env:VisualStudioVersion" +# +# Determine VisualStudioVersion +# + if (("$VisualStudioVersion" -eq "") -And ($configInfo -ne $null)) { + $VisualStudioVersion=$configInfo.Configuration.vcversion + } + if ("$VisualStudioVersion" -eq "") { + $VisualStudioVersion = $env:VisualStudioVersion # VC11 or later version of C++ command prompt sets this variable + } + if ("$VisualStudioVersion" -eq "") { + if ("${env:WindowsSDKVersionOverride}" -eq "v7.1") { # SDK7.1+ command prompt + $VisualStudioVersion = "10.0" + } elseif ("${env:VCInstallDir}" -ne "") { # C++ command prompt + if ("${env:VCInstallDir}" -match "Visual Studio\s*(\S+)\\VC\\$") { + $VisualStudioVersion = $matches[1] + } + } + } +# neither C++ nor SDK prompt + if ("$VisualStudioVersion" -eq "") { + if ("${env:VS120COMNTOOLS}" -ne "") { # VC12 is installed (current official) + $VisualStudioVersion = "12.0" + } elseif ("${env:VS100COMNTOOLS}" -ne "") { # VC10 is installed + $VisualStudioVersion = "10.0" + } elseif ("${env:VS140COMNTOOLS}" -ne "") { # VC14 is installed + $VisualStudioVersion = "14.0" + } elseif ("${env:VS110COMNTOOLS}" -ne "") { # VC11 is installed + $VisualStudioVersion = "11.0" + } else { + Write-Error "Visual Studio >= 10.0 not found" -Category InvalidArgument;return + } + } elseif ([int]::TryParse($VisualStudioVersion, [ref]$refnum)) { + $VisualStudioVersion="${refnum}.0" + } +# Check VisualStudioVersion and prepare for ToolsVersion + switch ($VisualStudioVersion) { + "10.0" { $tv = "4.0" } + "11.0" { $tv = "4.0" } + "12.0" { $tv = "12.0" } + "14.0" { $tv = "14.0" } + default { Write-Error "Selected Visual Stuidio is Version ${VisualStudioVersion}. Please use VC10 or later" -Category InvalidArgument; return } + } +# +# Determine ToolsVersion +# + if ("$MSToolsVersionv" -eq "") { + $MSToolsVersionv=$env:ToolsVersion + } + if ("$MSToolsVersionv" -eq "") { + $MSToolsVersionv = $tv + } elseif ([int]::TryParse($MSToolsVersionv, [ref]$refnum)) { + $MSToolsVersionv="${refnum}.0" + } +# +# Determine MSBuild executable +# + Write-Debug "ToolsVersion=$MSToolsVersionv VisualStudioVersion=$VisualStudioVersion" + try { + $msbver = invoke-expression "msbuild /ver /nologo" + if ("$msbver" -match "^(\d+)\.(\d+)") { + $major1 = [int] $matches[1] + $minor1 = [int] $matches[2] + if ($MSToolsVersionv -match "^(\d+)\.(\d+)") { + $bavail = $false + $major2 = [int] $matches[1] + $minor2 = [int] $matches[2] + if ($major1 -gt $major2) { + Write-Debug "$major1 > $major2" + $bavail = $true + } + elseif ($major1 -eq $major2 -And $minor1 -ge $minor2) { + Write-Debug "($major1, $minor1) >= ($major2, $minor2)" + $bavail = $true + } + if ($bavail) { + $msbuildexe = "MSBuild" + } + } + } + } catch {} + if ("$msbuildexe" -eq "") { + $msbindir="" + $regKey="HKLM:\Software\Wow6432Node\Microsoft\MSBuild\ToolsVersions\${MSToolsVersionv}" + if (Test-Path -path $regkey) { + $msbitem=Get-ItemProperty $regKey + if ($msbitem -ne $null) { + $msbindir=$msbitem.MSBuildToolsPath + } + } else { + $regKey="HKLM:\Software\Microsoft\MSBuild\ToolsVersions\${MSToolsVersionv}" + if (Test-Path -path $regkey) { + $msbitem=Get-ItemProperty $regKey + if ($msbitem -ne $null) { + $msbindir=$msbitem.MSBuildToolsPath + } + } else { + Write-Error "MSBuild ToolsVersion $MSToolsVersionv not Found" -Category NotInstalled; return + } + } + $msbuildexe = "$msbindir\msbuild" + } +# +# Determine PlatformToolset +# + if (("$Toolsetv" -eq "") -And ($configInfo -ne $null)) { + $Toolsetv=$configInfo.Configuration.toolset + } + if ("$Toolsetv" -eq "") { + $Toolsetv=$env:PlatformToolset + } + if ("$Toolsetv" -eq "") { + switch ($VisualStudioVersion) { + "10.0" { + if (Test-path "HKLM:\Software\Microsoft\Microsoft SDKs\Windows\v7.1") { + $Toolsetv=$WSDK71Set + } else { + $Toolsetv="v100" + } + } + "11.0" {$Toolsetv="v110_xp"} + "12.0" {$Toolsetv="v120_xp"} + "14.0" {$Toolsetv="v140_xp"} + } + } +# avoid a bug of Windows7.1SDK PlatformToolset + if ($Toolsetv -eq $WSDK71Set) { + $env:TARGET_CPU="" + } +# Restore PATH & current directory + $env:PATH = $path_save +# + $VCVersion.value=$VisualStudioVersion + $MSToolsVersion.value=$MSToolsVersionv + $Toolset.value=$Toolsetv + + return $msbuildexe +} diff --git a/winbuild/regress.ps1 b/winbuild/regress.ps1 new file mode 100644 index 0000000..6778eed --- /dev/null +++ b/winbuild/regress.ps1 @@ -0,0 +1,210 @@ +<# +.SYNOPSIS + Build all dlls of psqlodbc project using MSbuild. +.DESCRIPTION + Build test programs and run them. +.PARAMETER Target + Specify the target of MSBuild. "Build"(default) or + "Clean" is available. +.PARAMETER VCVersion + Visual Studio version is determined automatically unless this + option is specified. +.PARAMETER Platform + Specify build platforms, "Win32"(default), "x64" or "both" is available. +.PARAMETER Toolset + MSBuild PlatformToolset is determined automatically unless this + option is specified. Currently "v100", "Windows7.1SDK", "v110", + "v110_xp", "v120", "v120_xp", "v140" or "v140_xp" is available. +.PARAMETER MSToolsVersion + MSBuild ToolsVersion is detemrined automatically unless this + option is specified. Currently "4.0", "12.0" or "14.0" is available. +.PARAMETER Configuration + Specify "Release"(default) or "Debug". +.PARAMETER BuildConfigPath + Specify the configuration xml file name if you want to use + the configuration file other than standard one. + The relative path is relative to the current directory. +.EXAMPLE + > .\regress + Build with default or automatically selected parameters + and run them. +.EXAMPLE + > .\regress Clean + Clean all generated files. +.EXAMPLE + > .\regress -V(CVersion) 14.0 + Build using Visual Studio 11.0 environment. +.EXAMPLE + > .\regress -P(latform) x64 + Build only 64bit dlls. +.NOTES + Author: Hiroshi Inoue + Date: August 2, 2016 +#> + +# +# build 32bit & 64bit dlls for VC10 or later +# +Param( +[ValidateSet("Build", "Clean")] +[string]$Target="Build", +[string]$VCVersion, +[ValidateSet("Win32", "x64", "both")] +[string]$Platform="Win32", +[string]$Toolset, +[ValidateSet("", "4.0", "12.0", "14.0")] +[string]$MSToolsVersion, +[ValidateSet("Debug", "Release")] +[String]$Configuration="Release", +[string]$BuildConfigPath +) + + +function vcxfile_make($testsf, $vcxfile, $usingExe) +{ + $testnames=@() + $testexes=@() + $f = (Get-Content -Path $testsf) -as [string[]] + $nstart=$false + foreach ($l in $f) { + if ($l[0] -eq "#") { + continue + } + $sary=-split $l + if ($sary[0] -eq "#") { + continue + } + if ($sary[0] -eq "TESTBINS") { + $nstart=$true + $sary[0]=$null + if ($sary[1] -eq "=") { + $sary[1]=$null + } + } + if ($nstart) { + if ($sary[$sary.length - 1] -eq "\") { + $sary[$sary.length - 1] = $null + } else { + $nstart=$false + } + $testnames+=$sary + if (-not $nstart) { + break + } + } + } + for ($i=0; $i -lt $testnames.length; $i++) { + Write-Debug "$i : $testnames[$i]" + } +# here-string + @' + + + + Release + ..\test\src\ + + + +'@ > $vcxfile + + foreach ($testbin in $testnames) { + if ("$testbin" -eq "") { + continue + } + $sary=$testbin.split("/") + $testname=$sary[$sary.length -1] + $dirname="" + for ($i=0;$i -lt $sary.length - 1;$i++) { + $dirname+=($sary[$i]+"`\") + } + Write-Debug "testname=$testname dirname=$dirname" + if ($usingExe) { + $testexes+=($dirname+$testname+".exe") + } else { + $testexes+=$testname.Replace("-test","") + } +# here-string + @" + +"@ >> $vcxfile + } +# here-string + @' + + + + + + + +'@ >> $vcxfile + + return $testexes +} + +function RunTest($scriptPath, $Platform) +{ + # Run regression tests + if ($Platform -eq "x64") { + $targetdir="test_x64" + } else { + $targetdir="test_x86" + } + $revsdir="..\" + $origdir="${revsdir}..\test" + + pushd $scriptPath\$targetdir + + $regdiff="regression.diffs" + $RESDIR="results" + if (Test-Path $regdiff) { + Remove-Item $regdiff + } + New-Item $RESDIR -ItemType Directory -Force > $null + Get-Content "${origdir}\sampletables.sql" | .\reset-db + .\runsuite $TESTEXES --inputdir=$origdir + + popd +} + +$usingExe=$false +$testsf="..\test\tests" +Write-Debug testsf=$testsf +$vcxfile="./generated_regress.vcxproj" + +$TESTEXES=vcxfile_make $testsf $vcxfile $usingExe + +$scriptPath = (Split-Path $MyInvocation.MyCommand.Path) +$configInfo = & "$scriptPath\configuration.ps1" "$BuildConfigPath" +Import-Module ${scriptPath}\MSBuild-Get.psm1 +$msbuildexe=Get-MSBuild ([ref]$VCVersion) ([ref]$MSToolsVersion) ([ref]$Toolset) $configInfo + +if ($Platform -ieq "both") { + $pary = @("Win32", "x64") +} else { + $pary = @($Platform) +} + +foreach ($pl in $pary) { + invoke-expression -Command "& `"${msbuildexe}`" $vcxfile /tv:$MSToolsVersion /p:Platform=$pl``;Configuration=$Configuration``;PlatformToolset=${Toolset} /t:$target /p:VisualStudioVersion=${VisualStudioVersion} /Verbosity:minimal" + + if ($target -ieq "Clean") { + continue + } + + RunTest $scriptPath $pl $TESTEXES +} diff --git a/winbuild/regress_one.vcxproj b/winbuild/regress_one.vcxproj new file mode 100755 index 0000000..bce45da --- /dev/null +++ b/winbuild/regress_one.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {BBD60387-0E82-48F9-A0B3-41659252D639} + Win32Proj + regress + regress + regressw + + + + + + + Application + true + v120 + Ansi + + + Application + true + v120 + Ansi + + + Application + false + v120 + true + Ansi + + + Application + false + v120 + true + Ansi + + + + + + + + + + + + + + + + + + x86 + + + x64 + + + $(TestName) + test_$(TARGET_CPU)\obj\ + test_$(TARGET_CPU)\$(SubDir) + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + true + + + Console + true + $(IntDir)common.obj;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + %(IgnoreSpecificDefaultLibraries) + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + true + + + Console + true + $(IntDir)common.obj;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + %(IgnoreSpecificDefaultLibraries) + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + $(IntDir)common.obj;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + %(IgnoreSpecificDefaultLibraries) + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + $(IntDir)common.obj;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + %(IgnoreSpecificDefaultLibraries) + + + + + + + + + + -- 2.39.5