|
Open Model Railroad Network (OpenMRN)
|
#include "nmranet_config.h"#include <stdio.h>#include <stdarg.h>#include <memory>#include <string>#include <functional>#include "gtest/gtest.h"#include "gmock/gmock.h"#include "can_frame.h"#include "executor/CallableFlow.hxx"#include "executor/Executor.hxx"#include "executor/Service.hxx"#include "os/TempFile.hxx"#include "os/os.h"#include "utils/StringPrintf.hxx"Go to the source code of this file.
Classes | |
| class | ExecutorStartupFix |
| Fixes race condition between test teardown and executor startup. More... | |
| class | ExecuteOnMainExecutor |
| Utility class to help running a "pthread"-like thread in the main executor. More... | |
| class | FnExecutable |
| Helper class to run a lambda in the main executor. More... | |
| class | RunInConstruct |
| Runs some code in the constructor. More... | |
| class | RunInConstructOnMain |
| Runs some code in the constructor on the main executor. More... | |
| struct | PendingInvocation< T > |
| Structure holding returned objects for an invoke_flow_nowait command. More... | |
| class | BlockExecutor |
| Utility class to block an executor for a while. More... | |
| class | ScopedOverride |
| Overrides the value of a variable and restores it to the original value when destructed. More... | |
| class | ScopedOverride::HolderBase |
| Virtual base class for the destructible holders. More... | |
| class | ScopedOverride::Holder< T > |
| Type-accurate class that holds the temporary variable with the old value, the pointer to the variable and restores the previous state upon destruction. More... | |
Macros | |
| #define | RX(statement) run_x([&](){ statement; }) |
| Helper macro to make running certain test commands run on the main executor simpler. | |
Functions | |
| int | appl_main (int argc, char *argv[]) |
| Entry point to application. | |
| void | log_output (char *buf, int size) |
| Prints a line of log to the log output destination. | |
| Executor< 1 > | g_executor ("ex_thread", 0, 1024) |
| Global executor thread for tests. | |
| OVERRIDE_CONST_ (gridconnect_buffer_size, 1) | |
| Do not buffer gridconnect bytes when we are running in a test. | |
| void | wait_for_main_executor () |
| Blocks the current thread until the main executor has run out of work. | |
| void | wait_for_main_timers () |
| Delays the current thread until all asynchronous processing and all pending timers have completed. | |
| void | run_x (std::function< void()> fn) |
| Synchronously runs a function in the main executor. | |
| template<class T , typename... Args> | |
| 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 | nibble_to_int (char n) |
| Converts a character containing a hex digit to the value of that digit. | |
| std::string | hex2str (const char *hex) |
| Converts a hex string into the respective byte string. | |
| std::string | str2hex (const string &s) |
| Converts a byte string into the hexadecimal representation, with no separators. | |
Variables | |
| bool | mute_log_output = false |
| Executor< 1 > | g_executor |
| Global executor thread for tests. | |
| class ExecutorStartupFix | unused_executor_startup_guard_instance |
| actual instance. | |
| const char | HEXCHR [17] = "0123456789abcdef" |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Include this file into your unittest to define the necessary symbols and main function.
Definition in file test_main.hxx.
| #define RX | ( | statement | ) | run_x([&](){ statement; }) |
Helper macro to make running certain test commands run on the main executor simpler.
Definition at line 218 of file test_main.hxx.
| int appl_main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Entry point to application.
| argc | number of arguments |
| argv | list of arguments |
Definition at line 66 of file test_main.hxx.
| Executor< 1 > g_executor | ( | "ex_thread" | , |
| 0 | , | ||
| 1024 | |||
| ) |
Global executor thread for tests.
| std::string hex2str | ( | const char * | hex | ) |
Converts a hex string into the respective byte string.
| hex | a string containing hex digits. Separators between hex bytes are allowed and ignored. |
Definition at line 422 of file test_main.hxx.
| 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.
Instead, returns a PendingInvocation object, where there is a wait() method to be called.
Definition at line 252 of file test_main.hxx.
| void log_output | ( | char * | buf, |
| int | size | ||
| ) |
Prints a line of log to the log output destination.
| buf | is the logging buffer. Guaranteed to be available until this function returns. |
| size | is now many bytes are there in the logging buffer. There is never a terminating in the log buffer. There is a terminating zero at buf[size]. |
Prints a line of log to the log output destination.
This is a definition fo a C++ symbol, and should be included exactly once into one .cxx file; typicall into main.cxx.
| buf | pointer to bytes to log. Does not contain a . |
| size | how may bytes to log. |
Definition at line 75 of file test_main.hxx.
| int nibble_to_int | ( | char | n | ) |
Converts a character containing a hex digit to the value of that digit.
| n | character with lower or upper case hex digit. |
Definition at line 401 of file test_main.hxx.
| void run_x | ( | std::function< void()> | fn | ) |
Synchronously runs a function in the main executor.
Definition at line 190 of file test_main.hxx.
| std::string str2hex | ( | const string & | s | ) |
Converts a byte string into the hexadecimal representation, with no separators.
| s | Arbitrary byte payload. |
Definition at line 445 of file test_main.hxx.
| void wait_for_main_executor | ( | ) |
Blocks the current thread until the main executor has run out of work.
Use this function in unittest functions to wait for any asynchronous work you may have scheduled on the main executor. This typically happens before expectations. Also if you have stack-allocated objects that will schedule themselves on the main executor, then you must call this function before ending the scope that will deallocate them – it is typical to have this as the last command in a TEST_F.
Definition at line 113 of file test_main.hxx.
| void wait_for_main_timers | ( | ) |
Delays the current thread until all asynchronous processing and all pending timers have completed.
Definition at line 121 of file test_main.hxx.
| Service g_service & g_executor |
Global executor thread for tests.
Definition at line 103 of file test_main.hxx.
| const char HEXCHR[17] = "0123456789abcdef" |
Definition at line 438 of file test_main.hxx.
| bool mute_log_output = false |
Definition at line 72 of file test_main.hxx.