diff --git a/core/libs/prx/libSceVideoOut/tests/Flip.cpp b/core/libs/prx/libSceVideoOut/tests/Flip.cpp index fa4a07c6f..02ff20088 100644 --- a/core/libs/prx/libSceVideoOut/tests/Flip.cpp +++ b/core/libs/prx/libSceVideoOut/tests/Flip.cpp @@ -7,6 +7,7 @@ #include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp" #include "prx/libSceAgcDriver/Submit/include/Dcb.hpp" #include "prx/libc/include/Shutdown.hpp" +#include "tests/VideoOutTestEnvironment.hpp" #include #include #include @@ -14,8 +15,6 @@ #include #include #include -#include -#include #include #include #include @@ -657,9 +656,8 @@ void testOneDevice() { } int main(int argc, char** argv) { + VideoOutTestEnvironment environment; try { - std::filesystem::create_directories("app0/sce_sys"); - std::ofstream("app0/sce_sys/param.json", std::ios::binary) << R"({"titleId":"PPSA00000","localizedParameters":{"en-US":{"titleName":"Example"}},"downloadDataSize":0})"; if (argc == 2 && std::string(argv[1]) == "decode") testDecode(); else if (argc == 2 && std::string(argv[1]) == "controls") testControls(); else if (argc == 2 && std::string(argv[1]) == "present") testPresentation(); diff --git a/core/libs/tests/GuestVideoOutResolutionStatus.cpp b/core/libs/tests/GuestVideoOutResolutionStatus.cpp index 0e81b766c..5294d7c29 100644 --- a/core/libs/tests/GuestVideoOutResolutionStatus.cpp +++ b/core/libs/tests/GuestVideoOutResolutionStatus.cpp @@ -1,5 +1,6 @@ #include "SceTypes.hpp" #include "prx/libc/include/Shutdown.hpp" +#include "tests/VideoOutTestEnvironment.hpp" #include #include #include @@ -28,6 +29,7 @@ static bool Rejects(int handle, VideoOutResolutionStatus* status) { } int main() { + VideoOutTestEnvironment environment; int handle = 0; try { handle = sceVideoOutOpen(SYSTEM_USER, MAIN_BUS, 0, nullptr); diff --git a/core/libs/tests/GuestVideoOutWqhdDetection.cpp b/core/libs/tests/GuestVideoOutWqhdDetection.cpp index 0cb8a54ec..c0e68b0c4 100644 --- a/core/libs/tests/GuestVideoOutWqhdDetection.cpp +++ b/core/libs/tests/GuestVideoOutWqhdDetection.cpp @@ -1,10 +1,9 @@ #include "SceTypes.hpp" #include "prx/libc/include/Shutdown.hpp" +#include "tests/VideoOutTestEnvironment.hpp" #include #include #include -#include -#include #include extern "C" { @@ -34,12 +33,7 @@ static bool SameStatus(const VideoOutOutputStatus& a, const VideoOutOutputStatus } int main() { - std::filesystem::create_directories("app0/sce_sys"); - { - std::ofstream param("app0/sce_sys/param.json", std::ios::binary); - param << R"({"titleId":"PPSA00000","localizedParameters":{"en-US":{"titleName":"Example"}},"downloadDataSize":0})"; - Require(static_cast(param)); - } + VideoOutTestEnvironment environment; int handle = 0; try { handle = sceVideoOutOpen(SYSTEM_USER, MAIN_BUS, 0, nullptr); diff --git a/core/libs/tests/VideoOutTestEnvironment.hpp b/core/libs/tests/VideoOutTestEnvironment.hpp new file mode 100644 index 000000000..786cf5e32 --- /dev/null +++ b/core/libs/tests/VideoOutTestEnvironment.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +class VideoOutTestEnvironment final { + std::filesystem::path previous; + std::filesystem::path root; + +public: + VideoOutTestEnvironment() : previous(std::filesystem::current_path()) { + const auto seed = static_cast(std::chrono::steady_clock::now().time_since_epoch().count()) ^ + (static_cast(std::random_device{}()) << 32u) ^ std::random_device{}(); + for (std::uint32_t attempt = 0; attempt < 64; ++attempt) { + const auto candidate = std::filesystem::temp_directory_path() / + ("anyps5-video-out-" + std::to_string(seed + attempt)); + std::error_code error; + if (std::filesystem::create_directory(candidate, error)) { + root = candidate; + break; + } + if (error) throw std::runtime_error("Cannot create VideoOut test directory: " + error.message()); + } + if (root.empty()) throw std::runtime_error("Cannot allocate a unique VideoOut test directory"); + try { + std::filesystem::current_path(root); + std::filesystem::create_directories("app0/sce_sys"); + std::ofstream param("app0/sce_sys/param.json", std::ios::binary); + param << R"({"titleId":"PPSA00000","localizedParameters":{"en-US":{"titleName":"Example"}},"downloadDataSize":0})"; + if (!param) throw std::runtime_error("Cannot write VideoOut param.json fixture"); + } catch (...) { + std::error_code error; + std::filesystem::current_path(previous, error); + std::filesystem::remove_all(root, error); + throw; + } + } + + ~VideoOutTestEnvironment() { + std::error_code error; + std::filesystem::current_path(previous, error); + std::filesystem::remove_all(root, error); + } + + VideoOutTestEnvironment(const VideoOutTestEnvironment&) = delete; + VideoOutTestEnvironment& operator=(const VideoOutTestEnvironment&) = delete; +};