Files
Echoion/tests/ModuleDescriptors.cpp
faumaray 0000c6232f
Modular container CI / release-build (push) Has been cancelled
Signed modular release / publish (push) Successful in 23m44s
Nightly product integration / publish-nightly (push) Successful in 4m20s
Read module test versions from component lock
2026-08-02 02:36:52 +03:00

131 lines
3.9 KiB
C++

#include <echoion/api/module/Module.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <dlfcn.h>
#include <array>
#include <string>
#include <string_view>
namespace
{
struct ModuleExpectation {
const char* path;
std::string_view moduleId;
std::string_view stableComponentId;
std::string_view version;
};
} // namespace
Void::Testing::Test component_module_descriptors_are_loadable()
{
const std::array modules{
ModuleExpectation{
.path = ECHOION_TEST_HOST,
.moduleId = "EchoionHost",
.stableComponentId = "EchoionHost",
.version = ECHOION_TEST_HOST_VERSION,
},
ModuleExpectation{
.path = ECHOION_TEST_CORE,
.moduleId = "EchoionCore",
.stableComponentId = "EchoionCore",
.version = ECHOION_TEST_CORE_VERSION,
},
ModuleExpectation{
.path = ECHOION_TEST_WEB,
.moduleId = "EchoionWeb",
.stableComponentId = "EchoionWeb",
.version = ECHOION_TEST_WEB_VERSION,
},
ModuleExpectation{
.path = ECHOION_TEST_PLUGIN_INTERNAL,
.moduleId = "url-shortener-internal",
.stableComponentId = "EchoionPluginUrlShortenerInternal",
.version = ECHOION_TEST_PLUGIN_INTERNAL_VERSION,
},
ModuleExpectation{
.path = ECHOION_TEST_PLUGIN_EXTERNAL,
.moduleId = "url-shortener-external",
.stableComponentId = "EchoionPluginUrlShortenerExternal",
.version = ECHOION_TEST_PLUGIN_EXTERNAL_VERSION,
},
};
for (const auto& expected : modules) {
void* library = dlopen(expected.path, RTLD_NOW | RTLD_LOCAL);
Void::Testing::expect(library != nullptr);
if (library == nullptr) {
continue;
}
const auto query = reinterpret_cast<Void::Plugin::module_query_fn>(
dlsym(library, Echoion::Api::Module::querySymbol));
Void::Testing::expect(query != nullptr);
if (query == nullptr) {
dlclose(library);
continue;
}
const auto* descriptor = query();
Void::Testing::expect(descriptor != nullptr);
if (descriptor == nullptr) {
dlclose(library);
continue;
}
Void::Testing::expect(descriptor->validate().has_value());
Void::Testing::expect_eq(std::string_view{descriptor->module_id},
expected.moduleId);
Void::Testing::expect_eq(descriptor->component_version.to_string(),
expected.version);
auto module = descriptor->create();
Void::Testing::expect(module != nullptr);
if (module != nullptr) {
Void::Testing::expect_eq(module->name(), expected.moduleId);
}
module.reset();
const auto stableQuery =
reinterpret_cast<echoion_module_abi_query_fn_v1>(
dlsym(library, Echoion::Api::Module::stableQuerySymbol));
Void::Testing::expect(stableQuery != nullptr);
if (stableQuery != nullptr) {
const echoion_module_descriptor_v1* stable = stableQuery();
Void::Testing::expect(stable != nullptr);
if (stable != nullptr) {
Void::Testing::expect_eq(stable->struct_size,
sizeof(echoion_module_descriptor_v1));
Void::Testing::expect_eq(stable->abi_version,
ECHOION_MODULE_ABI_VERSION);
Void::Testing::expect_eq(
std::string_view{stable->component_id.data,
stable->component_id.size},
expected.stableComponentId);
const auto stableVersion =
std::to_string(stable->version_major) + "." +
std::to_string(stable->version_minor) + "." +
std::to_string(stable->version_patch);
Void::Testing::expect_eq(stableVersion, expected.version);
Void::Testing::expect(stable->api != nullptr);
if (stable->api != nullptr) {
Void::Testing::expect_eq(stable->api->struct_size,
sizeof(echoion_module_api_v1));
Void::Testing::expect(stable->api->create != nullptr);
Void::Testing::expect(stable->api->destroy != nullptr);
echoion_module_instance_v1 instance = nullptr;
const auto status = stable->api->create(nullptr, &instance);
Void::Testing::expect_eq(status, ECHOION_STATUS_OK_V1);
Void::Testing::expect(instance != nullptr);
if (instance != nullptr) {
stable->api->destroy(instance);
}
}
}
}
dlclose(library);
}
}