|
SatCat5
|
Miscellaneous simulation and test helper functions.
This file contains a variety of "small" utilities used in simulations and unit tests. Anything that requires more than a few lines of code should generally be moved into its own file.
Definition in file sim_utils.h.
#include <hal_posix/posix_utils.h>#include <satcat5/cfgbus_core.h>#include <satcat5/cfgbus_interrupt.h>#include <satcat5/ethernet.h>#include <satcat5/interrupts.h>#include <satcat5/ip_stack.h>#include <satcat5/log.h>#include <satcat5/polling.h>#include <satcat5/ptp_source.h>#include <satcat5/timeref.h>#include <string>#include <qcbor/qcbor_decode.h>Go to the source code of this file.
Classes | |
| class | satcat5::test::CborParser |
| A simple CBOR decoder for use in unit tests. More... | |
| class | satcat5::test::CountHelper |
| Base object for counting specific callback or event types. More... | |
| class | satcat5::test::CountAlways |
Count calls to poll_always(). More... | |
| class | satcat5::test::CountArpResponse |
Count calls to arp_event(). More... | |
| class | satcat5::test::CountOnDemand |
Count calls to poll_demand(). More... | |
| class | satcat5::test::CountPingResponse |
Count calls to ping_event(). More... | |
| class | satcat5::test::CountPtpCallback |
Count calls to ptp_ready(). More... | |
| class | satcat5::test::CountTimer |
Count calls to timer_event(). More... | |
| class | satcat5::test::DebugAddress |
| Dummy implementation of net::Address that writes data to a buffer. More... | |
| class | satcat5::test::FastPosixTimer |
| Accelerated version of PosixTimer is 256x real-time. More... | |
| class | satcat5::test::IoEventCounter |
Count calls to data_rcvd(). More... | |
| class | satcat5::test::LogProtocol |
| Log any received Ethernet traffic of the designated type. More... | |
| class | satcat5::test::MockConfigBusMmap |
| Mockup for a memory-mapped ConfigBus. More... | |
| class | satcat5::test::MockInterrupt |
| Mockup for a ConfigBus interrupt register. More... | |
| class | satcat5::test::RandomSource |
| Readable source for a pseudorandom block of data. More... | |
| class | satcat5::test::Statistics |
| Measure various statistics of a discrete-time series. More... | |
| class | satcat5::test::TimerSimulation |
| Timekeeper object for granular simulation of elapsed time. More... | |
Macros | |
| #define | SATCAT5_MAKE_STRING(x) (std::string(x, x + sizeof(x))) |
| Macro for making a std::string from a byte-array. More... | |
| #define | SATCAT5_TEST_START |
| Boilerplate for configuring each unit test. More... | |
Functions | |
| bool | satcat5::test::pre_test_reset () |
| Reset the global PRNG state used for rand_*(), below. | |
| std::string | satcat5::test::sim_filename (const char *pre, const char *ext) |
| Generate a unique filename for storing unit-test results. More... | |
| void | satcat5::test::write_random_bytes (satcat5::io::Writeable *dst, unsigned nbytes) |
| Write random bytes, without finalizing. More... | |
| bool | satcat5::test::write_random_final (satcat5::io::Writeable *dst, unsigned nbytes) |
| Write random bytes and finalize. More... | |
| bool | satcat5::test::read_equal (satcat5::io::Readable *src1, satcat5::io::Readable *src2) |
| Check if two streams are equal. | |
| u8 | satcat5::test::rand_u8 () |
| Reproducible PRNG used for unit tests. | |
| u32 | satcat5::test::rand_u32 () |
| Reproducible PRNG used for unit tests. | |
| u64 | satcat5::test::rand_u64 () |
| Reproducible PRNG used for unit tests. | |
| bool | satcat5::test::write (satcat5::io::Writeable *dst, unsigned nbytes, const u8 *data) |
| Write byte array and finalize. | |
| bool | satcat5::test::write (satcat5::io::Writeable *dst, const std::string &dat) |
| Write byte array and finalize. | |
| bool | satcat5::test::read (satcat5::io::Readable *src, unsigned nbytes, const u8 *data) |
| Compare next frame to reference array. More... | |
| bool | satcat5::test::read (satcat5::io::Readable *src, const std::string &ref) |
| Compare next frame to reference array. More... | |
| bool | satcat5::test::read (satcat5::io::ArrayRead src, const std::string &ref) |
| Compare next frame to reference array. More... | |
| #define SATCAT5_MAKE_STRING | ( | x | ) | (std::string(x, x + sizeof(x))) |
Macro for making a std::string from a byte-array.
Note: Only works for locally defined constants.
Definition at line 34 of file sim_utils.h.
| #define SATCAT5_TEST_START |
Boilerplate for configuring each unit test.
Includes a hard-reset of SatCat5 global variables and enables log::ToConsole. An error in this macro indicates the previous test didn't exit cleanly.
Definition at line 39 of file sim_utils.h.
| bool satcat5::test::read | ( | satcat5::io::ArrayRead | src, |
| const std::string & | ref | ||
| ) |
Compare next frame to reference array.
Returns true on exact match, false otherwise. Logs messages indicating each mismatch.
Definition at line 112 of file sim_utils.cc.
| bool satcat5::test::read | ( | satcat5::io::Readable * | src, |
| const std::string & | ref | ||
| ) |
Compare next frame to reference array.
Returns true on exact match, false otherwise. Logs messages indicating each mismatch.
Definition at line 108 of file sim_utils.cc.
| bool satcat5::test::read | ( | satcat5::io::Readable * | src, |
| unsigned | nbytes, | ||
| const u8 * | data | ||
| ) |
Compare next frame to reference array.
Returns true on exact match, false otherwise. Logs messages indicating each mismatch.
Definition at line 72 of file sim_utils.cc.
| std::string satcat5::test::sim_filename | ( | const char * | pre, |
| const char * | ext | ||
| ) |
Generate a unique filename for storing unit-test results.
In most cases, the "pre" argument should be set to FILE. Output is "simulations/[pre]_[###].[ext]". (Where ### is a sequential counter for each unique "pre" value.)
Definition at line 51 of file sim_utils.cc.
| void satcat5::test::write_random_bytes | ( | satcat5::io::Writeable * | dst, |
| unsigned | nbytes | ||
| ) |
Write random bytes, without finalizing.
Definition at line 116 of file sim_utils.cc.
| bool satcat5::test::write_random_final | ( | satcat5::io::Writeable * | dst, |
| unsigned | nbytes | ||
| ) |
Write random bytes and finalize.
Definition at line 121 of file sim_utils.cc.