[+] Added first loop test
[TODO] todos added to fs
This commit is contained in:
parent
4ebf813fd7
commit
1480a7ca00
@ -143,6 +143,10 @@ static void PrintSystemRoot()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: sample and test code for:
|
||||
// * async
|
||||
// * file stream objects
|
||||
|
||||
void RunTests()
|
||||
{
|
||||
Aurora::RuntimeStartInfo info;
|
||||
|
91
Tests/Public/5. Hello Loop/Main.cpp
Normal file
91
Tests/Public/5. Hello Loop/Main.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/***
|
||||
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: Main.cpp
|
||||
Date: 2022-2-18
|
||||
Author: Reece
|
||||
***/
|
||||
#include <AuroraRuntime.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Loop, Semaphore)
|
||||
{
|
||||
auto semaA = Aurora::Loop::NewLSSemaphore(1);
|
||||
auto semaB = Aurora::Loop::NewLSSemaphore(0);
|
||||
auto semac = Aurora::Loop::NewLSSemaphore(0);
|
||||
auto loop = Aurora::Loop::NewLoopQueue();
|
||||
|
||||
|
||||
// Add initial loop sources
|
||||
ASSERT_TRUE(loop->SourceAdd(semaA));
|
||||
ASSERT_TRUE(loop->SourceAdd(semaB));
|
||||
ASSERT_TRUE(loop->SourceAddWithTimeout(semac, 2000));
|
||||
|
||||
// Commit source changes
|
||||
ASSERT_TRUE(loop->Commit());
|
||||
|
||||
auto semACallback = AuMakeShared<Aurora::Loop::ILoopSourceSubscriberFunctional>([](const AuSPtr<Aurora::Loop::ILoopSource> &source) -> bool
|
||||
{
|
||||
AuLogInfo("Hello from semaphore a's work queue");
|
||||
return false; // dont evict, we'll reuse this *1
|
||||
});
|
||||
|
||||
auto semBCallback = AuMakeShared<Aurora::Loop::ILoopSourceSubscriberFunctional>([](const AuSPtr<Aurora::Loop::ILoopSource> &source) -> bool
|
||||
{
|
||||
AuLogInfo("Hello from semaphore b's work queue");
|
||||
return true; // evict
|
||||
});
|
||||
|
||||
|
||||
auto semCCallback = AuMakeShared<Aurora::Loop::ILoopSourceSubscriberExFunctional>([](const AuSPtr<Aurora::Loop::ILoopSource> &source) -> bool
|
||||
{
|
||||
AuLogInfo("This should not have been triggered from C");
|
||||
return false;
|
||||
},
|
||||
|
||||
[](const AuSPtr<Aurora::Loop::ILoopSource> &source) -> void
|
||||
{
|
||||
AuLogInfo("C timedout succesfully!");
|
||||
});
|
||||
|
||||
// Add optional subscriptions (must come after commit)
|
||||
ASSERT_TRUE(loop->AddCallback(semaA, semACallback));
|
||||
ASSERT_TRUE(loop->AddCallback(semaB, semBCallback));
|
||||
ASSERT_TRUE(loop->AddCallbackEx(semac, semCCallback));
|
||||
|
||||
// Dispatch any (IE: semaphore A) non-blocking
|
||||
ASSERT_TRUE(loop->IsSignaled());
|
||||
|
||||
// Reuse semaphore A
|
||||
semaA->AddOne(); // *1
|
||||
|
||||
// And demonstrate blocking function
|
||||
ASSERT_TRUE(loop->WaitAny(0)); // *1
|
||||
|
||||
ASSERT_FALSE(loop->WaitAny(1000));
|
||||
|
||||
// Trigger A and B
|
||||
semaB->AddOne();
|
||||
semaA->AddOne();
|
||||
|
||||
// Dispatch all
|
||||
ASSERT_TRUE(loop->WaitAny(1000));
|
||||
|
||||
// Stall for 10s unless A comes alives (it wont)
|
||||
loop->WaitAll(10000);
|
||||
ASSERT_FALSE(loop->WaitAll(100));
|
||||
|
||||
// Manually evict semaphore A
|
||||
loop->SourceRemove(semaA);
|
||||
loop->Commit();
|
||||
|
||||
ASSERT_TRUE(loop->WaitAll(100));
|
||||
}
|
||||
|
||||
void RunTests()
|
||||
{
|
||||
Aurora::RuntimeStartInfo info;
|
||||
info.console.fio.enableLogging = false;
|
||||
info.console.forceToolKitWindow = false;
|
||||
Aurora::RuntimeStart(info);
|
||||
}
|
Loading…
Reference in New Issue
Block a user