From 47162ec6717f3610d94b73ca7b253e6e3a8068dc Mon Sep 17 00:00:00 2001 From: Reece Date: Wed, 13 Apr 2022 12:14:34 +0100 Subject: [PATCH] [+] Added early async file io test --- Tests/Public/4. Hello FS/Main.cpp | 55 +++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/Tests/Public/4. Hello FS/Main.cpp b/Tests/Public/4. Hello FS/Main.cpp index 57a6dd1..71de86e 100644 --- a/Tests/Public/4. Hello FS/Main.cpp +++ b/Tests/Public/4. Hello FS/Main.cpp @@ -185,9 +185,58 @@ TEST(FS, Watcher) { AuLogDbg(" {}: {} {}", AuIOFS::EWatchEventToString(update.event), update.file, update.watch.path); } - } +TEST(FS, Async) +{ + auto stream = AuIOFS::OpenAsyncUnique("./AsyncFile", AuIOFS::EFileOpenMode::eReadWrite, true); + ASSERT_TRUE(bool(stream)); + + AuByteBuffer rngbuffer(32); + AuRng::RngFillRange(rngbuffer); + + auto transaction = stream->NewTransaction(); + ASSERT_TRUE(bool(transaction)); + + transaction->SetCallback(AuMakeShared([](AuUInt64 offset, AuUInt32 length) + { + AuLogDbg("AIO 1 callback: {} {}", offset, length); + })); + + AuMemoryViewRead readView(rngbuffer); + ASSERT_TRUE(transaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); + + AuLogDbg("AIO 1: waiting...."); + ASSERT_TRUE(transaction->Wait(0)); + AuLogDbg("AIO 1: wait complete...."); + ASSERT_TRUE(transaction->NewLoopSource()->IsSignaled()); + ASSERT_TRUE(transaction->Complete()); +} + +TEST(FS, AsyncAltWait) +{ + auto stream = AuIOFS::OpenAsyncUnique("./AsyncFile", AuIOFS::EFileOpenMode::eReadWrite, true); + ASSERT_TRUE(bool(stream)); + + AuByteBuffer rngbuffer(32); + AuRng::RngFillRange(rngbuffer); + + auto transaction = stream->NewTransaction(); + ASSERT_TRUE(bool(transaction)); + + transaction->SetCallback(AuMakeShared([](AuUInt64 offset, AuUInt32 length) + { + AuLogDbg("AIO 2 callback: {} {}", offset, length); + })); + + AuMemoryViewRead readView(rngbuffer); + ASSERT_TRUE(transaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); + + AuLogDbg("AIO 2: waiting...."); + ASSERT_TRUE(transaction->NewLoopSource()->WaitOn()); + AuLogDbg("AIO 2: wait complete...."); + ASSERT_TRUE(transaction->Complete()); +} static void PrintSystemRoot() { @@ -266,14 +315,16 @@ static void PrintSystemRoot() } // TODO: sample and test code for: -// * async // * file stream objects +// * stat +// * iterate void RunTests() { Aurora::RuntimeStartInfo info; info.console.fio.enableLogging = false; info.fio.defaultBrand = "AuSdkBrand"; + info.bFIODisableBatching = false; Aurora::RuntimeStart(info); PrintSystemRoot();