Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TestSession.cs
Go to the documentation of this file.
1 using SiliconStudio.Core.Diagnostics;
2 using SiliconStudio.Core.IO;
3 using SiliconStudio.Core.Serialization;
4 using System;
5 using System.Collections.Generic;
6 using System.Diagnostics;
7 using System.IO;
8 using System.Reflection;
9 using System.Threading.Tasks;
10 
11 namespace SiliconStudio.BuildEngine
12 {
13  public class DoNothingCommand : Command
14  {
15  /// <inheritdoc/>
16  public override string Title { get { return "Do nothing!"; } }
17 
18  private static int commandCounter;
19  private readonly int commandId;
20 
21  protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
22  {
23  return Task.Run(() => ResultStatus.Successful);
24  }
25 
26  public static void ResetCounter()
27  {
28  commandCounter = 0;
29  }
30 
32  {
33  commandId = ++commandCounter;
34  }
35 
36  public override string ToString()
37  {
38  return GetType().Name + " " + commandId;
39  }
40 
41  protected override void ComputeParameterHash(Stream stream)
42  {
43  base.ComputeParameterHash(stream);
44 
45  var writer = new BinarySerializationWriter(stream);
46  writer.Write(commandId);
47  }
48  }
49 
50  public class TestSession
51  {
52  public void RunTest(string testName, Logger logger)
53  {
54  foreach (MethodInfo method in typeof(TestSession).GetMethods())
55  {
56  if (method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(Logger))
57  {
58  if (string.Compare(method.Name, testName, StringComparison.OrdinalIgnoreCase) == 0)
59  method.Invoke(this, new object[] { logger });
60  }
61  }
62  }
63 
64  //private static PluginResolver pluginManager;
65  private static void BuildStepsRecursively(Builder builder, ICollection<BuildStep> steps, int stepsPerLevel, int maxLevel, BuildStep curParent = null, int curLevel = 0)
66  {
67  if (curLevel == maxLevel)
68  return;
69 
70  for (var i = 0; i < stepsPerLevel; ++i)
71  {
72  BuildStep step = builder.Root.Add(new DoNothingCommand());
73  if (curParent != null)
74  BuildStep.LinkBuildSteps(curParent, step);
75  BuildStepsRecursively(builder, steps, stepsPerLevel, maxLevel, step, curLevel + 1);
76  steps.Add(step);
77  }
78  }
79 
80  public static void TestVeryLargeNumberOfEmptyCommands(Logger logger)
81  {
82  string appPath = VirtualFileSystem.GetAbsolutePath("/data/TestVeryLargeNumberOfEmptyCommands");
83  string dbPath = appPath + "/TestVeryLargeNumberOfEmptyCommands";
84 
85  if (Directory.Exists(dbPath))
86  Directory.Delete(dbPath, true);
87 
88  Directory.CreateDirectory(dbPath);
89  VirtualFileSystem.MountFileSystem("/data/db", dbPath);
90  logger.ActivateLog(LogMessageType.Debug);
91  var builder = new Builder("TestBuilder", appPath, Builder.Mode.Build, logger);
92  var steps = new List<BuildStep>();
93  const int StepsPerLevel = 5;
94  const int MaxLevel = 5;
95 
96  BuildStepsRecursively(builder, steps, StepsPerLevel, MaxLevel);
97  int stepCount = 0;
98  for (var i = 0; i < MaxLevel; ++i)
99  {
100  stepCount += (int)Math.Pow(StepsPerLevel, i + 1);
101  }
102  Debug.Assert(steps.Count == stepCount);
103 
104  logger.Info(stepCount + " steps registered.");
105  logger.Info("Starting builder (logger disabled)");
106  logger.ActivateLog(LogMessageType.Fatal);
107  builder.Run();
108  logger.ActivateLog(LogMessageType.Debug);
109  logger.Info("Build finished (logger re-enabled)");
110 
111  foreach (BuildStep step in steps)
112  {
113  Debug.Assert(step.Status == ResultStatus.Successful);
114  }
115  }
116 
117  }
118 }
override void ComputeParameterHash(Stream stream)
Definition: TestSession.cs:41
Implements SerializationStream as a binary writer.
ResultStatus
Status of a command.
Definition: ResultStatus.cs:8
Base implementation for ILogger.
Definition: Logger.cs:10
Mode
Indicate which mode to use with this builder
Definition: Builder.cs:69
override Task< ResultStatus > DoCommandOverride(ICommandContext commandContext)
The method to override containing the actual command code. It is called by the DoCommand function ...
Definition: TestSession.cs:21
static void TestVeryLargeNumberOfEmptyCommands(Logger logger)
Definition: TestSession.cs:80
void RunTest(string testName, Logger logger)
Definition: TestSession.cs:52