Skip to content

Commit

Permalink
Merge branch 'master' into fix-gamehost-collect-on-android
Browse files Browse the repository at this point in the history
  • Loading branch information
Susko3 committed May 24, 2024
2 parents 673fa11 + efb30d9 commit 33a58f5
Show file tree
Hide file tree
Showing 107 changed files with 6,714 additions and 713 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ jobs:

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21.9

- name: Install httpbin
run: go install github.com/mccutchen/go-httpbin/v2/cmd/go-httpbin@latest
Expand Down
11 changes: 0 additions & 11 deletions osu.Framework.Android/AndroidGameActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ public abstract class AndroidGameActivity : SDLActivity
protected override IRunnable CreateSDLMainRunnable() => new Runnable(() =>
{
var host = new AndroidGameHost(this);
host.AllowScreenSuspension.Result.BindValueChanged(allow =>
{
RunOnUiThread(() =>
{
if (!allow.NewValue)
Window?.AddFlags(WindowManagerFlags.KeepScreenOn);
else
Window?.ClearFlags(WindowManagerFlags.KeepScreenOn);
});
}, true);

host.Run(CreateGame());

if (!IsFinishing)
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.Android/AndroidGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace osu.Framework.Android
{
public class AndroidGameHost : SDL3GameHost
public class AndroidGameHost : SDLGameHost
{
private readonly AndroidGameActivity activity;

Expand Down
3 changes: 2 additions & 1 deletion osu.Framework.Android/AndroidGameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
using System;
using osu.Framework.Bindables;
using osu.Framework.Platform;
using osu.Framework.Platform.SDL3;

namespace osu.Framework.Android
{
internal class AndroidGameWindow : SDL3MobileWindow
{
public override IntPtr DisplayHandle => AndroidGameActivity.Surface.NativeSurface?.Handle ?? IntPtr.Zero;
public override IntPtr SurfaceHandle => AndroidGameActivity.Surface.NativeSurface?.Handle ?? IntPtr.Zero;

public AndroidGameWindow(GraphicsSurfaceType surfaceType, string appName)
: base(surfaceType, appName)
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.Android/osu.Framework.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.SDL3-CS.Android" Version="2024.418.1" />
<PackageReference Include="Xamarin.AndroidX.Window" Version="1.2.0.1" />
<PackageReference Include="Xamarin.AndroidX.Window" Version="1.2.0.1" PrivateAssets="compile" />
</ItemGroup>
</Project>
62 changes: 62 additions & 0 deletions osu.Framework.Benchmarks/BenchmarkSRGBColourMultiplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using BenchmarkDotNet.Attributes;
using osu.Framework.Graphics.Colour;
using osuTK.Graphics;

namespace osu.Framework.Benchmarks
{
public class BenchmarkSRGBColourMultiplication : BenchmarkTest
{
private static readonly SRGBColour white = new SRGBColour
{
SRGB = new Color4(1f, 1f, 1f, 1f)
};

private static readonly SRGBColour white_with_opacity = new SRGBColour
{
SRGB = new Color4(1f, 1f, 1f, 0.5f)
};

private static readonly SRGBColour gray = new SRGBColour
{
SRGB = Color4.Gray
};

private static readonly SRGBColour gray_light = new SRGBColour
{
SRGB = Color4.LightGray
};

[Benchmark]
public SRGBColour MultiplyNonWhite()
{
return gray * gray_light;
}

[Benchmark]
public SRGBColour MultiplyWhite()
{
return gray * white;
}

[Benchmark]
public SRGBColour MultiplyWhiteWithOpacity()
{
return gray * white_with_opacity;
}

[Benchmark]
public SRGBColour MultiplyConstOne()
{
return gray * 1;
}

[Benchmark]
public SRGBColour MultiplyConstNonOne()
{
return gray * 0.5f;
}
}
}
55 changes: 53 additions & 2 deletions osu.Framework.Tests/FlakyTestAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,75 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands;

namespace osu.Framework.Tests
{
/// <summary>
/// An attribute to mark any flaky tests.
/// Will add a retry count unless environment variable `FAIL_FLAKY_TESTS` is set to `1`.
/// </summary>
public class FlakyTestAttribute : RetryAttribute
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public class FlakyTestAttribute : NUnitAttribute, IRepeatTest
{
private readonly int tryCount;

public FlakyTestAttribute()
: this(10)
{
}

public FlakyTestAttribute(int tryCount)
: base(FrameworkEnvironment.FailFlakyTests ? 1 : tryCount)
{
this.tryCount = tryCount;
}

public TestCommand Wrap(TestCommand command) => new FlakyTestCommand(command, tryCount);

// Adapted from https://github.com/nunit/nunit/blob/4eaab2eef3713907ca37bfb2f7f47e3fc2785214/src/NUnitFramework/framework/Attributes/RetryAttribute.cs
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
public class FlakyTestCommand : DelegatingTestCommand
{
private readonly int tryCount;

public FlakyTestCommand(TestCommand innerCommand, int tryCount)
: base(innerCommand)
{
this.tryCount = tryCount;
}

public override TestResult Execute(TestExecutionContext context)
{
int count = FrameworkEnvironment.FailFlakyTests ? 1 : tryCount;

while (count-- > 0)
{
try
{
context.CurrentResult = innerCommand.Execute(context);
}
catch (Exception ex)
{
context.CurrentResult ??= context.CurrentTest.MakeTestResult();
context.CurrentResult.RecordException(ex);
}

if (context.CurrentResult.ResultState != ResultState.Failure)
break;

if (count > 0)
{
context.CurrentResult = context.CurrentTest.MakeTestResult();
context.CurrentRepeatCount++;
}
}

return context.CurrentResult;
}
}
}
}
121 changes: 121 additions & 0 deletions osu.Framework.Tests/IO/TestOnlineStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Extensions;
using osu.Framework.IO.Stores;

namespace osu.Framework.Tests.IO
{
[TestFixture]
[Category("httpbin")]
public class TestOnlineStore
{
private const string default_protocol = "http";

private static readonly string host;
private static readonly IEnumerable<string> protocols;

private bool oldAllowInsecureRequests;
private OnlineStore store = null!;

static TestOnlineStore()
{
bool localHttpBin = Environment.GetEnvironmentVariable("OSU_TESTS_LOCAL_HTTPBIN") == "1";

if (localHttpBin)
{
// httpbin very frequently falls over and causes random tests to fail
// Thus github actions builds rely on a local httpbin instance to run the tests

host = "127.0.0.1:8080";
protocols = new[] { default_protocol };
}
else
{
host = "httpbin.org";
protocols = new[] { default_protocol, "https" };
}
}

[OneTimeSetUp]
public void GlobalSetup()
{
oldAllowInsecureRequests = FrameworkEnvironment.AllowInsecureRequests;
FrameworkEnvironment.AllowInsecureRequests = true;
}

[OneTimeTearDown]
public void GlobalTeardown()
{
FrameworkEnvironment.AllowInsecureRequests = oldAllowInsecureRequests;
}

[SetUp]
public void Setup()
{
store = new OnlineStore();
}

[Test, Retry(5)]
public void TestValidUrlReturnsData([ValueSource(nameof(protocols))] string protocol, [Values(true, false)] bool async)
{
byte[]? result = async
? store.GetAsync($"{protocol}://{host}/image/png").GetResultSafely()
: store.Get($"{protocol}://{host}/image/png");

Assert.That(result, Is.Not.Null);
Assert.That(result, Has.Length.GreaterThan(0));
}

[Test]
public void TestMissingSchemeReturnsNull([Values(true, false)] bool async)
{
byte[]? result = async
? store.GetAsync($"{host}/image/png").GetResultSafely()
: store.Get($"{host}/image/png");

Assert.That(result, Is.Null);
}

[Test]
public void TestInvalidUrlReturnsNull()
{
byte[]? result = store.Get("this is not a valid url");
Assert.That(result, Is.Null);
}

[Test]
public void TestNullUrlReturnsNull()
{
// Not sure if this store should accept a null URL, but let's test it anyway.
byte[]? result = store.Get(null);
Assert.That(result, Is.Null);
}

[Test]
public void TestFileUrlFails([Values(true, false)] bool async)
{
// Known, guaranteed file path.
string path = new Uri(AppContext.BaseDirectory).AbsoluteUri;

byte[]? result = async
? store.GetAsync(path).GetResultSafely()
: store.Get(path);

Assert.That(result, Is.Null);
}

[Test]
public void TestBadWebRequest([ValueSource(nameof(protocols))] string protocol, [Values(true, false)] bool async)
{
byte[]? result = async
? store.GetAsync($"{protocol}://{host}/status/500").GetResultSafely()
: store.Get($"{protocol}://{host}/status/500");

Assert.That(result, Is.Null);
}
}
}
Loading

0 comments on commit 33a58f5

Please sign in to comment.