mattercontrol/Tests/MatterControl.Tests/MatterControl/ReleaseBuildTests.cs

154 lines
4.8 KiB
C#
Raw Normal View History

2017-08-20 15:52:43 -07:00
#if !__ANDROID__
using MatterHackers.MatterControl.Tests.Automation;
2016-09-28 10:24:11 -07:00
#endif
2015-05-05 07:25:47 -07:00
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
2015-05-05 07:25:47 -07:00
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using System.Threading.Tasks;
using System.Threading;
using MatterHackers.MatterControl;
2015-05-05 07:25:47 -07:00
namespace MatterControl.Tests
{
[TestFixture, Apartment(ApartmentState.STA), RunInApplicationDomain]
2015-12-22 16:44:54 -08:00
public class ReleaseBuildTests
{
private static Type debuggableAttribute = typeof(DebuggableAttribute);
[Test, Category("ReleaseQuality")]
public void MatterControlAssemblyIsOptimized()
{
#if (!DEBUG)
IsAssemblyOptimized(Assembly.Load("MatterControlLib, Culture=neutral, PublicKeyToken=null"));
2015-05-05 07:25:47 -07:00
#endif
2015-12-22 16:44:54 -08:00
}
2015-05-05 07:25:47 -07:00
[Test, Category("ReleaseQuality")]
public void MatterControlKnownAssembliesAreOptimized()
{
#if DEBUG
string configuration = "Debug";
#else
string configuration = "Release";
#endif
2018-08-17 19:19:39 -07:00
//MatterHackers.RenderOpenGl.dll
// This list can be refreshed via the rebuildDependencies() helper function below
2018-08-09 11:58:47 -07:00
string knownAssemblies = @"VectorMath.dll
Agg.dll
PolygonMesh.dll
2019-06-29 09:06:23 -07:00
agg_clipper_library.dll
2018-08-09 11:58:47 -07:00
Gui.dll
Tesselate.dll
2018-08-09 11:58:47 -07:00
DataConverters2D.dll
RayTracer.dll
2018-08-09 11:58:47 -07:00
DataConverters3D.dll
Localizations.dll
Community.CsharpSqlite.dll
MatterHackers.Agg.ImageProcessing.dll
MatterHackers.MarchingSquares.dll
2018-07-27 22:17:38 -07:00
GuiAutomation.dll";
foreach (string assemblyName in knownAssemblies.Split('\n').Select(s => s.Trim()))
{
var assemblyPath = TestContext.CurrentContext.ResolveProjectPath(4, "bin", configuration, assemblyName);
// Missing/renamed assemblies should fail the test and force a correction
2016-10-11 17:42:03 -07:00
Assert.IsTrue(File.Exists(assemblyPath), "Assembly missing: " + assemblyPath);
#if (!DEBUG)
var assembly = Assembly.LoadFrom(assemblyPath);
IsAssemblyOptimized(assembly);
#endif
}
}
private void rebuildDependencies()
{
2016-10-11 18:00:04 -07:00
// Modify path to point at a recent BuildAgent results file
var elem = XElement.Load(@"C:\Data\Sources\MatterHackers\BuildAndDeployment\MatterControl\build_sln.xml");
var items = elem.Descendants().Where(e => e.Name == "target" && "CopyFilesToOutputDirectory" == (string)e.Attribute("name")).SelectMany(e => e.Elements("message").Select(e2 => e2.Value.TrimEnd('.')).Where(s => s.Contains("Copying") && s.Contains(".dll")));
var referencedItems = new List<string>();
foreach (var item in items)
{
var segments = System.Text.RegularExpressions.Regex.Split(item, "to \"");
var relativeAssemblyName = segments[1].TrimEnd('"');
var assemblyName = Path.GetFileName(relativeAssemblyName);
referencedItems.Add(assemblyName);
}
Console.WriteLine(referencedItems);
}
2016-09-28 10:24:11 -07:00
#if !__ANDROID__
[Test]
public async Task MatterControlRuns()
{
await MatterControlUtilities.RunTest((testRunner) =>
{
testRunner.WaitForName("PartPreviewContent");
Assert.IsTrue(testRunner.NameExists("PartPreviewContent"));
return Task.CompletedTask;
});
}
2016-09-28 10:24:11 -07:00
#endif
[Test, Category("ReleaseQuality")]
2015-12-22 16:44:54 -08:00
public void MatterControlDependenciesAreOptimized()
{
#if (!DEBUG)
var matterControl = Assembly.Load("MatterControlLib, Culture=neutral, PublicKeyToken=null");
2015-05-05 07:25:47 -07:00
2017-11-20 14:01:51 -08:00
// Loop over all referenced assemblies to verify they are optimized and lack (symbols and Debug compile flag)
foreach (var assemblyName in matterControl.GetReferencedAssemblies())
{
var assembly = Assembly.Load(assemblyName.FullName);
var firstNamespace = assembly?.GetTypes()?.FirstOrDefault()?.Namespace;
2015-05-05 07:25:47 -07:00
2017-11-20 14:01:51 -08:00
// Only validate our assemblies
2015-06-02 15:08:05 -07:00
if (firstNamespace != null && (firstNamespace.Contains("MatterHackers") || firstNamespace.Contains("MatterControl")))
2017-11-20 14:01:51 -08:00
{
IsAssemblyOptimized(assembly);
}
}
2015-05-05 07:25:47 -07:00
#endif
}
2015-05-05 07:25:47 -07:00
[Test, Category("ReleaseQuality")]
2015-12-22 16:44:54 -08:00
public void ClassicDebugComplicationFlagTests()
{
#if (!DEBUG)
BuildValidationTests.CheckKnownAssemblyConditionalCompSymbols();
2015-05-05 07:25:47 -07:00
#endif
2015-12-22 16:44:54 -08:00
}
2015-05-05 07:25:47 -07:00
2015-12-22 16:44:54 -08:00
private static void IsAssemblyOptimized(Assembly assm)
{
var matchedAttributes = assm.GetCustomAttributes(debuggableAttribute, false);
var assemblyName = assm.GetName();
2015-05-05 07:25:47 -07:00
2015-12-22 16:44:54 -08:00
if (matchedAttributes.Count() == 0)
{
Assert.Inconclusive("Symbols likely missing from Release build: " + assemblyName.FullName + ". \r\n\r\nTo resolve the issue, switch Project Properties -> Build -> Advanced -> Debug Info property to 'pdb-only'");
}
2015-05-05 07:25:47 -07:00
2015-12-22 16:44:54 -08:00
var debuggable = matchedAttributes.First() as DebuggableAttribute;
Assert.IsFalse(debuggable.IsJITOptimizerDisabled, "Referenced assembly is not optimized: " + assemblyName.Name);
Assert.IsFalse(debuggable.IsJITTrackingEnabled, "Referenced assembly has symbols: " + assemblyName.Name);
2015-12-22 16:44:54 -08:00
Console.WriteLine("Assembly is optimized: " + assemblyName.Name);
}
}
2015-05-05 07:25:47 -07:00
}