Skip to content

Commit

Permalink
chore(reg): Fix CI build - iteration 3: Disable tests that relies on …
Browse files Browse the repository at this point in the history
…screenshots
  • Loading branch information
dr1rrb committed Jul 26, 2024
1 parent 388bc57 commit 63a0506
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,20 @@ public async Task When_MultipleItems()
[ActivePlatforms(Platform.iOS, Platform.Android)]
#if __SKIA__
[Ignore("Invalid layout of items")]
#elif !HAS_RENDER_TARGET_BITMAP
[Ignore("Test relies on screenshots which is not available on this platform.")]
#endif
public Task When_InListView()
=> When_InScrollableContainer("UITests.Windows_UI_Xaml_Controls.SwipeControlTests.SwipeControl_ListView");

[Test]
[AutoRetry]
[ActivePlatforms(Platform.iOS, Platform.Android)]
#if __SKIA__
[Ignore("Invalid layout of items")]
#elif !HAS_RENDER_TARGET_BITMAP
[Ignore("Test relies on screenshots which is not available on this platform.")]
#endif
public Task When_InScrollViewer()
=> When_InScrollableContainer("UITests.Windows_UI_Xaml_Controls.SwipeControlTests.SwipeControl_ScrollViewer");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ private async Task RunTest(string testName, Action<QueryEx> act = null)
App.WaitForElement(target);
act(target);

#if HAS_RENDER_TARGET_BITMAP
await TakeScreenshotAsync("Result");
#endif

result.GetDependencyPropertyValue<string>("Text").Should().Be("SUCCESS");
}
Expand Down
15 changes: 8 additions & 7 deletions src/Uno.CrossTargetting.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
uses render transforms instead of native scroll feature (if any)
- UNO_HAS_MANAGED_POINTERS: Determines if the pointer events are dispatched by uno instead of the system (if any).
- HAS_NATIVE_IMPLICIT_POINTER_CAPTURE: Indicate if the OS once a pointer is pressed, OS will send all pointer event to the same target (a.k.a. OriginalSource)
- HAS_RENDER_TARGET_BITMAP : Determines if the render target bitmap is implemented (and can be used to take screenshot in runtime tests)
- Constants for Xamarin backends and SDK versions: https://docs.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/building-cross-platform-applications/platform-divergence-abstraction-divergent-implementation#conditional-compilation
-->
Expand All @@ -68,7 +69,7 @@

<PropertyGroup Condition="'$(UnoRuntimeIdentifier)'=='Skia'">
<DefineConstants>$(DefineConstants);__SKIA__;UNO_HAS_ENHANCED_HIT_TEST_PROPERTY;UNO_HAS_MANAGED_SCROLL_PRESENTER;UNO_HAS_MANAGED_POINTERS;SUPPORTS_RTL;UNO_HAS_ENHANCED_LIFECYCLE;UNO_HAS_BORDER_VISUAL</DefineConstants>
<DefineConstants>$(DefineConstants);UNO_SUPPORTS_NATIVEHOST;HAS_INPUT_INJECTOR</DefineConstants>
<DefineConstants>$(DefineConstants);UNO_SUPPORTS_NATIVEHOST;HAS_INPUT_INJECTOR;HAS_RENDER_TARGET_BITMAP</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(UnoRuntimeIdentifier)'=='Reference'">
Expand All @@ -80,21 +81,21 @@
</PropertyGroup>

<PropertyGroup Condition="$(IsIOS)">
<DefineConstants>$(DefineConstants);XAMARIN;UNO_HAS_UIELEMENT_IMPLICIT_PINNING;HAS_NATIVE_IMPLICIT_POINTER_CAPTURE</DefineConstants>
<DefineConstants>$(DefineConstants);XAMARIN;UNO_HAS_UIELEMENT_IMPLICIT_PINNING;HAS_NATIVE_IMPLICIT_POINTER_CAPTURE;HAS_RENDER_TARGET_BITMAP</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="$(IsCatalyst)">
<DefineConstants>$(DefineConstants);XAMARIN;UNO_HAS_UIELEMENT_IMPLICIT_PINNING;HAS_NATIVE_IMPLICIT_POINTER_CAPTURE</DefineConstants>
<DefineConstants>$(DefineConstants);XAMARIN;UNO_HAS_UIELEMENT_IMPLICIT_PINNING;HAS_NATIVE_IMPLICIT_POINTER_CAPTURE;HAS_RENDER_TARGET_BITMAP</DefineConstants>
<SupportedOSPlatformVersion>13.1</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="$(IsMacOS)">
<DefineConstants>$(DefineConstants);__MACOS__;XAMARIN;UNO_HAS_UIELEMENT_IMPLICIT_PINNING;UNO_HAS_MANAGED_SCROLL_PRESENTER;UNO_HAS_MANAGED_POINTERS</DefineConstants>
<DefineConstants>$(DefineConstants);__MACOS__;XAMARIN;UNO_HAS_UIELEMENT_IMPLICIT_PINNING;UNO_HAS_MANAGED_SCROLL_PRESENTER;UNO_HAS_MANAGED_POINTERS;HAS_RENDER_TARGET_BITMAP</DefineConstants>
<SupportedOSPlatformVersion>10.15</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="$(IsAndroid)">
<DefineConstants>$(DefineConstants);__ANDROID__;XAMARIN;HAS_NATIVE_IMPLICIT_POINTER_CAPTURE</DefineConstants>
<DefineConstants>$(DefineConstants);__ANDROID__;XAMARIN;HAS_NATIVE_IMPLICIT_POINTER_CAPTURE;HAS_RENDER_TARGET_BITMAP</DefineConstants>
<SupportedOSPlatformVersion>21.0</SupportedOSPlatformVersion>
</PropertyGroup>

