Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call TestUtilities.InitUtilities appropriately #11148

Merged
merged 2 commits into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 15 additions & 93 deletions src/Test/Perf/util/TestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public class TestUtilities
//
public static string _myWorkingFile = null;

/// <summary>
/// This method should be called *ONLY* by the csx scripts.
/// This method *MUST NOT* be called from within the library itself. If this method is called within the library instead of csx scripts
/// then <param name="sourceFilePath"/> will be set to the path of the file when the library is actual built.
/// For Eg: If SomeLibarayFile.cs calls this method and if the library is built is some build machine where SomeLibarayFile.cs is saved at
/// Y:/Project/SomeLibarayFile.cs then when the library is used in any machine where there is no Y: drive then we will see errors saying
/// invalid directory path. Also note that <param name="sourceFilePath"/> will be set to "Y:/Project/SomeLibarayFile.cs" and not set to
/// the path of the file from where the call to SomeLibarayFile.cs which in turn called <see cref="InitUtilities(string)"/>
/// </summary>
public static void InitUtilities([CallerFilePath] string sourceFilePath = "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InitUtilitiesFromCsx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

{
_myWorkingFile = sourceFilePath;
Expand All @@ -35,97 +44,6 @@ public static string MyWorkingDirectory()
return Directory.GetParent(_myWorkingFile).FullName;
}

/// Returns the directory that you can put artifacts like
/// etl traces or compiled binaries
public static string MyArtifactsDirectory()
{
var path = Path.Combine(MyWorkingDirectory(), "artifacts");
Directory.CreateDirectory(path);
return path;
}

public static string MyTempDirectory()
{
var workingDir = MyWorkingDirectory();
var path = Path.Combine(workingDir, "temp");
Directory.CreateDirectory(path);
return path;
}

public static string RoslynDirectory()
{
var workingDir = MyWorkingDirectory();
var binaryDebug = Path.Combine("Binaries", "Debug").ToString();
int binaryDebugIndex = workingDir.IndexOf(binaryDebug, StringComparison.OrdinalIgnoreCase);
if (binaryDebugIndex != -1)
{
return workingDir.Substring(0, binaryDebugIndex);
}

var binaryRelease= Path.Combine("Binaries", "Release").ToString();
return workingDir.Substring(0, workingDir.IndexOf(binaryRelease, StringComparison.OrdinalIgnoreCase));
}

public static string CscPath()
{
return Path.Combine(MyBinaries(), "csc.exe");
}

public static string MyBinaries()
{
var workingDir = MyWorkingDirectory();
// We may be a release or debug build
var debug = workingDir.IndexOf("debug", StringComparison.CurrentCultureIgnoreCase);
if (debug != -1)
return workingDir.Substring(0, debug + "debug".Length);

var release = workingDir.IndexOf("release", StringComparison.CurrentCultureIgnoreCase);
if (release != -1)
return workingDir.Substring(0, release + "release".Length);

throw new Exception("You are attempting to run performance test from the src directory. Run it from binaries");
}

public static string PerfDirectory()
{
return Path.Combine(RoslynDirectory(), "src", "Test", "Perf");
}

public static string BinDirectory()
{
return Path.Combine(RoslynDirectory(), "Binaries");
}

public static string BinDebugDirectory()
{
return Path.Combine(BinDirectory(), "Debug");
}

public static string BinReleaseDirectory()
{
return Path.Combine(BinDirectory(), "Release");
}

public static string DebugCscPath()
{
return Path.Combine(BinDebugDirectory(), "csc.exe");
}

public static string ReleaseCscPath()
{
return Path.Combine(BinReleaseDirectory(), "csc.exe");
}

public static string DebugVbcPath()
{
return Path.Combine(BinDebugDirectory(), "vbc.exe");
}

public static string ReleaseVbcPath()
{
return Path.Combine(BinReleaseDirectory(), "vbc.exe");
}

public static string GetCPCDirectoryPath()
{
return Environment.ExpandEnvironmentVariables(@"%SYSTEMDRIVE%\CPC");
Expand Down Expand Up @@ -154,6 +72,8 @@ public class ProcessResult

/// Shells out, and if the process fails, log the error
/// and quit the script.
/// NOTE: <param name="workingDirectory"/> should be set when called inside the library and not from csx. see <see cref="InitUtilities(string)"/>
/// for more information
public static void ShellOutVital(
string file,
string args,
Expand All @@ -170,6 +90,8 @@ public class ProcessResult
}
}

/// NOTE: <param name="workingDirectory"/> should be set when called inside the library and not from csx. see <see cref="InitUtilities(string)"/>
/// for more information
public static ProcessResult ShellOut(
string file,
string args,
Expand Down Expand Up @@ -240,9 +162,9 @@ public class ProcessResult
};
}

