/* BufferProviderLoad(Test) - cover the interface to a central buffer manager Copyright (C) 2026, Hermann Vosseler   **Lumiera** is free software; you can redistribute it and/or modify it   under the terms of the GNU General Public License as published by the   Free Software Foundation; either version 2 of the License, or (at your   option) any later version. See the file COPYING for further details. * *****************************************************************/ /** @file engine-buffer-manager-test.cpp ** unit test \ref BufferProviderLoad_test */ #include "test/run.hpp" #include "test/test-helper.hpp" #include "vault/mem/buffer-provider-setup.hpp" #include "vault/mem/engine-buffer-metadata.hpp" #include "vault/mem/engine-buffer-manager.hpp" #include "vault/mem/local-buffer-stage.hpp" #include "vault/mem/local-buffer-store.hpp" #include "vault/gear/test-chain-load.hpp" #include "lib/scoped-collection.hpp" #include "lib/depend-inject.hpp" #include "lib/iter-explorer.hpp" #include "lib/sync-barrier.hpp" #include "lib/iter-stack.hpp" #include "lib/thread.hpp" #include "lib/symbol.hpp" #include "lib/random.hpp" #include "test/diagnostic-output.hpp"////////////TODO #include #include #include using lib::explore; using lib::Depend; using lib::DependInject; using lib::Random; using lib::Literal; using lib::Thread; using lib::SyncBarrier; using lib::ScopedCollection; using vault::gear::test::ComputationalLoad; using std::this_thread::yield; using std::this_thread::sleep_for; using std::chrono::microseconds; using std::chrono_literals::operator ""us; using std::chrono_literals::operator ""ms; namespace vault { namespace mem { namespace test { namespace { // Test parameters...... const size_t NUM_THREADS = 100; ///< press concurrently const size_t MAX_SCALE = 5; ///< maximum scale step for randomised resources /** seed a per-thread random generator */ inline Random makeRandGen() { return Random{lib::seedFromDefaultGen()}; } class MultithreadBufferSetup : public BufferProviderSetup { public: MultithreadBufferSetup() : BufferProviderSetup{*this} { } auto buildStage() { return std::make_unique("BufferProviderLoad_test"); } auto buildStore() { return std::make_unique(); } }; using BuffTypes = ScopedCollection; /** * Mock dependency injection context * to emulate a Render Engine setup */ struct Ctx { static Depend bufferProvider; static BuffTypes buffType_; // install mock instances for the relevant services DependInject::Local metaHub; DependInject::Local globalPool; DependInject::Local frontEnd; }; // static storage for the mock-engine entrance point Depend Ctx::bufferProvider; BuffTypes Ctx::buffType_{MAX_SCALE}; } struct WorkSetup { static constexpr uint NUM_JOBS = 10; static constexpr size_t BASE_BUFFSIZ = 100_KiB; /// local random generator per thread Random rand_; ComputationalLoad load_; WorkSetup() : rand_{makeRandGen()} { load_.timeBase = 1ms; load_.sizeBase = BASE_BUFFSIZ; load_.useAllocation = true; } }; /** * Emulation of the load produced by a worker thread */ template class DummyWorkerThread : CONF , public Thread { void workActivity() { for (uint i=0; i