Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all the tests to WASM runner #1524

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions native/wasm/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Task("libSkiaSharp")
.WithCriteria(IsRunningOnLinux())
.Does(() =>
{

GnNinja($"wasm", "SkiaSharp",
$"target_os='linux' " +
$"target_cpu='wasm' " +
Expand Down Expand Up @@ -58,7 +57,8 @@ Task("libSkiaSharp")

// separate all the .a files into .o files
var skiaOut = SKIA_PATH.Combine("out/wasm");
var mergeDir = skiaOut.Combine("obj/merge");
var objDir = skiaOut.Combine("obj");
var mergeDir = objDir.Combine("merge");
EnsureDirectoryExists(mergeDir);
CleanDirectories(mergeDir.FullPath);
foreach (var file in GetFiles($"{skiaOut}/*.a")) {
Expand All @@ -68,14 +68,11 @@ Task("libSkiaSharp")
});
}

// add the default font
var input = SKIA_PATH.CombineWithFilePath("modules/canvaskit/fonts/NotoMono-Regular.ttf");
var embed_resources = SKIA_PATH.CombineWithFilePath("tools/embed_resources.py");
RunProcess(PYTHON_EXE, new ProcessSettings {
Arguments = $"{embed_resources} --name SK_EMBEDDED_FONTS --input {input} --output {input}.cpp --align 4",
WorkingDirectory = SKIA_PATH.FullPath,
});
RunProcess(CC, $"-std=c++17 -I. {input}.cpp -r -o {mergeDir}/NotoMonoRegularttf.o");
// add the default fonts
CompileFonts(
ROOT_PATH.CombineWithFilePath("native/wasm/fonts/NotoMono-Regular.ttf").FullPath,
ROOT_PATH.CombineWithFilePath("native/wasm/fonts/DejaVuSans-Bold.ttf").FullPath,
ROOT_PATH.CombineWithFilePath("native/wasm/fonts/DejaVuSans.ttf").FullPath);

// merge all the .o files into the final .a file
var oFiles = GetFiles($"{mergeDir}/*.o");
Expand All @@ -84,6 +81,16 @@ Task("libSkiaSharp")
var outDir = OUTPUT_PATH.Combine($"wasm");
EnsureDirectoryExists(outDir);
CopyFileToDirectory(a, outDir);

void CompileFonts(params string[] fonts)
{
var embed_resources = SKIA_PATH.CombineWithFilePath("tools/embed_resources.py");
RunProcess(PYTHON_EXE, new ProcessSettings {
Arguments = $"{embed_resources} --name SK_EMBEDDED_FONTS --input {string.Join(" ", fonts)} --output {objDir}/embeddedfonts.cpp --align 4",
WorkingDirectory = SKIA_PATH.FullPath,
});
RunProcess(CC, $"-std=c++17 -I. {objDir}/embeddedfonts.cpp -r -o {mergeDir}/embeddedfonts.o");
}
});

Task("libHarfBuzzSharp")
Expand Down
Binary file added native/wasm/fonts/DejaVuSans-Bold.ttf
Binary file not shown.
Binary file added native/wasm/fonts/DejaVuSans.ttf
Binary file not shown.
Binary file added native/wasm/fonts/NotoMono-Regular.ttf
Binary file not shown.
20 changes: 10 additions & 10 deletions scripts/azure-templates-bootstrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parameters:
condition: succeeded() # whether or not to run this template
shouldPublish: true # whether or not to publish the artifacts
configuration: $(CONFIGURATION) # the build configuration
buildExternals: '' # the build number to download externals from
buildExternals: '4127355' # the build number to download externals from
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
verbosity: $(VERBOSITY) # the level of verbosity to use when building
docker: '' # the Docker image to build and use
dockerArgs: '' # any additional arguments to pass to docker build
Expand All @@ -26,16 +26,16 @@ parameters:
installEmsdk: false # whether or not to install the Emscripten SDK

jobs:
# - ${{ if and(ne(parameters.buildExternals, ''), startsWith(parameters.name, 'native_')) }}:
# - template: azure-templates-download.yml
# parameters:
# name: ${{ parameters.name }}
# displayName: ${{ parameters.displayName }}
# vmImage: ${{ parameters.vmImage }}
# condition: ${{ parameters.condition }}
# buildExternals: ${{ parameters.buildExternals }}
- ${{ if and(ne(parameters.buildExternals, ''), startsWith(parameters.name, 'native_')) }}:
- template: azure-templates-download.yml
parameters:
name: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
vmImage: ${{ parameters.vmImage }}
condition: ${{ parameters.condition }}
buildExternals: ${{ parameters.buildExternals }}