Expand All @@ -108,13 +109,13 @@
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-windows10.0.19041.0'">
<DefineConstants>$(DefineConstants);HAS_INPUT_INJECTOR;WINDOWS_WINUI</DefineConstants>
<DefineConstants>$(DefineConstants);HAS_INPUT_INJECTOR;WINDOWS_WINUI;HAS_RENDER_TARGET_BITMAP</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'uap10.0.19041' ">
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<DefineConstants>$(DefineConstants);NETFX_CORE;HAS_INPUT_INJECTOR</DefineConstants>
<DefineConstants>$(DefineConstants);NETFX_CORE;HAS_INPUT_INJECTOR;HAS_RENDER_TARGET_BITMAP</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(CI_Build)'!='' OR '$(TF_BUILD)' == 'true'">
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI.RuntimeTests/Helpers/UITestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static async Task<Rect> Load<T>(T element, Func<T, bool>? isLoaded = null
/// <returns></returns>
public static async Task<RawBitmap> ScreenShot(FrameworkElement element, bool opaque = false, ScreenShotScalingMode scaling = ScreenShotScalingMode.UsePhysicalPixelsWithImplicitScaling)
{
#if HAS_RENDER_TARGET_BITMAP
var renderer = new RenderTargetBitmap();
element.UpdateLayout();
await TestServices.WindowHelper.WaitForIdle();
Expand Down Expand Up @@ -96,6 +97,9 @@ public static async Task<RawBitmap> ScreenShot(FrameworkElement element, bool op
}

return bitmap;
#else
throw new NotSupportedException("Cannot take screenshot on this platform.");
#endif
}

public enum ScreenShotScalingMode
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI.RuntimeTests/UITests/_Engine/RuntimeTestsApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public async Task RunAsync(string metadataName)
{
assemblyName = "UnoIslands" + assemblyName;
}

if (Type.GetType($"{metadataName}, {assemblyName}") is { } sampleType
&& Activator.CreateInstance(sampleType) is FrameworkElement sample)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#if !__ANDROID__
#nullable enable
using System;
using System.Buffers;
using System.Linq;
using System.Runtime.InteropServices;

namespace Microsoft.UI.Xaml.Media.Imaging;

public partial class RenderTargetBitmap
{
private unsafe class UnmanagedArrayOfBytes
{
public nint Pointer;
public int Length { get; }

public UnmanagedArrayOfBytes(int length)
{
Length = length;
Pointer = Marshal.AllocHGlobal(length);
GC.AddMemoryPressure(length);
}

public byte this[int index]
{
get
{
return ((byte*)Pointer.ToPointer())[index];
}
set
{
((byte*)Pointer.ToPointer())[index] = value;
}
}

~UnmanagedArrayOfBytes()
{
Marshal.FreeHGlobal(Pointer);
GC.RemoveMemoryPressure(Length);
}
}

// This is to avoid LOH array allocations
// https://stackoverflow.com/questions/52190423/c-sharp-access-unmanaged-array-using-memoryt-or-arraysegmentt
private sealed unsafe class UnmanagedMemoryManager<T> : MemoryManager<T>
where T : unmanaged
{
private readonly T* _pointer;
private readonly int _length;

/// <summary>
/// Create a new UnmanagedMemoryManager instance at the given pointer and size
/// </summary>
public UnmanagedMemoryManager(T* pointer, int length)
{
if (length < 0) throw new ArgumentOutOfRangeException(nameof(length));

Check failure on line 56 in src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs#L56

Add curly braces around the nested statement(s) in this 'if' block.
_pointer = pointer;
_length = length;
}
/// <summary>
/// Obtains a span that represents the region
/// </summary>
public override Span<T> GetSpan() => new(_pointer, _length);

/// <summary>
/// Provides access to a pointer that represents the data (note: no actual pin occurs)
/// </summary>
public override MemoryHandle Pin(int elementIndex = 0)
{
if (elementIndex < 0 || elementIndex >= _length)

Check failure on line 70 in src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs#L70

Add curly braces around the nested statement(s) in this 'if' block.
throw new ArgumentOutOfRangeException(nameof(elementIndex));
return new MemoryHandle(_pointer + elementIndex);
}

/// <summary>
/// Has no effect
/// </summary>
public override void Unpin() { }

/// <summary>
/// Releases all resources associated with this object
/// </summary>
protected override void Dispose(bool disposing) { }
}
}
#endif
Loading

0 comments on commit 63a0506

Please sign in to comment.