[+] Add event + semaphore IPC test
[*] Update runtime
This commit is contained in:
parent
47162ec671
commit
9ce2f7e63e
@ -1 +1 @@
|
|||||||
Subproject commit 415116c891dd0bc6c43c2fae409e1561690eaab9
|
Subproject commit 44839e6234f6a8eb9c39a09a5ea8cd5ee348ac7f
|
97
Tests/Public/21. Hello IPC/Main.cpp
Executable file
97
Tests/Public/21. Hello IPC/Main.cpp
Executable file
@ -0,0 +1,97 @@
|
|||||||
|
/***
|
||||||
|
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>
|
||||||
|
|
||||||
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
||||||
|
|
||||||
|
TEST(IPC, ShareUnixFd)
|
||||||
|
{
|
||||||
|
int fds[2];
|
||||||
|
|
||||||
|
ASSERT_EQ(pipe(fds), 0);
|
||||||
|
|
||||||
|
ASSERT_EQ(write(fds[1], "hello", 5), 5);
|
||||||
|
|
||||||
|
auto handleString = AuIO::UNIX::ShareFileDescriptor(fds[0]);
|
||||||
|
AuLogDbg("UNIX IPC Handle: {}", handleString);
|
||||||
|
ASSERT_TRUE(bool(handleString.size()));
|
||||||
|
|
||||||
|
auto acceptFd = AuIO::UNIX::ShareFileDescriptorAccept(handleString);
|
||||||
|
AuLogDbg("Got FD: {}, started with: {}", acceptFd, fds[0]);
|
||||||
|
|
||||||
|
char hello[5];
|
||||||
|
ASSERT_EQ(read(acceptFd, hello, 5), 5);
|
||||||
|
|
||||||
|
AuLogDbg("Write side said: {}", AuString(hello, hello + 5));
|
||||||
|
ASSERT_EQ(AuString(hello, hello + 5), "hello");
|
||||||
|
|
||||||
|
close(fds[0]);
|
||||||
|
close(fds[1]);
|
||||||
|
close(acceptFd);
|
||||||
|
|
||||||
|
AuIO::UNIX::ShareFileDescriptorStop(handleString);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TEST(IPC, Event)
|
||||||
|
{
|
||||||
|
auto event = Aurora::IPC::NewEvent(false, true);
|
||||||
|
ASSERT_TRUE(bool(event));
|
||||||
|
|
||||||
|
auto handleString = event->ExportToString();
|
||||||
|
ASSERT_TRUE(bool(handleString.size()));
|
||||||
|
AuLogDbg("Exported event handle: {}", handleString);
|
||||||
|
|
||||||
|
auto eventImported = Aurora::IPC::ImportEvent(handleString);
|
||||||
|
ASSERT_TRUE(bool(eventImported));
|
||||||
|
|
||||||
|
ASSERT_FALSE(eventImported->IsSignaled());
|
||||||
|
ASSERT_FALSE(event->IsSignaled());
|
||||||
|
|
||||||
|
event->Set();
|
||||||
|
ASSERT_TRUE(eventImported->IsSignaled());
|
||||||
|
|
||||||
|
ASSERT_FALSE(eventImported->IsSignaled());
|
||||||
|
ASSERT_FALSE(event->IsSignaled());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IPC, Semaphore)
|
||||||
|
{
|
||||||
|
auto semaphore = Aurora::IPC::NewSemaphore(2);
|
||||||
|
ASSERT_TRUE(bool(semaphore));
|
||||||
|
|
||||||
|
auto handleString = semaphore->ExportToString();
|
||||||
|
ASSERT_TRUE(bool(handleString.size()));
|
||||||
|
AuLogDbg("Exported semaphore handle: {}", handleString);
|
||||||
|
|
||||||
|
auto semaphoreImported = Aurora::IPC::ImportSemaphore(handleString);
|
||||||
|
ASSERT_TRUE(bool(semaphoreImported));
|
||||||
|
|
||||||
|
ASSERT_TRUE(semaphoreImported->IsSignaled());
|
||||||
|
ASSERT_TRUE(semaphore->IsSignaled());
|
||||||
|
|
||||||
|
ASSERT_FALSE(semaphoreImported->IsSignaled());
|
||||||
|
ASSERT_FALSE(semaphore->IsSignaled());
|
||||||
|
|
||||||
|
semaphore->AddOne();
|
||||||
|
|
||||||
|
ASSERT_TRUE(semaphore->IsSignaled());
|
||||||
|
|
||||||
|
ASSERT_FALSE(semaphoreImported->IsSignaled());
|
||||||
|
ASSERT_FALSE(semaphore->IsSignaled());
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunTests()
|
||||||
|
{
|
||||||
|
Aurora::RuntimeStartInfo info;
|
||||||
|
info.console.fio.enableLogging = false;
|
||||||
|
info.console.asyncVSLog = true;
|
||||||
|
Aurora::RuntimeStart(info);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user