36#ifdef _UTILS_TEST_MAIN_HXX_
37#error Only ever include test_main into the main unittest file.
39#define _UTILS_TEST_MAIN_HXX_
48#include "gtest/gtest.h"
49#include "gmock/gmock.h"
60#include <gperftools/profiler.h>
62std::function<void()> profiler_enable{&ProfilerEnable};
63std::function<void()> profiler_disable{&ProfilerDisable};
68 testing::InitGoogleMock(&argc, argv);
69 return RUN_ALL_TESTS();
72bool mute_log_output =
false;
76 if (size <= 0 || mute_log_output)
return;
77 fwrite(buf, size, 1, stderr);
78 fwrite(
"\n", 1, 1, stderr);
90void os_emscripten_yield() {
116 guard->wait_for_notification();
186 std::function<void()> fn_;
218#define RX(statement) run_x([&](){ statement; })
251template <
class T,
typename... Args>
255 auto ret = std::make_unique<PendingInvocation<T>>();
256 ret->b.reset(flow->alloc());
257 ret->b->data()->reset(std::forward<Args>(args)...);
258 ret->b->data()->done.reset(&ret->barrier);
259 flow->send(ret->b->ref());
295#ifndef __EMSCRIPTEN__
310#ifndef __EMSCRIPTEN__
341 template <
class T,
typename U>
376 *variable = new_value;
403 if (
'0' <= n && n <=
'9')
407 if (
'a' <= n && n <=
'f')
411 if (
'A' <= n && n <=
'F')
415 DIE(
"Unknown nibble arrived.");
425 while (*hex && *(hex + 1))
438const char HEXCHR[17] =
"0123456789abcdef";
450 ret.push_back(HEXCHR[c >> 4]);
451 ret.push_back(HEXCHR[c & 0xf]);
AutoReleaseBuffer< T > BufferPtr
Smart pointer for buffers.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
Utility class to block an executor for a while.
BlockExecutor(ExecutorBase *e)
Creates a block against executor e and waits until the block suceeds.
void wait_for_blocked()
Blocks the current thread until the BlockExecutor manages to block the executor it was scheduled on.
void release_block()
Releases the executor that was blocked.
SyncNotifiable n_
notified (from the executor thread) when the block gets in place.
SyncNotifiable m_
notified (from the test/operator thread) to release the block.
virtual void run()
Entry point.
Base class for all QMember types that hold data in an expandable format.
An object that can be scheduled on an executor to run.
Utility class to help running a "pthread"-like thread in the main executor.
thread_fn_t * fn_
pointer to function to run.
void * arg_
argument to pass to function.
ExecuteOnMainExecutor(thread_fn_t *fn, void *arg)
Schedules the function fn with argument arg on the main executor.
void run() OVERRIDE
Runs the intended function with the given argument and then deletes this when done.
void * thread_fn_t(void *)
Function type for a thread's main entry point.
This class implements an execution of tasks pulled off an input queue.
void sync_run(std::function< void()> fn)
Synchronously runs a closure on this executor.
ActiveTimers * active_timers()
virtual void add(Executable *action, unsigned priority=UINT_MAX)=0
Send a message to this Executor's queue.
bool loop_once()
Performs one loop of the execution on the calling thread.
This class can be given an executor, and will notify itself when that executor is out of work.
Fixes race condition between test teardown and executor startup.
Implementation the ExecutorBase with a specific number of priority bands.
void add(Executable *msg, unsigned priority=UINT_MAX) OVERRIDE
Send a message to this Executor's queue.
Abstract class for message recipients.
Helper class to run a lambda in the main executor.
void run() OVERRIDE
Entry point.
Runs some code in the constructor on the main executor.
Runs some code in the constructor.
Virtual base class for the destructible holders.
Type-accurate class that holds the temporary variable with the old value, the pointer to the variable...
T * variable_
Points to the variable that needs resetting.
T oldValue_
old value to reset variable_ to when destroyed.
Holder(T *variable, T new_value)
Overrides the value of a variable and restores it to the original value when destructed.
void restore()
Restores the original value.
std::unique_ptr< HolderBase > holder_
Smart ptr that will reset the variable to the previous value when going out of scope.
ScopedOverride(T *variable, U new_value)
Constructor.
Collection of related state machines that pend on incoming messages.
A Notifiable for synchronously waiting for a notification.
void notify() override
Implementation of notification receive.
void wait_for_notification()
Blocks the current thread until the notification is delivered.
#define OVERRIDE_CONST(name, value)
Overrides the value of a constant.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define DIE(MSG)
Unconditionally terminates the current process with a message.
Structure holding returned objects for an invoke_flow_nowait command.
BufferPtr< T > b
Buffer sent to the flow.
SyncNotifiable notifiable
Notifiable to wait for.
bool isWaited
True if wait has been invoked.
BarrierNotifiable barrier
Barrier notifiable given to the buffer.
void wait_for_main_executor()
Blocks the current thread until the main executor has run out of work.
int nibble_to_int(char n)
Converts a character containing a hex digit to the value of that digit.
class ExecutorStartupFix unused_executor_startup_guard_instance
actual instance.
std::unique_ptr< PendingInvocation< T > > invoke_flow_nowait(FlowInterface< Buffer< T > > *flow, Args &&...args)
Executes a callable flow similar to invoke_flow(...) but does not wait for the result to come back.
int appl_main(int argc, char *argv[])
Entry point to application.
Executor< 1 > g_executor
Global executor thread for tests.
void run_x(std::function< void()> fn)
Synchronously runs a function in the main executor.
std::string hex2str(const char *hex)
Converts a hex string into the respective byte string.
void log_output(char *buf, int size)
Prints a line of log to the log output destination.
std::string str2hex(const string &s)
Converts a byte string into the hexadecimal representation, with no separators.
void wait_for_main_timers()
Delays the current thread until all asynchronous processing and all pending timers have completed.