#include "IronsPerformanceSubsystem.h" #include "Misc/AutomationTest.h" #include #if WITH_DEV_AUTOMATION_TESTS IMPLEMENT_SIMPLE_AUTOMATION_TEST(FIronsPerformanceWindowTest,"IRONSPORE.Performance.RollingWindow",EAutomationTestFlags::EditorContext|EAutomationTestFlags::EngineFilter) bool FIronsPerformanceWindowTest::RunTest(const FString& Parameters) { FIronsPerformanceWindow W; W.Add(10,.01,1,2,3,4);W.Add(10.03,.03,3,4,5,6); auto S=W.Read(10.03); TestEqual(TEXT("FPS uses total elapsed time, not average reciprocal"),S.Fps,50.0); TestEqual(TEXT("Frame time in milliseconds"),S.FrameMs,20.0); TestEqual(TEXT("CPU samples averaged independently"),S.GameMs,2.0); W.Add(11.2,.02,5,6,-1,-1);S=W.Read(11.2); TestEqual(TEXT("Expired samples removed"),S.Samples,1); TestTrue(TEXT("Unavailable GPU does not retain last valid number"),S.GpuMs<0); TestTrue(TEXT("Disabled RHI thread is unavailable"),S.RhiMs<0); TestEqual(TEXT("An idle CPU may legitimately measure zero"),[&](){W.Add(11.22,.02,0,0,0,0);return W.Read(11.22).GpuMs;}(),0.0); TestTrue(TEXT("A stale window produces no FPS"),W.Read(13).Fps<0); return true; } IMPLEMENT_SIMPLE_AUTOMATION_TEST(FIronsPerformanceClockTest,"IRONSPORE.Performance.ClockAndValidity",EAutomationTestFlags::EditorContext|EAutomationTestFlags::EngineFilter) bool FIronsPerformanceClockTest::RunTest(const FString& Parameters) { FIronsPerformanceWindow W;const double Nan=std::numeric_limits::quiet_NaN(); W.Add(1,0,1,2,3,4);W.Add(1,Nan,1,2,3,4); TestEqual(TEXT("Invalid frame intervals rejected"),W.Read(1).Samples,0); W.Add(2,.02,Nan,2,-1,Nan); TestTrue(TEXT("Invalid timings unavailable"),W.Read(2).GameMs<0&&W.Read(2).GpuMs<0); W.Add(1,.5,1,2,3,4); TestEqual(TEXT("Backwards clock starts a new timeline"),W.Read(1).Samples,1); TestEqual(TEXT("Wall clock remains meaningful during gameplay pause"),W.Read(1).Fps,2.0); W.Reset();TestTrue(TEXT("Travel reset clears old numbers"),W.Read(1).Fps<0); return true; } #endif