2 using System.Collections.Generic;
3 using System.Diagnostics;
7 using System.Net.NetworkInformation;
8 using System.Net.Sockets;
9 using System.Reflection;
10 using System.Runtime.InteropServices;
12 using System.Threading;
14 using NUnit.Framework;
16 using SiliconStudio.Paradox.Games;
18 namespace SiliconStudio.
Paradox.Graphics.Regression
21 public class GraphicsTestBase : TestGameBase
23 #region Constant strings
25 private const string SaveDirectory =
@"";
27 private const string AndroidReferenceName =
@"SC-02C";
29 private const string PcReferenceName =
@"";
31 private const string IosReferenceName =
@"";
33 private const char IpAddressesSplitCharacter =
'%';
37 #region Private members
42 private bool isServer;
47 private bool saveLocally;
52 private int buildNumber;
57 private string serverAddresses;
62 private int serverPort;
67 private TcpListener server;
72 private bool serverUp;
77 private ManualResetEvent dataReceivedEvent;
82 private TcpClient client;
87 private ConnectedDevice currentDevice;
92 private bool imageReceived;
97 private bool testPerformed;
102 private bool onBamboo;
107 private string paradoxSdkDir;
112 private bool isClientConnected;
117 private string assemblyNameForAndroid =
"SiliconStudio.Paradox.Graphics.Regression";
122 private string branchName;
127 private bool runTests;
131 #region Public properties
133 public FrameGameSystem FrameGameSystem {
get;
private set; }
137 #region Public members
162 public string CsprojLocationForAndroid =
@"sources\engine\SiliconStudio.Paradox.Graphics.Regression\SiliconStudio.Paradox.Graphics.Regression.Android.csproj";
172 BaseVersionNumber = 0;
173 CurrentVersionNumber = 0;
179 isClientConnected =
false;
181 onBamboo = Environment.GetEnvironmentVariable(
"PARADOX_BAMBOO_TEST") != null;
182 if (!
Int32.TryParse(Environment.GetEnvironmentVariable(
@"BAMBOO_BUILD_NUMBER"), out buildNumber))
185 paradoxSdkDir = Environment.GetEnvironmentVariable(
@"ParadoxSdkDir");
189 branchName = Environment.GetEnvironmentVariable(
"PARADOX_BAMBOO_BRANCH_NAME");
190 if (branchName != null)
191 branchName = branchName.Trim();
196 assemblyNameForAndroid = this.GetType().Assembly.ManifestModule.ScopeName;
199 FrameGameSystem.Visible =
true;
200 FrameGameSystem.Enabled =
true;
211 public void Init(
string ipString,
int port,
int bNumber,
string serial)
213 serverAddresses = ipString;
215 buildNumber = bNumber;
220 #region public methods
226 FrameGameSystem.Visible =
false;
227 FrameGameSystem.Enabled =
false;
230 [TestFixtureTearDown]
247 currentDevice = device;
249 Console.WriteLine(
@"Running test " + this.GetType().Name +
@" on device " + device.
Name +
@" (" + device.
Platform +
@")");
256 Console.WriteLine(
@"Running server" + (onBamboo ?
@" on Bamboo" :
@"" ));
262 Assert.Fail(
"Unable to create a server.");
267 imageReceived =
false;
268 testPerformed =
false;
269 dataReceivedEvent =
new ManualResetEvent(
false);
272 Console.WriteLine(
@"Waiting for a connection... ");
274 RunTestOnDevice(device);
277 dataReceivedEvent.WaitOne(Timeout);
281 Console.WriteLine(
@"Stopping the server.");
287 Console.WriteLine(
@"Stopping the server threw an error.");
292 Assert.IsTrue(imageReceived,
"The image was not received.");
293 Assert.IsTrue(testPerformed,
"The tests were not correctly performed");
298 Console.WriteLine(
@"Running test client");
325 if (textureToSave == null)
328 Console.WriteLine(
@"Saving non null image");
329 var testName = NUnit.Framework.TestContext.CurrentContext.Test.FullName;
332 Console.WriteLine(
@"saving locally.");
333 using (var image = textureToSave.GetDataAsImage())
335 var textureName = testName +
"_" + PlatformPermutator.GetCurrentPlatformName();
336 using (var resultFileStream = File.OpenWrite(FileNameGenerator.GetFileName(textureName)))
338 image.Save(resultFileStream, ImageFileType.Png);
342 else if (client != null)
344 Console.WriteLine(
@"saving remotely.");
345 using (var image = textureToSave.GetDataAsImage())
349 SendImage(image, currentDevice.Serial, testName, frameIndex);
353 Console.WriteLine(
@"An error occured when trying to send the data to the server.");
365 Console.WriteLine(
@"Saving the backbuffer");
375 var devices =
new List<ConnectedDevice>();
377 var addPcD3DDevices = Environment.GetEnvironmentVariable(
"PARADOX_PC_DIRECT3D_DEVICES") != null;
378 var addPcOglDevices = Environment.GetEnvironmentVariable(
"PARADOX_PC_OPENGL_DEVICES") != null;
379 var addPcOglEsDevices = Environment.GetEnvironmentVariable(
"PARADOX_PC_OPENGLES_DEVICES") != null;
380 var addAndroidDevices = Environment.GetEnvironmentVariable(
"PARADOX_ANDROID_DEVICES") != null;
381 var addiOsDevices = Environment.GetEnvironmentVariable(
"PARADOX_IOS_DEVICES") != null;
383 if (!(addPcD3DDevices || addPcOglDevices || addPcOglEsDevices || addAndroidDevices || addiOsDevices))
385 devices.AddRange(ListPcD3DDevices());
386 devices.AddRange(ListPcOglDevices());
387 devices.AddRange(ListPcOglEsDevices());
388 devices.AddRange(ListAndroidDevices());
389 devices.AddRange(ListIOsDevices());
394 devices.AddRange(ListPcD3DDevices());
396 devices.AddRange(ListPcOglDevices());
397 if (addPcOglEsDevices)
398 devices.AddRange(ListPcOglEsDevices());
399 if (addAndroidDevices)
400 devices.AddRange(ListAndroidDevices());
402 devices.AddRange(ListIOsDevices());
405 return devices.ToArray();
414 var devices =
new List<ConnectedDevice>();
416 var devicesOutputs = ShellHelper.RunProcessAndGetOutput(
@"adb",
@"devices");
417 var whitespace =
new[] {
' ',
'\t' };
418 for (var i = 1; i < devicesOutputs.OutputLines.Count; ++i)
420 var line = devicesOutputs.OutputLines[i];
423 var res = line.Split(whitespace);
427 device.Serial = res[0];
428 device.Name = res[1];
429 device.Platform = TestPlatform.Android;
436 for (var i = 0; i < devices.Count; ++i)
438 var device = devices[i];
440 var deviceNameOutputs = ShellHelper.RunProcessAndGetOutput(
@"adb",
@"-s " + device.Serial +
@" shell cat /system/build.prop");
441 foreach (var line
in deviceNameOutputs.OutputLines)
443 if (line != null && line.StartsWith(
@"ro.product.model"))
445 var parts = line.Split(
'=');
447 if (parts.Length > 1)
449 device.Name = parts[1];
459 foreach (var device
in devices)
461 if (device.Name.Equals(AndroidReferenceName))
468 return devices.ToArray();
477 var devices =
new List<ConnectedDevice>();
478 return devices.ToArray();
487 var devices =
new List<ConnectedDevice>();
490 pcDdevice.Serial =
"Local";
491 pcDdevice.Name =
"LocalPC";
492 pcDdevice.Platform = TestPlatform.WindowsDx;
493 devices.Add(pcDdevice);
495 return devices.ToArray();
504 var devices =
new List<ConnectedDevice>();
507 pcDdevice.Serial =
"Local";
508 pcDdevice.Name =
"LocalPC";
509 pcDdevice.Platform = TestPlatform.WindowsOgl;
510 devices.Add(pcDdevice);
512 return devices.ToArray();
521 var devices =
new List<ConnectedDevice>();
524 pcDdevice.Serial =
"Local";
525 pcDdevice.Name =
"LocalPC";
526 pcDdevice.Platform = TestPlatform.WindowsOgles;
529 return devices.ToArray();
534 #region Protected methods
551 if (runTests && !isServer)
557 #if SILICONSTUDIO_PLATFORM_ANDROID
558 Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
568 #region Private methods
573 private void SetUpServer()
576 NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
578 serverAddresses =
"";
580 foreach (var adapter
in nics)
582 var ip = adapter.GetIPProperties();
583 foreach (var addr
in ip.UnicastAddresses)
585 if (addr.Address.AddressFamily == AddressFamily.InterNetwork && !String.IsNullOrEmpty(addr.Address.ToString()) && !addr.Address.ToString().Equals(
@"127.0.0.1"))
586 serverAddresses = String.Join(IpAddressesSplitCharacter.ToString(), serverAddresses, addr.Address);
590 if (serverAddresses.Equals(
""))
592 Console.WriteLine(
@"No IP address found.");
596 var rand =
new Random();
597 serverPort = 20000 + (int)(100.0 * rand.NextDouble());
598 server =
new TcpListener(IPAddress.Any, serverPort);
599 Console.WriteLine(
@"Server listening to port {0}", serverPort);
609 client =
new TcpClient();
616 private void RunTestOnDevice(ConnectedDevice device)
618 switch (device.Platform)
620 case TestPlatform.WindowsDx:
621 case TestPlatform.WindowsOgl:
622 case TestPlatform.WindowsOgles:
623 RunWindowsTest(device.Serial, device.Platform);
625 case TestPlatform.Android:
627 RunAndroidTestOnBamboo(device.Serial);
629 RunAndroidTest(device.Serial);
631 case TestPlatform.Ios:
634 throw new ArgumentOutOfRangeException();
641 private void RunAndroidTest(
string serial)
645 var testName = this.GetType().Name;
647 new ProcessStartInfo(
@"Scripts\RunAndroidUnitTest.bat", serverAddresses +
" "
652 + assemblyNameForAndroid +
" "
653 + CsprojLocationForAndroid)
655 UseShellExecute =
false,
656 CreateNoWindow =
false,
661 Console.WriteLine(
@"An error was thrown when running the test on Android.");
662 dataReceivedEvent.Set();
669 private void RunAndroidTestOnBamboo(
string serial)
674 var o0 = ShellHelper.RunProcessAndGetOutput(
@"adb",
@"-s " + serial +
@" am shell force-stop " + assemblyNameForAndroid);
677 var o1 = ShellHelper.RunProcessAndGetOutput(
@"adb",
@"-s " + serial +
@" -d install -r ..\..\Bin\Android-AnyCPU-OpenGLES\" + assemblyNameForAndroid +
"-Signed.apk");
680 var parameters =
new StringBuilder();
681 parameters.Append(
"-s "); parameters.Append(serial);
682 parameters.Append(
@" shell am start -a android.intent.action.MAIN -n " + assemblyNameForAndroid +
"/siliconstudio.paradox.graphicstests.GraphicsTestRunner");
683 AddAndroidParameter(parameters, TestRunner.ParadoxServerIp, serverAddresses);
684 AddAndroidParameter(parameters, TestRunner.ParadoxServerPort, serverPort.ToString());
685 AddAndroidParameter(parameters, TestRunner.ParadoxBuildNumber, buildNumber.ToString());
686 AddAndroidParameter(parameters, TestRunner.ParadoxDeviceSerial, serial);
687 AddAndroidParameter(parameters, TestRunner.ParadoxTestName,
this.GetType().Name);
689 Console.WriteLine(parameters.ToString());
691 ShellHelper.RunProcess(
@"adb", parameters.ToString());
695 Console.WriteLine(
@"An error was thrown when running the test on Android.");
696 dataReceivedEvent.Set();
703 private void RunWindowsTest(
string serial,
TestPlatform platform)
707 var command =
new StringBuilder();
708 var parameters =
new StringBuilder();
709 command.Append(
@"..\..\Bin\");
712 case TestPlatform.WindowsDx:
713 command.Append(
@"Windows-AnyCPU-Direct3D\");
715 case TestPlatform.WindowsOgl:
716 command.Append(
@"Windows-AnyCPU-OpenGL\");
718 case TestPlatform.WindowsOgles:
719 command.Append(
@"Windows-AnyCPU-OpenGLES\");
722 throw new ArgumentOutOfRangeException(
"platform");
724 command.Append(
@"SiliconStudio.Paradox.Graphics.Regression.exe");
726 parameters.Append(serverAddresses);
727 parameters.Append(
" "); parameters.Append(serverPort);
728 parameters.Append(
" "); parameters.Append(buildNumber);
729 parameters.Append(
" "); parameters.Append(serial);
730 parameters.Append(
" "); parameters.Append(this.GetType().Name);
731 parameters.Append(
" "); parameters.Append(this.GetType().Assembly.ManifestModule.Name);
733 Console.WriteLine(
@"Running: " + command.ToString() +
@" " + parameters.ToString());
735 var outputs = ShellHelper.RunProcessAndGetOutput(command.ToString(), parameters.ToString());
736 foreach (var output
in outputs.OutputLines)
737 Console.WriteLine(output);
739 foreach (var output
in outputs.OutputErrors)
740 Console.WriteLine(output);
744 Console.WriteLine(
@"An error was thrown when running the test on Windows.");
745 dataReceivedEvent.Set();
755 public void SendImage(
Image image,
string serial,
string testName,
int frameIndex)
757 ImageTester.SendImage(
new TestResultImage { BaseVersionFileName = BaseVersionFileName, BaseVersion = BaseVersionNumber, CurrentVersion = CurrentVersionNumber,
Image = image }, testName);
763 private void CloseClient()
765 if (isClientConnected)
767 Console.WriteLine(
@"Close client.");
768 client.GetStream().Close();
770 isClientConnected =
false;
776 #region Helper structures and classes
781 public struct ConnectedDevice
783 public string Serial;
789 return Name +
" " + Serial +
" " + PlatformPermutator.GetPlatformName(Platform);
int BaseVersionNumber
The version to compare to.
ConnectedDevice[] ListIOsDevices()
Lists all the Android devices accessible from the computer.
void Init(string ipString, int port, int bNumber, string serial)
Initialize the game with the corresponding values.
void SaveBackBuffer(int frameIndex)
Save the image locally or on the server.
Provides method to instantiate an image 1D/2D/3D supporting TextureArray and mipmaps on the CPU or to...
RenderTarget BackBuffer
Gets the back buffer sets by the current Presenter setup on this device.
ConnectedDevice[] ListAndroidDevices()
Lists all the Android devices accessible from the computer.
string GenerateBaseFileNameFromVersion(TestPlatform platform, string deviceName)
Get the name of the base image to compare the generated images to.
string BaseVersionFileName
Forced name of the base version.
void RunTest(ConnectedDevice device, GameContext gameContext=null)
Run the test.
int CurrentVersionNumber
The current version of the test
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
virtual void RegisterTests()
Method to register the tests.
Current timing used for variable-step (real time) or fixed-step (game time) games.
ConnectedDevice[] ListDevices()
Lists all the devices accessible from the computer.
bool TakeSnapshot
Flag stating that a screenshot should be taken.
void SetUpClient()
Setup all needed for the client.
int FrameCount
Gets the current frame count since the start of the game.
ConnectedDevice[] ListPcD3DDevices()
Lists all the D3D PC devices accessible from the computer.
void SendImage(Image image, string serial, string testName, int frameIndex)
Send the data of the test to the server.
bool AllTestsCompleted
Flag stating that all the tests have been rendered.
Contains context used to render the game (Control for WinForm, a DrawingSurface for WP8...
override void Draw(GameTime gameTime)
Loop through all the tests and save the images.
int Timeout
The timeout of the server in milliseconds.
readonly Texture Texture
The underlying texture.
ConnectedDevice[] ListPcOglEsDevices()
Lists all the OpenGL ES PC devices accessible from the computer.
void SaveImage(Texture textureToSave, int frameIndex)
Save the image locally or on the server.
override string ToString()
ConnectedDevice[] ListPcOglDevices()
Lists all the OpenGL PC devices accessible from the computer.
Base class for texture resources.
A structure to store information about the connected test devices.