# - ${{ if or(eq(parameters.buildExternals, ''), not(startsWith(parameters.name, 'native_'))) }}:
- ${{ if or(eq(parameters.buildExternals, ''), not(startsWith(parameters.name, 'native_'))) }}:
- job: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
timeoutInMinutes: 120
Expand Down
28 changes: 26 additions & 2 deletions tests/SkiaSharp.Wasm.Tests.sln
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30212.25
VisualStudioVersion = 16.0.29102.215

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong, but this looks like user-specific change

MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Wasm.Tests", "SkiaSharp.Wasm.Tests\SkiaSharp.Wasm.Tests.csproj", "{E7D44825-9F38-4ADA-BCF5-EB9420200DE4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp", "..\binding\SkiaSharp\SkiaSharp.csproj", "{3E1B158B-6C3B-4340-9F01-28E77D24F31D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HarfBuzzSharp", "..\binding\HarfBuzzSharp\HarfBuzzSharp.csproj", "{38FFD397-8A5E-421A-8649-24FE463E1DE9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.HarfBuzz", "..\source\SkiaSharp.HarfBuzz\SkiaSharp.HarfBuzz\SkiaSharp.HarfBuzz.csproj", "{0DE402FA-A101-438E-8528-6EA82E0FF803}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkiaSharp.Wasm.Tests", "SkiaSharp.Wasm.Tests\SkiaSharp.Wasm.Tests.csproj", "{E7D44825-9F38-4ADA-BCF5-EB9420200DE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3E1B158B-6C3B-4340-9F01-28E77D24F31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E1B158B-6C3B-4340-9F01-28E77D24F31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E1B158B-6C3B-4340-9F01-28E77D24F31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E1B158B-6C3B-4340-9F01-28E77D24F31D}.Release|Any CPU.Build.0 = Release|Any CPU
{38FFD397-8A5E-421A-8649-24FE463E1DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38FFD397-8A5E-421A-8649-24FE463E1DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38FFD397-8A5E-421A-8649-24FE463E1DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38FFD397-8A5E-421A-8649-24FE463E1DE9}.Release|Any CPU.Build.0 = Release|Any CPU
{0DE402FA-A101-438E-8528-6EA82E0FF803}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DE402FA-A101-438E-8528-6EA82E0FF803}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DE402FA-A101-438E-8528-6EA82E0FF803}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DE402FA-A101-438E-8528-6EA82E0FF803}.Release|Any CPU.Build.0 = Release|Any CPU
{E7D44825-9F38-4ADA-BCF5-EB9420200DE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7D44825-9F38-4ADA-BCF5-EB9420200DE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7D44825-9F38-4ADA-BCF5-EB9420200DE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7D44825-9F38-4ADA-BCF5-EB9420200DE4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8355B800-A642-459B-8675-B545839DE6C7}
EndGlobalSection
EndGlobal
55 changes: 52 additions & 3 deletions tests/SkiaSharp.Wasm.Tests/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
namespace SkiaSharp.Tests
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Xunit;

