Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
RegressionHelpers.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Diagnostics;
6 using System.IO;
8 using System.Runtime.InteropServices;
9 using System.Text;
10 using SiliconStudio.Core.LZ4;
11 
12 #if SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
13 using Windows.Security.Cryptography;
14 using Windows.Security.Cryptography.Core;
15 using Windows.System.Profile;
16 using Windows.Security.ExchangeActiveSyncProvisioning;
17 #endif
18 
19 namespace SiliconStudio.Paradox.Graphics.Regression
20 {
21  public partial class TestRunner
22  {
23  public const string ParadoxServerIp = "PARADOX_SERVER_IP";
24 
25  public const string ParadoxServerPort = "PARADOX_SERVER_PORT";
26 
27  public const string ParadoxBuildNumber = "PARADOX_BUILD_NUMBER";
28 
29  public const string ParadoxTestName = "PARADOX_TEST_NAME";
30 
31  public const string ParadoxBranchName = "PARADOX_BRANCH_NAME";
32  }
33 
35  {
37  SendImage = 1,
39  }
40 
41  public class PlatformPermutator
42  {
44  {
45  var result = new ImageTestResultConnection();
46 
47  // TODO: Check build number in environment variables
48  result.BuildNumber = -1;
49 
50 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
51  result.Platform = "Windows";
52  result.Serial = Environment.MachineName;
53 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
54  result.DeviceName = "Direct3D";
55 #elif SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
56  result.DeviceName = "OpenGLES";
57 #elif SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL
58  result.DeviceName = "OpenGL";
59 #endif
60 #elif SILICONSTUDIO_PLATFORM_ANDROID
61  result.Platform = "Android";
62  result.DeviceName = Android.OS.Build.Manufacturer + " " + Android.OS.Build.Model;
63  result.Serial = Android.OS.Build.Serial ?? "Unknown";
64 #elif SILICONSTUDIO_PLATFORM_IOS
65  result.Platform = "iOS";
66  result.DeviceName = iOSDeviceType.Version.ToString();
67  result.Serial = MonoTouch.UIKit.UIDevice.CurrentDevice.Name;
68 #elif SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
69 #if SILICONSTUDIO_PLATFORM_WINDOWS_PHONE
70  result.Platform = "WindowsPhone";
71 #elif SILICONSTUDIO_PLATFORM_WINDOWS_STORE
72  result.Platform = "WindowsStore";
73 #endif
74  var deviceInfo = new EasClientDeviceInformation();
75  result.DeviceName = deviceInfo.SystemManufacturer + " " + deviceInfo.SystemProductName;
76  try
77  {
78  result.Serial = deviceInfo.Id.ToString();
79  }
80  catch (Exception)
81  {
82  var token = HardwareIdentification.GetPackageSpecificToken(null);
83  var hardwareId = token.Id;
84 
85  var hasher = HashAlgorithmProvider.OpenAlgorithm("MD5");
86  var hashed = hasher.HashData(hardwareId);
87 
88  result.Serial = CryptographicBuffer.EncodeToHexString(hashed);
89  }
90 #endif
91 
92  return result;
93  }
94 
95  public static string GetCurrentPlatformName()
96  {
97  return GetPlatformName(GetPlatform());
98  }
99 
100  public static string GetPlatformName(TestPlatform platform)
101  {
102  switch (platform)
103  {
104  case TestPlatform.WindowsDx:
105  return "Windows_Direct3D11";
106  case TestPlatform.WindowsOgl:
107  return "Windows_OpenGL";
108  case TestPlatform.WindowsOgles:
109  return "Windows_OpenGLES";
110  case TestPlatform.Android:
111  return "Android";
112  case TestPlatform.Ios:
113  return "IOS";
114  case TestPlatform.WindowsPhone:
115  return "Windows_Phone";
116  case TestPlatform.WindowsStore:
117  return "Windows_Store";
118  default:
119  throw new ArgumentOutOfRangeException();
120  }
121  }
122 
123  public static TestPlatform GetPlatform()
124  {
125 #if SILICONSTUDIO_PLATFORM_ANDROID
126  return TestPlatform.Android;
127 #elif SILICONSTUDIO_PLATFORM_IOS
128  return TestPlatform.Ios;
129 #elif SILICONSTUDIO_PLATFORM_WINDOWS_PHONE
130  return TestPlatform.WindowsPhone;
131 #elif SILICONSTUDIO_PLATFORM_WINDOWS_STORE
132  return TestPlatform.WindowsStore;
133 #elif SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
134  return TestPlatform.WindowsDx;
135 #elif SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
136  return TestPlatform.WindowsOgles;
137 #elif SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL
138  return TestPlatform.WindowsOgl;
139 #endif
140 
141  }
142  }
143 
144  [Flags]
146  {
147  CopyOnShare = 1,
148  }
149 
151  {
152  public int BuildNumber;
153  public string Platform;
154  public string Serial;
155  public string DeviceName;
156  public string BranchName;
158 
159  public void Read(BinaryReader reader)
160  {
161  Platform = reader.ReadString();
162  BuildNumber = reader.ReadInt32();
163  Serial = reader.ReadString();
164  DeviceName = reader.ReadString();
165  BranchName = reader.ReadString();
166  Flags = (ImageComparisonFlags)reader.ReadInt32();
167  }
168 
169  public void Write(BinaryWriter writer)
170  {
171  writer.Write(Platform);
172  writer.Write(BuildNumber);
173  writer.Write(Serial);
174  writer.Write(DeviceName);
175  writer.Write(BranchName);
176  writer.Write((int)Flags);
177  }
178  }
179 
180  public class TestResultImage
181  {
182  public string TestName;
183  public string CurrentVersion;
184  public string Frame;
185 
186  // Image
187  public Image Image;
188 
190  {
191  }
192 
193  public unsafe void Read(BinaryReader reader)
194  {
195  TestName = reader.ReadString();
196  CurrentVersion = reader.ReadString();
197  Frame = reader.ReadString();
198 
199  // Read image header
200  var width = reader.ReadInt32();
201  var height = reader.ReadInt32();
202  var format = (PixelFormat)reader.ReadInt32();
203  var textureSize = reader.ReadInt32();
204 
205  // Read image data
206  var imageData = new byte[textureSize];
207  var copiedSize = 0;
208  using (var lz4Stream = new LZ4Stream(new BlockingBufferStream(reader.BaseStream), CompressionMode.Decompress, false, textureSize))
209  {
210  lz4Stream.Read(imageData, copiedSize, textureSize - copiedSize);
211  }
212 
213  var pinnedImageData = GCHandle.Alloc(imageData, GCHandleType.Pinned);
214  var description = new ImageDescription
215  {
216  Dimension = TextureDimension.Texture2D,
217  Width = width,
218  Height = height,
219  ArraySize = 1,
220  Depth = 1,
221  Format = format,
222  MipLevels = 1,
223  };
224  Image = Image.New(description, pinnedImageData.AddrOfPinnedObject(), 0, pinnedImageData, false);
225  }
226 
227  public void Write(BinaryWriter writer)
228  {
229  writer.Write(TestName);
230  writer.Write(CurrentVersion);
231  writer.Write(Frame);
232 
233  // This call returns the pixels without any extra stride
234  var pixels = Image.PixelBuffer[0].GetPixels<byte>();
235 
236  writer.Write(Image.PixelBuffer[0].Width);
237  writer.Write(Image.PixelBuffer[0].Height);
238  writer.Write((int)Image.PixelBuffer[0].Format);
239  writer.Write(pixels.Length);
240 
241  var sw = new Stopwatch();
242 
243  sw.Start();
244  // Write image data
245  var lz4Stream = new LZ4Stream(writer.BaseStream, CompressionMode.Compress, false, pixels.Length);
246  lz4Stream.Write(pixels, 0, pixels.Length);
247  lz4Stream.Flush();
248  writer.BaseStream.Flush();
249  sw.Stop();
250 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
251  Console.WriteLine("Total calculation time: {0}", sw.Elapsed);
252 #else
253  TestGameBase.TestGameLogger.Info("Total calculation time: {0}", sw.Elapsed);
254 #endif
255  //writer.Write(pixels, 0, pixels.Length);
256  }
257  }
258 
259  public struct ImageInformation
260  {
261  public int Width;
262  public int Height;
263  public int TextureSize;
264  public int BaseVersion;
265  public int CurrentVersion;
266  public int FrameIndex;
269  }
270 
271  public enum TestPlatform
272  {
273  WindowsDx,
274  WindowsOgl,
275  WindowsOgles,
276  WindowsStore,
277  WindowsPhone,
278  Android,
279  Ios
280  }
281 }
static ImageTestResultConnection GetDefaultImageTestResultConnection()
Provides method to instantiate an image 1D/2D/3D supporting TextureArray and mipmaps on the CPU or to...
Definition: Image.cs:88
Flags
Enumeration of the new Assimp's flags.
Block compression stream. Allows to use LZ4 for stream compression.
Definition: LZ4Stream.cs:32
PixelBufferArray PixelBuffer
Provides access to all pixel buffers.
Definition: Image.cs:279
Compression
Compression method enumeration
Definition: Compression.cs:20
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175
PixelFormat
Defines various types of pixel formats.
Definition: PixelFormat.cs:32