mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(tests): align agc flip waits and memory synchronization checks
This commit is contained in:
@@ -41,6 +41,21 @@ struct State {
|
||||
AgcDriver::FlipInfo last{};
|
||||
};
|
||||
|
||||
class FlipRelease final {
|
||||
public:
|
||||
explicit FlipRelease(std::shared_ptr<State> state) : state(std::move(state)) {}
|
||||
~FlipRelease() { Release(); }
|
||||
void Release() {
|
||||
{
|
||||
std::lock_guard lock(state->mutex);
|
||||
state->block = false;
|
||||
}
|
||||
state->changed.notify_all();
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<State> state;
|
||||
};
|
||||
|
||||
class Request final : public AgcDriver::IFlipRequest {
|
||||
public:
|
||||
explicit Request(std::shared_ptr<State> value) : state(std::move(value)) { ++state->alive; }
|
||||
@@ -104,24 +119,23 @@ void testFlipAndBoundary() {
|
||||
output->state->block = true;
|
||||
output->state->checkSelfWait = true;
|
||||
}
|
||||
std::future<void> boundary;
|
||||
FlipRelease release(output->state);
|
||||
submitFlip();
|
||||
{
|
||||
std::unique_lock lock(output->state->mutex);
|
||||
check(output->state->changed.wait_for(lock, std::chrono::seconds(5), [&] { return output->state->entered; }), "worker did not reach flip");
|
||||
check(output->state->last.argument == -0x123456789abcdefLL && output->state->last.index == -2, "decoded flip arguments changed");
|
||||
}
|
||||
auto boundary = std::async(std::launch::async, [] { AgcDriverSuspendPoint_nid_postfix(); });
|
||||
check(boundary.wait_for(std::chrono::milliseconds(30)) == std::future_status::timeout, "suspend completed before preceding work");
|
||||
boundary = std::async(std::launch::async, [] { AgcDriverSuspendPoint_nid_postfix(); });
|
||||
check(boundary.wait_for(std::chrono::seconds(5)) == std::future_status::ready, "suspend blocked on preceding work");
|
||||
boundary.get();
|
||||
check(output->state->ready == 0, "blocked flip completed before release");
|
||||
AgcDriverUnregisterVideoOutput_nid_postfix(7, output);
|
||||
auto replacement = std::make_shared<Output>();
|
||||
AgcDriverRegisterVideoOutput_nid_postfix(7, replacement);
|
||||
submitFlip();
|
||||
{
|
||||
std::lock_guard lock(output->state->mutex);
|
||||
output->state->block = false;
|
||||
}
|
||||
output->state->changed.notify_all();
|
||||
boundary.get();
|
||||
release.Release();
|
||||
AgcDriverWaitIdle_nid_postfix();
|
||||
check(output->state->ready == 1 && replacement->state->ready == 1, "registration lifetime or FIFO was lost");
|
||||
check(output->state->failed == 0, "successful request failed");
|
||||
@@ -140,6 +154,7 @@ void testFlipAndBoundary() {
|
||||
for (auto& producer : producers) producer.join();
|
||||
for (auto error : errors) if (error) std::rethrow_exception(error);
|
||||
AgcDriverSuspendPoint_nid_postfix();
|
||||
AgcDriverWaitIdle_nid_postfix();
|
||||
check(replacement->state->ready == 201, "concurrent submissions were lost");
|
||||
AgcDriverUnregisterVideoOutput_nid_postfix(7, replacement);
|
||||
}
|
||||
@@ -151,10 +166,11 @@ void testFailure() {
|
||||
submitFlip();
|
||||
std::array<std::string, 4> messages;
|
||||
std::vector<std::thread> waiters;
|
||||
for (auto& message : messages) waiters.emplace_back([&message] { message = expectFailure([] { AgcDriverSuspendPoint_nid_postfix(); }); });
|
||||
for (auto& message : messages) waiters.emplace_back([&message] { message = expectFailure([] { AgcDriverWaitIdle_nid_postfix(); }); });
|
||||
for (auto& waiter : waiters) waiter.join();
|
||||
for (auto& message : messages) check(message == "intentional flip failure", "asynchronous failure was lost");
|
||||
check(expectFailure([] { AgcDriverWaitIdle_nid_postfix(); }) == messages[0], "idle lost flip failure");
|
||||
check(expectFailure([] { AgcDriverSuspendPoint_nid_postfix(); }) == messages[0], "suspend lost flip failure");
|
||||
check(expectFailure([] { submitFlip(); }) == messages[0], "submit lost flip failure");
|
||||
check(output->state->ready == 0 && output->state->failed == 1, "failed flip was completed successfully");
|
||||
AgcDriverUnregisterVideoOutput_nid_postfix(7, output);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/MemoryAccessScope.hpp"
|
||||
#include "prx/libSceAgcDriver/Execution/include/Driver.hpp"
|
||||
#include "prx/libSceAgcDriver/Submit/include/Dcb.hpp"
|
||||
#include "prx/libc/include/Shutdown.hpp"
|
||||
@@ -308,13 +307,16 @@ void testMemorySynchronization() {
|
||||
std::uint32_t destination = 0;
|
||||
bool read = false;
|
||||
bool written = false;
|
||||
} memory;
|
||||
};
|
||||
static MemoryState memory;
|
||||
memory = {};
|
||||
AgcDriver::QueueState state;
|
||||
const auto resolve = [](void* context, std::uint64_t address, std::size_t bytes, bool writable) {
|
||||
auto& memory = *static_cast<MemoryState*>(context);
|
||||
struct FlushHookReset {
|
||||
~FlushHookReset() { AgcDriver::GuestMemory::SetFlushHook(nullptr); }
|
||||
} reset;
|
||||
const auto resolve = [](std::uint64_t address, std::size_t bytes) {
|
||||
check(bytes == sizeof(std::uint32_t), "memory transfer resolved an unrelated range");
|
||||
if (writable) {
|
||||
check(address == reinterpret_cast<std::uintptr_t>(&memory.destination), "memory transfer resolved an unrelated destination");
|
||||
if (address == reinterpret_cast<std::uintptr_t>(&memory.destination)) {
|
||||
memory.written = true;
|
||||
} else {
|
||||
check(address == reinterpret_cast<std::uintptr_t>(&memory.source), "memory transfer resolved an unrelated source");
|
||||
@@ -322,7 +324,7 @@ void testMemorySynchronization() {
|
||||
memory.read = true;
|
||||
}
|
||||
};
|
||||
const AgcDriver::GuestMemory::MemoryAccessScope scope(&memory, resolve);
|
||||
AgcDriver::GuestMemory::SetFlushHook(resolve);
|
||||
execute(state, makePacket(0x37, {0x100, low(&memory.destination), high(&memory.destination), 17}));
|
||||
check(memory.written && !memory.read && memory.destination == 17, "WRITE_DATA did not synchronize its destination");
|
||||
for (const auto opcode : {0x40u, 0x50u}) {
|
||||
@@ -333,7 +335,7 @@ void testMemorySynchronization() {
|
||||
execute(state, packet);
|
||||
check(memory.read && memory.written && memory.destination == 42, "memory copy used stale data before range synchronization");
|
||||
}
|
||||
const AgcDriver::GuestMemory::MemoryAccessScope rejecting(&memory, [](void*, std::uint64_t, std::size_t, bool) {
|
||||
AgcDriver::GuestMemory::SetFlushHook([](std::uint64_t, std::size_t) {
|
||||
throw std::runtime_error("range synchronization failed");
|
||||
});
|
||||
expectFailure([&] { execute(state, makePacket(0x37, {0x100, low(&memory.destination), high(&memory.destination), 99})); }, "range synchronization failed");
|
||||
|
||||
Reference in New Issue
Block a user