mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-10 17:55:47 -04:00
Add regression test runner
This commit is contained in:
@ -29,3 +29,6 @@ if(BUILD_LIBRETRO_CORE)
|
||||
add_subdirectory(duckstation-libretro)
|
||||
endif()
|
||||
|
||||
if(BUILD_REGTEST)
|
||||
add_subdirectory(duckstation-regtest)
|
||||
endif()
|
||||
|
10
src/duckstation-regtest/CMakeLists.txt
Normal file
10
src/duckstation-regtest/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
add_executable(duckstation-regtest
|
||||
regtest_host_display.cpp
|
||||
regtest_host_display.h
|
||||
regtest_host_interface.cpp
|
||||
regtest_host_interface.h
|
||||
regtest_settings_interface.cpp
|
||||
regtest_settings_interface.h
|
||||
)
|
||||
|
||||
target_link_libraries(duckstation-regtest PRIVATE core common frontend-common scmversion)
|
25
src/duckstation-regtest/duckstation-regtest.vcxproj
Normal file
25
src/duckstation-regtest/duckstation-regtest.vcxproj
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\dep\msvc\vsprops\Configurations.props" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{3029310E-4211-4C87-801A-72E130A648EF}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="regtest_host_display.cpp" />
|
||||
<ClCompile Include="regtest_host_interface.cpp" />
|
||||
<ClCompile Include="regtest_settings_interface.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="regtest_host_display.h" />
|
||||
<ClInclude Include="regtest_host_interface.h" />
|
||||
<ClInclude Include="regtest_settings_interface.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\dep\msvc\vsprops\ConsoleApplication.props" />
|
||||
<Import Project="..\frontend-common\frontend-common.props" />
|
||||
<ItemDefinitionGroup>
|
||||
<Link>
|
||||
<AdditionalDependencies>$(RootBuildDir)frontend-common\frontend-common.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="..\..\dep\msvc\vsprops\Targets.props" />
|
||||
</Project>
|
13
src/duckstation-regtest/duckstation-regtest.vcxproj.filters
Normal file
13
src/duckstation-regtest/duckstation-regtest.vcxproj.filters
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="regtest_host_interface.cpp" />
|
||||
<ClCompile Include="regtest_host_display.cpp" />
|
||||
<ClCompile Include="regtest_settings_interface.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="regtest_host_interface.h" />
|
||||
<ClInclude Include="regtest_host_display.h" />
|
||||
<ClInclude Include="regtest_settings_interface.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
221
src/duckstation-regtest/regtest_host_display.cpp
Normal file
221
src/duckstation-regtest/regtest_host_display.cpp
Normal file
@ -0,0 +1,221 @@
|
||||
#include "regtest_host_display.h"
|
||||
#include "common/align.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/file_system.h"
|
||||
#include "common/image.h"
|
||||
#include "common/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include <array>
|
||||
#include <tuple>
|
||||
Log_SetChannel(RegTestHostDisplay);
|
||||
|
||||
RegTestHostDisplay::RegTestHostDisplay() = default;
|
||||
|
||||
RegTestHostDisplay::~RegTestHostDisplay() = default;
|
||||
|
||||
HostDisplay::RenderAPI RegTestHostDisplay::GetRenderAPI() const
|
||||
{
|
||||
return RenderAPI::None;
|
||||
}
|
||||
|
||||
void* RegTestHostDisplay::GetRenderDevice() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* RegTestHostDisplay::GetRenderContext() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::HasRenderDevice() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::HasRenderSurface() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device,
|
||||
bool threaded_presentation)
|
||||
{
|
||||
m_window_info = wi;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device,
|
||||
bool threaded_presentation)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::MakeRenderContextCurrent()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::DoneRenderContextCurrent()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::DestroyRenderDevice()
|
||||
{
|
||||
ClearSoftwareCursor();
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::DestroyRenderSurface() {}
|
||||
|
||||
bool RegTestHostDisplay::CreateResources()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::DestroyResources() {}
|
||||
|
||||
HostDisplay::AdapterAndModeList RegTestHostDisplay::GetAdapterAndModeList()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::CreateImGuiContext()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::DestroyImGuiContext()
|
||||
{
|
||||
// noop
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::UpdateImGuiFontTexture()
|
||||
{
|
||||
// noop
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::ChangeRenderWindow(const WindowInfo& wi)
|
||||
{
|
||||
m_window_info = wi;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_window_height)
|
||||
{
|
||||
m_window_info.surface_width = new_window_width;
|
||||
m_window_info.surface_height = new_window_height;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::SupportsFullscreen() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::IsFullscreen()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::SetPostProcessingChain(const std::string_view& config)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<HostDisplayTexture> RegTestHostDisplay::CreateTexture(u32 width, u32 height, u32 layers, u32 levels,
|
||||
u32 samples, HostDisplayPixelFormat format,
|
||||
const void* data, u32 data_stride,
|
||||
bool dynamic /* = false */)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height,
|
||||
const void* data, u32 data_stride)
|
||||
{
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::DownloadTexture(const void* texture_handle, HostDisplayPixelFormat texture_format, u32 x,
|
||||
u32 y, u32 width, u32 height, void* out_data, u32 out_data_stride)
|
||||
{
|
||||
const u32 pixel_size = GetDisplayPixelFormatSize(texture_format);
|
||||
const u32 input_stride = Common::AlignUpPow2(width * pixel_size, 4);
|
||||
const u8* input_start = static_cast<const u8*>(texture_handle) + (x * pixel_size);
|
||||
StringUtil::StrideMemCpy(out_data, out_data_stride, input_start, input_stride, width * pixel_size, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::SupportsDisplayPixelFormat(HostDisplayPixelFormat format) const
|
||||
{
|
||||
return (format == HostDisplayPixelFormat::RGBA8);
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::BeginSetDisplayPixels(HostDisplayPixelFormat format, u32 width, u32 height, void** out_buffer,
|
||||
u32* out_pitch)
|
||||
{
|
||||
const u32 pixel_size = GetDisplayPixelFormatSize(format);
|
||||
const u32 pitch = Common::AlignUpPow2(width * GetDisplayPixelFormatSize(format), 4);
|
||||
const u32 required_size = height * pitch;
|
||||
if (m_frame_buffer.size() != (required_size / 4))
|
||||
{
|
||||
m_frame_buffer.clear();
|
||||
m_frame_buffer.resize(required_size / 4);
|
||||
}
|
||||
|
||||
// border is already filled here
|
||||
m_frame_buffer_pitch = pitch;
|
||||
SetDisplayTexture(m_frame_buffer.data(), format, width, height, 0, 0, width, height);
|
||||
*out_buffer = reinterpret_cast<u8*>(m_frame_buffer.data());
|
||||
*out_pitch = pitch;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::EndSetDisplayPixels()
|
||||
{
|
||||
// noop
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::DumpFrame(const std::string& filename)
|
||||
{
|
||||
if (!HasDisplayTexture())
|
||||
{
|
||||
if (FileSystem::FileExists(filename.c_str()))
|
||||
FileSystem::DeleteFile(filename.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Common::RGBA8Image image(m_display_texture_width, m_display_texture_height,
|
||||
static_cast<const u32*>(m_display_texture_handle));
|
||||
|
||||
// set alpha channel on all pixels
|
||||
u32* pixels = image.GetPixels();
|
||||
u32* pixels_end = pixels + (image.GetWidth() * image.GetHeight());
|
||||
while (pixels != pixels_end)
|
||||
*(pixels++) |= 0xFF000000u;
|
||||
|
||||
if (!Common::WriteImageToFile(image, filename.c_str()))
|
||||
Log_ErrorPrintf("Failed to dump frame '%s'", filename.c_str());
|
||||
}
|
||||
|
||||
void RegTestHostDisplay::SetVSync(bool enabled)
|
||||
{
|
||||
Log_DevPrintf("Ignoring SetVSync(%u)", BoolToUInt32(enabled));
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::Render()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegTestHostDisplay::RenderScreenshot(u32 width, u32 height, std::vector<u32>* out_pixels, u32* out_stride,
|
||||
HostDisplayPixelFormat* out_format)
|
||||
{
|
||||
return false;
|
||||
}
|
70
src/duckstation-regtest/regtest_host_display.h
Normal file
70
src/duckstation-regtest/regtest_host_display.h
Normal file
@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
#include "core/host_display.h"
|
||||
#include <string>
|
||||
|
||||
class RegTestHostDisplay final : public HostDisplay
|
||||
{
|
||||
public:
|
||||
RegTestHostDisplay();
|
||||
~RegTestHostDisplay();
|
||||
|
||||
void DumpFrame(const std::string& filename);
|
||||
|
||||
RenderAPI GetRenderAPI() const override;
|
||||
void* GetRenderDevice() const override;
|
||||
void* GetRenderContext() const override;
|
||||
|
||||
bool HasRenderDevice() const override;
|
||||
bool HasRenderSurface() const override;
|
||||
|
||||
bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device,
|
||||
bool threaded_presentation) override;
|
||||
bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device,
|
||||
bool threaded_presentation) override;
|
||||
void DestroyRenderDevice() override;
|
||||
|
||||
bool MakeRenderContextCurrent() override;
|
||||
bool DoneRenderContextCurrent() override;
|
||||
|
||||
bool ChangeRenderWindow(const WindowInfo& wi) override;
|
||||
void ResizeRenderWindow(s32 new_window_width, s32 new_window_height) override;
|
||||
bool SupportsFullscreen() const override;
|
||||
bool IsFullscreen() override;
|
||||
bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override;
|
||||
void DestroyRenderSurface() override;
|
||||
|
||||
bool SetPostProcessingChain(const std::string_view& config) override;
|
||||
|
||||
bool CreateResources() override;
|
||||
void DestroyResources() override;
|
||||
|
||||
AdapterAndModeList GetAdapterAndModeList() override;
|
||||
bool CreateImGuiContext() override;
|
||||
void DestroyImGuiContext() override;
|
||||
bool UpdateImGuiFontTexture() override;
|
||||
|
||||
std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
|
||||
HostDisplayPixelFormat format, const void* data, u32 data_stride,
|
||||
bool dynamic = false) override;
|
||||
void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data,
|
||||
u32 data_stride) override;
|
||||
bool DownloadTexture(const void* texture_handle, HostDisplayPixelFormat texture_format, u32 x, u32 y, u32 width,
|
||||
u32 height, void* out_data, u32 out_data_stride) override;
|
||||
|
||||
void SetVSync(bool enabled) override;
|
||||
|
||||
bool Render() override;
|
||||
bool RenderScreenshot(u32 width, u32 height, std::vector<u32>* out_pixels, u32* out_stride,
|
||||
HostDisplayPixelFormat* out_format) override;
|
||||
|
||||
bool SupportsDisplayPixelFormat(HostDisplayPixelFormat format) const override;
|
||||
|
||||
bool BeginSetDisplayPixels(HostDisplayPixelFormat format, u32 width, u32 height, void** out_buffer,
|
||||
u32* out_pitch) override;
|
||||
void EndSetDisplayPixels() override;
|
||||
|
||||
private:
|
||||
std::vector<u32> m_frame_buffer;
|
||||
HostDisplayPixelFormat m_frame_buffer_format = HostDisplayPixelFormat::Unknown;
|
||||
u32 m_frame_buffer_pitch = 0;
|
||||
};
|
498
src/duckstation-regtest/regtest_host_interface.cpp
Normal file
498
src/duckstation-regtest/regtest_host_interface.cpp
Normal file
@ -0,0 +1,498 @@
|
||||
#include "regtest_host_interface.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/audio_stream.h"
|
||||
#include "common/byte_stream.h"
|
||||
#include "common/file_system.h"
|
||||
#include "common/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/system.h"
|
||||
#include "frontend-common/game_database.h"
|
||||
#include "frontend-common/game_settings.h"
|
||||
#include "regtest_host_display.h"
|
||||
#include "scmversion/scmversion.h"
|
||||
#include <cstdio>
|
||||
Log_SetChannel(RegTestHostInterface);
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "frontend-common/d3d11_host_display.h"
|
||||
#include "frontend-common/d3d12_host_display.h"
|
||||
#endif
|
||||
|
||||
#include "frontend-common/opengl_host_display.h"
|
||||
#include "frontend-common/vulkan_host_display.h"
|
||||
|
||||
static int s_frames_to_run = 60 * 60;
|
||||
static int s_frame_dump_interval = 0;
|
||||
static std::shared_ptr<SystemBootParameters> s_boot_parameters;
|
||||
static std::string s_dump_base_directory;
|
||||
static std::string s_dump_game_directory;
|
||||
static GPURenderer s_renderer_to_use = GPURenderer::Software;
|
||||
static GameSettings::Database s_game_settings_db;
|
||||
static GameDatabase s_game_database;
|
||||
|
||||
RegTestHostInterface::RegTestHostInterface() = default;
|
||||
|
||||
RegTestHostInterface::~RegTestHostInterface() = default;
|
||||
|
||||
bool RegTestHostInterface::Initialize()
|
||||
{
|
||||
if (!HostInterface::Initialize())
|
||||
return false;
|
||||
|
||||
SetUserDirectoryToProgramDirectory();
|
||||
s_game_database.Load();
|
||||
LoadGameSettingsDatabase();
|
||||
InitializeSettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegTestHostInterface::Shutdown()
|
||||
{
|
||||
HostInterface::Shutdown();
|
||||
}
|
||||
|
||||
void RegTestHostInterface::ReportError(const char* message)
|
||||
{
|
||||
Log_ErrorPrintf("Error: %s", message);
|
||||
}
|
||||
|
||||
void RegTestHostInterface::ReportMessage(const char* message)
|
||||
{
|
||||
Log_InfoPrintf("Info: %s", message);
|
||||
}
|
||||
|
||||
void RegTestHostInterface::ReportDebuggerMessage(const char* message)
|
||||
{
|
||||
Log_DevPrintf("Debugger: %s", message);
|
||||
}
|
||||
|
||||
bool RegTestHostInterface::ConfirmMessage(const char* message)
|
||||
{
|
||||
Log_InfoPrintf("Confirm: %s", message);
|
||||
return false;
|
||||
}
|
||||
|
||||
void RegTestHostInterface::AddOSDMessage(std::string message, float duration /*= 2.0f*/)
|
||||
{
|
||||
Log_InfoPrintf("OSD: %s", message.c_str());
|
||||
}
|
||||
|
||||
void RegTestHostInterface::DisplayLoadingScreen(const char* message, int progress_min /*= -1*/,
|
||||
int progress_max /*= -1*/, int progress_value /*= -1*/)
|
||||
{
|
||||
Log_InfoPrintf("Loading: %s (%d / %d)", message, progress_value + progress_min, progress_max);
|
||||
}
|
||||
|
||||
void RegTestHostInterface::GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title)
|
||||
{
|
||||
if (image)
|
||||
{
|
||||
GameDatabaseEntry database_entry;
|
||||
if (s_game_database.GetEntryForDisc(image, &database_entry))
|
||||
{
|
||||
*code = std::move(database_entry.serial);
|
||||
*title = std::move(database_entry.title);
|
||||
return;
|
||||
}
|
||||
|
||||
*code = System::GetGameCodeForImage(image, true);
|
||||
}
|
||||
|
||||
*title = FileSystem::GetFileTitleFromPath(path);
|
||||
}
|
||||
|
||||
void RegTestHostInterface::OnRunningGameChanged(const std::string& path, CDImage* image, const std::string& game_code,
|
||||
const std::string& game_title)
|
||||
{
|
||||
HostInterface::OnRunningGameChanged(path, image, game_code, game_title);
|
||||
|
||||
Log_InfoPrintf("Game Path: %s", path.c_str());
|
||||
Log_InfoPrintf("Game Code: %s", game_code.c_str());
|
||||
Log_InfoPrintf("Game Title: %s", game_title.c_str());
|
||||
|
||||
if (!s_dump_base_directory.empty())
|
||||
{
|
||||
s_dump_game_directory = StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s",
|
||||
s_dump_base_directory.c_str(), game_title.c_str());
|
||||
|
||||
if (!FileSystem::DirectoryExists(s_dump_game_directory.c_str()))
|
||||
{
|
||||
Log_InfoPrintf("Creating directory '%s'...", s_dump_game_directory.c_str());
|
||||
if (!FileSystem::CreateDirectory(s_dump_game_directory.c_str(), false))
|
||||
Panic("Failed to create dump directory.");
|
||||
}
|
||||
|
||||
Log_InfoPrintf("Dumping frames to '%s'...", s_dump_game_directory.c_str());
|
||||
}
|
||||
|
||||
UpdateSettings();
|
||||
}
|
||||
|
||||
std::string RegTestHostInterface::GetStringSettingValue(const char* section, const char* key,
|
||||
const char* default_value /*= ""*/)
|
||||
{
|
||||
return m_settings_interface.GetStringValue(section, key, default_value);
|
||||
}
|
||||
|
||||
bool RegTestHostInterface::GetBoolSettingValue(const char* section, const char* key, bool default_value /*= false*/)
|
||||
{
|
||||
return m_settings_interface.GetBoolValue(section, key, default_value);
|
||||
}
|
||||
|
||||
int RegTestHostInterface::GetIntSettingValue(const char* section, const char* key, int default_value /*= 0*/)
|
||||
{
|
||||
return m_settings_interface.GetIntValue(section, key, default_value);
|
||||
}
|
||||
|
||||
float RegTestHostInterface::GetFloatSettingValue(const char* section, const char* key, float default_value /*= 0.0f*/)
|
||||
{
|
||||
return m_settings_interface.GetFloatValue(section, key, default_value);
|
||||
}
|
||||
|
||||
std::vector<std::string> RegTestHostInterface::GetSettingStringList(const char* section, const char* key)
|
||||
{
|
||||
return m_settings_interface.GetStringList(section, key);
|
||||
}
|
||||
|
||||
void RegTestHostInterface::UpdateSettings()
|
||||
{
|
||||
SettingsInterface& si = m_settings_interface;
|
||||
HostInterface::LoadSettings(si);
|
||||
|
||||
const std::string& code = System::GetRunningCode();
|
||||
if (!code.empty())
|
||||
{
|
||||
const GameSettings::Entry* entry = s_game_settings_db.GetEntry(code);
|
||||
if (entry)
|
||||
{
|
||||
Log_InfoPrintf("Applying game settings for '%s'", code.c_str());
|
||||
entry->ApplySettings(true);
|
||||
}
|
||||
}
|
||||
|
||||
HostInterface::FixIncompatibleSettings(true);
|
||||
}
|
||||
|
||||
void RegTestHostInterface::LoadGameSettingsDatabase()
|
||||
{
|
||||
const char* path = "database" FS_OSPATH_SEPARATOR_STR "gamesettings.ini";
|
||||
std::unique_ptr<ByteStream> stream = OpenPackageFile(path, BYTESTREAM_OPEN_READ | BYTESTREAM_OPEN_STREAMED);
|
||||
if (!stream)
|
||||
{
|
||||
Log_ErrorPrintf("Failed to open game settings database from '%s'. This could cause compatibility issues.", path);
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string data(FileSystem::ReadStreamToString(stream.get()));
|
||||
if (data.empty() || !s_game_settings_db.Load(data))
|
||||
{
|
||||
Log_ErrorPrintf("Failed to load game settings database from '%s'. This could cause compatibility issues.", path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RegTestHostInterface::InitializeSettings()
|
||||
{
|
||||
SettingsInterface& si = m_settings_interface;
|
||||
HostInterface::SetDefaultSettings(si);
|
||||
|
||||
// Set the settings we need for testing.
|
||||
si.SetStringValue("GPU", "Renderer", Settings::GetRendererName(s_renderer_to_use));
|
||||
si.SetStringValue("Controller1", "Type", Settings::GetControllerTypeName(ControllerType::DigitalController));
|
||||
si.SetStringValue("Controller2", "Type", Settings::GetControllerTypeName(ControllerType::None));
|
||||
si.SetStringValue("MemoryCards", "Card1Type", Settings::GetMemoryCardTypeName(MemoryCardType::NonPersistent));
|
||||
si.SetStringValue("MemoryCards", "Card2Type", Settings::GetMemoryCardTypeName(MemoryCardType::None));
|
||||
si.SetStringValue("ControllerPorts", "MultitapMode", Settings::GetMultitapModeName(MultitapMode::Disabled));
|
||||
si.SetStringValue("Logging", "LogLevel", Settings::GetLogLevelName(LOGLEVEL_DEV));
|
||||
si.SetBoolValue("Logging", "LogToConsole", true);
|
||||
|
||||
HostInterface::LoadSettings(si);
|
||||
}
|
||||
|
||||
std::string RegTestHostInterface::GetBIOSDirectory()
|
||||
{
|
||||
return GetUserDirectoryRelativePath("bios");
|
||||
}
|
||||
|
||||
std::unique_ptr<ByteStream> RegTestHostInterface::OpenPackageFile(const char* path, u32 flags)
|
||||
{
|
||||
std::string full_path(GetProgramDirectoryRelativePath("%s", path));
|
||||
return ByteStream_OpenFileStream(full_path.c_str(), flags);
|
||||
}
|
||||
|
||||
bool RegTestHostInterface::AcquireHostDisplay()
|
||||
{
|
||||
switch (g_settings.gpu_renderer)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
case GPURenderer::HardwareD3D11:
|
||||
m_display = std::make_unique<FrontendCommon::D3D11HostDisplay>();
|
||||
break;
|
||||
|
||||
case GPURenderer::HardwareD3D12:
|
||||
m_display = std::make_unique<FrontendCommon::D3D12HostDisplay>();
|
||||
break;
|
||||
#endif
|
||||
|
||||
case GPURenderer::HardwareOpenGL:
|
||||
m_display = std::make_unique<FrontendCommon::OpenGLHostDisplay>();
|
||||
break;
|
||||
|
||||
case GPURenderer::HardwareVulkan:
|
||||
m_display = std::make_unique<FrontendCommon::VulkanHostDisplay>();
|
||||
break;
|
||||
|
||||
case GPURenderer::Software:
|
||||
default:
|
||||
m_display = std::make_unique<RegTestHostDisplay>();
|
||||
break;
|
||||
}
|
||||
|
||||
WindowInfo wi;
|
||||
wi.type = WindowInfo::Type::Surfaceless;
|
||||
wi.surface_width = 640;
|
||||
wi.surface_height = 480;
|
||||
if (!m_display->CreateRenderDevice(wi, std::string_view(), false, false))
|
||||
{
|
||||
Log_ErrorPrintf("Failed to create render device");
|
||||
m_display.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_display->InitializeRenderDevice(std::string_view(), false, false))
|
||||
{
|
||||
Log_ErrorPrintf("Failed to initialize render device");
|
||||
m_display->DestroyRenderDevice();
|
||||
m_display.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegTestHostInterface::ReleaseHostDisplay()
|
||||
{
|
||||
if (!m_display)
|
||||
return;
|
||||
|
||||
m_display->DestroyRenderDevice();
|
||||
m_display.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioStream> RegTestHostInterface::CreateAudioStream(AudioBackend backend)
|
||||
{
|
||||
return AudioStream::CreateNullAudioStream();
|
||||
}
|
||||
|
||||
static void PrintCommandLineVersion()
|
||||
{
|
||||
const bool was_console_enabled = Log::IsConsoleOutputEnabled();
|
||||
if (!was_console_enabled)
|
||||
Log::SetConsoleOutputParams(true);
|
||||
|
||||
std::fprintf(stderr, "DuckStation Regression Test Runner Version %s (%s)\n", g_scm_tag_str, g_scm_branch_str);
|
||||
std::fprintf(stderr, "https://github.com/stenzek/duckstation\n");
|
||||
std::fprintf(stderr, "\n");
|
||||
|
||||
if (!was_console_enabled)
|
||||
Log::SetConsoleOutputParams(false);
|
||||
}
|
||||
|
||||
static void PrintCommandLineHelp(const char* progname)
|
||||
{
|
||||
const bool was_console_enabled = Log::IsConsoleOutputEnabled();
|
||||
if (!was_console_enabled)
|
||||
Log::SetConsoleOutputParams(true);
|
||||
|
||||
PrintCommandLineVersion();
|
||||
std::fprintf(stderr, "Usage: %s [parameters] [--] [boot filename]\n", progname);
|
||||
std::fprintf(stderr, "\n");
|
||||
std::fprintf(stderr, " -help: Displays this information and exits.\n");
|
||||
std::fprintf(stderr, " -version: Displays version information and exits.\n");
|
||||
std::fprintf(stderr, " -dumpdir: Set frame dump base directory (will be dumped to basedir/gametitle).\n");
|
||||
std::fprintf(stderr, " -dumpinterval: Dumps every N frames.\n");
|
||||
std::fprintf(stderr, " -frames: Sets the number of frames to execute.\n");
|
||||
std::fprintf(stderr, " -log <level>: Sets the log level. Defaults to verbose.\n");
|
||||
std::fprintf(stderr, " -renderer <renderer>: Sets the graphics renderer. Default to software.\n");
|
||||
std::fprintf(stderr, " --: Signals that no more arguments will follow and the remaining\n"
|
||||
" parameters make up the filename. Use when the filename contains\n"
|
||||
" spaces or starts with a dash.\n");
|
||||
std::fprintf(stderr, "\n");
|
||||
|
||||
if (!was_console_enabled)
|
||||
Log::SetConsoleOutputParams(false);
|
||||
}
|
||||
|
||||
static bool ParseCommandLineArgs(int argc, char* argv[])
|
||||
{
|
||||
s_boot_parameters = std::make_shared<SystemBootParameters>();
|
||||
|
||||
bool no_more_args = false;
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (!no_more_args)
|
||||
{
|
||||
#define CHECK_ARG(str) !std::strcmp(argv[i], str)
|
||||
#define CHECK_ARG_PARAM(str) (!std::strcmp(argv[i], str) && ((i + 1) < argc))
|
||||
|
||||
if (CHECK_ARG("-help"))
|
||||
{
|
||||
PrintCommandLineHelp(argv[0]);
|
||||
return false;
|
||||
}
|
||||
else if (CHECK_ARG("-version"))
|
||||
{
|
||||
PrintCommandLineVersion();
|
||||
return false;
|
||||
}
|
||||
else if (CHECK_ARG_PARAM("-dumpdir"))
|
||||
{
|
||||
s_dump_base_directory = argv[++i];
|
||||
if (s_dump_base_directory.empty())
|
||||
{
|
||||
Log_ErrorPrintf("Invalid dump directory specified.");
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
else if (CHECK_ARG_PARAM("-dumpinterval"))
|
||||
{
|
||||
s_frame_dump_interval = StringUtil::FromChars<int>(argv[++i]).value_or(0);
|
||||
if (s_frames_to_run <= 0)
|
||||
{
|
||||
Log_ErrorPrintf("Invalid dump interval specified: -1", s_frame_dump_interval);
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
else if (CHECK_ARG_PARAM("-frames"))
|
||||
{
|
||||
s_frames_to_run = StringUtil::FromChars<int>(argv[++i]).value_or(-1);
|
||||
if (s_frames_to_run <= 0)
|
||||
{
|
||||
Log_ErrorPrintf("Invalid frame count specified: %d", s_frames_to_run);
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
else if (CHECK_ARG_PARAM("-log"))
|
||||
{
|
||||
std::optional<LOGLEVEL> level = Settings::ParseLogLevelName(argv[++i]);
|
||||
if (!level.has_value())
|
||||
{
|
||||
Log_ErrorPrintf("Invalid log level specified.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Log::SetConsoleOutputParams(true, nullptr, level.value());
|
||||
continue;
|
||||
}
|
||||
else if (CHECK_ARG_PARAM("-renderer"))
|
||||
{
|
||||
std::optional<GPURenderer> renderer = Settings::ParseRendererName(argv[++i]);
|
||||
if (!renderer.has_value())
|
||||
{
|
||||
Log_ErrorPrintf("Invalid renderer specified.");
|
||||
return false;
|
||||
}
|
||||
|
||||
s_renderer_to_use = renderer.value();
|
||||
continue;
|
||||
}
|
||||
else if (CHECK_ARG("--"))
|
||||
{
|
||||
no_more_args = true;
|
||||
continue;
|
||||
}
|
||||
else if (argv[i][0] == '-')
|
||||
{
|
||||
Log_ErrorPrintf("Unknown parameter: '%s'", argv[i]);
|
||||
return false;
|
||||
}
|
||||
|
||||
#undef CHECK_ARG
|
||||
#undef CHECK_ARG_PARAM
|
||||
}
|
||||
|
||||
if (!s_boot_parameters->filename.empty())
|
||||
s_boot_parameters->filename += ' ';
|
||||
s_boot_parameters->filename += argv[i];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string GetFrameDumpFilename(int frame)
|
||||
{
|
||||
return StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "frame_%05d.png", s_dump_game_directory.c_str(),
|
||||
frame);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Log::SetConsoleOutputParams(true, nullptr, LOGLEVEL_VERBOSE);
|
||||
|
||||
if (!ParseCommandLineArgs(argc, argv))
|
||||
return -1;
|
||||
|
||||
int result = -1;
|
||||
|
||||
Log_InfoPrintf("Initializing...");
|
||||
g_host_interface = new RegTestHostInterface();
|
||||
if (!g_host_interface->Initialize())
|
||||
goto cleanup;
|
||||
|
||||
if (s_boot_parameters->filename.empty())
|
||||
{
|
||||
Log_ErrorPrintf("No boot path specified.");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
Log_InfoPrintf("Trying to boot '%s'...", s_boot_parameters->filename.c_str());
|
||||
if (!g_host_interface->BootSystem(std::move(s_boot_parameters)))
|
||||
{
|
||||
Log_ErrorPrintf("Failed to boot system.");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (s_frame_dump_interval > 0)
|
||||
{
|
||||
if (s_dump_base_directory.empty())
|
||||
{
|
||||
Log_ErrorPrint("Dump directory not specified.");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
Log_InfoPrintf("Dumping every %dth frame to '%s'.", s_frame_dump_interval, s_dump_base_directory.c_str());
|
||||
}
|
||||
|
||||
Log_InfoPrintf("Running for %d frames...", s_frames_to_run);
|
||||
|
||||
for (int frame = 1; frame <= s_frames_to_run; frame++)
|
||||
{
|
||||
System::RunFrame();
|
||||
|
||||
if (s_frame_dump_interval > 0 && (s_frame_dump_interval == 1 || (frame % s_frame_dump_interval) == 0))
|
||||
{
|
||||
std::string dump_filename(GetFrameDumpFilename(frame));
|
||||
g_host_interface->GetDisplay()->WriteDisplayTextureToFile(std::move(dump_filename));
|
||||
}
|
||||
|
||||
g_host_interface->GetDisplay()->Render();
|
||||
|
||||
System::UpdatePerformanceCounters();
|
||||
}
|
||||
|
||||
Log_InfoPrintf("All done, shutting down system.");
|
||||
g_host_interface->DestroySystem();
|
||||
|
||||
Log_InfoPrintf("Exiting with success.");
|
||||
result = 0;
|
||||
|
||||
cleanup:
|
||||
delete g_host_interface;
|
||||
return result;
|
||||
}
|
49
src/duckstation-regtest/regtest_host_interface.h
Normal file
49
src/duckstation-regtest/regtest_host_interface.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "core/host_interface.h"
|
||||
#include "regtest_settings_interface.h"
|
||||
|
||||
class RegTestHostInterface : public HostInterface
|
||||
{
|
||||
public:
|
||||
RegTestHostInterface();
|
||||
~RegTestHostInterface();
|
||||
|
||||
bool Initialize() override;
|
||||
void Shutdown() override;
|
||||
|
||||
void ReportError(const char* message) override;
|
||||
void ReportMessage(const char* message) override;
|
||||
void ReportDebuggerMessage(const char* message) override;
|
||||
bool ConfirmMessage(const char* message) override;
|
||||
|
||||
void AddOSDMessage(std::string message, float duration = 2.0f) override;
|
||||
void DisplayLoadingScreen(const char* message, int progress_min = -1, int progress_max = -1,
|
||||
int progress_value = -1) override;
|
||||
void GetGameInfo(const char* path, CDImage* image, std::string* code, std::string* title) override;
|
||||
|
||||
void OnRunningGameChanged(const std::string& path, CDImage* image, const std::string& game_code,
|
||||
const std::string& game_title);
|
||||
|
||||
std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override;
|
||||
bool GetBoolSettingValue(const char* section, const char* key, bool default_value = false) override;
|
||||
int GetIntSettingValue(const char* section, const char* key, int default_value = 0) override;
|
||||
float GetFloatSettingValue(const char* section, const char* key, float default_value = 0.0f) override;
|
||||
std::vector<std::string> GetSettingStringList(const char* section, const char* key) override;
|
||||
|
||||
std::string GetBIOSDirectory() override;
|
||||
|
||||
std::unique_ptr<ByteStream> OpenPackageFile(const char* path, u32 flags) override;
|
||||
|
||||
protected:
|
||||
bool AcquireHostDisplay() override;
|
||||
void ReleaseHostDisplay() override;
|
||||
|
||||
std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) override;
|
||||
|
||||
private:
|
||||
void LoadGameSettingsDatabase();
|
||||
void InitializeSettings();
|
||||
void UpdateSettings();
|
||||
|
||||
RegTestSettingsInterface m_settings_interface;
|
||||
};
|
156
src/duckstation-regtest/regtest_settings_interface.cpp
Normal file
156
src/duckstation-regtest/regtest_settings_interface.cpp
Normal file
@ -0,0 +1,156 @@
|
||||
#include "regtest_settings_interface.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/log.h"
|
||||
#include "common/string_util.h"
|
||||
Log_SetChannel(RegTestSettingsInterface);
|
||||
|
||||
RegTestSettingsInterface::RegTestSettingsInterface() = default;
|
||||
|
||||
RegTestSettingsInterface::~RegTestSettingsInterface() = default;
|
||||
|
||||
bool RegTestSettingsInterface::Save()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void RegTestSettingsInterface::Clear()
|
||||
{
|
||||
m_keys.clear();
|
||||
}
|
||||
|
||||
static std::string GetFullKey(const char* section, const char* key)
|
||||
{
|
||||
return StringUtil::StdStringFromFormat("%s/%s", section, key);
|
||||
}
|
||||
|
||||
int RegTestSettingsInterface::GetIntValue(const char* section, const char* key, int default_value /*= 0*/)
|
||||
{
|
||||
int retval = default_value;
|
||||
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
auto iter = m_keys.find(fullkey);
|
||||
if (iter != m_keys.end())
|
||||
retval = StringUtil::FromChars<int>(iter->second, 10).value_or(default_value);
|
||||
|
||||
Log_DevPrintf("GetIntValue(%s) -> %d", fullkey.c_str(), retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
float RegTestSettingsInterface::GetFloatValue(const char* section, const char* key, float default_value /*= 0.0f*/)
|
||||
{
|
||||
float retval = default_value;
|
||||
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
auto iter = m_keys.find(fullkey);
|
||||
if (iter != m_keys.end())
|
||||
retval = StringUtil::FromChars<float>(iter->second).value_or(default_value);
|
||||
|
||||
Log_DevPrintf("GetFloatValue(%s) -> %f", fullkey.c_str(), retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool RegTestSettingsInterface::GetBoolValue(const char* section, const char* key, bool default_value /*= false*/)
|
||||
{
|
||||
bool retval = default_value;
|
||||
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
auto iter = m_keys.find(fullkey);
|
||||
if (iter != m_keys.end())
|
||||
retval = StringUtil::FromChars<bool>(iter->second).value_or(default_value);
|
||||
|
||||
Log_DevPrintf("GetBoolValue(%s) -> %s", fullkey.c_str(), retval ? "true" : "false");
|
||||
return retval;
|
||||
}
|
||||
|
||||
std::string RegTestSettingsInterface::GetStringValue(const char* section, const char* key,
|
||||
const char* default_value /*= ""*/)
|
||||
{
|
||||
std::string retval;
|
||||
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
auto iter = m_keys.find(fullkey);
|
||||
if (iter != m_keys.end())
|
||||
retval = iter->second;
|
||||
else
|
||||
retval = default_value;
|
||||
|
||||
Log_DevPrintf("GetStringValue(%s) -> %s", fullkey.c_str(), retval.c_str());
|
||||
return retval;
|
||||
}
|
||||
|
||||
void RegTestSettingsInterface::SetIntValue(const char* section, const char* key, int value)
|
||||
{
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
Log_DevPrintf("SetIntValue(%s, %d)", fullkey.c_str(), value);
|
||||
m_keys[std::move(fullkey)] = std::to_string(value);
|
||||
}
|
||||
|
||||
void RegTestSettingsInterface::SetFloatValue(const char* section, const char* key, float value)
|
||||
{
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
Log_DevPrintf("SetFloatValue(%s, %f)", fullkey.c_str(), value);
|
||||
m_keys[std::move(fullkey)] = std::to_string(value);
|
||||
}
|
||||
|
||||
void RegTestSettingsInterface::SetBoolValue(const char* section, const char* key, bool value)
|
||||
{
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
Log_DevPrintf("SetBoolValue(%s, %s)", fullkey.c_str(), value ? "true" : "false");
|
||||
m_keys[std::move(fullkey)] = std::string(value ? "true" : "false");
|
||||
}
|
||||
|
||||
void RegTestSettingsInterface::SetStringValue(const char* section, const char* key, const char* value)
|
||||
{
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
Log_DevPrintf("SetStringValue(%s, %s)", fullkey.c_str(), value);
|
||||
m_keys[std::move(fullkey)] = value;
|
||||
}
|
||||
|
||||
std::vector<std::string> RegTestSettingsInterface::GetStringList(const char* section, const char* key)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
Panic("Not implemented");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void RegTestSettingsInterface::SetStringList(const char* section, const char* key,
|
||||
const std::vector<std::string>& items)
|
||||
{
|
||||
Panic("Not implemented");
|
||||
}
|
||||
|
||||
bool RegTestSettingsInterface::RemoveFromStringList(const char* section, const char* key, const char* item)
|
||||
{
|
||||
Panic("Not implemented");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RegTestSettingsInterface::AddToStringList(const char* section, const char* key, const char* item)
|
||||
{
|
||||
Panic("Not implemented");
|
||||
return false;
|
||||
}
|
||||
|
||||
void RegTestSettingsInterface::DeleteValue(const char* section, const char* key)
|
||||
{
|
||||
const std::string fullkey(GetFullKey(section, key));
|
||||
Log_DevPrintf("DeleteValue(%s)", fullkey.c_str());
|
||||
|
||||
auto iter = m_keys.find(fullkey);
|
||||
if (iter != m_keys.end())
|
||||
m_keys.erase(iter);
|
||||
}
|
||||
|
||||
void RegTestSettingsInterface::ClearSection(const char* section)
|
||||
{
|
||||
Log_DevPrintf("ClearSection(%s)", section);
|
||||
|
||||
const std::string start(StringUtil::StdStringFromFormat("%s/", section));
|
||||
for (auto iter = m_keys.begin(); iter != m_keys.end();)
|
||||
{
|
||||
if (StringUtil::StartsWith(iter->first, start.c_str()))
|
||||
iter = m_keys.erase(iter);
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
}
|
36
src/duckstation-regtest/regtest_settings_interface.h
Normal file
36
src/duckstation-regtest/regtest_settings_interface.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "core/settings.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class RegTestSettingsInterface final : public SettingsInterface
|
||||
{
|
||||
public:
|
||||
RegTestSettingsInterface();
|
||||
~RegTestSettingsInterface();
|
||||
|
||||
bool Save() override;
|
||||
void Clear() override;
|
||||
|
||||
int GetIntValue(const char* section, const char* key, int default_value = 0) override;
|
||||
float GetFloatValue(const char* section, const char* key, float default_value = 0.0f) override;
|
||||
bool GetBoolValue(const char* section, const char* key, bool default_value = false) override;
|
||||
|
||||
std::string GetStringValue(const char* section, const char* key, const char* default_value = "") override;
|
||||
void SetIntValue(const char* section, const char* key, int value) override;
|
||||
void SetFloatValue(const char* section, const char* key, float value) override;
|
||||
void SetBoolValue(const char* section, const char* key, bool value) override;
|
||||
void SetStringValue(const char* section, const char* key, const char* value) override;
|
||||
|
||||
std::vector<std::string> GetStringList(const char* section, const char* key) override;
|
||||
void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) override;
|
||||
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
|
||||
bool AddToStringList(const char* section, const char* key, const char* item) override;
|
||||
|
||||
void DeleteValue(const char* section, const char* key) override;
|
||||
void ClearSection(const char* section) override;
|
||||
|
||||
private:
|
||||
using KeyMap = std::unordered_map<std::string, std::string>;
|
||||
KeyMap m_keys;
|
||||
};
|
Reference in New Issue
Block a user