diff --git a/Aurora/ROXTL b/Aurora/ROXTL index af438c8..122fc74 160000 --- a/Aurora/ROXTL +++ b/Aurora/ROXTL @@ -1 +1 @@ -Subproject commit af438c8c172478c9f6f9c71e2ede533898def63b +Subproject commit 122fc74a669596e200481ada884497854d07c5d1 diff --git a/Aurora/Runtime b/Aurora/Runtime index 401cf09..85a575e 160000 --- a/Aurora/Runtime +++ b/Aurora/Runtime @@ -1 +1 @@ -Subproject commit 401cf0996267da87b7d4d98c46a7a15ceeb11013 +Subproject commit 85a575eb9531d92c67cae5a547206494b55f4ebf diff --git a/Build_Scripts b/Build_Scripts index cf22904..1e9053b 160000 --- a/Build_Scripts +++ b/Build_Scripts @@ -1 +1 @@ -Subproject commit cf2290444cb0554aa9f7605679f476d945109034 +Subproject commit 1e9053b9383167eca317a941945ecf5d6a61aed4 diff --git a/README.md b/README.md index e69de29..128dbe0 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,81 @@ +# Hello + +Aurora runtime *basic* tests and demos for barebones use cases. + +# Getting ready + +``` +git clone --recursive https://gitea.reece.sx/AuroraSupport/HelloAurora +``` + + +# Building + + +## Building for Windows + +Tools required: MSVC (modernish?), premake5 + +No special steps are required. Assuming premake is present in %PATH%, run .\Win_x64_NoToolkit.bat and open the sln generated in the .\Build\Workspace directory. + +Cross-arch: `--target-x86_[32/64]` can be added to either family of scripts to readd the specified architecture. + +Important: if you wish to work with JavaScript projects in the future, you must ensure you have an x86_64 build of premake5. + + +## Building for Linux + + + +* Procure or build; and install libc++ (clangs native not fit-for-linux STL) + +Build: +``` + git clone https://github.com/llvm/llvm-project.git + cd llvm-project + mkdir build + cmake \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ + -DLLVM_EXTERNAL_LIT=/usr/bin/lit \ + -DLIBCXX_INSTALL_EXPERIMENTAL_LIBRARY=NO \ + -B build \ + -S llvm + ninja -C build cxx cxxabi + ninja -C build check-cxx check-cxxabi + ninja -C build install-cxx install-cxxabi +``` +Note: We use libc++ as a one-size-fits-all cross-platform STL solution. Its' core platform abstraction might suck, but it does well to maintain modern container and utility support. Plus, it's the defacto standard for embedded systems, meme web technology, and non-standard pc things including games consoles and mac. Pipeline and software dependencies can be better optimized and QA'd once normalized to one or two main STL targets. The bits that do suck, like thread primitives, aren't used by most developers who care about performance anyway. The quirks that are there, like locale fetch issues, don't affect us. + +* Procure or compile; and install premake + +Build: + +``` +git clone https://gitea.reece.sx/AuroraPipeline/premake +cd premake +make -f Bootstrap.mak linux +cp bin/release/premake5 /usr/bin/premake5 +chmod +x /usr/bin/premake5 +``` + +* Run the final premake script +``` +./Linux_x64_NoToolkit.sh +``` + +* Compile... +``` +cd Build/Workspace +make -jthreadsN config=[debug/stage/ship]_linux +``` + +Cross-arch: none yet. + +# Regeneration/rebuild + +Repeat the last batch/bash script; and rerun make/msbuild, or reload all in Visual Studio \ No newline at end of file diff --git a/Tests/Public/1. Hello System/Main.cpp b/Tests/Public/1. Hello System/Main.cpp index bf3efbf..3966f68 100644 --- a/Tests/Public/1. Hello System/Main.cpp +++ b/Tests/Public/1. Hello System/Main.cpp @@ -96,6 +96,36 @@ static void DumpAddressSpace() AuLogInfo(""); } +static void PrintWindowsVersion() +{ + AuLogInfo("IsWindowsXPOrGreater() : {}. \n" + "IsWindowsXPSP1OrGreater() : {}. \n" + "IsWindowsXPSP2OrGreater() : {}. \n" + "IsWindowsXPSP3OrGreater() : {}. \n" + "IsWindowsVistaOrGreater() : {}. \n" + "IsWindowsVistaSP1OrGreater() : {}. \n" + "IsWindowsVistaSP2OrGreater() : {}. \n" + "IsWindows7OrGreater() : {}. \n" + "IsWindows7SP1OrGreater() : {}. \n" + "IsWindows8OrGreater() : {}. \n" + "IsWindows8Point1OrGreater() : {}. \n" + "IsWindows10OrGreater() : {}. \n" + "IsWindows11OrGreater() : {}. \n", + AuSwInfo::IsWindowsXPOrGreater(), + AuSwInfo::IsWindowsXPSP1OrGreater(), + AuSwInfo::IsWindowsXPSP2OrGreater(), + AuSwInfo::IsWindowsXPSP3OrGreater(), + AuSwInfo::IsWindowsVistaOrGreater(), + AuSwInfo::IsWindowsVistaSP1OrGreater(), + AuSwInfo::IsWindowsVistaSP2OrGreater(), + AuSwInfo::IsWindows7OrGreater(), + AuSwInfo::IsWindows7SP1OrGreater(), + AuSwInfo::IsWindows8OrGreater(), + AuSwInfo::IsWindows8Point1OrGreater(), + AuSwInfo::IsWindows10OrGreater(), + AuSwInfo::IsWindows11OrGreater()); +} + void RunTests() { Aurora::RuntimeStartInfo info; @@ -106,4 +136,5 @@ void RunTests() PrintRamSpecs(); PrintCPUSpecs(); DumpAddressSpace(); + PrintWindowsVersion(); } \ No newline at end of file diff --git a/Tests/Public/12. Hello Crypto/Main.cpp b/Tests/Public/12. Hello Crypto/Main.cpp new file mode 100644 index 0000000..d41ccc0 --- /dev/null +++ b/Tests/Public/12. Hello Crypto/Main.cpp @@ -0,0 +1,396 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: Main.cpp + Date: 2022-2-18 + Author: Reece +***/ +#include +#include +#include +#include +#include + +static const auto kPassword = "testpassword"; + +TEST(Crypto, HashCash) +{ + +} + +TEST(BCrypt, RoundTrip) +{ + auto salt = AuCrypto::BCrypt::GenSalt(14); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt: {}", salt); + + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); + + ASSERT_TRUE(AuCrypto::BCrypt::CheckPassword(kPassword, hash)); +} + +TEST(BCrypt, KnownGood) +{ + // Trust me bro +} + +TEST(BCryptSalt, T_10) +{ + auto salt = AuCrypto::BCrypt::GenSalt(10); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt 10: {}", salt); + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); +} + +TEST(BCryptSalt, T_11) +{ + auto salt = AuCrypto::BCrypt::GenSalt(11); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt 11: {}", salt); + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); +} + +TEST(BCryptSalt, T_12) +{ + auto salt = AuCrypto::BCrypt::GenSalt(12); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt 12: {}", salt); + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); +} + +TEST(BCryptSalt, T_13) +{ + auto salt = AuCrypto::BCrypt::GenSalt(13); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt 13: {}", salt); + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); +} + +TEST(BCryptSalt, T_14) +{ + auto salt = AuCrypto::BCrypt::GenSalt(14); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt 14: {}", salt); + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); +} + +TEST(BCryptSalt, T_15) +{ + auto salt = AuCrypto::BCrypt::GenSalt(15); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt 15: {}", salt); + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); +} + +TEST(BCryptSalt, T_16) +{ + auto salt = AuCrypto::BCrypt::GenSalt(16); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt 16: {}", salt); + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); +} + + +TEST(BCryptSalt, T_17) +{ + auto salt = AuCrypto::BCrypt::GenSalt(17); + ASSERT_FALSE(salt.empty()); + AuLogDbg("salt 17: {}", salt); + auto hash = AuCrypto::BCrypt::HashPassword(kPassword, salt); + ASSERT_FALSE(hash.empty()); + AuLogDbg("password: {}", hash); +} + +#define ADD_HASHCASH(n) \ +TEST(HashCash, Power_## n) \ +{ \ + auto token = AuRng::RngU64(); \ + auto answer = AuCrypto::HashCash::FindAnswer(token, n); \ + ASSERT_TRUE(AuCrypto::HashCash::CheckSalt(token, n, answer)); \ +} + +ADD_HASHCASH(18) // +ADD_HASHCASH(19) // +ADD_HASHCASH(20) // +ADD_HASHCASH(21) // +ADD_HASHCASH(22) // +ADD_HASHCASH(23) // +ADD_HASHCASH(24) // +ADD_HASHCASH(25) // +ADD_HASHCASH(26) // +ADD_HASHCASH(27) // +//ADD_HASHCASH(28) // 47936 +//ADD_HASHCASH(32) // + +TEST(RSA, RSARng) +{ + auto pRSAPrivate = AuCrypto::RSA::NewRSAKeyShared(4096); + ASSERT_TRUE(bool(pRSAPrivate)); +} + +TEST(RSACerts, GenerateOne) +{ + auto pRSAPrivate = AuCrypto::RSA::NewRSAKeyShared(4096); + ASSERT_TRUE(bool(pRSAPrivate)); + + AuCrypto::X509::CertRequest request; + request.pSelfSigningRSAKey = pRSAPrivate; + request.pRSAKey = pRSAPrivate->ToPublic(); + request.bSubjectKeyId = true; + request.name.commonName = "Aurora Test"; + request.name.state = "Shithole"; + request.name.countryCode = "GB"; + request.name.name = "Firstname Lastname"; + request.digest = AuHashing::EHashType::eSHA2_64; + + auto cert = AuCrypto::X509::GenerateCertificate(request); + ASSERT_TRUE(bool(cert)); + + ASSERT_TRUE(AuFS::WriteFile("./SelfSigned_RSA.crt", cert.GetResult())); +} + +TEST(ECCCerts, GenerateNist521) +{ + auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurve521); + ASSERT_TRUE(bool(pECCPrivate)); + + AuByteBuffer a; + pECCPrivate->AsPublicECC(a); + auto pECCPublic = AuCrypto::ECC::OpenPublicECCShared(a); + ASSERT_TRUE(bool(pECCPublic)); + + AuCrypto::X509::CertRequest request; + request.pSelfSigningECCKey = pECCPrivate; + request.pECCKey = pECCPublic; + request.bSubjectKeyId = true; + request.name.commonName = "Aurora Test"; + request.name.state = "Shithole"; + request.name.countryCode = "GB"; + request.name.name = "Firstname Lastname"; + request.digest = AuHashing::EHashType::eSHA2_64; + + auto cert = AuCrypto::X509::GenerateCertificate(request); + ASSERT_TRUE(bool(cert)); + + ASSERT_TRUE(AuFS::WriteFile("./SelfSigned_N521.crt", cert.GetResult())); +} + +TEST(ECCCerts, GenerateSECP256K1) +{ + auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurveSECP256K1); + ASSERT_TRUE(bool(pECCPrivate)); + + AuByteBuffer a; + pECCPrivate->AsPublicECC(a); + auto pECCPublic = AuCrypto::ECC::OpenPublicECCShared(a); + ASSERT_TRUE(bool(pECCPublic)); + + AuCrypto::X509::CertRequest request; + request.pSelfSigningECCKey = pECCPrivate; + request.pECCKey = pECCPublic; + request.bSubjectKeyId = true; + request.name.commonName = "Aurora Test"; + request.name.state = "Shithole"; + request.name.countryCode = "GB"; + request.name.name = "Firstname Lastname"; + request.digest = AuHashing::EHashType::eSHA2_64; + request.usage.push_back(AuCrypto::X509::EExtendedUsage::eCodeSigning); + request.usage.push_back(AuCrypto::X509::EExtendedUsage::eOCSPSigning); + + auto cert = AuCrypto::X509::GenerateCertificate(request); + ASSERT_TRUE(bool(cert)); + + ASSERT_TRUE(AuFS::WriteFile("./SelfSigned_256K1.crt", cert.GetResult())); +} + +TEST(ECCReimport, SECP256K1) +{ + auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurveSECP256K1); + ASSERT_TRUE(bool(pECCPrivate)); + + AuByteBuffer a; + pECCPrivate->AsPublicECC(a); + auto pECCPublic = AuCrypto::ECC::OpenPublicECCShared(a); + ASSERT_TRUE(bool(pECCPublic)); +} + +TEST(ECCReimport, SECP256K1Private) +{ + auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurveSECP256K1); + ASSERT_TRUE(bool(pECCPrivate)); + + AuByteBuffer a; + pECCPrivate->AsPrivateECC(a); + + auto pECCPublic = AuCrypto::ECC::OpenPrivateECCShared(a); + ASSERT_TRUE(bool(pECCPublic)); +} + +TEST(ECCReimport, x25519) +{ + auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurveX25519); + ASSERT_TRUE(bool(pECCPrivate)); + + AuByteBuffer a; + pECCPrivate->AsPublicECC(a); + auto pECCPublic = AuCrypto::ECC::OpenPublicECCShared(a); + ASSERT_TRUE(bool(pECCPublic)); +} + +TEST(ECCReimport, x25519Private) +{ + auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurveX25519); + ASSERT_TRUE(bool(pECCPrivate)); + + AuByteBuffer a; + pECCPrivate->AsPrivateECC(a); + + auto pECCPublic = AuCrypto::ECC::OpenPrivateECCShared(a); + ASSERT_TRUE(bool(pECCPublic)); +} + +TEST(ECCReimport, ed25519) +{ + auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurveEd25519); + ASSERT_TRUE(bool(pECCPrivate)); + + AuByteBuffer a; + pECCPrivate->AsPublicECC(a); + auto pECCPublic = AuCrypto::ECC::OpenPublicECCShared(a); + ASSERT_TRUE(bool(pECCPublic)); +} + +TEST(ECCReimport, ed25519Private) +{ + auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurveEd25519); + ASSERT_TRUE(bool(pECCPrivate)); + + AuByteBuffer a; + pECCPrivate->AsPrivateECC(a); + + auto pECCPublic = AuCrypto::ECC::OpenPrivateECCShared(a); + ASSERT_TRUE(bool(pECCPublic)); +} + +// +//TEST(ECCCerts, x25519) +//{ +// auto pECCPrivate = AuCrypto::ECC::NewECCShared(AuCrypto::ECC::EECCCurve::eCurveEd25519); +// ASSERT_TRUE(bool(pECCPrivate)); +// +// AuByteBuffer a; +// pECCPrivate->AsPublicECC(a); +// auto pECCPublic = AuCrypto::ECC::OpenPublicECCShared(a); +// +// AuCrypto::X509::CertRequest request; +// request.pSelfSigningECCKey = pECCPrivate; +// request.pECCKey = pECCPublic; +// request.bSubjectKeyId = true; +// request.name.commonName = "Aurora Test"; +// request.name.state = "Shithole"; +// request.name.countryCode = "GB"; +// request.name.name = "Firstname Lastname"; +// +// auto cert = AuCrypto::X509::GenerateCertificate(request); +// ASSERT_TRUE(bool(cert)); +// +// ASSERT_TRUE(AuFS::WriteFile("./SelfSigned_X25519.crt", cert.GetResult())); +//} + + +TEST(RSA, RSAExportImport) +{ +} + +TEST(RSA, RSAEncrypt) +{ +} + +TEST(RSA, RSAVerify) +{ +} + +TEST(ECC, ECCVerify) +{ +} + +TEST(ECC, ECCECDH) +{ +} + +TEST(PEM, A) +{ +} + +TEST(CBC, AES) +{ + char IV[16]; + char key[24]; + + AuRng::RngFillArray(IV); + AuRng::RngFillArray(key); + + auto pContext = AuCrypto::CBC::NewContextUnique(); + auto pContext2 = AuCrypto::CBC::NewContextUnique(); + ASSERT_TRUE(pContext); + ASSERT_TRUE(pContext2); + + ASSERT_TRUE(pContext->Initialize(key, IV)); + ASSERT_TRUE(pContext2->Initialize(key, IV)); + char textBuffer[] { "The quick brown fox jumps over the lazy dog!!!!" }; + char textBuffer2[] { "The quick brown fox jumps over the lazy dog!!!!" }; + + ASSERT_TRUE(AuCrypto::AES::CBCEncrypt(AuUnsafeRaiiToShared(pContext), textBuffer)); + EXPECT_NE(AuMemcmp(textBuffer, textBuffer2, sizeof(textBuffer2)), 0); + + ASSERT_TRUE(AuCrypto::AES::CBCDecrypt(AuUnsafeRaiiToShared(pContext2), textBuffer)); + EXPECT_EQ(AuMemcmp(textBuffer, textBuffer2, sizeof(textBuffer2)), 0); +} + +TEST(CBC, TDES) +{ + char IV[16]; + char key[24]; + + AuRng::RngFillArray(IV); + AuRng::RngFillArray(key); + + auto pContext = AuCrypto::CBC::NewContextUnique(); + auto pContext2 = AuCrypto::CBC::NewContextUnique(); + ASSERT_TRUE(pContext); + ASSERT_TRUE(pContext2); + + ASSERT_TRUE(pContext->Initialize(key, IV)); + ASSERT_TRUE(pContext2->Initialize(key, IV)); + char textBuffer[] { "The quick brown fox jumps over the lazy dog!!!!" }; + char textBuffer2[] { "The quick brown fox jumps over the lazy dog!!!!" }; + + ASSERT_TRUE(AuCrypto::TDES::CBCEncrypt(AuUnsafeRaiiToShared(pContext), textBuffer)); + EXPECT_NE(AuMemcmp(textBuffer, textBuffer2, sizeof(textBuffer2)), 0); + + ASSERT_TRUE(AuCrypto::TDES::CBCDecrypt(AuUnsafeRaiiToShared(pContext2), textBuffer)); + EXPECT_EQ(AuMemcmp(textBuffer, textBuffer2, sizeof(textBuffer2)), 0); +} + +void RunTests() +{ + Aurora::RuntimeStartInfo info; + info.console.fio.enableLogging = false; + Aurora::RuntimeStart(info); +} \ No newline at end of file diff --git a/Tests/Public/13. Hello Networking/Main.cpp b/Tests/Public/13. Hello Networking/Main.cpp index 5db477a..30d4bc0 100644 --- a/Tests/Public/13. Hello Networking/Main.cpp +++ b/Tests/Public/13. Hello Networking/Main.cpp @@ -301,6 +301,33 @@ TEST(Resolve, GoogleAAAA) } } +TEST(Adapters, Print) +{ + auto pNetProcessor = AuNet::NewNetworkInterface(); + ASSERT_TRUE(bool(pNetProcessor)); + + AuLogInfo("Hostname: {}", pNetProcessor->GetInterfacesService()->GetHostname()); + + auto ifaces = pNetProcessor->GetInterfacesService()->GetAdapters(); + for (const auto &pAdapter : ifaces) + { + AuString dns = ""; + for (const auto &dnsIP : pAdapter->GetDNS()) + { + dns += fmt::format(" dns-server={}", dnsIP.ToString()); + } + + AuLogInfo("Found adapter interface (family: {}): \n\tName: {}\n\tDevice: {}\n\tAddress: {}\n\tMulticast: {}\n\tGateway: {}\n\tDNS: {}\n\n", + AuNet::EIPProtocolToString(pAdapter->ToFamily()), + pAdapter->ToName(), + pAdapter->ToDevice(), + pAdapter->ToAddress().ToString(), + pAdapter->ToBroadcastAddress().ToString(), + pAdapter->ToGateway().ToString(), + dns); + } +} + void RunTests() { Aurora::RuntimeStartInfo info; diff --git a/Tests/Public/14. Hello RNG/Main.cpp b/Tests/Public/14. Hello RNG/Main.cpp new file mode 100644 index 0000000..9a298fb --- /dev/null +++ b/Tests/Public/14. Hello RNG/Main.cpp @@ -0,0 +1,15 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: Main.cpp + Date: 2022-2-18 + Author: Reece +***/ +#include + +void RunTests() +{ + Aurora::RuntimeStartInfo info; + info.console.fio.enableLogging = false; + Aurora::RuntimeStart(info); +} \ No newline at end of file diff --git a/Tests/Public/15. Hello ByteBuffer/Main.cpp b/Tests/Public/15. Hello ByteBuffer/Main.cpp new file mode 100644 index 0000000..9a298fb --- /dev/null +++ b/Tests/Public/15. Hello ByteBuffer/Main.cpp @@ -0,0 +1,15 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: Main.cpp + Date: 2022-2-18 + Author: Reece +***/ +#include + +void RunTests() +{ + Aurora::RuntimeStartInfo info; + info.console.fio.enableLogging = false; + Aurora::RuntimeStart(info); +} \ No newline at end of file diff --git a/Tests/Public/19. Hello Debug/Main.cpp b/Tests/Public/19. Hello Debug/Main.cpp new file mode 100644 index 0000000..dd4e04b --- /dev/null +++ b/Tests/Public/19. Hello Debug/Main.cpp @@ -0,0 +1,133 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: Main.cpp + Date: 2022-2-18 + Author: Reece +***/ +#include +#include + +TEST(ErrorStack, A) +{ + AuErrorStack errors; + + SysPushErrorIO("Something something IO error"); + SysPushErrorIO("Something something IO error 1"); + SysPushErrorIO("Something something IO error 2 {}", "hello worlds"); + + ASSERT_TRUE(errors.HasCaptured()); + ASSERT_TRUE(errors.HasMultipleOccurred()); + ASSERT_TRUE(errors.FirstMessage()->pNextThreadMesage); + ASSERT_TRUE(errors.FirstMessage()->pNextThreadMesage->pNextThreadMesage); + + AuLogDbg("{}, {}, {}", + *errors.ToString(), + errors.FirstMessage()->pNextThreadMesage->ToString(), + errors.FirstMessage()->pNextThreadMesage->pNextThreadMesage->ToString()); +} + +TEST(ErrorStack, B) +{ + AuErrorStack errors; + + try + { + AU_THROW_CONST_STRING("Hello error stack"); + } + catch (...) + { + + } + + ASSERT_TRUE(errors.HasCaptured()); + + AuLogDbg("{}", *errors.ToString()); +} + +TEST(CatchMessage, B) +{ + try + { + AU_THROW_CONST_STRING("Hello try/catch"); + } + catch (...) + { + AuLogDbg("caught message: {}", AuDebug::GetLastException()); + } +} + +TEST(DemoFormattedThrow, a) +{ + try + { + AU_THROW_FORMATTED("hello people {}", 23423423); + } + catch (...) + { + } +} + +TEST(DemoTelemetryPoke, TelemetryHint) +{ + try + { + errno = 3269420; + AU_THROW_CONST_STRING("Hello telemetry"); + } + catch (...) + { + AuDebug::CheckErrors(); // techincally not required for exception logging + } +} + + +TEST(Demo, ThrowStringLiteral) +{ + try + { + throw "hello most modern platforms"; + } + catch (...) + { + + } +} + +TEST(DemoTelemetryPoke, ErrnoHint) +{ + errno = 3269420; + AuDebug::CheckErrors(); +} + +TEST(DemoSysError, AA) +{ + SysPushErrorGeneric("Hello World"); +} + +TEST(DemoAssert, A) +{ + SysAssertExp(true, "i will not fail {}", 100); + SysAssert(true, "i will not fail {}", 100); + + SysAssertDbgExp(true, "i will not fail {} (our clients fucking suck. i hate them.)", 100); + SysAssertDbg(true, "i will not fail {} (our clients fucking suck. i hate them.)", 100); +} + + +TEST(DemoPanic, ASDASd) +{ + //SysPanic("bye bye {}", 234); +} + + +// tests/demos: +// TODO: function name demangling] +// TODo: stack trace printing/expansion + +void RunTests() +{ + Aurora::RuntimeStartInfo info; + info.console.fio.enableLogging = false; + Aurora::RuntimeStart(info); +} \ No newline at end of file diff --git a/Tests/Public/20. Hello Time/Main.cpp b/Tests/Public/20. Hello Time/Main.cpp index 853d2ff..156ed6f 100644 --- a/Tests/Public/20. Hello Time/Main.cpp +++ b/Tests/Public/20. Hello Time/Main.cpp @@ -8,14 +8,14 @@ #include #include -TEST(Benchmark, CurrentInternalClockMS) +TEST(Benchmark, HighResClockMS) { - SysBenchmark("CurrentInternalClockMS"); + SysBenchmark("HighResClockMS"); AuUInt c {}; for (int i = 0; i < 100'000'000; i++) { - c += AuTime::CurrentInternalClockMS(); + c += AuTime::HighResClockMS(); } } diff --git a/Tests/Public/24. Hello IO/Main.cpp b/Tests/Public/24. Hello IO/Main.cpp index 99f21c0..7823281 100644 --- a/Tests/Public/24. Hello IO/Main.cpp +++ b/Tests/Public/24. Hello IO/Main.cpp @@ -9,14 +9,135 @@ #include #include -TEST(IO, Proceessor_SoftAbort) +//TEST(IO, Proceessor_SoftAbort) +//{ +// static int counter {}; +// static int counter2 {}; +// static int counter3 {}; +// static int counter4 {}; +// auto pIODrivenQueue = AuIO::NewIOProcessorNoQueue(false); +// ASSERT_TRUE(bool(pIODrivenQueue)); +// +// auto timer = AuIO::NewWaitableIOTimer(); +// +// auto listener = AuMakeShared(); +// listener->Tick_SelfIOEventFunctional = [&]() +// { +// AuLogDbg("SelfIO event fired"); +// counter++; +// }; +// listener->Tick_AnyFunctional = []() +// { +// AuLogDbg("* tick event fired"); +// counter2++; +// }; +// listener->OnNominalCompletionFunctional = [&]() +// { +// AuLogDbg("* complete"); +// counter3++; +// }; +// listener->OnFailureCompletionFunctional = [&]() +// { +// AuLogDbg("* failure"); +// counter4++; +// }; +// +// timer->SetConstantTick(AuMSToNS(500)); +// +// AuLogDbg("Start watch"); +// auto watch = pIODrivenQueue->StartIOWatch(timer, listener); +// +// for (int i = 0; i < 4; i++) +// { +// auto pumpedEvents = pIODrivenQueue->RunTick(); +// AuLogDbg("{} ln: {} io watches ticked", __LINE__, pumpedEvents); +// } +// +// AuLogDbg("Aborting / SOFT"); +// watch->StopWatch(); +// +// // Nop +// watch->FailWatch(); +// +// auto pumpedEvents = pIODrivenQueue->RunTick(); +// AuLogDbg("{} ln: {} io watches ticked", __LINE__, pumpedEvents); +// +// ASSERT_EQ(counter, 4); +// ASSERT_EQ(counter2, 4); +// ASSERT_EQ(counter3, 1); +// ASSERT_EQ(counter4, 0); +// +//} +// +//TEST(IO, Proceessor_FailAbort) +//{ +// static int counter {}; +// static int counter2 {}; +// static int counter3 {}; +// static int counter4 {}; +// auto pIODrivenQueue = AuIO::NewIOProcessorNoQueue(false); +// ASSERT_TRUE(bool(pIODrivenQueue)); +// +// auto timer = AuIO::NewWaitableIOTimer(); +// +// auto listener = AuMakeShared(); +// listener->Tick_SelfIOEventFunctional = [&]() +// { +// AuLogDbg("SelfIO event fired"); +// counter++; +// }; +// listener->Tick_AnyFunctional = []() +// { +// AuLogDbg("* tick event fired"); +// counter2++; +// }; +// listener->OnNominalCompletionFunctional = [&]() +// { +// AuLogDbg("* complete"); +// counter3++; +// }; +// listener->OnFailureCompletionFunctional = [&]() +// { +// AuLogDbg("* failure"); +// counter4++; +// }; +// +// timer->SetConstantTick(AuMSToNS(500)); +// +// AuLogDbg("Start watch"); +// auto watch = pIODrivenQueue->StartIOWatch(timer, listener); +// +// for (int i = 0; i < 4; i++) +// { +// auto pumpedEvents = pIODrivenQueue->RunTick(); +// AuLogDbg("{} ln: {} io watches ticked", __LINE__, pumpedEvents); +// } +// +// AuLogDbg("Aborting / HARD"); +// watch->FailWatch(); +// +// // Nop +// watch->StopWatch(); +// +// auto pumpedEvents = pIODrivenQueue->RunTick(); +// AuLogDbg("{} ln: {} io watches ticked", __LINE__, pumpedEvents); +// +// ASSERT_EQ(counter, 4); +// ASSERT_EQ(counter2, 4); +// ASSERT_EQ(counter3, 0); +// ASSERT_EQ(counter4, 1); +// +//} + +#if 0 +TEST(IO, AA) { static int counter {}; static int counter2 {}; static int counter3 {}; static int counter4 {}; - auto ioDrivenQueue = AuIO::NewIOProcessorNoQueue(false); - ASSERT_TRUE(bool(ioDrivenQueue)); + auto pIODrivenQueue = AuIO::NewIOProcessorNoQueue(false); + ASSERT_TRUE(bool(pIODrivenQueue)); auto timer = AuIO::NewWaitableIOTimer(); @@ -42,74 +163,15 @@ TEST(IO, Proceessor_SoftAbort) counter4++; }; - timer->SetConstantTick(AuMSToNS(500)); + timer->SetConstantTick(AuMSToNS(5)); AuLogDbg("Start watch"); - auto watch = ioDrivenQueue->StartIOWatch(timer, listener); + auto watch = pIODrivenQueue->StartIOWatch(timer, listener); - for (int i = 0; i < 4; i++) + for (int i = 0; i < 10'000'000; i++) { - auto pumpedEvents = ioDrivenQueue->RunTick(); - AuLogDbg("{} ln: {} io watches ticked", __LINE__, pumpedEvents); - } - - AuLogDbg("Aborting / SOFT"); - watch->StopWatch(); - - // Nop - watch->FailWatch(); - - auto pumpedEvents = ioDrivenQueue->RunTick(); - AuLogDbg("{} ln: {} io watches ticked", __LINE__, pumpedEvents); - - ASSERT_EQ(counter, 4); - ASSERT_EQ(counter2, 4); - ASSERT_EQ(counter3, 1); - ASSERT_EQ(counter4, 0); - -} - -TEST(IO, Proceessor_FailAbort) -{ - static int counter {}; - static int counter2 {}; - static int counter3 {}; - static int counter4 {}; - auto ioDrivenQueue = AuIO::NewIOProcessorNoQueue(false); - ASSERT_TRUE(bool(ioDrivenQueue)); - - auto timer = AuIO::NewWaitableIOTimer(); - - auto listener = AuMakeShared(); - listener->Tick_SelfIOEventFunctional = [&]() - { - AuLogDbg("SelfIO event fired"); - counter++; - }; - listener->Tick_AnyFunctional = []() - { - AuLogDbg("* tick event fired"); - counter2++; - }; - listener->OnNominalCompletionFunctional = [&]() - { - AuLogDbg("* complete"); - counter3++; - }; - listener->OnFailureCompletionFunctional = [&]() - { - AuLogDbg("* failure"); - counter4++; - }; - - timer->SetConstantTick(AuMSToNS(500)); - - AuLogDbg("Start watch"); - auto watch = ioDrivenQueue->StartIOWatch(timer, listener); - - for (int i = 0; i < 4; i++) - { - auto pumpedEvents = ioDrivenQueue->RunTick(); + SysBenchmark("Root tick"); + auto pumpedEvents = pIODrivenQueue->RunTick(); AuLogDbg("{} ln: {} io watches ticked", __LINE__, pumpedEvents); } @@ -119,62 +181,61 @@ TEST(IO, Proceessor_FailAbort) // Nop watch->StopWatch(); - auto pumpedEvents = ioDrivenQueue->RunTick(); + auto pumpedEvents = pIODrivenQueue->RunTick(); AuLogDbg("{} ln: {} io watches ticked", __LINE__, pumpedEvents); - ASSERT_EQ(counter, 4); - ASSERT_EQ(counter2, 4); - ASSERT_EQ(counter3, 0); - ASSERT_EQ(counter4, 1); } +#endif -TEST(IO, ReadFileThroughPipeProcessor2MBReadsEQ) + +TEST(IO, WriteMassive200MBFileBenchmarkDisk) { // Write 20MB of RNG asynchronously - AuByteBuffer rngbuffer(512 * 1024 * 40, AuUInt(AuHwInfo::GetPageSize())); + AuByteBuffer rngbuffer(200 * 1024 * 1024, AuUInt(AuHwInfo::GetPageSize())); { - auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE", AuIOFS::EFileOpenMode::eReadWrite, true); + auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE2", AuIOFS::EFileOpenMode::eReadWrite, true); ASSERT_TRUE(bool(stream)); AuRng::RngFillRange(rngbuffer); - auto transaction = stream->NewTransaction(); - ASSERT_TRUE(bool(transaction)); + auto pTransaction = stream->NewTransaction(); + ASSERT_TRUE(bool(pTransaction)); - transaction->SetCallback(AuMakeShared([=](AuUInt64 offset, AuUInt32 length) + pTransaction->SetCallback(AuMakeShared([=](AuUInt64 offset, AuUInt32 length) { - AuLogDbg("AIO 1 callback: {} {} {}", offset, length, transaction->GetOSErrorCode()); - SysAssert(length == 512 * 1024 * 40); + AuLogDbg("AIO 1 callback: {} {} {}", offset, length, pTransaction->GetOSErrorCode()); + //SysAssert(length == 200 * 1024 * 40); })); AuMemoryViewRead readView(rngbuffer); - ASSERT_TRUE(transaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); + ASSERT_TRUE(pTransaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); AuLogDbg("AIO 1: waiting...."); - ASSERT_TRUE(transaction->Wait(0)); + ASSERT_TRUE(pTransaction->Wait(0)); AuLogDbg("AIO 1: wait complete...."); - ASSERT_TRUE(transaction->NewLoopSource()->IsSignaled()); - ASSERT_TRUE(transaction->Complete()); + ASSERT_TRUE(pTransaction->NewLoopSource()->IsSignaled()); + ASSERT_TRUE(pTransaction->Complete()); } { + SysBenchmark("Total write time"); // Create the io processor - auto ioDrivenQueue = AuIO::NewIOProcessorNoQueue(false); - ASSERT_TRUE(bool(ioDrivenQueue)); + auto pIODrivenQueue = AuIO::NewIOProcessorNoQueue(false); + ASSERT_TRUE(bool(pIODrivenQueue)); - auto pipeProcessor = ioDrivenQueue->ToPipeProcessor(); - ASSERT_TRUE(bool(pipeProcessor)); + auto pPipeProcessor = pIODrivenQueue->ToPipeProcessor(); + ASSERT_TRUE(bool(pPipeProcessor)); - // Open the file and prepare an async transaction for the pipe processor to use + // Open the file and prepare an async pTransaction for the pipe processor to use - auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE", AuIOFS::EFileOpenMode::eRead, true); + auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE2", AuIOFS::EFileOpenMode::eRead, true); ASSERT_TRUE(bool(stream)); - auto transaction = stream->NewTransaction(); - ASSERT_TRUE(bool(transaction)); + auto pTransaction = stream->NewTransaction(); + ASSERT_TRUE(bool(pTransaction)); // Create an event listener for the callbacks @@ -199,7 +260,121 @@ TEST(IO, ReadFileThroughPipeProcessor2MBReadsEQ) // Setup the IOPipeRequest AuIO::IOPipeRequestAIO aio; - aio.pAsyncTransaction = transaction; + aio.pAsyncTransaction = pTransaction; + aio.pListener = listener; + aio.bIsStream = false; + aio.output.type = AuIO::EPipeCallbackType::eTryHandleBufferedPart; + aio.uPageLengthOrZero = 1024 * 1024 *5; // read in 2MB chunks + aio.uBufferLengthOrZero = 1024 * 1024 * 5; // read in 2MB chunks + + static auto localCount = 0; + localCount = 0; + + auto onData = AuMakeShared(); + AuByteBuffer outBuffer; + onData->OnDataAvailableFunctional = [&](AuByteBuffer &view) + { + AuLogDbg("Pipe processing: {}, tick: {}", view.RemainingBytes(), localCount++); + outBuffer.Write(view.readPtr, view.RemainingBytes()); + view.Skip(view.RemainingBytes()); + return true; + }; + aio.output.handleBufferedStream.pOnData = onData; + + // Finally create the damn pipe + + auto filePipe = pPipeProcessor->NewAIOPipe(aio); + ASSERT_TRUE(bool(filePipe)); + + ASSERT_TRUE(filePipe->Start()); + + // Main loop + while (pIODrivenQueue->HasItems()) + { + // Since we aren't using an external loop queue, we manually pump the processor in here under this spinloop + // If we were using a loop queue, we wouldn't need to do anything at all. You could still technically + // use pIODrivenQueue->ToQueue()->WaitAny() to trigger the tick. + + pIODrivenQueue->RunTick(); // also: TryTick and ManualTick + AuLogDbg("throughput benchmark: {} mb/s", filePipe->GetPredictedThroughput() / 1024 / 1024); + } + //ASSERT_EQ(localCount, 10); + + ASSERT_EQ(outBuffer, rngbuffer); + } +} + +TEST(IO, ReadFileThroughpPipeProcessor2MBReadsEQ) +{ + // Write 20MB of RNG asynchronously + AuByteBuffer rngbuffer(512 * 1024 * 40, AuUInt(AuHwInfo::GetPageSize())); + { + auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE", AuIOFS::EFileOpenMode::eReadWrite, true); + ASSERT_TRUE(bool(stream)); + + AuRng::RngFillRange(rngbuffer); + + auto pTransaction = stream->NewTransaction(); + ASSERT_TRUE(bool(pTransaction)); + + pTransaction->SetCallback(AuMakeShared([=](AuUInt64 offset, AuUInt32 length) + { + AuLogDbg("AIO 1 callback: {} {} {}", offset, length, pTransaction->GetOSErrorCode()); + SysAssert(length == 512 * 1024 * 40); + })); + + AuMemoryViewRead readView(rngbuffer); + ASSERT_TRUE(pTransaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); + + AuLogDbg("AIO 1: waiting...."); + ASSERT_TRUE(pTransaction->Wait(0)); + AuLogDbg("AIO 1: wait complete...."); + ASSERT_TRUE(pTransaction->NewLoopSource()->IsSignaled()); + ASSERT_TRUE(pTransaction->Complete()); + } + + { + // Create the io processor + + auto pIODrivenQueue = AuIO::NewIOProcessorNoQueue(false); + ASSERT_TRUE(bool(pIODrivenQueue)); + + auto pPipeProcessor = pIODrivenQueue->ToPipeProcessor(); + ASSERT_TRUE(bool(pPipeProcessor)); + + + // Open the file and prepare an async pTransaction for the pipe processor to use + + auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE", AuIOFS::EFileOpenMode::eRead, true); + ASSERT_TRUE(bool(stream)); + + auto pTransaction = stream->NewTransaction(); + ASSERT_TRUE(bool(pTransaction)); + + // Create an event listener for the callbacks + + auto listener = AuMakeShared(); + ASSERT_TRUE(bool(listener)); + + listener->OnPipeSuccessEventFunctional = []() + { + AuLogInfo("File IO pipe complete"); + }; + + listener->OnPipeFailureEventFunctional = []() + { + AuLogInfo("File IO pipe failure"); + }; + + listener->OnPipePartialEventFunctional = [](AuUInt tranferred) + { + AuLogInfo("on part: {}", tranferred); + }; + + // Setup the IOPipeRequest + + AuIO::IOPipeRequestAIO aio; + aio.pAsyncTransaction = pTransaction; aio.pListener = listener; aio.bIsStream = false; aio.output.type = AuIO::EPipeCallbackType::eTryHandleBufferedPart; @@ -222,19 +397,19 @@ TEST(IO, ReadFileThroughPipeProcessor2MBReadsEQ) // Finally create the damn pipe - auto filePipe = pipeProcessor->NewAIOPipe(aio); + auto filePipe = pPipeProcessor->NewAIOPipe(aio); ASSERT_TRUE(bool(filePipe)); ASSERT_TRUE(filePipe->Start()); // Main loop - while (ioDrivenQueue->HasItems()) + while (pIODrivenQueue->HasItems()) { // Since we aren't using an external loop queue, we manually pump the processor in here under this spinloop // If we were using a loop queue, we wouldn't need to do anything at all. You could still technically - // use ioDrivenQueue->ToQueue()->WaitAny() to trigger the tick. + // use pIODrivenQueue->ToQueue()->WaitAny() to trigger the tick. - ioDrivenQueue->RunTick(); // also: TryTick and ManualTick + pIODrivenQueue->RunTick(); // also: TryTick and ManualTick } ASSERT_EQ(localCount, 10); @@ -242,9 +417,9 @@ TEST(IO, ReadFileThroughPipeProcessor2MBReadsEQ) } } -TEST(IO, ReadFileThroughPipeProcessorDefaultConfigEQ) +TEST(IO, ReadFileThroughpPipeProcessorDefaultConfigEQ) { - // Write 20MB of RNG asynchronously + // Write 20MB of RNG using overlapped IO (we will block regardless bc its a test) AuByteBuffer rngbuffer(512 * 1024 * 40, AuUInt(AuHwInfo::GetPageSize())); { auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE", AuIOFS::EFileOpenMode::eReadWrite, true); @@ -252,41 +427,41 @@ TEST(IO, ReadFileThroughPipeProcessorDefaultConfigEQ) AuRng::RngFillRange(rngbuffer); - auto transaction = stream->NewTransaction(); - ASSERT_TRUE(bool(transaction)); + auto pTransaction = stream->NewTransaction(); + ASSERT_TRUE(bool(pTransaction)); - transaction->SetCallback(AuMakeShared([=](AuUInt64 offset, AuUInt32 length) + pTransaction->SetCallback(AuMakeShared([=](AuUInt64 offset, AuUInt32 length) { AuLogDbg("AIO 1 callback: {} {}", offset, length); })); AuMemoryViewRead readView(rngbuffer); - ASSERT_TRUE(transaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); + ASSERT_TRUE(pTransaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); AuLogDbg("AIO 1: waiting...."); - ASSERT_TRUE(transaction->Wait(0)); + ASSERT_TRUE(pTransaction->Wait(0)); AuLogDbg("AIO 1: wait complete...."); - ASSERT_TRUE(transaction->NewLoopSource()->IsSignaled()); - ASSERT_TRUE(transaction->Complete()); + ASSERT_TRUE(pTransaction->NewLoopSource()->IsSignaled()); + ASSERT_TRUE(pTransaction->Complete()); } { // Create the io processor - auto ioDrivenQueue = AuIO::NewIOProcessorNoQueue(false); - ASSERT_TRUE(bool(ioDrivenQueue)); + auto pIODrivenQueue = AuIO::NewIOProcessorNoQueue(false); + ASSERT_TRUE(bool(pIODrivenQueue)); - auto pipeProcessor = ioDrivenQueue->ToPipeProcessor(); - ASSERT_TRUE(bool(pipeProcessor)); + auto pPipeProcessor = pIODrivenQueue->ToPipeProcessor(); + ASSERT_TRUE(bool(pPipeProcessor)); - // Open the file and prepare an async transaction for the pipe processor to use + // Open the file and prepare an async pTransaction for the pipe processor to use auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE", AuIOFS::EFileOpenMode::eRead, true); ASSERT_TRUE(bool(stream)); - auto transaction = stream->NewTransaction(); - ASSERT_TRUE(bool(transaction)); + auto pTransaction = stream->NewTransaction(); + ASSERT_TRUE(bool(pTransaction)); // Create an event listener for the callbacks @@ -311,7 +486,7 @@ TEST(IO, ReadFileThroughPipeProcessorDefaultConfigEQ) // Setup the IOPipeRequest AuIO::IOPipeRequestAIO aio; - aio.pAsyncTransaction = transaction; + aio.pAsyncTransaction = pTransaction; aio.pListener = listener; aio.bIsStream = false; aio.output.type = AuIO::EPipeCallbackType::eTryHandleBufferedPart; @@ -332,23 +507,23 @@ TEST(IO, ReadFileThroughPipeProcessorDefaultConfigEQ) // Finally create the damn pipe - auto filePipe = pipeProcessor->NewAIOPipe(aio); + auto filePipe = pPipeProcessor->NewAIOPipe(aio); ASSERT_TRUE(bool(filePipe)); ASSERT_TRUE(filePipe->Start()); // Main loop - while (ioDrivenQueue->HasItems()) + while (pIODrivenQueue->HasItems()) { - ioDrivenQueue->RunTick(); // also: TryTick and ManualTick + pIODrivenQueue->RunTick(); // also: TryTick and ManualTick } ASSERT_EQ(outBuffer, rngbuffer); } } -static void ReadFileThroughPipeProcessorCongested(int i) +static void ReadFileThroughpPipeProcessorCongested(int i) { - // Write 20MB of RNG asynchronously + // Write 20MB of RNG using overlapped IO (we will block regardless bc its a test) { auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE", AuIOFS::EFileOpenMode::eReadWrite, true); ASSERT_TRUE(bool(stream)); @@ -356,42 +531,42 @@ static void ReadFileThroughPipeProcessorCongested(int i) AuByteBuffer rngbuffer(512 * 1024 * 40, AuUInt(AuHwInfo::GetPageSize())); AuRng::RngFillRange(rngbuffer); - auto transaction = stream->NewTransaction(); - ASSERT_TRUE(bool(transaction)); + auto pTransaction = stream->NewTransaction(); + ASSERT_TRUE(bool(pTransaction)); - transaction->SetCallback(AuMakeShared([=](AuUInt64 offset, AuUInt32 length) + pTransaction->SetCallback(AuMakeShared([=](AuUInt64 offset, AuUInt32 length) { AuLogDbg("AIO 1 callback: {} {}", offset, length); SysAssert(length == 512 * 1024 * 40); })); AuMemoryViewRead readView(rngbuffer); - ASSERT_TRUE(transaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); + ASSERT_TRUE(pTransaction->StartWrite(0, AuUnsafeRaiiToShared(&readView))); AuLogDbg("AIO 1: waiting...."); - ASSERT_TRUE(transaction->Wait(0)); + ASSERT_TRUE(pTransaction->Wait(0)); AuLogDbg("AIO 1: wait complete...."); - ASSERT_TRUE(transaction->NewLoopSource()->IsSignaled()); - ASSERT_TRUE(transaction->Complete()); + ASSERT_TRUE(pTransaction->NewLoopSource()->IsSignaled()); + ASSERT_TRUE(pTransaction->Complete()); } { // Create the io processor - auto ioDrivenQueue = AuIO::NewIOProcessorNoQueue(false); - ASSERT_TRUE(bool(ioDrivenQueue)); + auto pIODrivenQueue = AuIO::NewIOProcessorNoQueue(false); + ASSERT_TRUE(bool(pIODrivenQueue)); - auto pipeProcessor = ioDrivenQueue->ToPipeProcessor(); - ASSERT_TRUE(bool(pipeProcessor)); + auto pPipeProcessor = pIODrivenQueue->ToPipeProcessor(); + ASSERT_TRUE(bool(pPipeProcessor)); - // Open the file and prepare an async transaction for the pipe processor to use + // Open the file and prepare an async pTransaction for the pipe processor to use auto stream = AuIOFS::OpenAsyncUnique("./AsyncFilePIPE", AuIOFS::EFileOpenMode::eRead, true); ASSERT_TRUE(bool(stream)); - auto transaction = stream->NewTransaction(); - ASSERT_TRUE(bool(transaction)); + auto pTransaction = stream->NewTransaction(); + ASSERT_TRUE(bool(pTransaction)); // Create an event listener for the callbacks @@ -416,7 +591,7 @@ static void ReadFileThroughPipeProcessorCongested(int i) // Setup the IOPipeRequest AuIO::IOPipeRequestAIO aio; - aio.pAsyncTransaction = transaction; + aio.pAsyncTransaction = pTransaction; aio.pListener = listener; aio.bIsStream = false; aio.output.type = AuIO::EPipeCallbackType::eTryHandleBufferedPart; @@ -438,39 +613,39 @@ static void ReadFileThroughPipeProcessorCongested(int i) // Finally create the damn pipe - auto filePipe = pipeProcessor->NewAIOPipe(aio); + auto filePipe = pPipeProcessor->NewAIOPipe(aio); ASSERT_TRUE(bool(filePipe)); ASSERT_TRUE(filePipe->Start()); // Main loop - while (ioDrivenQueue->HasItems()) + while (pIODrivenQueue->HasItems()) { // Since we aren't using an external loop queue, we manually pump the processor in here under this spinloop // If we were using a loop queue, we wouldn't need to do anything at all. You could still technically - // use ioDrivenQueue->ToQueue()->WaitAny() to trigger the tick. + // use pIODrivenQueue->ToQueue()->WaitAny() to trigger the tick. - ioDrivenQueue->RunTick(); // also: TryTick and ManualTick + pIODrivenQueue->RunTick(); // also: TryTick and ManualTick } SysAssert(localCount == ((512 * 1024 * 40) / aio.uPageLengthOrZero)); } } -TEST(IO, ReadFileThroughPipeProcessorCongestedFourth) +TEST(IO, ReadFileThroughpPipeProcessorCongestedFourth) { - ReadFileThroughPipeProcessorCongested(4); + ReadFileThroughpPipeProcessorCongested(4); } -TEST(IO, ReadFileThroughPipeProcessorCongestedHalf) +TEST(IO, ReadFileThroughpPipeProcessorCongestedHalf) { - ReadFileThroughPipeProcessorCongested(2); + ReadFileThroughpPipeProcessorCongested(2); } -TEST(IO, ReadFileThroughPipeProcessorCongestedThird) +TEST(IO, ReadFileThroughpPipeProcessorCongestedThird) { - ReadFileThroughPipeProcessorCongested(3); + ReadFileThroughpPipeProcessorCongested(3); } diff --git a/Tests/Public/25. Hello Address Map/Main.cpp b/Tests/Public/25. Hello Address Map/Main.cpp index 4e12ec7..8253137 100644 --- a/Tests/Public/25. Hello Address Map/Main.cpp +++ b/Tests/Public/25. Hello Address Map/Main.cpp @@ -12,26 +12,28 @@ TEST(Map, FSNoLock) { int size = 4096 * 4; AuByteBuffer rngbuffer(size); + ASSERT_TRUE(rngbuffer); { - auto fsInit = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); - ASSERT_TRUE(bool(fsInit)); + auto pFile = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); AuRng::RngFillRange(rngbuffer); - fsInit->Write(AuMemoryViewStreamRead(rngbuffer)); + pFile->Write(AuMemoryViewStreamRead(rngbuffer)); + pFile->Flush(); } { auto fsMap = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eReadWrite, AuFS::EFileAdvisoryLockLevel::eNoSafety); ASSERT_TRUE(bool(fsMap)); - auto shared = AuProcess::GetGlobalProcessSpace(); - SysAssert(shared); + auto pStream = AuProcess::GetGlobalProcessSpace(); + ASSERT_TRUE(bool(pStream)); - auto obj = shared->MapFileByObject(fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + auto obj = pStream->MapFileByObject(fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); ASSERT_TRUE(bool(obj)); - ASSERT_TRUE(memcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); + ASSERT_TRUE(AuMemcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); } } @@ -39,79 +41,80 @@ TEST(Map, FSNestedReadLock) { int size = 4096 * 4; AuByteBuffer rngbuffer(size); + ASSERT_TRUE(rngbuffer); { - auto fsInit = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); - ASSERT_TRUE(bool(fsInit)); + auto pFile = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); AuRng::RngFillRange(rngbuffer); - fsInit->Write(AuMemoryViewStreamRead(rngbuffer)); + pFile->Write(AuMemoryViewStreamRead(rngbuffer)); } { auto fsMap = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eReadWrite, AuFS::EFileAdvisoryLockLevel::eBlockWrite); ASSERT_TRUE(bool(fsMap)); - auto shared = AuProcess::GetGlobalProcessSpace(); - SysAssert(shared); + auto pStream = AuProcess::GetGlobalProcessSpace(); + ASSERT_TRUE(bool(pStream)); - auto obj = shared->MapFileByObject(fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + auto obj = pStream->MapFileByObject(fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); ASSERT_TRUE(bool(obj)); - ASSERT_TRUE(memcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); + ASSERT_TRUE(AuMemcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); } } - TEST(Map, FSNestedReadLock2) { int size = 4096 * 4; AuByteBuffer rngbuffer(size); + ASSERT_TRUE(rngbuffer); { - auto fsInit = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); - ASSERT_TRUE(bool(fsInit)); + auto pFile = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); AuRng::RngFillRange(rngbuffer); - fsInit->Write(AuMemoryViewStreamRead(rngbuffer)); + pFile->Write(AuMemoryViewStreamRead(rngbuffer)); } { auto fsMap = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); ASSERT_TRUE(bool(fsMap)); - auto shared = AuProcess::GetGlobalProcessSpace(); - SysAssert(shared); + auto pStream = AuProcess::GetGlobalProcessSpace(); + ASSERT_TRUE(bool(pStream)); - auto obj = shared->MapFileByObject(fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + auto obj = pStream->MapFileByObject(fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); ASSERT_TRUE(bool(obj)); - ASSERT_TRUE(memcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); + ASSERT_TRUE(AuMemcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); } } - TEST(Map, FSNestedReadLockFail1) { int size = 4096 * 4; AuByteBuffer rngbuffer(size); + ASSERT_TRUE(rngbuffer); { - auto fsInit = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); - ASSERT_TRUE(bool(fsInit)); + auto pFile = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); AuRng::RngFillRange(rngbuffer); - fsInit->Write(AuMemoryViewStreamRead(rngbuffer)); + pFile->Write(AuMemoryViewStreamRead(rngbuffer)); } { auto fsMap = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); ASSERT_TRUE(bool(fsMap)); - auto shared = AuProcess::GetGlobalProcessSpace(); - SysAssert(shared); + auto pStream = AuProcess::GetGlobalProcessSpace(); + ASSERT_TRUE(bool(pStream)); - auto obj = shared->MapFileByObject(fsMap, 0, size, AuIOFS::EFileOpenMode::eWrite, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + auto obj = pStream->MapFileByObject(fsMap, 0, size, AuIOFS::EFileOpenMode::eWrite, AuFS::EFileAdvisoryLockLevel::eBlockWrite); ASSERT_TRUE(!bool(obj)); } } @@ -127,23 +130,169 @@ TEST(Map, IPC) auto handleString = memory->ExportToString(); ASSERT_TRUE(bool(handleString.size())); - AuLogDbg("Exported shared view handle: {}", handleString); + AuLogDbg("Exported pStream view handle: {}", handleString); { - auto shared = AuProcess::GetGlobalProcessSpace(); - SysAssert(shared); + auto pStream = AuProcess::GetGlobalProcessSpace(); + ASSERT_TRUE(bool(pStream)); - auto obj = shared->MapIPCMemory(handleString, 0, 4096, AuIOFS::EFileOpenMode::eWrite); + auto obj = pStream->MapIPCMemory(handleString, 0, 4096, AuIOFS::EFileOpenMode::eWrite); ASSERT_TRUE(bool(obj)); AuLogDbg("Shared Memory String: {}", (char *)obj->GetBasePointer()); - ASSERT_TRUE(memcmp(obj->GetBasePointer(), obj->GetBasePointer(), kHelloWorld.size() - 1) == 0); + ASSERT_TRUE(AuMemcmp(obj->GetBasePointer(), obj->GetBasePointer(), kHelloWorld.size() - 1) == 0); } } +TEST(Reserve, HasInterface) +{ + ASSERT_TRUE(bool(AuProcess::ReserveAddressSpace(4096 * 2))); +} + +TEST(Reserve, TestMap2SubSections) +{ + int size = 4096 * 4; + AuByteBuffer rngbuffer(size); + ASSERT_TRUE(rngbuffer); + + { + auto pFile = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); + + AuRng::RngFillRange(rngbuffer); + pFile->Write(AuMemoryViewStreamRead(rngbuffer)); + } + + { + auto fsMap = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eReadWrite, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(fsMap)); + + auto pStream = AuProcess::ReserveAddressSpace(size * 2); + ASSERT_TRUE(bool(pStream)); + + auto obj = pStream->MapFileByObjectEx(0, fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(obj)); + + ASSERT_TRUE(AuMemcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); + + auto obj2 = pStream->MapFileByObjectEx(size, fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(obj2)); + + ASSERT_TRUE(AuMemcmp(obj2->GetBasePointer(), rngbuffer.base, size) == 0); + + ASSERT_EQ(obj2->GetBasePointer(), obj->GetPointer(size)); + } +} + +TEST(Reserve, TestReMap2SubSections) +{ + int size = 4096 * 4; + AuByteBuffer rngbuffer(size); + AuByteBuffer rngbuffer2(size); + ASSERT_TRUE(rngbuffer); + ASSERT_TRUE(rngbuffer2); + + { + auto pFile = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); + + AuRng::RngFillRange(rngbuffer); + pFile->Write(AuMemoryViewStreamRead(rngbuffer)); + } + + { + auto pFile = AuIOFS::OpenShared("./FSMap2", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); + + AuRng::RngFillRange(rngbuffer2); + pFile->Write(AuMemoryViewStreamRead(rngbuffer2)); + } + + { + auto fsMap = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eReadWrite, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(fsMap)); + + auto fsMap2 = AuIOFS::OpenShared("./FSMap2", AuIOFS::EFileOpenMode::eReadWrite, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(fsMap2)); + + auto pStream = AuProcess::ReserveAddressSpace(size * 2); + ASSERT_TRUE(bool(pStream)); + + auto obj = pStream->MapFileByObjectEx(0, fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(obj)); + + ASSERT_TRUE(AuMemcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); + + auto obj2 = pStream->MapFileByObjectEx(size, fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(obj2)); + + ASSERT_TRUE(AuMemcmp(obj2->GetBasePointer(), rngbuffer.base, size) == 0); + + ASSERT_EQ(obj2->GetBasePointer(), obj->GetPointer(size)); + + obj->Unmap(); + + auto obj3 = pStream->MapFileByObjectEx(0, fsMap2, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(obj3)); + + ASSERT_TRUE(AuMemcmp(obj3->GetBasePointer(), rngbuffer2.base, size) == 0); + } +} + +TEST(Reserve, TestReMap2SubSections_Fail) +{ + int size = 4096 * 4; + AuByteBuffer rngbuffer(size); + AuByteBuffer rngbuffer2(size); + ASSERT_TRUE(rngbuffer); + ASSERT_TRUE(rngbuffer2); + + { + auto pFile = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); + + AuRng::RngFillRange(rngbuffer); + pFile->Write(AuMemoryViewStreamRead(rngbuffer)); + } + + { + auto pFile = AuIOFS::OpenShared("./FSMap2", AuIOFS::EFileOpenMode::eWrite); + ASSERT_TRUE(bool(pFile)); + + AuRng::RngFillRange(rngbuffer2); + pFile->Write(AuMemoryViewStreamRead(rngbuffer2)); + } + + { + auto fsMap = AuIOFS::OpenShared("./FSMap", AuIOFS::EFileOpenMode::eReadWrite, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(fsMap)); + + auto fsMap2 = AuIOFS::OpenShared("./FSMap2", AuIOFS::EFileOpenMode::eReadWrite, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(fsMap)); + + auto pStream = AuProcess::ReserveAddressSpace(size * 2); + ASSERT_TRUE(bool(pStream)); + + auto obj = pStream->MapFileByObjectEx(0, fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(obj)); + + ASSERT_TRUE(AuMemcmp(obj->GetBasePointer(), rngbuffer.base, size) == 0); + + auto obj2 = pStream->MapFileByObjectEx(size, fsMap, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_TRUE(bool(obj2)); + + ASSERT_TRUE(AuMemcmp(obj2->GetBasePointer(), rngbuffer.base, size) == 0); + + ASSERT_EQ(obj2->GetBasePointer(), obj->GetPointer(size)); + + auto obj3 = pStream->MapFileByObjectEx(0, fsMap2, 0, size, AuIOFS::EFileOpenMode::eRead, AuFS::EFileAdvisoryLockLevel::eBlockWrite); + ASSERT_FALSE(bool(obj3)); + } +} + void RunTests() { Aurora::RuntimeStartInfo info; diff --git a/Tests/Public/26. Protocol Stacks/Main.cpp b/Tests/Public/26. Protocol Stacks/Main.cpp new file mode 100644 index 0000000..ebbe36b --- /dev/null +++ b/Tests/Public/26. Protocol Stacks/Main.cpp @@ -0,0 +1,193 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: Main.cpp + Date: 2022-2-18 + Author: Reece +***/ +#include +#include +#include +#include + +#include +#include + + +static const unsigned char compressMe[779] +{ + 0x2F, 0x2A, 0x2A, 0x2A, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x43, 0x6F, + 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x43, 0x29, 0x20, + 0x32, 0x30, 0x32, 0x31, 0x20, 0x4A, 0x20, 0x52, 0x65, 0x65, 0x63, 0x65, + 0x20, 0x57, 0x69, 0x6C, 0x73, 0x6F, 0x6E, 0x20, 0x28, 0x61, 0x2F, 0x6B, + 0x2F, 0x61, 0x20, 0x22, 0x52, 0x65, 0x65, 0x63, 0x65, 0x22, 0x29, 0x2E, + 0x20, 0x41, 0x6C, 0x6C, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, + 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x2E, 0x0D, 0x0A, 0x0D, + 0x0A, 0x20, 0x20, 0x20, 0x20, 0x46, 0x69, 0x6C, 0x65, 0x3A, 0x20, 0x4F, + 0x70, 0x65, 0x6E, 0x2E, 0x55, 0x6E, 0x69, 0x78, 0x2E, 0x63, 0x70, 0x70, + 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x44, 0x61, 0x74, 0x65, 0x3A, 0x20, + 0x32, 0x30, 0x32, 0x31, 0x2D, 0x36, 0x2D, 0x31, 0x32, 0x0D, 0x0A, 0x20, + 0x20, 0x20, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, 0x3A, 0x20, 0x52, + 0x65, 0x65, 0x63, 0x65, 0x0D, 0x0A, 0x2A, 0x2A, 0x2A, 0x2F, 0x0D, 0x0A, + 0x23, 0x70, 0x72, 0x61, 0x67, 0x6D, 0x61, 0x20, 0x6F, 0x6E, 0x63, 0x65, + 0x0D, 0x0A, 0x23, 0x69, 0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x20, 0x3C, + 0x52, 0x75, 0x6E, 0x74, 0x69, 0x6D, 0x65, 0x49, 0x6E, 0x74, 0x65, 0x72, + 0x6E, 0x61, 0x6C, 0x2E, 0x68, 0x70, 0x70, 0x3E, 0x0D, 0x0A, 0x23, 0x69, + 0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x20, 0x22, 0x50, 0x72, 0x6F, 0x63, + 0x65, 0x73, 0x73, 0x65, 0x73, 0x2E, 0x68, 0x70, 0x70, 0x22, 0x0D, 0x0A, + 0x23, 0x69, 0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x20, 0x22, 0x4F, 0x70, + 0x65, 0x6E, 0x2E, 0x55, 0x6E, 0x69, 0x78, 0x2E, 0x68, 0x70, 0x70, 0x22, + 0x0D, 0x0A, 0x0D, 0x0A, 0x23, 0x69, 0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, + 0x20, 0x3C, 0x75, 0x6E, 0x69, 0x73, 0x74, 0x64, 0x2E, 0x68, 0x3E, 0x0D, + 0x0A, 0x23, 0x69, 0x6E, 0x63, 0x6C, 0x75, 0x64, 0x65, 0x20, 0x3C, 0x53, + 0x6F, 0x75, 0x72, 0x63, 0x65, 0x2F, 0x49, 0x4F, 0x2F, 0x46, 0x53, 0x2F, + 0x46, 0x53, 0x2E, 0x68, 0x70, 0x70, 0x3E, 0x0D, 0x0A, 0x0D, 0x0A, 0x6E, + 0x61, 0x6D, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x41, 0x75, 0x72, + 0x6F, 0x72, 0x61, 0x3A, 0x3A, 0x50, 0x72, 0x6F, 0x63, 0x65, 0x73, 0x73, + 0x65, 0x73, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x73, + 0x74, 0x61, 0x74, 0x69, 0x63, 0x20, 0x76, 0x6F, 0x69, 0x64, 0x20, 0x55, + 0x6E, 0x69, 0x78, 0x4F, 0x70, 0x65, 0x6E, 0x41, 0x73, 0x79, 0x6E, 0x63, + 0x28, 0x63, 0x6F, 0x6E, 0x73, 0x74, 0x20, 0x41, 0x75, 0x53, 0x74, 0x72, + 0x69, 0x6E, 0x67, 0x20, 0x26, 0x6F, 0x70, 0x65, 0x6E, 0x29, 0x0D, 0x0A, + 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x2F, 0x2F, 0x20, 0x54, 0x4F, 0x44, 0x4F, 0x3A, 0x20, + 0x6D, 0x61, 0x63, 0x20, 0x6F, 0x73, 0x20, 0x69, 0x73, 0x20, 0x73, 0x70, + 0x65, 0x63, 0x69, 0x61, 0x6C, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x66, 0x6F, 0x72, 0x6B, 0x28, + 0x29, 0x20, 0x3D, 0x3D, 0x20, 0x30, 0x29, 0x0D, 0x0A, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x65, 0x74, 0x73, + 0x69, 0x64, 0x28, 0x29, 0x3B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x78, 0x65, 0x63, 0x6C, + 0x28, 0x22, 0x78, 0x64, 0x67, 0x2D, 0x6F, 0x70, 0x65, 0x6E, 0x22, 0x2C, + 0x20, 0x6F, 0x70, 0x65, 0x6E, 0x2E, 0x63, 0x5F, 0x73, 0x74, 0x72, 0x28, + 0x29, 0x29, 0x3B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x7D, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0D, 0x0A, 0x0D, + 0x0A, 0x20, 0x20, 0x20, 0x20, 0x41, 0x55, 0x4B, 0x4E, 0x5F, 0x53, 0x59, + 0x4D, 0x20, 0x76, 0x6F, 0x69, 0x64, 0x20, 0x4F, 0x70, 0x65, 0x6E, 0x55, + 0x72, 0x69, 0x28, 0x63, 0x6F, 0x6E, 0x73, 0x74, 0x20, 0x41, 0x75, 0x53, + 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x26, 0x75, 0x72, 0x69, 0x29, 0x0D, + 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x55, 0x6E, 0x69, 0x78, 0x4F, 0x70, 0x65, 0x6E, + 0x41, 0x73, 0x79, 0x6E, 0x63, 0x28, 0x75, 0x72, 0x69, 0x29, 0x3B, 0x0D, + 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0D, 0x0A, 0x0D, 0x0A, 0x20, 0x20, + 0x20, 0x20, 0x41, 0x55, 0x4B, 0x4E, 0x5F, 0x53, 0x59, 0x4D, 0x20, 0x76, + 0x6F, 0x69, 0x64, 0x20, 0x4F, 0x70, 0x65, 0x6E, 0x46, 0x69, 0x6C, 0x65, + 0x28, 0x63, 0x6F, 0x6E, 0x73, 0x74, 0x20, 0x41, 0x75, 0x53, 0x74, 0x72, + 0x69, 0x6E, 0x67, 0x20, 0x26, 0x66, 0x69, 0x6C, 0x65, 0x29, 0x0D, 0x0A, + 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x55, 0x6E, 0x69, 0x78, 0x4F, 0x70, 0x65, 0x6E, 0x41, + 0x73, 0x79, 0x6E, 0x63, 0x28, 0x49, 0x4F, 0x3A, 0x3A, 0x46, 0x53, 0x3A, + 0x3A, 0x4E, 0x6F, 0x72, 0x6D, 0x61, 0x6C, 0x69, 0x7A, 0x65, 0x50, 0x61, + 0x74, 0x68, 0x52, 0x65, 0x74, 0x28, 0x66, 0x69, 0x6C, 0x65, 0x29, 0x29, + 0x3B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0D, 0x0A, 0x7D +}; + +static AuByteBuffer GetCompressableBlob() +{ + AuByteBuffer compressMeBytes; + + for (int i = 0; i < 100000; i++) + { + compressMeBytes.Write(compressMe, AuArraySize(compressMe)); + } + + return compressMeBytes; +} + +TEST(DecompressAllInSingleTick, deflate) +{ + auto compressMeBytes = GetCompressableBlob(); + +// Legacy API + AuIO::Buffered::BlobWriter compressed; + { + AuIO::Buffered::BlobReader reader(AuMove(compressMeBytes)); + AuCompression::CompressionPipe pipe; + AuCompression::CompressInfo info (AuCompression::ECompressionType::eDeflate); + + pipe.pReadPipe = AuUnsafeRaiiToShared(&reader); + pipe.pWritePipe = AuUnsafeRaiiToShared(&compressed); + + ASSERT_TRUE(AuCompression::Compress(pipe, info)); + } +// compress over. ignore me + + auto pProtoStack = AuIO::Protocol::NewBufferedProtocolStack(compressed.GetBuffer()->size()); + ASSERT_TRUE(pProtoStack); + + // Ingest via AsStreamWriter/AsWritableByteBuffer, read-back through AsReadableByteBuffer or AsStreamReader later + ASSERT_EQ(pProtoStack->AsStreamWriter()->Write(AuMemoryViewRead(*compressed.GetBuffer())), AuIO::EStreamError::eErrorNone); + + // Setup an interceptor (an interface of data in, data out given nonlinear memory views) + AuCompression::DecompressInfo info(AuCompression::ECompressionType::eDeflate); + info.uInternalStreamSize = 100 * 1024 * 1024; + auto pCompressionInterceptor = AuCompression::NewDecompressionInterceptor(info); + ASSERT_TRUE(pProtoStack->AppendInterceptorEx(pCompressionInterceptor, info.uInternalStreamSize)); + + // Do (all) work + pProtoStack->DoTick(); + + // Read + auto pRawBuffer = pProtoStack->AsReadableByteBuffer(); + + AuLogDbg("{}::{}", (void *)compressMeBytes.base, compressMeBytes.RemainingBytes()); + AuLogDbg("{}::{}", (void *)pRawBuffer->base, pRawBuffer->RemainingBytes()); + + ASSERT_EQ(compressMeBytes.RemainingBytes(), pRawBuffer->RemainingBytes()); +} + +TEST(DecompressAllInSingleTick, zstd) +{ + auto compressMeBytes = GetCompressableBlob(); + +// Legacy API + AuIO::Buffered::BlobWriter compressed; + { + AuIO::Buffered::BlobReader reader(AuMove(compressMeBytes)); + AuCompression::CompressionPipe pipe; + AuCompression::CompressInfo info(AuCompression::ECompressionType::eZSTD); + + pipe.pReadPipe = AuUnsafeRaiiToShared(&reader); + pipe.pWritePipe = AuUnsafeRaiiToShared(&compressed); + + ASSERT_TRUE(AuCompression::Compress(pipe, info)); + } +// compress over. ignore me + + auto pProtoStack = AuIO::Protocol::NewBufferedProtocolStack(compressed.GetBuffer()->size()); + ASSERT_TRUE(pProtoStack); + + // Ingest via AsStreamWriter/AsWritableByteBuffer, read-back through AsReadableByteBuffer or AsStreamReader later + ASSERT_EQ(pProtoStack->AsStreamWriter()->Write(AuMemoryViewRead(*compressed.GetBuffer())), AuIO::EStreamError::eErrorNone); + + // Setup an interceptor (an interface of data in, data out given nonlinear memory views) + AuCompression::DecompressInfo info(AuCompression::ECompressionType::eZSTD); + info.uInternalStreamSize = 100 * 1024 * 1024; + auto pCompressionInterceptor = AuCompression::NewDecompressionInterceptor(info); + ASSERT_TRUE(pProtoStack->AppendInterceptorEx(pCompressionInterceptor, info.uInternalStreamSize)); + + // Do (all) work + pProtoStack->DoTick(); + + // Read + auto pRawBuffer = pProtoStack->AsReadableByteBuffer(); + + AuLogDbg("{}::{}", (void *)compressMeBytes.base, compressMeBytes.RemainingBytes()); + AuLogDbg("{}::{}", (void *)pRawBuffer->base, pRawBuffer->RemainingBytes()); + + ASSERT_EQ(compressMeBytes.RemainingBytes(), pRawBuffer->RemainingBytes()); +} + +TEST(ProcessAllFramesInStreamBuffer, StreamProtos) +{ + // TODO: ... + // (AppendSingleFrameProcessor) +} + +void RunTests() +{ + Aurora::RuntimeStartInfo info; + info.console.fio.enableLogging = false; + Aurora::RuntimeStart(info); +} \ No newline at end of file diff --git a/Tests/Public/6. Hello Compression/Main.cpp b/Tests/Public/6. Hello Compression/Main.cpp index dc72295..d96ffcf 100644 --- a/Tests/Public/6. Hello Compression/Main.cpp +++ b/Tests/Public/6. Hello Compression/Main.cpp @@ -89,6 +89,51 @@ static AuByteBuffer GetCompressableBlob() return compressMeBytes; } +TEST(Demo, One) +{ + auto compressMeBytes = GetCompressableBlob(); + AuIO::Buffered::BlobReader reader(AuUnsafeRaiiToShared(&compressMeBytes)); + + AuCompression::CompressInfo compressStream { AuCompression::ECompressionType::eZSTD }; + compressStream.uInternalStreamSize = compressMeBytes.size(); + compressStream.uCompressionLevel = 7; + + // Create a compressor given a shared IStreamReader and CompressInfo + auto pCompressor = AuCompression::CompressorShared(AuUnsafeRaiiToShared(&reader), compressStream); + ASSERT_TRUE(bool(pCompressor)); + + // Consume exactly `compressMeBytes.RemainingBytes()` from the reader + // (optionally: use ReadEx to ad-hoc read from the underlying stream) + auto uToConsume = compressMeBytes.RemainingBytes(); + auto readWrittenBytes = pCompressor->Ingest(uToConsume); + ASSERT_EQ(readWrittenBytes.first, uToConsume); + + // Compression requires a finalize or a flush before read + ASSERT_TRUE(pCompressor->Finish()); + + // Assert deflated blob > inflated blob + ASSERT_LE(pCompressor->GetAvailableProcessedBytes(), readWrittenBytes.first); + + // Take from the underlying buffer + AuByteBuffer deflatedCopy(pCompressor->GetAvailableProcessedBytes()); + auto uBytesCopied = pCompressor->Read(AuMemoryViewWrite(deflatedCopy.writePtr, deflatedCopy.length)); + ASSERT_TRUE(uBytesCopied); + deflatedCopy.writePtr += uBytesCopied; + + ASSERT_TRUE(AuFS::WriteFile("Test File.zstd", deflatedCopy)); +} + +TEST(Demo, One2) +{ + auto compressMeBytes = GetCompressableBlob(); + AuIO::Buffered::BlobReader reader(AuUnsafeRaiiToShared(&compressMeBytes)); + + AuByteBuffer expandableBuffer; + + ASSERT_TRUE(AuCompression::Compress(compressMeBytes, expandableBuffer, 14)); + ASSERT_TRUE(AuFS::WriteFile("Test File 2.zstd", expandableBuffer)); +} + static void TestBasicCompression(AuCompression::ECompressionType type) { auto compressMeBytes = GetCompressableBlob(); @@ -98,13 +143,13 @@ static void TestBasicCompression(AuCompression::ECompressionType type) { AuIO::Buffered::BlobReader reader(AuMove(compressMeBytes)); AuCompression::CompressionPipe pipe; - AuCompression::CompressionInfo info; + AuCompression::CompressInfo info; info.type = type; pipe.pReadPipe = AuUnsafeRaiiToShared(&reader); pipe.pWritePipe = AuUnsafeRaiiToShared(&compressed); - info.compressionLevel = 4; + info.uCompressionLevel = 4; ASSERT_TRUE(AuCompression::Compress(pipe, info)); } compressed.GetBuffer()->ResetReadPointer(); @@ -132,17 +177,17 @@ static void TestBasicCompression(AuCompression::ECompressionType type) auto decompressLength = decompressed.GetBuffer()->size(); AuCompression::DecompressInfo decompressStream {type}; - decompressStream.internalStreamSize = decompressLength; + decompressStream.uInternalStreamSize = decompressLength + 1; AuIO::Buffered::BlobReader reader(compressed.GetBuffer()); auto decompressor = AuCompression::DecompressorShared(AuUnsafeRaiiToShared(&reader), decompressStream); - auto readWrittenBytes = decompressor->Ingest(decompressLength); - //ASSERT_EQ(readWrittenBytes, AuMakePair(AuUInt32(compressed.GetBuffer()->size()), AuUInt32(decompressLength))); - //ASSERT_LE(readWrittenBytes.first, readWrittenBytes.second); + auto readWrittenBytes = decompressor->Ingest(compressed.GetBuffer()->RemainingBytes()); - AuByteBuffer inflated(decompressLength); - ASSERT_TRUE(decompressor->Read(AuMemoryViewWrite(inflated.data(), inflated.size()))); + AuByteBuffer inflated(decompressor->GetAvailableProcessedBytes()); + auto uWritten = decompressor->Read(AuMemoryViewWrite(inflated.data(), inflated.size())); + ASSERT_TRUE(uWritten); + inflated.writePtr += uWritten; ASSERT_EQ(inflated, *decompressed.GetBuffer()); } @@ -156,9 +201,9 @@ static void TestBasicCompression(AuCompression::ECompressionType type) { auto decompressLength = decompressed.GetBuffer()->size(); - AuCompression::CompressionInfo compressStream{ type }; - compressStream.internalStreamSize = decompressLength * 10; - compressStream.compressionLevel = 4; + AuCompression::CompressInfo compressStream{ type }; + compressStream.uInternalStreamSize = decompressLength * 10; + compressStream.uCompressionLevel = 4; AuIO::Buffered::BlobReader reader(decompressed.GetBuffer()); auto compressor = AuCompression::CompressorShared(AuUnsafeRaiiToShared(&reader), compressStream); @@ -167,12 +212,11 @@ static void TestBasicCompression(AuCompression::ECompressionType type) compressor->Finish(); readWrittenBytes = { 0, compressor->GetAvailableProcessedBytes() }; - //ASSERT_GE(readWrittenBytes.first, readWrittenBytes.second); - //AuLogDbg("{} {}, {}", readWrittenBytes.first, readWrittenBytes.second, compressor->GetAvailableProcessedBytes()); - deflated2 = AuByteBuffer(compressor->GetAvailableProcessedBytes()); - ASSERT_TRUE(compressor->Read(AuMemoryViewWrite(deflated2.data(), deflated2.size()))); - deflated2.writePtr += deflated2.length; + deflated2 = AuByteBuffer(readWrittenBytes.second); + auto uRead = compressor->Read(AuMemoryViewWrite(deflated2.writePtr, readWrittenBytes.second)); + ASSERT_EQ(uRead, readWrittenBytes.second); + deflated2.writePtr += uRead; } deflated2.ResetReadPointer(); @@ -181,18 +225,18 @@ static void TestBasicCompression(AuCompression::ECompressionType type) auto decompressLength = decompressed.GetBuffer()->size(); AuCompression::DecompressInfo decompressStream{ type }; - decompressStream.internalStreamSize = decompressLength; + decompressStream.uInternalStreamSize = decompressLength + 1; - deflated2.readPtr = deflated2.base; AuIO::Buffered::BlobReader reader(deflated2); auto decompressor = AuCompression::DecompressorShared(AuUnsafeRaiiToShared(&reader), decompressStream); - auto readWrittenBytes = decompressor->Ingest(deflated2.size()); - //AuLogDbg("2> {} {}, {} {} {}", readWrittenBytes.first, readWrittenBytes.second, decompressor->GetAvailableProcessedBytes(), AuUInt32(deflated2.size()), AuUInt32(decompressLength)); - //ASSERT_EQ(readWrittenBytes, AuMakePair(AuUInt32(deflated2.size()), AuUInt32(decompressLength))); + auto readWrittenBytes = decompressor->Ingest(deflated2.RemainingBytes()); - AuByteBuffer inflated(decompressLength); - ASSERT_TRUE(decompressor->Read(AuMemoryViewWrite(inflated.data(), inflated.size()))); + auto bytes = decompressor->GetAvailableProcessedBytes(); + + AuByteBuffer inflated(bytes); + auto uRead = decompressor->Read(AuMemoryViewWrite(inflated.writePtr, bytes)); + inflated.writePtr += uRead; decompressed.GetBuffer()->ResetReadPointer(); ASSERT_EQ(inflated, *decompressed.GetBuffer()); diff --git a/Tests/Public/Net. TLS Google/Main.cpp b/Tests/Public/Net. TLS Google/Main.cpp index 554ab03..5339458 100644 --- a/Tests/Public/Net. TLS Google/Main.cpp +++ b/Tests/Public/Net. TLS Google/Main.cpp @@ -127,7 +127,24 @@ TEST(Net, TLSGoogle) #define ENABLE_TLS #if defined(ENABLE_TLS) Aurora::IO::TLS::TLSMeta tlsMeta; - //tlsMeta.sSNIServerName = "google.com"; + tlsMeta.bIsClient = true; + tlsMeta.client.sSNIServerName = "google.com"; + tlsMeta.pCertPin = AuMakeSharedThrow([] + (const AuSPtr &pChain, + const AuMemoryViewRead &derCertificate) -> bool + { + AuLogDbg("Incoming handshake..."); + for (AuUInt32 i = 0; i < pChain->GetCertificateCount(); i++) + { + auto details = pChain->GetCertificateDetails(i); + auto cert = pChain->GetCertificate(i); + + AuLogDbg("{}: {} (from {})", i, details.subject.commonName, details.issuer.commonName); + } + + return true; + }); + auto pContext = Aurora::IO::TLS::NewTLSContextEx(socket->ToChannel()->NewProtocolSendStack(), socket->ToChannel()->NewProtocolRecvStack(), tlsMeta); diff --git a/Tests/Public/Net. Telnet TCP Server Multithreaded/Main.cpp b/Tests/Public/Net. Telnet TCP Server Multithreaded/Main.cpp new file mode 100644 index 0000000..318cd89 --- /dev/null +++ b/Tests/Public/Net. Telnet TCP Server Multithreaded/Main.cpp @@ -0,0 +1,131 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: Main.cpp + Date: 2022-2-18 + Author: Reece +***/ +#include +#include +#include +#include + +TEST(Net, ServerDemo) +{ + auto app = AuAsync::GetAsyncApp(); + + auto pIoProcessor1 = AuIO::NewIOProcessorOnThread(false, { AuAsync::GetSharedAsyncApp(), 0, 1 }); + ASSERT_TRUE(bool(pIoProcessor1)); + + auto pIoProcessor2 = AuIO::NewIOProcessorOnThread(false, { AuAsync::GetSharedAsyncApp(), 0, 2 }); + ASSERT_TRUE(bool(pIoProcessor2)); + + auto pNetProcessor = AuNet::NewNetworkInterface(); + ASSERT_TRUE(bool(pNetProcessor)); + + auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor1); + ASSERT_TRUE(bool(pNetWorker)); + + auto pNetWorker2 = pNetProcessor->GetWorkersService()->Attach(pIoProcessor2); + ASSERT_TRUE(bool(pNetWorker2)); + + auto pSocketFactory = AuMakeShared(); + ASSERT_TRUE(bool(pSocketFactory)); + + pSocketFactory->NewSocketDriverFunctional = []() -> AuSPtr + { + struct TempDriver : AuNet::ISocketDriverFunctional + { + AuSPtr pDriverSocket; + }; + + auto pRealDriver = AuMakeSharedPanic(); + + pRealDriver->OnPreestablishFunctional = [=](const AuSPtr &socket) -> bool + { + pRealDriver->pDriverSocket = socket; + return true; + }; + + pRealDriver->OnEstablishFunctional = [=]() + { + AuLogDbg("New session on thread: {}", AuThreads::GetThreadId()); + auto pChannel = pRealDriver->pDriverSocket->ToChannel(); + pChannel->AsStreamWriter()->Write(AuMemoryViewRead("Hello World", 11)); + }; + + pRealDriver->OnFatalErrorReportedFunctional = [=](const AuNet::NetError &error) + { + AuLogDbg("[2] On error: {}", NetErrorToExtendedString(error)); + }; + + pRealDriver->OnStreamUpdatedFunctional = [=]() + { + auto pChannel = pRealDriver->pDriverSocket->ToChannel(); + auto pReader = pChannel->AsReadableByteBuffer(); + + AuString message; + message.resize(pReader->RemainingBytes()); + pReader->Read(message.data(), message.size()); + + AuLogDbg("[2] Got: {}", message); + }; + + pRealDriver->OnFinalizeFunctional = [=]() + { + AuResetMember(*pRealDriver.get()); // reset circular dependence on captured pRealDriver + AuLogDbg("[2] Finalize"); + }; + + return pRealDriver; + }; + + auto pServerDriver = AuMakeShared(); + ASSERT_TRUE(bool(pServerDriver)); + + pServerDriver->OnBindFunctional = [&]() + { + AuLogDbg("[1] On bind"); + }; + + pServerDriver->OnFatalErrorReportedFunctional = [&](const AuNet::NetError &error) + { + AuLogDbg("[1] On error: {}", NetErrorToExtendedString(error)); + }; + + pServerDriver->OnFinalizeFunctional = [&]() + { + AuLogDbg("[1] On finalize"); + }; + + AuNet::NetSocketBind nsSocketBind; + nsSocketBind.pDriver = pServerDriver; + nsSocketBind.ip = AuNet::IPAddress("127.0.0.1"); + nsSocketBind.protocol = AuNet::ETransportProtocol::eProtocolTCP; + nsSocketBind.uPort = 8087; + nsSocketBind.pFactory = pSocketFactory; + nsSocketBind.bMultiThreaded = true; + + auto pSocket = pNetProcessor->GetSocketService()->NewServer(nsSocketBind); + ASSERT_TRUE(bool(pSocket)); + + app->Main(); +} + +void RunTests() +{ + Aurora::RuntimeStartInfo info; + info.async.enableSchedularThread = true; + info.async.schedularFrequency = 2; + info.async.sysPumpFrequency = 2; + info.async.enableSysPumpFreqnecy = true; + info.console.fio.enableLogging = false; + info.console.asyncVSLog = false; + Aurora::RuntimeStart(info); + + auto app = AuAsync::GetAsyncApp(); + + app->Create({ 0, 0 }); + app->Spawn({ 0, 1 }); + app->Spawn({ 0, 2 }); +} \ No newline at end of file diff --git a/Tests/Public/Net. Telnet TCP Server/Main.cpp b/Tests/Public/Net. Telnet TCP Server/Main.cpp index df938f7..fde9214 100644 --- a/Tests/Public/Net. Telnet TCP Server/Main.cpp +++ b/Tests/Public/Net. Telnet TCP Server/Main.cpp @@ -63,7 +63,7 @@ TEST(Net, ServerDemo) pRealDriver->OnFinalizeFunctional = [=]() { - pRealDriver->~TempDriver(); // reset circular dependence on captured pRealDriver + AuResetMember(*pRealDriver.get()); // reset circular dependence on captured pRealDriver AuLogDbg("[2] Finalize"); }; diff --git a/Tests/Public/Net. Telnet UDP Session Stream Based Server/Main.cpp b/Tests/Public/Net. Telnet UDP Session Stream Based Server/Main.cpp new file mode 100644 index 0000000..7b95f65 --- /dev/null +++ b/Tests/Public/Net. Telnet UDP Session Stream Based Server/Main.cpp @@ -0,0 +1,113 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: Main.cpp + Date: 2022-2-18 + Author: Reece +***/ +#include +#include +#include +#include + +TEST(Net, ServerDemo) +{ + auto pIoProcessor = AuIO::NewIOProcessorNoQueue(false); + ASSERT_TRUE(bool(pIoProcessor)); + + auto pNetProcessor = AuNet::NewNetworkInterface(); + ASSERT_TRUE(bool(pNetProcessor)); + + auto pNetWorker = pNetProcessor->GetWorkersService()->Attach(pIoProcessor); + ASSERT_TRUE(bool(pNetWorker)); + + auto pSocketFactory = AuMakeShared(); + ASSERT_TRUE(bool(pSocketFactory)); + + pSocketFactory->NewSocketDriverFunctional = []() -> AuSPtr + { + struct TempDriver : AuNet::ISocketDriverFunctional + { + AuSPtr pDriverSocket; + }; + auto pRealDriver = AuMakeShared(); + + pRealDriver->OnPreestablishFunctional = [=](const AuSPtr &socket) -> bool + { + pRealDriver->pDriverSocket = socket; + return true; + }; + + pRealDriver->OnEstablishFunctional = [=]() + { + auto pChannel = pRealDriver->pDriverSocket->ToChannel(); + AuLogDbg("[2] New channel created"); + pChannel->AsStreamWriter()->Write(AuMemoryViewRead("Hello World", 11)); + }; + + pRealDriver->OnFatalErrorReportedFunctional = [=](const AuNet::NetError &error) + { + AuLogDbg("[2] On error: {}", NetErrorToExtendedString(error)); + }; + + pRealDriver->OnStreamUpdatedFunctional = [=]() + { + auto pChannel = pRealDriver->pDriverSocket->ToChannel(); + auto pReader = pChannel->AsReadableByteBuffer(); + + AuString message; + message.resize(pReader->RemainingBytes()); + pReader->Read(message.data(), message.size()); + + AuLogDbg("[2] Got: {}", message); + }; + + pRealDriver->OnFinalizeFunctional = [=]() + { + AuResetMember(*pRealDriver.get()); // reset circular dependence on captured pRealDriver + AuLogDbg("[2] Finalize"); + }; + + return pRealDriver; + }; + + auto pServerDriver = AuMakeShared(); + ASSERT_TRUE(bool(pServerDriver)); + + pServerDriver->OnBindFunctional = [&]() + { + AuLogDbg("[1] On bind"); + }; + + pServerDriver->OnFatalErrorReportedFunctional = [&](const AuNet::NetError &error) + { + AuLogDbg("[1] On error: {}", NetErrorToExtendedString(error)); + }; + + pServerDriver->OnFinalizeFunctional = [&]() + { + AuLogDbg("[1] On finalize"); + }; + + AuNet::NetSocketBind nsSocketBind; + nsSocketBind.pDriver = pServerDriver; + nsSocketBind.ip = AuNet::IPAddress("127.0.0.1"); + nsSocketBind.protocol = AuNet::ETransportProtocol::eProtocolUDP; + nsSocketBind.uPort = 8087; + nsSocketBind.pFactory = pSocketFactory; + + auto pSocket = pNetProcessor->GetSocketService()->NewServer(nsSocketBind); + ASSERT_TRUE(bool(pSocket)); + + while (pIoProcessor->HasItems()) + { + pIoProcessor->RunTick(); + } +} + +void RunTests() +{ + Aurora::RuntimeStartInfo info; + info.console.fio.enableLogging = false; + Aurora::RuntimeStart(info); +} \ No newline at end of file diff --git a/Tests/Public/Net. UDP Datagram Service Server/Main.cpp b/Tests/Public/Net. UDP Datagram Service Server/Main.cpp index b7b8411..9500362 100644 --- a/Tests/Public/Net. UDP Datagram Service Server/Main.cpp +++ b/Tests/Public/Net. UDP Datagram Service Server/Main.cpp @@ -24,15 +24,34 @@ TEST(UDP, DatagramServer) auto pDriver = AuMakeShared(); ASSERT_TRUE(bool(pDriver)); + AuSPtr pSocket; + pDriver->OnBindFunctional = []() { AuLogDbg("[UDP] On bind"); }; - pDriver->OnPacketFunctional = [](const AuNet::NetEndpoint &client, - const AuSPtr &pPacket) + pDriver->OnPacketFunctional = [&](const AuNet::NetEndpoint &client, + const AuSPtr &pInboundPacket) { AuLogDbg("[UDP] On packet"); + + struct Packet : AuMemoryViewRead + { + AuByteBuffer buffer; + }; + + auto pPacket = AuMakeSharedPanic(); + pPacket->buffer.Write(0xAAAABBBB); + pPacket->buffer.Write(0x13371337); + pPacket->buffer.Write("Hello World"); + pPacket->buffer.Write(0xAAAABBBB); + pPacket->buffer.Write(0x13371337); + pPacket->buffer.WriteFrom(*pInboundPacket); + pPacket->ptr = pPacket->buffer.readPtr; + pPacket->length = pPacket->buffer.RemainingBytes(); + SysAssert(!pPacket->buffer.flagWriteError); + pSocket->SendPacket(client, pPacket, {}); }; pDriver->OnErrorFunctional = [](const AuNet::NetError &error) @@ -56,7 +75,7 @@ TEST(UDP, DatagramServer) nsDatagramBind.uPort = 8087; nsDatagramBind.pDriver = pDriver; - auto pSocket = pNetProcessor->GetDatagramService()->NewDatagramServer(nsDatagramBind); + pSocket = pNetProcessor->GetDatagramService()->NewDatagramServer(nsDatagramBind); ASSERT_TRUE(bool(pSocket)); while (pIoProcessor->HasItems()) diff --git a/Tests/googletest b/Tests/googletest index 7274ec1..9c33214 160000 --- a/Tests/googletest +++ b/Tests/googletest @@ -1 +1 @@ -Subproject commit 7274ec186442c96e4c7dcc99c684a03e5db2ff48 +Subproject commit 9c332145b71c36a5bad9688312c79184f98601ff diff --git a/Vendor/mbedtls b/Vendor/mbedtls index 13784a5..742439e 160000 --- a/Vendor/mbedtls +++ b/Vendor/mbedtls @@ -1 +1 @@ -Subproject commit 13784a572a40e5f5e756ab325b67655348fd67a8 +Subproject commit 742439e92315ab4185a78a8de6c5a0795ed336d9 diff --git a/Vendor/nlohmannjson b/Vendor/nlohmannjson index 09fb481..a3e6e26 160000 --- a/Vendor/nlohmannjson +++ b/Vendor/nlohmannjson @@ -1 +1 @@ -Subproject commit 09fb4819ff4b35a6ba5d391f87e4e44f25ad6789 +Subproject commit a3e6e26dc83a726b292f5be0492fcc408663ce55 diff --git a/Vendor/o1heap b/Vendor/o1heap index b026aef..f30d520 160000 --- a/Vendor/o1heap +++ b/Vendor/o1heap @@ -1 +1 @@ -Subproject commit b026aef3b155282556b9c88c75398d0054b17bc5 +Subproject commit f30d520343f50d456cdb90089a24d5e9953fc07c diff --git a/Win_x86_x64_NoToolkit.bat b/Win_x86_x64_NoToolkit.bat new file mode 100644 index 0000000..7137a83 --- /dev/null +++ b/Win_x86_x64_NoToolkit.bat @@ -0,0 +1,2 @@ +cd .\Build_Scripts +win_x86.bat %* --target-x86_64 \ No newline at end of file