public static string StdoutFrom(string program, bool verbose, ILogger logger, string args = "")
public static string StdoutFrom(string program, bool verbose, ILogger logger, string args = "", string workingDirectory = null)
{
var result = ShellOut(program, args, verbose, logger);
var result = ShellOut(program, args, verbose, logger, workingDirectory);
if (result.Failed)
{
LogProcessResult(result, logger);
Expand Down
4 changes: 2 additions & 2 deletions src/Test/Perf/util/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static string GetViBenchJsonFromCsv(string compilerTimeCsvFilePath, strin

arguments = arguments.Replace("\r\n", " ").Replace("\n", "");

ShellOutVital(Path.Combine(GetCPCDirectoryPath(), "ViBenchToJson.exe"), arguments, verbose, logger);
ShellOutVital(Path.Combine(GetCPCDirectoryPath(), "ViBenchToJson.exe"), arguments, verbose, logger, workingDirectory: "");

return outJson;
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public static void UploadTraces(string sourceFolderPath, string destinationFolde

public static void CopyDirectory(string source, ILogger logger, string destination, string argument = @"/mir")
{
var result = ShellOut("Robocopy", $"{argument} {source} {destination}", verbose: true, logger: logger);
var result = ShellOut("Robocopy", $"{argument} {source} {destination}", verbose: true, logger: logger, workingDirectory: "");

// Robocopy has a success exit code from 0 - 7
if (result.Code > 7)
Expand Down
12 changes: 4 additions & 8 deletions src/Test/Perf/util/TraceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public class TraceManager : ITraceManager
_scenarioGenerator = new ScenarioGenerator(scenarioPath);
_verbose = verbose;
_logger = logger;

// Since TraceManager.Setup() and few other functions use ShellOutVital,
// which requires the TestUtilities.InitUtilities() to be called
InitUtilities();
}

public bool HasWarmUpIteration
Expand Down Expand Up @@ -63,24 +59,24 @@ public void Initialize()

public void Setup()
{
ShellOutVital(_cpcPath, "/Setup /DisableArchive", _verbose, _logger);
ShellOutVital(_cpcPath, "/Setup /DisableArchive", _verbose, _logger, workingDirectory: "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't specify the value explicitly then we will try to run the command inside MyWorkingDirectory() directory. This scenario holds true only when called from csx files.

In short, both calling InitUtilities() from within library and not setting the value of _workingDirectory are wrong. The correct approach is to always provide the directory to run the command if it is run outside of the context of csx.

}

public void Start()
{
ShellOutVital(_cpcPath, "/Start /DisableArchive", _verbose, _logger);
ShellOutVital(_cpcPath, "/Start /DisableArchive", _verbose, _logger, workingDirectory: "");
}

public void Stop()
{
var scenariosXmlPath = Path.Combine(GetCPCDirectoryPath(), "scenarios.xml");
var consumptionTempResultsPath = Path.Combine(GetCPCDirectoryPath(), "ConsumptionTempResults.xml");
ShellOutVital(_cpcPath, $"/Stop /DisableArchive /ScenarioPath=\"{scenariosXmlPath}\" /ConsumptionTempResultsPath=\"{consumptionTempResultsPath}\"", _verbose, _logger);
ShellOutVital(_cpcPath, $"/Stop /DisableArchive /ScenarioPath=\"{scenariosXmlPath}\" /ConsumptionTempResultsPath=\"{consumptionTempResultsPath}\"", _verbose, _logger, workingDirectory: "");
}

public void Cleanup()
{
ShellOutVital(_cpcPath, "/Cleanup /DisableArchive", _verbose, _logger);
ShellOutVital(_cpcPath, "/Cleanup /DisableArchive", _verbose, _logger, workingDirectory: "");
}

public void StartScenarios()
Expand Down