asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
diag.hpp
1
11#pragma once
12
13#include "../asrtl/asrt_assert.h"
14#include "../asrtl/log.h"
15#include "../asrtl/status_to_str.h"
16#include "../asrtlpp/callback.hpp"
17#include "../asrtlpp/task.hpp"
18#include "../asrtlpp/util.hpp"
19#include "../asrtr/diag.h"
20
21namespace asrt
22{
23
24using status = asrt_status;
25
28inline void rec_diag(
29 ref< asrt_diag_client > d,
30 char const* file,
31 uint32_t line,
32 char const* extra,
34{
35 asrt_diag_client_record( d, file, line, extra, done_cb.fn, done_cb.ptr );
36}
37
39ASRT_NODISCARD inline status init( ref< asrt_diag_client > d, asrt_node& prev )
40{
41 return asrt_diag_client_init( d, &prev );
42}
43
45inline void deinit( ref< asrt_diag_client > d )
46{
47 asrt_diag_client_deinit( d );
48}
49
51struct _diag_rec_ctx
52{
53 using completion_signatures =
54 ecor::completion_signatures< ecor::set_value_t(), ecor::set_error_t( status ) >;
55
57 char const* file;
58 uint32_t line;
59 char const* extra;
60
61 template < typename OP >
62 void start( OP& op )
63 {
64 asrt_diag_client_record(
65 d,
66 file,
67 line,
68 extra,
69 +[]( void* p, enum asrt_status s ) {
70 auto& o = *static_cast< OP* >( p );
71 if ( s == ASRT_SUCCESS )
72 o.receiver.set_value();
73 else
74 o.receiver.set_error( s );
75 },
76 &op );
77 }
78};
79
82using diag_rec_sender = ecor::sender_from< _diag_rec_ctx >;
83
86inline ecor::sender auto rec_diag(
87 ref< asrt_diag_client > d,
88 char const* file,
89 uint32_t line,
90 char const* extra )
91{
92 return diag_rec_sender{ { d, file, line, extra } };
93}
94
95#define ASRT_CO_REQUIRE( diag, rec, x ) \
96 do { \
97 if ( !( x ) ) { \
98 ( rec )->state = ASRT_TEST_FAIL; \
99 co_await rec_diag( diag, ASRT_FILENAME, __LINE__, #x ); \
100 co_return; \
101 } \
102 } while ( 0 )
103
104#define ASRT_CO_CHECK( diag, rec, x ) \
105 do { \
106 if ( !( x ) ) { \
107 ( rec )->state = ASRT_TEST_FAIL; \
108 co_await rec_diag( diag, ASRT_FILENAME, __LINE__, #x ); \
109 } \
110 } while ( 0 )
111
112} // namespace asrt
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: callback.hpp:17
ecor::sender_from< _diag_rec_ctx > diag_rec_sender
Sender backing co_await rec_diag(d, file, line, extra).
Definition: diag.hpp:82
void rec_diag(ref< asrt_diag_client > d, char const *file, uint32_t line, char const *extra, callback< asrt_diag_record_done_cb > done_cb)
Enqueue a diagnostic record from file:@p line with optional expression extra.
Definition: diag.hpp:28
ASRT_NODISCARD enum asrt_status init(ref< asrt_cntr_assm > assm, asrt_allocator alloc)
Initialise the controller assembly — wires controller, diag, param, collect and stream channels.
Definition: cntr_assm.hpp:25
void deinit(ref< asrt_cntr_assm > assm)
Release all resources owned by the assembly.
Definition: cntr_assm.hpp:52
A type-erasing wrapper for C-style callback + void* pairs.
Definition: callback.hpp:27
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: diag.h:28
A node in a doubly-linked channel chain.
Definition: chann.h:122