Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd237207d4 | ||
|
|
20893d1bf3 | ||
|
|
3ef1013b85 | ||
|
|
ff70dc685d | ||
|
|
d95e11ea3e | ||
|
|
531b604154 | ||
|
|
8531bea681 | ||
|
|
68d86f76a2 | ||
|
|
cb58236538 |
No files matched your search
@@ -45,16 +45,17 @@ jobs:
|
|||||||
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build-release -G Ninja \
|
cmake -S . -B build-relwithdebinfo -G Ninja \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||||
-DBUILD_SHARED_LIBS=ON \
|
-DBUILD_SHARED_LIBS=ON \
|
||||||
-DVOID_ENABLE_TESTING=ON \
|
-DVOID_ENABLE_TESTING=ON \
|
||||||
-DVOID_WARNINGS_AS_ERRORS=ON
|
-DVOID_WARNINGS_AS_ERRORS=ON
|
||||||
|
|
||||||
- name: Build and test
|
- name: Build and test
|
||||||
run: |
|
run: |
|
||||||
cmake --build build-release --parallel
|
cmake --build build-relwithdebinfo --config RelWithDebInfo --parallel
|
||||||
ctest --test-dir build-release --output-on-failure
|
ctest --test-dir build-relwithdebinfo \
|
||||||
|
--build-config RelWithDebInfo --output-on-failure
|
||||||
|
|
||||||
- name: Install and package
|
- name: Install and package
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -63,8 +64,11 @@ jobs:
|
|||||||
version="${GITHUB_REF_NAME#v}"
|
version="${GITHUB_REF_NAME#v}"
|
||||||
package="voidlibrary-${version}-linux-x86_64"
|
package="voidlibrary-${version}-linux-x86_64"
|
||||||
epoch="$(git show -s --format=%ct HEAD)"
|
epoch="$(git show -s --format=%ct HEAD)"
|
||||||
cmake --install build-release \
|
cmake --install build-relwithdebinfo \
|
||||||
|
--config RelWithDebInfo \
|
||||||
--prefix "$PWD/stage/$package"
|
--prefix "$PWD/stage/$package"
|
||||||
|
python3 .release-tools/scripts/verify-relwithdebinfo.py \
|
||||||
|
--root "$PWD/stage/$package"
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
SOURCE_DATE_EPOCH="$epoch" \
|
SOURCE_DATE_EPOCH="$epoch" \
|
||||||
tar --sort=name --mtime="@$epoch" \
|
tar --sort=name --mtime="@$epoch" \
|
||||||
@@ -78,7 +82,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Publish native Gitea release
|
- name: Publish native Gitea release
|
||||||
env:
|
env:
|
||||||
GITEA_RELEASE_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_RELEASE_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
python3 .release-tools/scripts/gitea_release.py \
|
python3 .release-tools/scripts/gitea_release.py \
|
||||||
--api-url "${{ gitea.api_url }}" \
|
--api-url "${{ gitea.api_url }}" \
|
||||||
|
|||||||
+46
-1
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 4.0.0)
|
cmake_minimum_required(VERSION 4.0.0)
|
||||||
project(Void VERSION 1.0.0 LANGUAGES CXX)
|
project(Void VERSION 1.2.1 LANGUAGES CXX)
|
||||||
if(PROJECT_IS_TOP_LEVEL)
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
option(BUILD_SHARED_LIBS "Build Void modules as shared libraries" ON)
|
option(BUILD_SHARED_LIBS "Build Void modules as shared libraries" ON)
|
||||||
elseif(NOT DEFINED BUILD_SHARED_LIBS)
|
elseif(NOT DEFINED BUILD_SHARED_LIBS)
|
||||||
@@ -30,8 +30,47 @@ set(EXPORT_SET_NAME ${PROJECT_NAME}Targets)
|
|||||||
|
|
||||||
include(cmake/Module.cmake)
|
include(cmake/Module.cmake)
|
||||||
|
|
||||||
|
# Modules to configure, with the modules they need (INTERNAL_DEPS, followed
|
||||||
|
# transitively); empty configures every module. OPTIONAL_DEPS are used only
|
||||||
|
# when named too. A project that embeds Void selects what it links, so the
|
||||||
|
# external packages of modules it never builds (LibArchive, OpenSSL, SQLite,
|
||||||
|
# libsodium) need not exist, as when cross-compiling.
|
||||||
|
set(VOID_ENABLED_MODULES "" CACHE STRING
|
||||||
|
"Void modules to configure (and their internal dependencies); empty for all")
|
||||||
|
set(_void_selected "")
|
||||||
|
if(VOID_ENABLED_MODULES)
|
||||||
|
set(_void_pending ${VOID_ENABLED_MODULES})
|
||||||
|
while(_void_pending)
|
||||||
|
list(POP_FRONT _void_pending _void_module)
|
||||||
|
if(_void_module IN_LIST _void_selected)
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
set(_void_module_file "${CMAKE_CURRENT_SOURCE_DIR}/src/${_void_module}/module.cmake")
|
||||||
|
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/${_void_module}")
|
||||||
|
message(FATAL_ERROR "[Void] VOID_ENABLED_MODULES names an unknown module '${_void_module}'")
|
||||||
|
endif()
|
||||||
|
list(APPEND _void_selected ${_void_module})
|
||||||
|
if(EXISTS "${_void_module_file}")
|
||||||
|
file(READ "${_void_module_file}" _void_text)
|
||||||
|
# The words after INTERNAL_DEPS up to the next keyword or ')'.
|
||||||
|
if(_void_text MATCHES "INTERNAL_DEPS([^)]*)")
|
||||||
|
separate_arguments(_void_words UNIX_COMMAND "${CMAKE_MATCH_1}")
|
||||||
|
foreach(_void_word IN LISTS _void_words)
|
||||||
|
if(_void_word MATCHES "^[A-Z0-9_]+$")
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
list(APPEND _void_pending ${_void_word})
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endwhile()
|
||||||
|
endif()
|
||||||
|
|
||||||
file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/*)
|
file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/*)
|
||||||
foreach(module_path ${children})
|
foreach(module_path ${children})
|
||||||
|
if(_void_selected AND NOT module_path IN_LIST _void_selected)
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/${module_path})
|
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/${module_path})
|
||||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/${module_path}/module.cmake)
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/${module_path}/module.cmake)
|
||||||
include(src/${module_path}/module.cmake)
|
include(src/${module_path}/module.cmake)
|
||||||
@@ -71,6 +110,12 @@ configure_package_config_file(
|
|||||||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Support headers shared by several modules (e.g. Void/Detail/Enum.hpp, used by
|
||||||
|
# Core, Log, Configuration and Data). They belong to no module's FILE_SET, so
|
||||||
|
# they are installed here; every module's install include dir covers them.
|
||||||
|
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/Void/Detail"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/Void")
|
||||||
|
|
||||||
install(EXPORT ${EXPORT_SET_NAME}
|
install(EXPORT ${EXPORT_SET_NAME}
|
||||||
NAMESPACE ${PROJECT_NAME}::
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
||||||
|
|||||||
@@ -13,10 +13,11 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
// ── Void::Log — the emission facade
|
// ── Void::Log — the emission facade
|
||||||
// ─────────────────────────────────────────── Header-only so every module
|
// ─────────────────────────────────────────── Header-only apart from its
|
||||||
// (including INTERFACE libraries) can log with zero link dependencies. The full
|
// state, which Void::LogState (a small library with no dependencies) holds
|
||||||
// sink framework lives in Void::Logging (Logger.hpp); bridge with
|
// once per process, so every module (including INTERFACE libraries) can log by
|
||||||
// Void/Log/LoggingAdapter.hpp.
|
// linking only that. The full sink framework lives in Void::Logging
|
||||||
|
// (Logger.hpp); bridge with Void/Log/LoggingAdapter.hpp.
|
||||||
//
|
//
|
||||||
// Integration contract:
|
// Integration contract:
|
||||||
// * No sink installed (the default) — every call is a single relaxed
|
// * No sink installed (the default) — every call is a single relaxed
|
||||||
@@ -85,11 +86,9 @@ namespace Void::Log
|
|||||||
std::shared_mutex mutex;
|
std::shared_mutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline State& state()
|
// The process's one State, defined in Void::LogState (a static in an
|
||||||
{
|
// inline function would be one per DLL on Windows).
|
||||||
static State s;
|
State& state();
|
||||||
return s;
|
|
||||||
}
|
|
||||||
} // namespace Detail
|
} // namespace Detail
|
||||||
|
|
||||||
/// Install the global sink. Any previously installed sink is replaced.
|
/// Install the global sink. Any previously installed sink is replaced.
|
||||||
|
|||||||
@@ -22,9 +22,8 @@ namespace Void::Logging
|
|||||||
/// to the per-level files.
|
/// to the per-level files.
|
||||||
bool combined = true;
|
bool combined = true;
|
||||||
std::size_t max_bytes = 1024 * 1024;
|
std::size_t max_bytes = 1024 * 1024;
|
||||||
/// Unused. Rotation here is a synchronized, unbounded history
|
/// Maximum number of synchronized history snapshots retained.
|
||||||
/// (see class comment) rather than a max_files-bounded rotation,
|
/// Zero removes a snapshot immediately after rotation.
|
||||||
/// so this has no effect — kept only for API compatibility.
|
|
||||||
std::size_t max_files = 5;
|
std::size_t max_files = 5;
|
||||||
Mode mode = Mode::Async;
|
Mode mode = Mode::Async;
|
||||||
std::size_t capacity = 512;
|
std::size_t capacity = 512;
|
||||||
@@ -43,8 +42,8 @@ namespace Void::Logging
|
|||||||
/// ones well under the limit) is moved, under its own name unchanged,
|
/// ones well under the limit) is moved, under its own name unchanged,
|
||||||
/// into `<dir>/history/<creation_time>/`, where `<creation_time>`
|
/// into `<dir>/history/<creation_time>/`, where `<creation_time>`
|
||||||
/// marks when this batch of files started filling up. Fresh, empty
|
/// marks when this batch of files started filling up. Fresh, empty
|
||||||
/// files then continue at their usual paths. Every snapshot is kept
|
/// files then continue at their usual paths. The oldest snapshots are
|
||||||
/// indefinitely — see SplitFileOptions::max_files.
|
/// pruned so at most SplitFileOptions::max_files remain.
|
||||||
class SplitFileLogger final : public Logger
|
class SplitFileLogger final : public Logger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -91,6 +90,7 @@ namespace Void::Logging
|
|||||||
/// owned file into a shared history/<creation_time> snapshot
|
/// owned file into a shared history/<creation_time> snapshot
|
||||||
/// directory and start each one fresh.
|
/// directory and start each one fresh.
|
||||||
void maybe_rotate_group();
|
void maybe_rotate_group();
|
||||||
|
void prune_history();
|
||||||
|
|
||||||
std::filesystem::path m_dir;
|
std::filesystem::path m_dir;
|
||||||
Options m_options;
|
Options m_options;
|
||||||
|
|||||||
@@ -95,6 +95,13 @@ namespace Void::Plugin
|
|||||||
// publication. A failed validation aborts load/reload
|
// publication. A failed validation aborts load/reload
|
||||||
// transactionally.
|
// transactionally.
|
||||||
std::function<bool(IPlugin&, const PluginInfo&)> instance_validator;
|
std::function<bool(IPlugin&, const PluginInfo&)> instance_validator;
|
||||||
|
// Binary-level contract checked immediately after the shared object
|
||||||
|
// is opened and identified, before configuration, activation, state
|
||||||
|
// transfer, or publication. Hosts can inspect optional exported
|
||||||
|
// symbols through the pinned handle. A rejection is transactional:
|
||||||
|
// initial loads are discarded and reloads keep the current
|
||||||
|
// instance.
|
||||||
|
std::function<bool(const PluginHandle&)> candidate_validator;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Identifies an on_reloaded observer for remove_on_reloaded.
|
// Identifies an on_reloaded observer for remove_on_reloaded.
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
void_add_module(Async)
|
void_add_module(Async
|
||||||
|
INTERNAL_DEPS LogState
|
||||||
|
)
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
#include <Void/Log/SplitFileLogger.hpp>
|
#include <Void/Log/SplitFileLogger.hpp>
|
||||||
#include <Void/Log/Log.hpp>
|
#include <Void/Log/Log.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Void::Logging
|
namespace Void::Logging
|
||||||
{
|
{
|
||||||
@@ -35,7 +37,7 @@ namespace Void::Logging
|
|||||||
}
|
}
|
||||||
if (m_options.combined) {
|
if (m_options.combined) {
|
||||||
m_combined = std::make_unique<Detail::RollingFile>(
|
m_combined = std::make_unique<Detail::RollingFile>(
|
||||||
m_dir / "trace.log",
|
m_dir / "all.log",
|
||||||
Detail::RollingFileOptions{m_options.max_bytes,
|
Detail::RollingFileOptions{m_options.max_bytes,
|
||||||
m_options.max_files},
|
m_options.max_files},
|
||||||
/*self_rotate=*/false);
|
/*self_rotate=*/false);
|
||||||
@@ -113,6 +115,36 @@ namespace Void::Logging
|
|||||||
m_combined->snapshot_into(snapshot_dir);
|
m_combined->snapshot_into(snapshot_dir);
|
||||||
}
|
}
|
||||||
m_epoch_start = std::chrono::system_clock::now();
|
m_epoch_start = std::chrono::system_clock::now();
|
||||||
|
prune_history();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplitFileLogger::prune_history()
|
||||||
|
{
|
||||||
|
const auto history_dir = m_dir / "history";
|
||||||
|
std::error_code ec;
|
||||||
|
if (!std::filesystem::exists(history_dir, ec) || ec) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::filesystem::path> snapshots;
|
||||||
|
for (std::filesystem::directory_iterator it{history_dir, ec}, end;
|
||||||
|
!ec && it != end; it.increment(ec)) {
|
||||||
|
if (it->is_directory(ec) && !ec) {
|
||||||
|
snapshots.push_back(it->path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ec) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ranges::sort(snapshots);
|
||||||
|
while (snapshots.size() > m_options.max_files) {
|
||||||
|
std::filesystem::remove_all(snapshots.front(), ec);
|
||||||
|
if (ec) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
snapshots.erase(snapshots.begin());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplitFileLogger::write(const Entry& entry)
|
void SplitFileLogger::write(const Entry& entry)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// The Void::Log facade's one state per process. Compiled into its own small
|
||||||
|
// library rather than an inline function's static: Windows gives every DLL
|
||||||
|
// that inlines a function its own static, so a sink set in one DLL would
|
||||||
|
// never see the events of another. Every module that includes
|
||||||
|
// <Void/Log/Log.hpp> links this (it has no dependencies of its own).
|
||||||
|
#include <Void/Log/Log.hpp>
|
||||||
|
|
||||||
|
namespace Void::Log::Detail
|
||||||
|
{
|
||||||
|
State& state()
|
||||||
|
{
|
||||||
|
static State s;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
} // namespace Void::Log::Detail
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
void_add_module(LogState)
|
||||||
@@ -254,6 +254,13 @@ namespace Void::Plugin
|
|||||||
return std::unexpected{inst.error()};
|
return std::unexpected{inst.error()};
|
||||||
}
|
}
|
||||||
std::string name{(*inst)->plugin->name()};
|
std::string name{(*inst)->plugin->name()};
|
||||||
|
if (m_options.candidate_validator &&
|
||||||
|
!m_options.candidate_validator(PluginHandle{*inst})) {
|
||||||
|
Void::Log::warn("Plugin.Manager",
|
||||||
|
"load '{}' aborted: binary validation failed",
|
||||||
|
name);
|
||||||
|
return std::unexpected{LoadError::ActivationFailed};
|
||||||
|
}
|
||||||
if (m_options.config_provider && (*inst)->configure != nullptr) {
|
if (m_options.config_provider && (*inst)->configure != nullptr) {
|
||||||
const std::string config = m_options.config_provider(name);
|
const std::string config = m_options.config_provider(name);
|
||||||
(*inst)->configure((*inst)->plugin, config.c_str());
|
(*inst)->configure((*inst)->plugin, config.c_str());
|
||||||
@@ -425,6 +432,13 @@ namespace Void::Plugin
|
|||||||
name, (*next)->plugin->name());
|
name, (*next)->plugin->name());
|
||||||
return std::unexpected{LoadError::NameMismatch};
|
return std::unexpected{LoadError::NameMismatch};
|
||||||
}
|
}
|
||||||
|
if (m_options.candidate_validator &&
|
||||||
|
!m_options.candidate_validator(PluginHandle{*next})) {
|
||||||
|
Void::Log::warn("Plugin.Manager",
|
||||||
|
"reload '{}' aborted: binary validation failed",
|
||||||
|
name);
|
||||||
|
return std::unexpected{LoadError::ActivationFailed};
|
||||||
|
}
|
||||||
|
|
||||||
if (m_options.config_provider && (*next)->configure != nullptr) {
|
if (m_options.config_provider && (*next)->configure != nullptr) {
|
||||||
const std::string config = m_options.config_provider(name);
|
const std::string config = m_options.config_provider(name);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
void_add_module(Stacktrace
|
void_add_module(Stacktrace
|
||||||
INTERNAL_DEPS Functional
|
INTERNAL_DEPS Functional LogState
|
||||||
EXTERNAL_DEPS ${_void_stacktrace_target}
|
EXTERNAL_DEPS ${_void_stacktrace_target}
|
||||||
DEPS_UNIX dl
|
DEPS_UNIX dl
|
||||||
OPTIONS_UNIX -g -fno-omit-frame-pointer
|
OPTIONS_UNIX -g -fno-omit-frame-pointer
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
void_add_module(System
|
void_add_module(System
|
||||||
INTERNAL_DEPS Functional
|
INTERNAL_DEPS Functional LogState
|
||||||
EXTERNAL_DEPS Threads::Threads
|
EXTERNAL_DEPS Threads::Threads
|
||||||
)
|
)
|
||||||
@@ -47,18 +47,27 @@ static void crash_handler(int sig) {
|
|||||||
|
|
||||||
void install_signal_handlers(CrashCallback on_crash) {
|
void install_signal_handlers(CrashCallback on_crash) {
|
||||||
g_crash_callback = std::move(on_crash);
|
g_crash_callback = std::move(on_crash);
|
||||||
|
#ifdef _WIN32
|
||||||
|
// No sigaction on Windows: the C runtime's signal() covers these four.
|
||||||
|
std::signal(SIGSEGV, crash_handler); std::signal(SIGABRT, crash_handler); std::signal(SIGFPE, crash_handler); std::signal(SIGILL, crash_handler);
|
||||||
|
#else
|
||||||
struct sigaction sa{}; sa.sa_handler = crash_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0;
|
struct sigaction sa{}; sa.sa_handler = crash_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0;
|
||||||
sigaction(SIGSEGV, &sa, nullptr); sigaction(SIGABRT, &sa, nullptr); sigaction(SIGFPE, &sa, nullptr); sigaction(SIGILL, &sa, nullptr);
|
sigaction(SIGSEGV, &sa, nullptr); sigaction(SIGABRT, &sa, nullptr); sigaction(SIGFPE, &sa, nullptr); sigaction(SIGILL, &sa, nullptr);
|
||||||
#ifdef SIGBUS
|
#ifdef SIGBUS
|
||||||
sigaction(SIGBUS, &sa, nullptr);
|
sigaction(SIGBUS, &sa, nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninstall_signal_handlers() {
|
void uninstall_signal_handlers() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::signal(SIGSEGV, SIG_DFL); std::signal(SIGABRT, SIG_DFL); std::signal(SIGFPE, SIG_DFL); std::signal(SIGILL, SIG_DFL);
|
||||||
|
#else
|
||||||
struct sigaction sa{}; sa.sa_handler = SIG_DFL;
|
struct sigaction sa{}; sa.sa_handler = SIG_DFL;
|
||||||
sigaction(SIGSEGV, &sa, nullptr); sigaction(SIGABRT, &sa, nullptr); sigaction(SIGFPE, &sa, nullptr); sigaction(SIGILL, &sa, nullptr);
|
sigaction(SIGSEGV, &sa, nullptr); sigaction(SIGABRT, &sa, nullptr); sigaction(SIGFPE, &sa, nullptr); sigaction(SIGILL, &sa, nullptr);
|
||||||
#ifdef SIGBUS
|
#ifdef SIGBUS
|
||||||
sigaction(SIGBUS, &sa, nullptr);
|
sigaction(SIGBUS, &sa, nullptr);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
g_crash_callback = nullptr;
|
g_crash_callback = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
void_add_module(Testing
|
void_add_module(Testing
|
||||||
|
INTERNAL_DEPS LogState
|
||||||
OPTIONAL_DEPS Stacktrace Log Async Configuration Text
|
OPTIONAL_DEPS Stacktrace Log Async Configuration Text
|
||||||
)
|
)
|
||||||
+30
-3
@@ -34,6 +34,10 @@ namespace Void::Update
|
|||||||
{
|
{
|
||||||
return value.is_array();
|
return value.is_array();
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] bool is_object(const Json::Value& value) noexcept
|
||||||
|
{
|
||||||
|
return value.is_object();
|
||||||
|
}
|
||||||
[[nodiscard]] bool is_string(const Json::Value& value) noexcept
|
[[nodiscard]] bool is_string(const Json::Value& value) noexcept
|
||||||
{
|
{
|
||||||
return value.is_string();
|
return value.is_string();
|
||||||
@@ -639,10 +643,24 @@ namespace Void::Update
|
|||||||
auto schema =
|
auto schema =
|
||||||
unsigned_number<std::uint32_t>(*envelope, "schemaVersion");
|
unsigned_number<std::uint32_t>(*envelope, "schemaVersion");
|
||||||
auto keyId = string_member(*envelope, "keyId");
|
auto keyId = string_member(*envelope, "keyId");
|
||||||
auto payloadText = string_member(*envelope, "payload");
|
|
||||||
auto signatureText = string_member(*envelope, "signature");
|
auto signatureText = string_member(*envelope, "signature");
|
||||||
if (!schema || !keyId || !payloadText || !signatureText ||
|
if (!schema || !keyId || !signatureText ||
|
||||||
(*schema != 1 && *schema != 2) || !valid_token(*keyId, 256)) {
|
(*schema != 1 && *schema != 2 && *schema != 3) ||
|
||||||
|
!valid_token(*keyId, 256)) {
|
||||||
|
return Void::Result::fail("Update feed: invalid envelope fields");
|
||||||
|
}
|
||||||
|
auto payloadText = string_member(
|
||||||
|
*envelope, *schema == 3 ? "signedPayload" : "payload");
|
||||||
|
const Json::Value* displayedDocument = nullptr;
|
||||||
|
if (*schema == 3) {
|
||||||
|
auto document =
|
||||||
|
member(*envelope, "document", is_object, "an object");
|
||||||
|
if (!document) {
|
||||||
|
return std::unexpected{document.error()};
|
||||||
|
}
|
||||||
|
displayedDocument = *document;
|
||||||
|
}
|
||||||
|
if (!payloadText) {
|
||||||
return Void::Result::fail("Update feed: invalid envelope fields");
|
return Void::Result::fail("Update feed: invalid envelope fields");
|
||||||
}
|
}
|
||||||
const auto key = keys.find(*keyId);
|
const auto key = keys.find(*keyId);
|
||||||
@@ -657,6 +675,15 @@ namespace Void::Update
|
|||||||
return Void::Result::fail(
|
return Void::Result::fail(
|
||||||
"Update feed: invalid or oversized envelope encoding");
|
"Update feed: invalid or oversized envelope encoding");
|
||||||
}
|
}
|
||||||
|
if (*schema == 3) {
|
||||||
|
auto signedDocument = Json::parse(*payload);
|
||||||
|
if (!signedDocument || !signedDocument->is_object() ||
|
||||||
|
displayedDocument == nullptr ||
|
||||||
|
*displayedDocument != *signedDocument) {
|
||||||
|
return Void::Result::fail("Update feed: readable document "
|
||||||
|
"differs from signed payload");
|
||||||
|
}
|
||||||
|
}
|
||||||
const auto signatureBytes =
|
const auto signatureBytes =
|
||||||
std::as_bytes(std::span{signature->data(), signature->size()});
|
std::as_bytes(std::span{signature->data(), signature->size()});
|
||||||
const auto payloadBytes =
|
const auto payloadBytes =
|
||||||
|
|||||||
@@ -38,6 +38,19 @@ namespace
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t snapshot_count(const std::filesystem::path& dir)
|
||||||
|
{
|
||||||
|
const auto history = dir / "history";
|
||||||
|
if (!std::filesystem::exists(history)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
std::size_t count = 0;
|
||||||
|
for (const auto& entry : std::filesystem::directory_iterator(history)) {
|
||||||
|
count += entry.is_directory() ? 1U : 0U;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class SplitFileLoggerTests : public Void::Testing::Fixture
|
class SplitFileLoggerTests : public Void::Testing::Fixture
|
||||||
@@ -81,7 +94,7 @@ class SplitFileLoggerTests : public Void::Testing::Fixture
|
|||||||
log.info("info one");
|
log.info("info one");
|
||||||
log.error("error one");
|
log.error("error one");
|
||||||
}
|
}
|
||||||
const auto all = slurp(dir / "trace.log");
|
const auto all = slurp(dir / "all.log");
|
||||||
Void::Testing::expect(all.find("info one") != std::string::npos);
|
Void::Testing::expect(all.find("info one") != std::string::npos);
|
||||||
Void::Testing::expect(all.find("error one") != std::string::npos);
|
Void::Testing::expect(all.find("error one") != std::string::npos);
|
||||||
}
|
}
|
||||||
@@ -94,9 +107,24 @@ class SplitFileLoggerTests : public Void::Testing::Fixture
|
|||||||
.mode = Void::Logging::Mode::Immediate}};
|
.mode = Void::Logging::Mode::Immediate}};
|
||||||
log.info("solo");
|
log.info("solo");
|
||||||
}
|
}
|
||||||
Void::Testing::expect(!std::filesystem::exists(dir / "trace.log"));
|
Void::Testing::expect(!std::filesystem::exists(dir / "all.log"));
|
||||||
Void::Testing::expect(std::filesystem::exists(dir / "info.log"));
|
Void::Testing::expect(std::filesystem::exists(dir / "info.log"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test bounds_synchronized_history()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
SplitFileLogger log{dir,
|
||||||
|
{.max_bytes = 32,
|
||||||
|
.max_files = 2,
|
||||||
|
.mode = Void::Logging::Mode::Immediate}};
|
||||||
|
for (int i = 0; i < 20; ++i) {
|
||||||
|
log.info("rotation payload " + std::to_string(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Void::Testing::expect(snapshot_count(dir) >= 1);
|
||||||
|
Void::Testing::expect(snapshot_count(dir) <= 2);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class HistoryLoggerTests : public Void::Testing::Fixture
|
class HistoryLoggerTests : public Void::Testing::Fixture
|
||||||
|
|||||||
@@ -61,6 +61,41 @@ Void::Testing::Test manager_unknown_plugin_yields_empty_handle()
|
|||||||
LoadError::UnknownPlugin);
|
LoadError::UnknownPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test manager_candidate_validator_rejects_initial_load()
|
||||||
|
{
|
||||||
|
int validations = 0;
|
||||||
|
PluginManager manager{
|
||||||
|
{.candidate_validator = [&](const PluginHandle& candidate) {
|
||||||
|
++validations;
|
||||||
|
Void::Testing::expect(static_cast<bool>(candidate));
|
||||||
|
Void::Testing::expect(candidate.raw_symbol(kInfoSymbol) != nullptr);
|
||||||
|
return false;
|
||||||
|
}}};
|
||||||
|
const auto loaded = manager.load(VOID_STATEFUL_V1_PATH);
|
||||||
|
Void::Testing::expect(!loaded.has_value());
|
||||||
|
Void::Testing::expect(loaded.error() == LoadError::ActivationFailed);
|
||||||
|
Void::Testing::expect_eq(validations, 1);
|
||||||
|
Void::Testing::expect(!manager.acquire("StatefulPlugin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test manager_candidate_validator_rejects_reload_transactionally()
|
||||||
|
{
|
||||||
|
bool accept = true;
|
||||||
|
PluginManager manager{
|
||||||
|
{.candidate_validator = [&](const PluginHandle&) { return accept; }}};
|
||||||
|
Void::Testing::require(manager.load(VOID_STATEFUL_V1_PATH).has_value());
|
||||||
|
auto before = manager.acquire("StatefulPlugin");
|
||||||
|
stateful(before)->bump();
|
||||||
|
accept = false;
|
||||||
|
const auto replaced =
|
||||||
|
manager.replace("StatefulPlugin", VOID_STATEFUL_V2_PATH);
|
||||||
|
Void::Testing::expect(!replaced.has_value());
|
||||||
|
Void::Testing::expect(replaced.error() == LoadError::ActivationFailed);
|
||||||
|
auto after = manager.acquire("StatefulPlugin");
|
||||||
|
Void::Testing::expect_eq(stateful(after)->schema_version(), 1);
|
||||||
|
Void::Testing::expect_eq(stateful(after)->counter(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
Void::Testing::Test manager_reload_migrates_v1_state_to_v2()
|
Void::Testing::Test manager_reload_migrates_v1_state_to_v2()
|
||||||
{
|
{
|
||||||
// Copy v1 into a temp path we control, then overwrite with v2 and
|
// Copy v1 into a temp path we control, then overwrite with v2 and
|
||||||
|
|||||||
@@ -101,6 +101,16 @@ namespace
|
|||||||
Void::Encoding::Base64::encode_url(sign(message)));
|
Void::Encoding::Base64::encode_url(sign(message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string signedReadableEnvelope(std::string_view message)
|
||||||
|
{
|
||||||
|
return std::format(
|
||||||
|
"{{\n \"schemaVersion\": 3,\n \"keyId\": \"test-key\",\n"
|
||||||
|
" \"document\": {},\n \"signedPayload\": \"{}\",\n"
|
||||||
|
" \"signature\": \"{}\"\n}}",
|
||||||
|
message, Void::Encoding::Base64::encode_url(message),
|
||||||
|
Void::Encoding::Base64::encode_url(sign(message)));
|
||||||
|
}
|
||||||
|
|
||||||
constexpr std::string_view componentCatalogPayload = R"json({
|
constexpr std::string_view componentCatalogPayload = R"json({
|
||||||
"schemaVersion": 2,
|
"schemaVersion": 2,
|
||||||
"document": "echoion-component-catalog",
|
"document": "echoion-component-catalog",
|
||||||
@@ -270,6 +280,24 @@ Void::Testing::Test component_feed_verifies_and_resolves_complete_set()
|
|||||||
!Void::Update::validateComponentSet(*catalog, releases).has_value());
|
!Void::Update::validateComponentSet(*catalog, releases).has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test readable_component_envelope_matches_signed_payload()
|
||||||
|
{
|
||||||
|
auto envelope = Void::Update::verifyEnvelope(
|
||||||
|
signedReadableEnvelope(componentCatalogPayload), keyring());
|
||||||
|
Void::Testing::require(envelope.has_value());
|
||||||
|
Void::Testing::expect_eq(envelope->schemaVersion, std::uint32_t{3});
|
||||||
|
Void::Testing::expect_eq(envelope->signedPayload,
|
||||||
|
std::string{componentCatalogPayload});
|
||||||
|
|
||||||
|
auto tampered = signedReadableEnvelope(componentCatalogPayload);
|
||||||
|
const auto position = tampered.find("\"sequence\": 11");
|
||||||
|
Void::Testing::require(position != std::string::npos);
|
||||||
|
tampered.replace(position, std::string{"\"sequence\": 11"}.size(),
|
||||||
|
"\"sequence\": 12");
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Update::verifyEnvelope(tampered, keyring()).has_value());
|
||||||
|
}
|
||||||
|
|
||||||
Void::Testing::Test update_feed_rejects_empty_fractional_timestamp()
|
Void::Testing::Test update_feed_rejects_empty_fractional_timestamp()
|
||||||
{
|
{
|
||||||
std::string malformed{payload};
|
std::string malformed{payload};
|
||||||
|
|||||||
Reference in new issue
Block a user