1 parent
4a92d09e63
commit
45eb2cab42
12 files changed
+991
-162
No files matched your search
@@ -0,0 +1,97 @@
|
||||
#include "echoion/host/CoreLoader.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
int fail(const char* message)
|
||||
{
|
||||
std::cerr << message << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = std::filesystem::temp_directory_path() /
|
||||
("echoion-core-reload-" + std::to_string(::getpid()));
|
||||
std::filesystem::create_directories(root);
|
||||
const auto cleanup = [&root] {
|
||||
std::error_code ec;
|
||||
std::filesystem::remove_all(root, ec);
|
||||
};
|
||||
|
||||
::setenv("XDG_CONFIG_HOME", root.c_str(), 1);
|
||||
::setenv("XDG_CACHE_HOME", root.c_str(), 1);
|
||||
::setenv("HOME", root.c_str(), 1);
|
||||
const auto ytDlp = root / ".local/share/echoion/yt-dlp/yt-dlp";
|
||||
std::filesystem::create_directories(ytDlp.parent_path());
|
||||
{
|
||||
std::ofstream output{ytDlp};
|
||||
output << "#!/bin/sh\necho 2026.01.01\n";
|
||||
}
|
||||
std::filesystem::permissions(ytDlp,
|
||||
std::filesystem::perms::owner_read |
|
||||
std::filesystem::perms::owner_write |
|
||||
std::filesystem::perms::owner_exec);
|
||||
const auto config = root / "config.json";
|
||||
{
|
||||
std::ofstream output{config};
|
||||
output << R"({
|
||||
"network": {"rpcEnabled": false},
|
||||
"web": {"enabled": false},
|
||||
"features": {"enableAutoUpdateCheck": false},
|
||||
"advanced": {"cacheEnabled": false}
|
||||
})";
|
||||
}
|
||||
|
||||
const auto corePath = root / "Echoion.ts";
|
||||
std::filesystem::copy_file(ECHOION_TEST_CORE_PATH, corePath);
|
||||
|
||||
Echoion::Host::CoreLoader loader;
|
||||
loader.setConfigPath(config);
|
||||
if (auto result = loader.load(corePath); !result) {
|
||||
cleanup();
|
||||
return fail(result.error().message.c_str());
|
||||
}
|
||||
const auto before = loader.getCore();
|
||||
if (!before) {
|
||||
cleanup();
|
||||
return fail("Core missing after initial load");
|
||||
}
|
||||
if (auto result = loader.hotReload(corePath); !result) {
|
||||
cleanup();
|
||||
return fail(result.error().message.c_str());
|
||||
}
|
||||
const auto after = loader.getCore();
|
||||
if (!after || after.get() == before.get()) {
|
||||
cleanup();
|
||||
return fail("Core instance was not transactionally replaced");
|
||||
}
|
||||
|
||||
const auto invalid = root / "Echoion.invalid";
|
||||
{
|
||||
std::ofstream output{invalid, std::ios::binary};
|
||||
output << "not a shared library";
|
||||
}
|
||||
std::filesystem::rename(invalid, corePath);
|
||||
if (auto result = loader.hotReload(corePath); result) {
|
||||
cleanup();
|
||||
return fail("invalid replacement unexpectedly activated");
|
||||
}
|
||||
const auto retained = loader.getCore();
|
||||
if (!retained || retained.get() != after.get() || !retained->isInitialized()) {
|
||||
cleanup();
|
||||
return fail("running Core was not retained after failed activation");
|
||||
}
|
||||
if (auto result = loader.unload(); !result) {
|
||||
cleanup();
|
||||
return fail(result.error().message.c_str());
|
||||
}
|
||||
cleanup();
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user