Skip to content

Commit

Permalink
improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
csoltenborn committed Sep 15, 2015
1 parent 9ea3843 commit c14e783
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 44 deletions.
Expand Up @@ -55,7 +55,6 @@ private static List<GoogleTestDiscoverer.SourceFileLocation> FindSymbolsFromExec
{
DiaSourceClass diaDataSource = new DiaSourceClass();
string path = ReplaceExtension(executable, ".pdb");
logger.SendMessage(TestMessageLevel.Informational, "Loading PDB: " + path);
try
{
Stream fileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
Expand All @@ -75,7 +74,7 @@ private static List<GoogleTestDiscoverer.SourceFileLocation> FindSymbolsFromExec
}

List<GoogleTestDiscoverer.SourceFileLocation> SourceFileLocations = foundSymbols.Select(symbol => GetSourceFileLocation(diaSession, logger, executable, symbol, allTraitSymbols)).ToList();
logger.SendMessage(TestMessageLevel.Informational, "From " + executable + ", found " + foundSymbols.Count + " symbols");
DebugUtils.LogUserDebugMessage(logger, new GoogleTestAdapterOptions(), TestMessageLevel.Informational, "GTA: found " + foundSymbols.Count + " symbols in executable " + executable);
return SourceFileLocations;
}
finally
Expand Down
Expand Up @@ -209,12 +209,7 @@ private List<string> GetSuitesRunningAllTests()

private List<string> GetAllSuitesOfTestCasesToRun()
{
// TODO remove debug code
Stopwatch Stopwatch = new Stopwatch();
Stopwatch.Start();
List<string> Result = CasesToRun.Select(GetTestsuiteNameFromCase).Distinct().ToList();
Stopwatch.Stop();
Logger.SendMessage(TestMessageLevel.Informational, "Duration for GetAllSuitesOfTestCasesToRun(): " + Stopwatch.Elapsed);
return Result;
}

Expand Down
Expand Up @@ -5,6 +5,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using GoogleTestAdapter.Scheduling;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

