Add simple script generator
authorSasha Semennikov <alsemenn@microsoft.com>
Tue, 15 Nov 2016 01:20:35 +0000 (17:20 -0800)
committerSasha Semennikov <alsemenn@microsoft.com>
Wed, 16 Nov 2016 23:51:22 +0000 (15:51 -0800)
Modify script generation to substitute config strings

Add Unix version of the script generation

Add config replacement

Fix windows deployment script issues

Add unix config generation

Address comments

tests/debugger_tests/ConfigFilesGenerators/ConfigTemplate.txt [new file with mode: 0644]
tests/debugger_tests/ConfigFilesGenerators/GenerateConfig.cmd [new file with mode: 0644]
tests/debugger_tests/ConfigFilesGenerators/GenerateConfig.sh [new file with mode: 0644]
tests/debugger_tests/setup-debuggertests.cmd [new file with mode: 0644]
tests/debugger_tests/setup-debuggertests.sh [new file with mode: 0644]
tests/setup-debuggertets.cmd [deleted file]
tests/setup-debuggertets.sh [deleted file]

diff --git a/tests/debugger_tests/ConfigFilesGenerators/ConfigTemplate.txt b/tests/debugger_tests/ConfigFilesGenerators/ConfigTemplate.txt
new file mode 100644 (file)
index 0000000..d674a72
--- /dev/null
@@ -0,0 +1,32 @@
+<Configuration> 
+ <TestRoot>..\..</TestRoot> 
+ <TargetArchitecture>x64</TargetArchitecture> 
+ <ScriptRootDir>$(TestRoot)\Scripts</ScriptRootDir> 
+ <DebuggeeRootDir>$(TestRoot)\Debuggees</DebuggeeRootDir> 
+ <DebuggeeSourceRoot>$(DebuggeeRootDir)\Source</DebuggeeSourceRoot>
+ <RuntimeRoot>##Insert_Runtime_Root##</RuntimeRoot>
+ <NugetCacheRoot>##Insert_Nuget_Cache_Root##</NugetCacheRoot>
+ <TestProduct>ProjectK</TestProduct> 
+ <HostExe>$(RuntimeRoot)\corerun.exe</HostExe> 
+ <DbgShim>$(RuntimeRoot)\dbgshim.dll</DbgShim> 
+ <RuntimeSymbolsPath>$(RuntimeRoot)</RuntimeSymbolsPath> 
+ <DebuggeeBuildProcess>cli</DebuggeeBuildProcess> 
+ <CliVersion>1.0.0-preview1-002702</CliVersion> 
+ <DebuggeeNativeLibRoot>$(DebuggeeRootDir)\native</DebuggeeNativeLibRoot> 
+ <DebuggeeBuildRoot>$(DebuggeeRootDir)\dotnet.$(CliVersion)</DebuggeeBuildRoot> 
+ <ProjectJsonNetStandardLibraryVersion>1.0.0-rc2-23811</ProjectJsonNetStandardLibraryVersion> 
+ <ProjectJsonSystemThreadingThreadVersion>4.0.0-rc2-24027</ProjectJsonSystemThreadingThreadVersion> 
+ <ProjectJsonMicrosoftCSharpVersion>4.0.1-rc2-23811</ProjectJsonMicrosoftCSharpVersion> 
+ <CliPath>##Cli_Path##</CliPath> 
+ <NuGetPackageCacheDir>$(NugetCacheRoot)</NuGetPackageCacheDir> 
+ <NuGetPackageFeeds> 
+     myget.org dotnet-core=https://dotnet.myget.org/F/dotnet-core/api/v3/index.json; 
+     myget.org=https://www.nuget.org/api/v2/ 
+ </NuGetPackageFeeds> 
+ <SOSPath>$(RuntimeRoot)\sos.dll</SOSPath> 
+ <MDbgDir>$(TestRoot)\mdbg</MDbgDir> 
+ <DebuggeeDumpOutputRootDir>$(WorkingDir)\dumps\$(TestProduct)</DebuggeeDumpOutputRootDir> 
+ <DebuggeeDumpInputRootDir>$(DebuggeeDumpOutputRootDir)</DebuggeeDumpInputRootDir> 
+ <LogDir>$(TestRoot)\logs_$(Timestamp)</LogDir> 
+ <CDBPath>$(TestRoot)\Debuggers\cdb\cdb.exe</CDBPath> 
+</Configuration> 
diff --git a/tests/debugger_tests/ConfigFilesGenerators/GenerateConfig.cmd b/tests/debugger_tests/ConfigFilesGenerators/GenerateConfig.cmd
new file mode 100644 (file)
index 0000000..635df95
--- /dev/null
@@ -0,0 +1,53 @@
+@echo off
+setlocal EnableDelayedExpansion
+
+:: Set the default arguments for script generation.
+set __RuntimeRoot=`$(TestRoot)\Runtimes\Coreclr1
+set __NugetCacheDir=`$(WorkingDir)\packages
+set __CliPath=
+set __ConfigFileName=Debugger.Tests.Config.txt
+set __TemplateFileName=%~dp0\ConfigTemplate.txt
+
+:Arg_Loop
+if "%1" == "" goto ArgsDone
+if /i "%1" == "/?" goto Usage
+
+if /i "%1" == "rt"      (set "__RuntimeRoot=%2"&shift&shift&goto Arg_Loop)
+if /i "%1" == "nc"      (set "__NugetCacheDir=%2"&shift&shift&goto Arg_Loop)
+if /i "%1" == "cli"     (set "__CliPath=%2"&shift&shift&goto Arg_Loop)
+
+echo Invalid commandline argument: %1
+goto Usage
+
+:ArgsDone
+
+if not exist %__TemplateFileName% (
+    echo Template file %__TemplateFileName% doesn't exist.
+    exit /b 1
+)
+
+:: Delete previous config file.
+if exist %__ConfigFileName% (
+    echo Deleting current config file.
+    del %__ConfigFileName%
+)
+
+:: powershell "Get-Content %__TemplateFileName% -replace (""##Insert_Runtime_Root##"", ""%__RuntimeRoot%"") | Output-File %__ConfigFileName% "
+powershell "(Get-Content \"%__TemplateFileName%\")`"^
+    "-replace \"##Insert_Runtime_Root##\", \"%__RuntimeRoot%\" `"^
+    "|ForEach-Object{$_ -replace \"##Insert_Nuget_Cache_Root##\", \"%__NugetCacheDir%\"} `"^
+    "|ForEach-Object{$_ -replace \"##Cli_Path##\", \"%__CliPath%\"} `"^
+    "| Out-File \"%__ConfigFileName%\""
+
+exit /b 0
+
+:Usage
+echo.
+echo Usage:
+echo %0 [rt ^<runtime_path^>] [nc ^<nuget_cache_path^>] [cli ^<cli_path^>] where:
+echo.
+echo ^<runtime_path^>: path to the runtime that you want to use for testing.
+echo ^<nuget_cache_path^>: path to the nuget cache.
+echo ^<cli_path^>: path to the cli tool.
+exit /b 1
+endlocal
diff --git a/tests/debugger_tests/ConfigFilesGenerators/GenerateConfig.sh b/tests/debugger_tests/ConfigFilesGenerators/GenerateConfig.sh
new file mode 100644 (file)
index 0000000..38834ed
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+function print_usage {
+    echo ''
+    echo 'Usage:'
+    echo '[rt=<runtime_path>] [nc=<nuget_cache_path>] [cli=<cli_path>] where:'
+    echo '  <runtime_path>: path to the runtime that you want to use for testing.'
+    echo '  <nuget_cache_path>: path to the nuget cache.'
+    echo '  <cli_path>: path to the cli tool.'
+    echo ''
+    echo ''
+}
+
+# Argument variables
+__RuntimeRoot='$(TestRoot)\Runtimes\Coreclr1'
+__NugetCacheDir='$(WorkingDir)\packages'
+__CliPath=
+__ConfigFileName='Debugger.Tests.Config.txt'
+__TemplateFileName='ConfigTemplate.txt'
+
+for i in "$@"
+do
+    case $i in
+        -h|--help)
+            print_usage
+            exit $EXIT_CODE_SUCCESS
+            ;;
+        rt=*)
+            __RuntimeRoot=${i#*=}
+            ;;
+        nc=*)
+            __NugetCacheDir=${i#*=}
+            ;;
+        cli=*)
+            __CliPath=${i#*=}
+            ;;
+        *)
+            echo "Unknown switch: $i"
+            print_usage
+            exit $EXIT_CODE_SUCCESS
+            ;;
+    esac
+done
+
+if ! -e "$__TemplateFileName"
+then
+    echo '$__TemplateFileName does not exist'
+    exit 1
+fi
+
+if -e "$__ConfigFileName"
+then
+    rm "$__ConfigFileName"
+fi
+
+cp "$__TemplateFileName" "$__ConfigFileName"
+
+sed -i \
+    's/##Insert_Runtime_Root##/$__RuntimeRoot/g;' \
+    's/##Insert_Nuget_Cache_Root##/$__NugetCacheDir/g'\
+    's/##Cli_Path##/$__CliPath/g'\
+    's/corerun.exe/corerun/g'\
+    "$__ConfigFileName"
+
+exit 0
\ No newline at end of file
diff --git a/tests/debugger_tests/setup-debuggertests.cmd b/tests/debugger_tests/setup-debuggertests.cmd
new file mode 100644 (file)
index 0000000..0305005
--- /dev/null
@@ -0,0 +1,95 @@
+@if not defined __echo @echo off
+setlocal
+
+set __ThisScriptShort=%0
+set __ThisScriptFull=%~f0
+set __ThisScriptPath=%~dp0
+
+REM =========================================================================================
+REM ===
+REM === Parse arguments
+REM ===
+REM =========================================================================================
+
+set __OutputDir=
+set __Arch= 
+set __CoreclrBinPath=
+set __NugetCacheDir=
+set __CliPath=
+
+:Arg_Loop
+if "%1" == "" goto ArgsDone
+
+if /i "%1" == "/?"    goto Usage
+if /i "%1" == "-?"    goto Usage
+if /i "%1" == "/h"    goto Usage
+if /i "%1" == "-h"    goto Usage
+if /i "%1" == "/help" goto Usage
+if /i "%1" == "-help" goto Usage
+
+if /i "%1" == "/outputDir"          (set __OutputDir=%2&shift&shift&goto Arg_Loop)
+if /i "%1" == "/coreclrBinDir"      (set __CoreclrBinPath=%2&shift&shift&goto Arg_Loop)
+if /i "%1" == "/nugetCacheDir"      (set __NugetCacheDir=%2&shift&shift&goto Arg_Loop)
+if /i "%1" == "/cliPath"            (set __CliPath=%2&shift&shift&goto Arg_Loop)
+
+
+echo Invalid command-line argument: %1
+goto Usage
+
+:ArgsDone
+
+if not defined __OutputDir goto Usage
+if not defined __Arch goto Usage 
+
+REM Create directories needed
+if exist "%__OutputDir%\debuggertests" rmdir /S /Q "%__OutputDir%\debuggertests"
+md "%__OutputDir%\debuggertests"
+set __InstallDir=%__OutputDir%\debuggertests
+
+REM =========================================================================================
+REM ===
+REM === download debuggertests package
+REM ===
+REM =========================================================================================
+set DEBUGGERTESTS_URL=https://dotnetbuilddrops.blob.core.windows.net/debugger-container/Windows.DebuggerTests.zip
+set LOCAL_ZIP_PATH=%__InstallDir%\debuggertests.zip
+if exist "%LOCAL_ZIP_PATH%" del "%LOCAL_ZIP_PATH%"
+set DEBUGGERTESTS_INSTALL_LOG="%__ThisScriptPath%debuggerinstall.log"
+REM Download the package
+echo Download and unzip debuggertests package to %LOCAL_ZIP_PATH%
+powershell -NoProfile -ExecutionPolicy unrestricted -Command "$retryCount = 0; $success = $false; do { try { (New-Object Net.WebClient).DownloadFile('%DEBUGGERTESTS_URL%', '%LOCAL_ZIP_PATH%'); $success = $true; } catch { if ($retryCount -ge 6) { throw; } else { $retryCount++; Start-Sleep -Seconds (5 * $retryCount); } } } while ($success -eq $false); Add-Type -Assembly 'System.IO.Compression.FileSystem' -ErrorVariable AddTypeErrors; if ($AddTypeErrors.Count -eq 0) { [System.IO.Compression.ZipFile]::ExtractToDirectory('%LOCAL_ZIP_PATH%', '%__InstallDir%') } else { (New-Object -com shell.application).namespace('%LOCAL_ZIP_PATH%').CopyHere((new-object -com shell.application).namespace('%__InstallDir%').Items(),16) }" >> %DEBUGGERTESTS_INSTALL_LOG%
+
+if errorlevel 1 (
+    echo Failed to install debuggertests to %__InstallDir%
+    goto Fail
+)
+
+REM =========================================================================================
+REM ===
+REM === Setting up the right config file.
+REM ===
+REM =========================================================================================
+echo Generating config file.
+
+call %__ThisScriptPath%\ConfigFilesGenerators\GenerateConfig.cmd rt %__CoreclrBinPath% nc %__NugetCacheDir% cli %__CliPath%
+move Debugger.Tests.Config.txt %__InstallDir%\\Debugger.Tests\dotnet\Debugger.Tests.Config.txt
+
+exit /b 0
+
+:Fail
+exit /b 1
+
+REM =========================================================================================
+REM ===
+REM === Helper routines
+REM ===
+REM =========================================================================================
+
+:Usage
+echo.
+echo install debugger tests
+echo.
+echo Usage:
+echo     %__ThisScriptShort% /coreclrBinDir ^<coreclr bin path^> /outputDir ^<debuggertests install path^> /nugetCacheDir ^<nuget cache dir path^>
+echo.
+exit /b 1
diff --git a/tests/debugger_tests/setup-debuggertests.sh b/tests/debugger_tests/setup-debuggertests.sh
new file mode 100644 (file)
index 0000000..315359c
Binary files /dev/null and b/tests/debugger_tests/setup-debuggertests.sh differ
diff --git a/tests/setup-debuggertets.cmd b/tests/setup-debuggertets.cmd
deleted file mode 100644 (file)
index 33686bd..0000000
Binary files a/tests/setup-debuggertets.cmd and /dev/null differ
diff --git a/tests/setup-debuggertets.sh b/tests/setup-debuggertets.sh
deleted file mode 100644 (file)
index 1487a33..0000000
Binary files a/tests/setup-debuggertets.sh and /dev/null differ