[+] Added async pipe test

This commit is contained in:
Reece Wilson 2022-04-17 23:47:24 +01:00
parent 5ce2c59161
commit 85df64a76c

View File

@ -170,7 +170,75 @@ TEST(IPC, Pipe)
pipeImported.reset();
ASSERT_FALSE(pipe->AsReadChannelIsOpen()->IsSignaled());
}
TEST(IPC, AsyncPipe)
{
auto pipe = Aurora::IPC::NewPipe();
ASSERT_TRUE(bool(pipe));
ASSERT_FALSE(pipe->AsReadChannelIsOpen()->IsSignaled());
auto handleString = pipe->ExportToString();
ASSERT_TRUE(bool(handleString.size()));
AuLogDbg("Exported pipe handle: {}", handleString);
auto pipeImported = Aurora::IPC::ImportPipe(handleString);
ASSERT_TRUE(bool(pipeImported));
ASSERT_TRUE(pipe->AsReadChannelIsOpen()->IsSignaled());
static const AuString kHelloWorldClient = "Hello Client";
static const AuString kHelloWorldServer = "Hello Server";
auto transactionA = pipe->NewAsyncTransaction();
auto transactionB = pipeImported->NewAsyncTransaction();
// Set callback
transactionA->SetCallback(AuMakeShared<AuIOFS::IAsyncFinishedSubscriberFunctional>([](AuUInt64 offset, AuUInt32 length)
{
AuLogDbg("IPC server callback: {} {}", offset, length);
}));
transactionB->SetCallback(AuMakeShared<AuIOFS::IAsyncFinishedSubscriberFunctional>([](AuUInt64 offset, AuUInt32 length)
{
AuLogDbg("IPC client callback: {} {}", offset, length);
}));
//
AuByteBuffer writeBuffer(512);
AuMemoryViewRead writeView(writeBuffer);
AuRng::RngFillRange(writeBuffer);
ASSERT_TRUE(transactionA->StartWrite(0, AuUnsafeRaiiToShared(&writeView)));
AuByteBuffer readBuffer(512);
AuMemoryViewWrite readView(readBuffer.begin(), readBuffer.end());
ASSERT_TRUE(transactionB->StartRead(0, AuUnsafeRaiiToShared(&readView)));
// Create loop to sync against the two outstanding IO requests
auto loop = Aurora::Loop::NewLoopQueue();
// Add initial loop sources
ASSERT_TRUE(loop->SourceAdd(transactionA->NewLoopSource()));
ASSERT_TRUE(loop->SourceAdd(transactionB->NewLoopSource()));
ASSERT_TRUE(loop->Commit());
// Wait for 100 MS
ASSERT_TRUE(loop->WaitAll(0));
ASSERT_EQ(writeBuffer, readBuffer);
// Reset client pipe
pipeImported.reset();
transactionB.reset();
transactionA.reset();
// Assert dead
ASSERT_FALSE(pipe->AsReadChannelIsOpen()->IsSignaled());
}
void RunTests()