|
micro-test-plus 4.1.0
µTest++ Testing Framework
|
A begin/end timestamp pair used to measure elapsed time. More...
#include <micro-os-plus/micro-test-plus.h>
Public Member Functions | |
| timestamps ()=default | |
| Default constructor. Both timestamps are uninitialised. | |
| timestamps (const timestamps &)=delete | |
| Deleted copy constructor to prevent copying. | |
| timestamps (timestamps &&)=delete | |
| Deleted move constructor to prevent moving. | |
| ~timestamps ()=default | |
| Defaulted destructor. | |
| void | compute_elapsed_time (uint32_t &milliseconds, uint32_t µseconds) const |
| Computes the elapsed time between begin and end timestamps. | |
| bool | has_begin () const noexcept |
| Returns true if the begin timestamp has been recorded. | |
| bool | has_end () const noexcept |
| Returns true if the end timestamp has been recorded. | |
| bool | has_timestamps (void) const noexcept |
| Returns true if both begin and end timestamps are available. | |
| timestamps & | operator= (const timestamps &)=delete |
| Deleted copy assignment operator to prevent copying. | |
| timestamps & | operator= (timestamps &&)=delete |
| Deleted move assignment operator to prevent moving. | |
| void | timestamp_begin (const timespec &ts) noexcept |
| Records the begin timestamp from a caller-supplied value. | |
| void | timestamp_begin (void) noexcept |
| Records the begin timestamp using the current system clock. | |
| void | timestamp_end (const timespec &ts) noexcept |
| Records the end timestamp from a caller-supplied value. | |
| void | timestamp_end (void) noexcept |
| Records the end timestamp using the current system clock. | |
Protected Attributes | |
| std::optional< timestamp > | begin_time_ |
| The timestamp recorded at the beginning of the test suite. | |
| std::optional< timestamp > | end_time_ |
| The timestamp recorded at the end of the test suite. | |
timestamps stores an optional begin timestamp and an optional end timestamp. When both are available, compute_elapsed_time() derives the elapsed interval in milliseconds and microseconds.
Typical usage in the framework:
If the platform does not provide a monotonic clock, the std::optional members remain empty and has_timestamps() returns false, so that the reporter can skip timing output.
The class is non-copyable and non-movable to prevent accidental sharing of live timing state.
|
default |
Referenced by timestamps(), timestamps(), operator=(), and operator=().
|
delete |
References timestamps().
|
delete |
References timestamps().
|
default |
References compute_elapsed_time(), has_end(), and has_timestamps().
| void micro_os_plus::micro_test_plus::detail::timestamps::compute_elapsed_time | ( | uint32_t & | milliseconds, |
| uint32_t & | microseconds ) const |
| [out] | milliseconds | The elapsed time in whole milliseconds. |
| [out] | microseconds | The sub-millisecond remainder in microseconds. |
Subtracts the begin timestamp from the end timestamp in nanoseconds. If the nanosecond difference is negative, one second is borrowed from the seconds delta to normalise the result. The total elapsed duration in microseconds is then split into whole milliseconds (written to milliseconds) and the remainder microseconds (written to microseconds). Requires has_timestamps() to be true; behaviour is undefined otherwise.
Definition at line 184 of file timings.cpp.
References begin_time_, end_time_, and has_timestamps().
Referenced by ~timestamps(), micro_os_plus::micro_test_plus::reporter_human::end_session(), micro_os_plus::micro_test_plus::reporter_tap::end_session(), micro_os_plus::micro_test_plus::reporter_human::end_suite(), and micro_os_plus::micro_test_plus::reporter_tap::end_suite().
|
inlinenoexcept |
| true | timestamp_begin() has been called. |
| false | timestamp_begin() has not been called. |
Returns true when begin_time_ holds a value, i.e. when timestamp_begin() has previously been called.
Definition at line 89 of file timings-inlines.h.
References begin_time_.
|
inlinenoexcept |
| true | timestamp_end() has been called. |
| false | timestamp_end() has not been called. |
Returns true when end_time_ holds a value, i.e. when timestamp_end() has previously been called.
Definition at line 100 of file timings-inlines.h.
References end_time_.
Referenced by ~timestamps().
|
noexcept |
| true | Both timestamps are present and elapsed time can be computed. |
| false | At least one timestamp is absent; elapsed time is not available. |
Returns true only when both the begin and end optional timestamps are engaged and each contains a valid (non-zero) clock reading, as determined by timestamp::has_clock().
Definition at line 167 of file timings.cpp.
References begin_time_, and end_time_.
Referenced by ~timestamps(), compute_elapsed_time(), micro_os_plus::micro_test_plus::reporter_human::end_session(), micro_os_plus::micro_test_plus::reporter_tap::end_session(), micro_os_plus::micro_test_plus::reporter_human::end_suite(), and micro_os_plus::micro_test_plus::reporter_tap::end_suite().
|
delete |
References timestamps().
|
delete |
References timestamps().
|
noexcept |
| ts | The timespec value to use as the begin timestamp. |
If the begin timestamp has not yet been set, a timestamp is constructed in-place from the supplied timespec value. Subsequent calls are silently ignored, ensuring idempotent behaviour.
Definition at line 118 of file timings.cpp.
References begin_time_.
|
noexcept |
If the begin timestamp has not yet been set, a timestamp is constructed in-place using the default constructor, which captures the current monotonic time. Subsequent calls are silently ignored, ensuring idempotent behaviour.
Definition at line 102 of file timings.cpp.
References begin_time_.
Referenced by micro_os_plus::micro_test_plus::static_suite::run().
|
noexcept |
| ts | The timespec value to use as the end timestamp. |
If the end timestamp has not yet been set, a timestamp is constructed in-place from the supplied timespec value. Subsequent calls are silently ignored, ensuring idempotent behaviour.
Definition at line 151 of file timings.cpp.
References end_time_.
|
noexcept |
If the end timestamp has not yet been set, a timestamp is constructed in-place using the default constructor, which captures the current monotonic time. Subsequent calls are silently ignored, ensuring idempotent behaviour.
Definition at line 135 of file timings.cpp.
References end_time_.
Referenced by micro_os_plus::micro_test_plus::static_suite::run().
|
protected |
Definition at line 333 of file timings.h.
Referenced by compute_elapsed_time(), has_begin(), has_timestamps(), timestamp_begin(), and timestamp_begin().
|
protected |
Definition at line 338 of file timings.h.
Referenced by compute_elapsed_time(), has_end(), has_timestamps(), timestamp_end(), and timestamp_end().