namespace SkiaSharp.Tests
{
public class Program
{
public static int Main()
private static readonly Assembly assembly = typeof(Program).Assembly;

public static int Main(string[] args)
{
Console.WriteLine($"args: {string.Join(" ", args)}");

// copy resources out of assembly
var prefix = "SkiaSharp.Tests.";
var resources = assembly.GetManifestResourceNames();
foreach (var resource in resources)
{
if (!resource.StartsWith(prefix))
continue;

if (resource.StartsWith(prefix + "fonts.") || resource.StartsWith(prefix + "images."))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong, but I think assemblies are in CamelCase notation, so this should be

Suggested change
if (resource.StartsWith(prefix + "fonts.") || resource.StartsWith(prefix + "images."))
if (resource.StartsWith(prefix + "Fonts.") || resource.StartsWith(prefix + "Images."))

{
var ext = Path.GetExtension(resource);
var fn = Path.GetFileNameWithoutExtension(resource);
var dest = fn.Substring(prefix.Length - 1).Replace(".", "/") + ext;
var dir = Path.GetDirectoryName(dest);

if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);

using (var stream = assembly.GetManifestResourceStream(resource))
using (var file = File.Create(dest))
stream.CopyTo(file);

Console.WriteLine($"Saved file to {dest}: {File.ReadAllBytes(dest)?.Length}");
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
}
}

var filters = new XunitFilters
{
ExcludedTraits =
{
{ BaseTest.CategoryKey, new List<string> { BaseTest.GpuCategory, BaseTest.MatchCharacterCategory } },
{ BaseTest.PlatformKey, new List<string> { BaseTest.WasmPlatform } },
},
ExcludedClasses =
{
"SkiaSharp.Tests.ApiTest",
},
};

var testRunner = new ThreadlessXunitTestRunner();
var result = testRunner.Run(typeof(Program).Assembly.GetName().Name + ".dll", null);
var result = testRunner.Run(assembly.GetName().Name + ".dll", filters);
return result ? 1 : 0;
}
}
Expand Down
32 changes: 27 additions & 5 deletions tests/SkiaSharp.Wasm.Tests/SkiaSharp.Wasm.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,46 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<DefineConstants>$(DefineConstants);USE_LIBRARY_LOADER</DefineConstants>
<RootNamespace>SkiaSharp.Tests</RootNamespace>
<AssemblyName>SkiaSharp.Tests</AssemblyName>
<WasmShellILLinkerEnabled>true</WasmShellILLinkerEnabled>
<SkipGenerateAssemblyVersionInfo>true</SkipGenerateAssemblyVersionInfo>
<SkipMDocGenerateDocs>true</SkipMDocGenerateDocs>
<SkipCopyToOutputDirectory>true</SkipCopyToOutputDirectory>
</PropertyGroup>
<ItemGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<WasmShellEnableEmccProfiling>true</WasmShellEnableEmccProfiling>
<MonoRuntimeDebuggerEnabled>true</MonoRuntimeDebuggerEnabled>
<WasmShellILLinkerEnabled>false</WasmShellILLinkerEnabled>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<WasmShellExtraEmccFlags Include="-s ASSERTIONS=1" />
<Content Include="..\..\output\native\wasm\libSkiaSharp.a" Visible="false" />
<Content Include="..\..\output\native\wasm\libHarfBuzzSharp.a" Visible="false" />
<LinkerDescriptor Include="LinkerConfig.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Uno.Wasm.Bootstrap" Version="1.4.0-dev.52" />
<PackageReference Include="Uno.Wasm.Bootstrap.DevServer" Version="1.4.0-dev.52" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.utility" Version="2.4.1" />
<PackageReference Include="xunit.skippablefact" Version="1.3.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\binding\HarfBuzzSharp\HarfBuzzSharp.csproj" />
<ProjectReference Include="..\..\binding\SkiaSharp\SkiaSharp.csproj" />
<ProjectReference Include="..\..\source\SkiaSharp.HarfBuzz\SkiaSharp.HarfBuzz\SkiaSharp.HarfBuzz.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Tests\**\*.cs" Link="%(RecursiveDir)%(FileName)%(Extension)" />
<Compile Include="..\..\binding\Binding.Shared\LibraryLoader.cs" Link="PlatformUtils\LibraryLoader.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\Content\**\*" Link="%(RecursiveDir)%(FileName)%(Extension)" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\output\native\wasm\libSkiaSharp.a" Visible="false" />
<Content Include="..\..\output\native\wasm\libHarfBuzzSharp.a" Visible="false" />
<LinkerDescriptor Include="LinkerConfig.xml" />
</ItemGroup>
</Project>
26 changes: 2 additions & 24 deletions tests/SkiaSharp.Wasm.Tests/Xunit/ThreadlessXunitTestRunner.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
Expand All @@ -11,18 +10,12 @@ namespace SkiaSharp.Tests
{
internal class ThreadlessXunitTestRunner
{
public bool Run(string assemblyFileName, IEnumerable<string> excludedTraits)
public bool Run(string assemblyFileName, XunitFilters filters)
{
WebAssembly.Runtime.InvokeJS($"if (document) document.body.innerHTML = ''");

Log("Starting tests...");

var filters = new XunitFilters();
foreach (var trait in excludedTraits ?? Array.Empty<string>())
{
ParseEqualSeparatedArgument(filters.ExcludedTraits, trait);
}

var configuration = new TestAssemblyConfiguration
{
ShadowCopy = false,
Expand Down Expand Up @@ -67,6 +60,7 @@ public bool Run(string assemblyFileName, IEnumerable<string> excludedTraits)
var resultsXmlAssembly = new XElement("assembly");
var resultsSink = new DelegatingXmlCreationSink(summarySink, resultsXmlAssembly);

testSink.Execution.TestStartingEvent += args => { Log($"{args.Message.Test.DisplayName}", color: "gray"); };
testSink.Execution.TestPassedEvent += args => { Log($"[PASS] {args.Message.Test.DisplayName}", color: "green"); };
testSink.Execution.TestSkippedEvent += args => { Log($"[SKIP] {args.Message.Test.DisplayName}", color: "orange"); };
testSink.Execution.TestFailedEvent += args => { Log($"[FAIL] {args.Message.Test.DisplayName}{Environment.NewLine}{ExceptionUtility.CombineMessages(args.Message)}{Environment.NewLine}{ExceptionUtility.CombineStackTraces(args.Message)}", color: "red"); };
Expand Down Expand Up @@ -107,22 +101,6 @@ private void Log(string contents, string color = null, string id = null)

WebAssembly.Runtime.InvokeJS($"if (document) document.body.innerHTML += '<pre {ele} style=\"{style}\">{contents.Replace("\n", "<br/>")}</pre>'");
}

private void ParseEqualSeparatedArgument(Dictionary<string, List<string>> targetDictionary, string argument)
{
var parts = argument.Split('=');
if (parts.Length != 2 || string.IsNullOrEmpty(parts[0]) || string.IsNullOrEmpty(parts[1]))
throw new ArgumentException("Invalid argument value '{argument}'.", nameof(argument));

var name = parts[0];
var value = parts[1];

List<string> excludedTraits;
if (targetDictionary.TryGetValue(name, out excludedTraits!))
excludedTraits.Add(value);
else
targetDictionary[name] = new List<string> { value };
}
}

internal class ThreadlessXunitDiscoverer : Xunit.Sdk.XunitTestFrameworkDiscoverer
Expand Down
8 changes: 5 additions & 3 deletions tests/Tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ namespace SkiaSharp.Tests
{
public abstract class BaseTest
{
protected const string CategoryKey = "Category";
public const string CategoryKey = "Category";
public const string GpuCategory = "GPU";
public const string MatchCharacterCategory = "MatchCharacter";

protected const string GpuCategory = "GPU";
protected const string MatchCharacterCategory = "MatchCharacter";
public const string PlatformKey = "Platform";
public const string WasmPlatform = "WASM";

protected static bool IsLinux = PlatformConfiguration.IsLinux;
protected static bool IsMac = PlatformConfiguration.IsMac;
Expand Down
1 change: 1 addition & 0 deletions tests/Tests/GRGlInterfaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace SkiaSharp.Tests
{
public class GRGlInterfaceTest : SKTest
{
[Trait(CategoryKey, GpuCategory)]
[SkippableFact]
public void InterfaceConstructionWithoutContextDoesNotCrash()
{
Expand Down
1 change: 1 addition & 0 deletions tests/Tests/SKBitmapTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ public void AlphaMaskIsApplied()
mask.FreeImage();
}

[Trait(PlatformKey, WasmPlatform)]
[SkippableTheory]
[InlineData(100, 1000)]
public static void ImageScalingMultipleThreadsTest(int numThreads, int numIterationsPerThread)
Expand Down
1 change: 1 addition & 0 deletions tests/Tests/SKCodecTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public void CanReadManagedStream()
Assert.NotNull(codec);
}

[Trait(PlatformKey, WasmPlatform)]
[SkippableFact (Skip = "This keeps breaking CI for some reason.")]
public async Task DownloadedStream ()
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Tests/SKObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private static IntPtr broken_native_method()
}
}

[Trait(PlatformKey, WasmPlatform)]
[SkippableTheory]
[InlineData(1)]
[InlineData(1000)]
Expand Down Expand Up @@ -321,6 +322,7 @@ protected override void DisposeNative()
}
}

[Trait(PlatformKey, WasmPlatform)]
[SkippableFact]
public async Task DelayedConstructionDoesNotCreateInvalidState()
{
Expand Down Expand Up @@ -371,6 +373,7 @@ public async Task DelayedConstructionDoesNotCreateInvalidState()
Assert.Same(objFast, objSlow);
}

[Trait(PlatformKey, WasmPlatform)]
[SkippableFact]
public async Task DelayedDestructionDoesNotCreateInvalidState()
{
Expand Down