asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
controller.hpp
1
12#pragma once
13
14#include "../asrtc/controller.h"
15#include "../asrtc/result.h"
16#include "../asrtlpp/callback.hpp"
17#include "../asrtlpp/task.hpp"
18#include "../asrtlpp/util.hpp"
19
20#include <functional>
21#include <string>
22
23namespace asrt
24{
25using status = asrt_status;
26using result = asrt_result;
27
29ASRT_NODISCARD inline status init( ref< asrt_controller > c, asrt_send_req_list* s, allocator a )
30{
31 return asrt_cntr_init( c, s, a );
32}
33
36ASRT_NODISCARD inline status start(
37 ref< asrt_controller > c,
39 uint32_t timeout )
40{
41 return asrt_cntr_start( c, cb.fn, cb.ptr, timeout );
42}
43
45ASRT_NODISCARD inline bool is_idle( ref< asrt_controller > c )
46{
47 return asrt_cntr_idle( c ) > 0;
48}
49
51ASRT_NODISCARD inline status query_desc(
52 ref< asrt_controller > c,
54 uint32_t timeout )
55{
56 return asrt_cntr_desc( c, cb.fn, cb.ptr, timeout );
57}
58
60ASRT_NODISCARD inline status query_test_count(
61 ref< asrt_controller > c,
63 uint32_t timeout )
64{
65 return asrt_cntr_test_count( c, cb.fn, cb.ptr, timeout );
66}
67
69ASRT_NODISCARD inline status query_test_info(
70 ref< asrt_controller > c,
71 uint16_t id,
73 uint32_t timeout )
74{
75 return asrt_cntr_test_info( c, id, cb.fn, cb.ptr, timeout );
76}
77
79ASRT_NODISCARD inline status exec_test(
80 ref< asrt_controller > c,
81 uint16_t id,
83 uint32_t timeout )
84{
85 return asrt_cntr_test_exec( c, id, cb.fn, cb.ptr, timeout );
86}
87
89inline void deinit( ref< asrt_controller > c )
90{
91 asrt_cntr_deinit( c );
92}
93
94// ---------------------------------------------------------------------------
95// Sender-based variants — for use with co_await in coroutine tasks.
96
98struct _cntr_start_ctx
99{
100 using completion_signatures =
101 ecor::completion_signatures< ecor::set_value_t(), ecor::set_error_t( status ) >;
102
104 uint32_t timeout;
105
106 template < typename OP >
107 void start( OP& op )
108 {
109 auto s = asrt_cntr_start(
110 c,
111 +[]( void* p, asrt_status s ) -> asrt_status {
112 auto& o = *static_cast< OP* >( p );
113 if ( s != ASRT_SUCCESS )
114 o.receiver.set_error( s );
115 else
116 o.receiver.set_value();
117 return ASRT_SUCCESS;
118 },
119 &op,
120 timeout );
121 if ( s != ASRT_SUCCESS )
122 op.receiver.set_error( s );
123 }
124};
125
128using cntr_start_sender = ecor::sender_from< _cntr_start_ctx >;
129
131struct _cntr_query_desc_ctx
132{
133 using completion_signatures = ecor::
134 completion_signatures< ecor::set_value_t( std::string ), ecor::set_error_t( status ) >;
135
137 uint32_t timeout;
138
139 template < typename OP >
140 void start( OP& op )
141 {
142 auto s = asrt_cntr_desc(
143 c,
144 +[]( void* p, asrt_status s, char const* desc ) -> asrt_status {
145 auto& o = *static_cast< OP* >( p );
146 if ( s != ASRT_SUCCESS )
147 o.receiver.set_error( s );
148 else
149 o.receiver.set_value( std::string{ desc } );
150 return ASRT_SUCCESS;
151 },
152 &op,
153 timeout );
154 if ( s != ASRT_SUCCESS )
155 op.receiver.set_error( s );
156 }
157};
158
161using cntr_query_desc_sender = ecor::sender_from< _cntr_query_desc_ctx >;
162
164struct _cntr_query_test_count_ctx
165{
166 using completion_signatures = ecor::
167 completion_signatures< ecor::set_value_t( uint16_t ), ecor::set_error_t( status ) >;
168
170 uint32_t timeout;
171
172 template < typename OP >
173 void start( OP& op )
174 {
175 auto s = asrt_cntr_test_count(
176 c,
177 +[]( void* p, asrt_status s, uint16_t count ) -> asrt_status {
178 auto& o = *static_cast< OP* >( p );
179 if ( s != ASRT_SUCCESS )
180 o.receiver.set_error( s );
181 else
182 o.receiver.set_value( count );
183 return ASRT_SUCCESS;
184 },
185 &op,
186 timeout );
187 if ( s != ASRT_SUCCESS )
188 op.receiver.set_error( s );
189 }
190};
191
194using cntr_query_test_count_sender = ecor::sender_from< _cntr_query_test_count_ctx >;
195
197struct _cntr_query_test_info_ctx
198{
199 using completion_signatures = ecor::completion_signatures<
200 ecor::set_value_t( uint16_t, std::string ),
201 ecor::set_error_t( status ) >;
202
204 uint16_t id;
205 uint32_t timeout;
206
207 template < typename OP >
208 void start( OP& op )
209 {
210 auto s = asrt_cntr_test_info(
211 c,
212 id,
213 +[]( void* p, asrt_status s, uint16_t tid, char const* desc ) -> asrt_status {
214 auto& o = *static_cast< OP* >( p );
215 if ( s != ASRT_SUCCESS )
216 o.receiver.set_error( s );
217 else
218 o.receiver.set_value( tid, std::string{ desc } );
219 return ASRT_SUCCESS;
220 },
221 &op,
222 timeout );
223 if ( s != ASRT_SUCCESS )
224 op.receiver.set_error( s );
225 }
226};
227
230using cntr_query_test_info_sender = ecor::sender_from< _cntr_query_test_info_ctx >;
231
233struct _cntr_exec_test_ctx
234{
235 using completion_signatures = ecor::
236 completion_signatures< ecor::set_value_t( asrt_result ), ecor::set_error_t( status ) >;
237
239 uint16_t id;
240 uint32_t timeout;
241
242 template < typename OP >
243 void start( OP& op )
244 {
245 auto s = asrt_cntr_test_exec(
246 c,
247 id,
248 +[]( void* p, asrt_status s, asrt_result* res ) -> asrt_status {
249 auto& o = *static_cast< OP* >( p );
250 if ( s != ASRT_SUCCESS )
251 o.receiver.set_error( s );
252 else
253 o.receiver.set_value( *res );
254 return ASRT_SUCCESS;
255 },
256 &op,
257 timeout );
258 if ( s != ASRT_SUCCESS )
259 op.receiver.set_error( s );
260 }
261};
262
265using cntr_exec_test_sender = ecor::sender_from< _cntr_exec_test_ctx >;
266
268inline ecor::sender auto start( ref< asrt_controller > c, uint32_t timeout )
269{
270 return cntr_start_sender{ { c, timeout } };
271}
272
274inline ecor::sender auto query_desc( ref< asrt_controller > c, uint32_t timeout )
275{
276 return cntr_query_desc_sender{ { c, timeout } };
277}
278
281inline ecor::sender auto query_test_count( ref< asrt_controller > c, uint32_t timeout )
282{
283 return cntr_query_test_count_sender{ { c, timeout } };
284}
285
288inline ecor::sender auto query_test_info( ref< asrt_controller > c, uint16_t id, uint32_t timeout )
289{
290 return cntr_query_test_info_sender{ { c, id, timeout } };
291}
292
294inline ecor::sender auto exec_test( ref< asrt_controller > c, uint16_t id, uint32_t timeout )
295{
296 return cntr_exec_test_sender{ { c, id, timeout } };
297}
298
299} // 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< _cntr_start_ctx > cntr_start_sender
Sender backing co_await start(c, timeout).
Definition: controller.hpp:128
ecor::sender_from< _cntr_query_test_count_ctx > cntr_query_test_count_sender
Sender backing co_await query_test_count(c, timeout).
Definition: controller.hpp:194
ecor::sender_from< _cntr_query_desc_ctx > cntr_query_desc_sender
Sender backing co_await query_desc(c, timeout).
Definition: controller.hpp:161
ASRT_NODISCARD bool is_idle(ref< asrt_controller > c)
Returns true if the controller has no pending operation.
Definition: controller.hpp:45
ecor::sender_from< _cntr_exec_test_ctx > cntr_exec_test_sender
Sender backing co_await exec_test(c, id, timeout).
Definition: controller.hpp:265
ASRT_NODISCARD status query_test_count(ref< asrt_controller > c, callback< asrt_test_count_callback > cb, uint32_t timeout)
Request the number of tests registered on the target; cb receives the count.
Definition: controller.hpp:60
ASRT_NODISCARD status start(ref< asrt_controller > c, callback< asrt_init_callback > cb, uint32_t timeout)
Begin the protocol handshake; cb is invoked once the target responds or the operation times out.
Definition: controller.hpp:36
ecor::sender_from< _cntr_query_test_info_ctx > cntr_query_test_info_sender
Sender backing co_await query_test_info(c, id, timeout).
Definition: controller.hpp:230
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
ASRT_NODISCARD status query_test_info(ref< asrt_controller > c, uint16_t id, callback< asrt_test_info_callback > cb, uint32_t timeout)
Request name and metadata for test id; cb receives the info.
Definition: controller.hpp:69
void deinit(ref< asrt_cntr_assm > assm)
Release all resources owned by the assembly.
Definition: cntr_assm.hpp:52
ASRT_NODISCARD enum asrt_status exec_test(ref< asrt_cntr_assm > assm, asrt_flat_tree const *tree, asrt_flat_id root_id, uint16_t tid, uint32_t timeout, callback< asrt_assembly_exec_cb > cb)
Execute test tid using the full assembly protocol sequence (param upload, collect ready,...
Definition: cntr_assm.hpp:40
ASRT_NODISCARD status query_desc(ref< asrt_controller > c, callback< asrt_desc_callback > cb, uint32_t timeout)
Request the target description string; cb receives it on success.
Definition: controller.hpp:51
A type-erasing wrapper for C-style callback + void* pairs.
Definition: callback.hpp:27
Controller module — CORE channel, host side.
Definition: controller.h:42
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: result.h:25
Intrusive FIFO of outgoing send requests.
Definition: chann.h:76