test(videoout): isolate application fixtures

(cherry picked from commit 7e982a521f2ba5fafabcba45c78cb23918fa9007)
This commit is contained in:
arcwiser 2026-10-10 12:11:09 +11:00 committed by MarcZX100
parent 57f96fd2b3
commit e5a81a3ca9
4 changed files with 59 additions and 12 deletions

View File

@ -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 <algorithm>
#include <array>
#include <atomic>
@ -14,8 +15,6 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <initializer_list>
#include <string>
#include <limits>
@ -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();

View File

@ -1,5 +1,6 @@
#include "SceTypes.hpp"
#include "prx/libc/include/Shutdown.hpp"
#include "tests/VideoOutTestEnvironment.hpp"
#include <cstdio>
#include <cstdlib>
#include <cstring>
@ -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);

View File

@ -1,10 +1,9 @@
#include "SceTypes.hpp"
#include "prx/libc/include/Shutdown.hpp"
#include "tests/VideoOutTestEnvironment.hpp"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <stdexcept>
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<bool>(param));
}
VideoOutTestEnvironment environment;
int handle = 0;
try {
handle = sceVideoOutOpen(SYSTEM_USER, MAIN_BUS, 0, nullptr);

View File

@ -0,0 +1,53 @@
#pragma once
#include <chrono>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <random>
#include <stdexcept>
#include <string>
#include <system_error>
class VideoOutTestEnvironment final {
std::filesystem::path previous;
std::filesystem::path root;
public:
VideoOutTestEnvironment() : previous(std::filesystem::current_path()) {
const auto seed = static_cast<std::uint64_t>(std::chrono::steady_clock::now().time_since_epoch().count()) ^
(static_cast<std::uint64_t>(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;
};