namespace GoogleTestAdapter
{
Expand All @@ -18,7 +19,7 @@ public void RunTests(bool runAllTestCases, IEnumerable<TestCase> allTestCases, I
{
if (testDirectory != null)
{
throw new ArgumentException("testDirectory should be null");
throw new ArgumentException("testDirectory must be null");
}

TestDurationSerializer serializer = new TestDurationSerializer();
Expand All @@ -27,14 +28,17 @@ public void RunTests(bool runAllTestCases, IEnumerable<TestCase> allTestCases, I
if (durations.Count < testCasesToRun.Count())
{
splitter = new NumberBasedTestsSplitter(testCasesToRun);
DebugUtils.LogUserDebugMessage(handle, Options, TestMessageLevel.Informational, "GTA: Using splitter based on number of tests");
}
else
{
splitter = new DurationBasedTestsSplitter(durations);
DebugUtils.LogUserDebugMessage(handle, Options, TestMessageLevel.Informational, "GTA: Using splitter based on test durations");
}

List<List<TestCase>> splittedTestCasesToRun = splitter.SplitTestcases();
List<Thread> threads = new List<Thread>();
handle.SendMessage(TestMessageLevel.Informational, "GTA: Executing " + testCasesToRun.Count() + " tests on " + splittedTestCasesToRun.Count + " threads");
foreach (List<TestCase> testcases in splittedTestCasesToRun)
{
IGoogleTestRunner runner = new PreparingTestRunner(new SequentialTestRunner(Options), Options);
Expand Down
Expand Up @@ -23,18 +23,18 @@ public void RunTests(bool runAllTestCases, IEnumerable<TestCase> allTestCases, I
{
if (testDirectory != null)
{
throw new ArgumentException("testDirectory should be null");
throw new ArgumentException("testDirectory must be null");
}

string tempFolder = Utils.GetTempDirectory();
testDirectory = Utils.GetTempDirectory();

// ProcessUtils.GetOutputOfCommand(handle, "", "", "", false, false, runContext, handle);

innerTestRunner.RunTests(runAllTestCases, allTestCases, testCasesToRun, runContext, handle, tempFolder);
innerTestRunner.RunTests(runAllTestCases, allTestCases, testCasesToRun, runContext, handle, testDirectory);

// ProcessUtils.GetOutputOfCommand(handle, "", "", "", false, false, runContext, handle);

Directory.Delete(tempFolder);
Directory.Delete(testDirectory);
}

}
Expand Down
Expand Up @@ -46,8 +46,8 @@ public class GoogleTestAdapterOptions : IOptions
private const string REG_OPTION_BASE_PRODUCTION = @"HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\ApplicationPrivateSettings\GoogleTestAdapterVSIX";
// ReSharper disable once UnusedMember.Local
private const string REG_OPTION_BASE_DEBUGGING = @"HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0Exp\ApplicationPrivateSettings\GoogleTestAdapterVSIX";
private const string REG_OPTION_GENERAL_BASE = REG_OPTION_BASE_PRODUCTION + @"\OptionPageGrid";
private const string REG_OPTION_PARALLELIZATION_BASE = REG_OPTION_BASE_PRODUCTION + @"\ParallelizationPageGrid";
private const string REG_OPTION_GENERAL_BASE = REG_OPTION_BASE_PRODUCTION + @"\GeneralOptionsDialogPage";
private const string REG_OPTION_PARALLELIZATION_BASE = REG_OPTION_BASE_PRODUCTION + @"\ParallelizationOptionsDialogPage";

//\OptionPageGrid
public const string OPTION_PRINT_TEST_OUTPUT = "Print test output";
Expand Down
12 changes: 6 additions & 6 deletions GoogleTestExtension/GoogleTestAdapter/GoogleTestDiscoverer.cs
Expand Up @@ -45,8 +45,8 @@ public List<TestCase> GetTestsFromExecutable(IMessageLogger logger, string execu
List<string> ConsoleOutput = ProcessUtils.GetOutputOfCommand(logger, "", executable, Constants.gtestListTests, false, false, null, null);
List<SuiteCasePair> SuiteCasePairs = ParseTestCases(ConsoleOutput);
SuiteCasePairs.Reverse();
logger.SendMessage(TestMessageLevel.Informational, "Found " + SuiteCasePairs.Count + " tests, resolving symbols...");
List<SourceFileLocation> SourceFileLocations = GetSourceFileLocations(executable, logger, SuiteCasePairs);
logger.SendMessage(TestMessageLevel.Informational, "GTA: Found " + SuiteCasePairs.Count + " tests in executable " + executable);
List<TestCase> TestCases = new List<TestCase>();
foreach (SuiteCasePair SuiteCasePair in SuiteCasePairs)
{
Expand Down Expand Up @@ -123,7 +123,7 @@ private TestCase ToTestCase(string executable, SuiteCasePair suiteCasePair, IMes
return TestCase;
}
}
logger.SendMessage(TestMessageLevel.Warning, "Could not find source location for test " + DisplayName);
logger.SendMessage(TestMessageLevel.Warning, "GTA: Could not find source location for test " + DisplayName);
return new TestCase(DisplayName, new Uri(GoogleTestExecutor.EXECUTOR_URI_STRING), executable)
{
DisplayName = DisplayName
Expand Down Expand Up @@ -179,19 +179,19 @@ public static bool IsGoogleTestExecutable(string executable, IMessageLogger logg
catch (ArgumentException e)
{
logger.SendMessage(TestMessageLevel.Error,
"Google Test Adapter: Regex '" + RegexUsed + "' configured under Options/Google Test Adapter can not be parsed: " + e.Message);
"GTA: Regex '" + RegexUsed + "' configured under Options/Google Test Adapter can not be parsed: " + e.Message);
Matches = false;
}
catch (RegexMatchTimeoutException e)
{
logger.SendMessage(TestMessageLevel.Error,
"Google Test Adapter: Regex '" + RegexUsed + "' configured under Options/Google Test Adapter timed out: " + e.Message);
"GTA: Regex '" + RegexUsed + "' configured under Options/Google Test Adapter timed out: " + e.Message);
Matches = false;
}
}

DebugUtils.LogDebugMessage(logger, TestMessageLevel.Informational,
"GoogleTestAdapter: Does " + executable + " match " + RegexUsed + ": " + Matches);
DebugUtils.LogUserDebugMessage(logger, new GoogleTestAdapterOptions(), TestMessageLevel.Informational,
"GTA: " + executable + (Matches ? " matches " : " does not match ") + "regex '" + RegexUsed + "'");

return Matches;
}
Expand Down
36 changes: 19 additions & 17 deletions GoogleTestExtension/GoogleTestAdapter/GoogleTestExecutor.cs
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

namespace GoogleTestAdapter
{
Expand Down Expand Up @@ -60,6 +61,24 @@ public void RunTests(IEnumerable<TestCase> testCasesToRun, IRunContext runContex
RunTests(false, AllTestCasesInAllExecutables, TestCasesToRun, runContext, frameworkHandle);
}

private void RunTests(bool runAllTestCases, IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, IRunContext runContext, IFrameworkHandle handle)
{
IGoogleTestRunner runner;
string testDirectory;
if (Options.ParallelTestExecution)
{
runner = new ParallelTestRunner(Options);
testDirectory = null;
}
else
{
runner = new SequentialTestRunner(Options);
testDirectory = Utils.GetTempDirectory();
}
runner.RunTests(runAllTestCases, allTestCases, testCasesToRun, runContext, handle, testDirectory);
handle.SendMessage(TestMessageLevel.Informational, "GTA: Test execution completed.");
}

public static IDictionary<string, List<TestCase>> GroupTestcasesByExecutable(IEnumerable<TestCase> testcases)
{
Dictionary<string, List<TestCase>> GroupedTestCases = new Dictionary<string, List<TestCase>>();
Expand All @@ -80,23 +99,6 @@ public void RunTests(IEnumerable<TestCase> testCasesToRun, IRunContext runContex
return GroupedTestCases;
}

private void RunTests(bool runAllTestCases, IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, IRunContext runContext, IFrameworkHandle handle)
{
IGoogleTestRunner runner;
string testDirectory;
if (Options.ParallelTestExecution)
{
runner = new ParallelTestRunner(Options);
testDirectory = null;
}
else
{
runner = new SequentialTestRunner(Options);
testDirectory = Utils.GetTempDirectory();
}
runner.RunTests(runAllTestCases, allTestCases, testCasesToRun, runContext, handle, testDirectory);
}

}

}
12 changes: 10 additions & 2 deletions GoogleTestExtension/GoogleTestAdapter/Helpers/DebugUtils.cs
Expand Up @@ -20,14 +20,22 @@ public static void LogDebugMessage(IMessageLogger logger, TestMessageLevel level
}
}

public static void LogUserDebugMessage(IMessageLogger logger, IOptions options, TestMessageLevel level, string message)
{
if (options.UserDebugMode)
{
logger.SendMessage(level, message);
}
}

public static void CheckDebugModeForExecutionCode(IMessageLogger logger = null)
{
CheckDebugMode("Test execution code", logger);
CheckDebugMode("GTA: Test execution code", logger);
}

public static void CheckDebugModeForDiscoverageCode(IMessageLogger logger = null)
{
CheckDebugMode("Test discoverage code", logger);
CheckDebugMode("GTA: Test discoverage code", logger);
}

private static void CheckDebugMode(string codeType, IMessageLogger logger = null)
Expand Down
Expand Up @@ -48,7 +48,7 @@ private List<TestResult> ParseTestResults()
{
XmlDocument XmlDocument = new XmlDocument();
XmlDocument.Load(XmlResultFile);
Logger.SendMessage(TestMessageLevel.Informational, "Opened results from " + XmlResultFile);
DebugUtils.LogUserDebugMessage(Logger, new GoogleTestAdapterOptions(), TestMessageLevel.Informational, "Loaded test results from " + XmlResultFile);

XmlNodeList TestsuiteNodes = XmlDocument.DocumentElement.SelectNodes("/testsuites/testsuite");
foreach (XmlNode TestsuiteNode in TestsuiteNodes)
Expand Down
11 changes: 7 additions & 4 deletions GoogleTestExtension/GoogleTestAdapterVSIX/TODOs.txt
@@ -1,9 +1,9 @@
Before release:
code review
improve logging
implement execution of setup/teardown batches
move settings into XML file to be saved into solution dir
more placeholders for batches and execution params
improve logging
move more constants to Constants.cs
refactor Helpers
reduce visibilities where possible
Expand All @@ -12,17 +12,20 @@
end-to-end tests
change target VS version to >= VS2015
change code style to follow C# conventions
docs
docs and/or improved option descriptions
fix "error message if run automatically after build" bug
goal: should work :-)
fix test stability of test ParallelGoogleTestExecutorTests.RunsHardCrashingX86TestsWithoutResult
fails occasionally, probably because of distribution of tests to invocations of executable
fix "not all test results are shown" bug
goal: remove waiting in TestResultsReporter
fix "error message if run automatically after build" bug
goal: should work :-)

For next release:
performance optimizations
scheduling
parallel test discovery
smarter scheduling
e.g. reduce number of times executables are invoked
refactor TestDurationSerializer
XML format
date, time?

0 comments on commit c14e783

Please sign in to comment.