forked from EvergreenCrypto/docker-finance
container: root: macros: add Pluggable support
- Adds requirements to support auto-(un)load'ing, refactors - Adds loader argument to unit tests and benchmarks * Filters can now be passed as a loader argument - Adds loader argument to Hash macro * Factored out from shell caller
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// docker-finance | modern accounting for the power-user
|
||||
//
|
||||
// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||
// Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@@ -61,27 +61,61 @@ class Benchmark
|
||||
|
||||
public:
|
||||
//! \brief Macro for running all benchmarks
|
||||
//! \todo parameter arg that takes list of benchmarks
|
||||
static void run()
|
||||
static void run() { ::benchmark::RunSpecifiedBenchmarks(); }
|
||||
|
||||
public:
|
||||
static constexpr std::initializer_list<std::string_view> m_paths{
|
||||
{"test/benchmark/hash.hh"},
|
||||
{"test/benchmark/random.hh"},
|
||||
{"test/benchmark/utility.hh"}};
|
||||
};
|
||||
|
||||
//! \brief Pluggable entrypoint
|
||||
//! \ingroup cpp_macro_impl
|
||||
//! \since docker-finance 1.1.0
|
||||
class benchmark_C final
|
||||
{
|
||||
public:
|
||||
benchmark_C() = default;
|
||||
~benchmark_C() = default;
|
||||
|
||||
benchmark_C(const benchmark_C&) = default;
|
||||
benchmark_C& operator=(const benchmark_C&) = default;
|
||||
|
||||
benchmark_C(benchmark_C&&) = default;
|
||||
benchmark_C& operator=(benchmark_C&&) = default;
|
||||
|
||||
public:
|
||||
//! \brief Macro auto-loader
|
||||
//! \param arg Optional code to execute after loading
|
||||
static void load(const std::string& arg = {})
|
||||
{
|
||||
static bool loaded{false};
|
||||
static const std::initializer_list<std::string> paths{
|
||||
{"test/benchmark/hash.hh"},
|
||||
{"test/benchmark/random.hh"},
|
||||
{"test/benchmark/utility.hh"}};
|
||||
for (auto path : Benchmark::m_paths)
|
||||
::dfi::common::load(std::string{path});
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
::dfi::common::Command::load(paths);
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
// TODO(unassigned): add argc,argv to macro/function signatures
|
||||
static int argc{1};
|
||||
static const char* argv{"docker-finance"};
|
||||
::benchmark::Initialize(&argc, const_cast<char**>(&argv));
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
|
||||
// NOTE: benchmark filters can only be set via environment
|
||||
// (when calling this macro via `dfi` `root`, as an argument)
|
||||
Benchmark::run();
|
||||
|
||||
if (!arg.empty())
|
||||
::dfi::common::line(arg);
|
||||
}
|
||||
|
||||
//! \brief Macro auto-unloader
|
||||
//! \param arg Optional code to execute before unloading
|
||||
static void unload(const std::string& arg = {})
|
||||
{
|
||||
if (!arg.empty())
|
||||
::dfi::common::line(arg);
|
||||
|
||||
::benchmark::Shutdown();
|
||||
|
||||
for (auto path : Benchmark::m_paths)
|
||||
::dfi::common::unload(std::string{path});
|
||||
}
|
||||
};
|
||||
} // namespace test
|
||||
|
||||
Reference in New Issue
Block a user