7 #include "../src/protocol.h"
8 void testProtocolRequesting() {
9 spec_is_str_equal(t2s(_sem_get_def(G_sem,REQUESTING)),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:REQUESTING)) (PROTOCOL_SEMANTICS (ROLE:REQUESTER) (ROLE:RESPONDER) (GOAL:RESPONSE_HANDLER) (GOAL:REQUEST_HANDLER) (USAGE:CHANNEL) (USAGE:REQUEST_TYPE) (USAGE:RESPONSE_TYPE) (USAGE:RESPONSE_HANDLER_PARAMETERS)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))) (backnforth (INITIATE (ROLE:REQUESTER) (DESTINATION (ROLE:RESPONDER)) (ACTION:send_request)) (EXPECT (ROLE:RESPONDER) (SOURCE (ROLE:REQUESTER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (ACTION:send_response))))");
10 spec_is_str_equal(t2s(_sem_get_def(G_sem,send_request)),
"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:send_request)) (PROCESS_INTENTION:send request) (SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (SLOT (USAGE:RESPONSE_HANDLER_PARAMETERS)) (process:REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response)) (SIGNATURE_ANY)) (TEMPLATE_SIGNATURE (EXPECTED_SLOT (USAGE:RESPONSE_HANDLER_PARAMETERS)) (EXPECTED_SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (EXPECTED_SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (EXPECTED_SLOT (USAGE:REQUEST_TYPE)) (EXPECTED_SLOT (GOAL:RESPONSE_HANDLER)))))");
12 spec_is_str_equal(t2s(_sem_get_def(G_sem,send_response)),
"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:send_response)) (PROCESS_INTENTION:send response) (process:RESPOND (SIGNAL_REF:/2/1/4) (SLOT (GOAL:REQUEST_HANDLER))) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response id)) (SIGNATURE_SYMBOL:SIGNAL_UUID)) (TEMPLATE_SIGNATURE (EXPECTED_SLOT (GOAL:REQUEST_HANDLER)))))");
18 void testProtocolRecognize() {
20 T *recog = _sem_get_def(G_sem,RECOGNIZE);
23 spec_is_str_equal(t2s(recog),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:RECOGNIZE)) (PROTOCOL_SEMANTICS) (INCLUSION (PNAME:REQUESTING) (LINKAGE (WHICH_ROLE (ROLE:REQUESTER) (ROLE:RECOGNIZER))) (LINKAGE (WHICH_ROLE (ROLE:RESPONDER) (ROLE:RECOGNIZEE))) (LINKAGE (WHICH_GOAL (GOAL:RESPONSE_HANDLER) (GOAL:RECOGNITION))) (RESOLUTION (WHICH_SYMBOL (USAGE:REQUEST_TYPE) (ACTUAL_SYMBOL:are_you))) (RESOLUTION (WHICH_SYMBOL (USAGE:RESPONSE_TYPE) (ACTUAL_SYMBOL:i_am))) (RESOLUTION (WHICH_SYMBOL (USAGE:CHANNEL) (ACTUAL_SYMBOL:DEFAULT_ASPECT))) (RESOLUTION (WHICH_PROCESS (GOAL:REQUEST_HANDLER) (ACTUAL_PROCESS:fill_i_am)))))");
28 spec_is_str_equal(t2s(t),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:RECOGNIZE)) (PROTOCOL_SEMANTICS (ROLE:RECOGNIZER) (GOAL:RECOGNITION) (USAGE:RESPONSE_HANDLER_PARAMETERS)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))) (backnforth (INITIATE (ROLE:RECOGNIZER) (DESTINATION (ROLE:RECOGNIZEE)) (ACTION:send_request)) (EXPECT (ROLE:RECOGNIZEE) (SOURCE (ROLE:RECOGNIZER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:are_you))) (ACTION:send_response))))");
31 spec_is_str_equal(t2s(sem_map),
"(SEMANTIC_MAP (SEMANTIC_LINK (ROLE:REQUESTER) (REPLACEMENT_VALUE (ROLE:RECOGNIZER))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (ROLE:RECOGNIZEE))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (GOAL:RECOGNITION))) (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:are_you))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:i_am))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:DEFAULT_ASPECT))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:fill_i_am))))");
39 _t_newi(noop,TEST_INT_SYMBOL,314);
44 T *res = _t_newr(bindings,RESOLUTION);
45 T *w = _t_newr(res,WHICH_PROCESS);
46 _t_news(w,GOAL,RECOGNITION);
47 _t_news(w,ACTUAL_PROCESS,proc);
54 spec_is_str_equal(_td(
self,self->flux),
"(FLUX (DEFAULT_ASPECT (EXPECTATIONS) (SIGNALS)))");
59 spec_is_str_equal(_td(
self,self->flux),
"(FLUX (DEFAULT_ASPECT (EXPECTATIONS (EXPECTATION (CARRIER:backnforth) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:are_you))) (ACTION:send_response) (PARAMS) (END_CONDITIONS (UNLIMITED)) (SEMANTIC_MAP (SEMANTIC_LINK (ROLE:REQUESTER) (REPLACEMENT_VALUE (ROLE:RECOGNIZER))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (ROLE:RECOGNIZEE))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (GOAL:RECOGNITION))) (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:are_you))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:i_am))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:DEFAULT_ASPECT))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:fill_i_am)))))) (SIGNALS)))");
62 Xaddr x = _v_new_receptor(v,v->
r,TEST_RECEPTOR,
self);
67 res = _t_newr(bindings,RESOLUTION);
68 w = _t_newr(res,WHICH_RECEPTOR);
69 _t_news(w,ROLE,RECOGNIZEE);
70 __r_make_addr(w,ACTUAL_RECEPTOR,self->addr);
71 res = _t_newr(bindings,RESOLUTION);
72 w = _t_newr(res,WHICH_PROCESS);
73 _t_news(w,GOAL,RECOGNITION);
74 _t_news(w,ACTUAL_PROCESS,NOOP);
75 res = _t_newr(bindings,RESOLUTION);
76 w = _t_newr(res,WHICH_VALUE);
77 _t_news(w,ACTUAL_SYMBOL,are_you);
78 T *val = _t_newr(w,ACTUAL_VALUE);
79 val = _t_newr(val,are_you);
80 _t_newr(val,SEMTREX_WALK);
82 spec_is_str_equal(t2s(bindings),
"(PROTOCOL_BINDINGS (RESOLUTION (WHICH_RECEPTOR (ROLE:RECOGNIZEE) (ACTUAL_RECEPTOR (RECEPTOR_ADDR:3)))) (RESOLUTION (WHICH_PROCESS (GOAL:RECOGNITION) (ACTUAL_PROCESS:NOOP))) (RESOLUTION (WHICH_VALUE (ACTUAL_SYMBOL:are_you) (ACTUAL_VALUE (are_you (SEMTREX_WALK))))))");
90 debug_disable(D_SIGNALS);
93 spec_is_str_equal(t2s(
_t_getv(self->pending_signals,1,SignalMessageIdx,MessageHeadIdx,HeadCarrierIdx,TREE_PATH_TERMINATOR)),
"(CARRIER:backnforth)");
94 spec_is_str_equal(t2s(
_t_getv(self->pending_signals,1,SignalMessageIdx,MessageBodyIdx,TREE_PATH_TERMINATOR)),
"(BODY:{(are_you (SEMTREX_WALK))})");
95 spec_is_str_equal(t2s(
_t_getv(self->pending_responses,1,PendingResponseCarrierIdx,TREE_PATH_TERMINATOR)),
"(CARRIER:backnforth)");
99 T *signals = __r_get_signals(
self,DEFAULT_ASPECT);
100 T *h =
_t_clone(
_t_getv(signals,1,SignalMessageIdx,MessageHeadIdx,TREE_PATH_TERMINATOR));
102 spec_is_str_equal(t2s(h),
"(HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:backnforth))");
104 spec_is_str_equal(t2s(
_t_getv(signals,1,SignalMessageIdx,MessageBodyIdx,TREE_PATH_TERMINATOR)),
"(BODY:{(are_you (SEMTREX_WALK))})");
105 spec_is_str_equal(t2s(
_t_getv(signals,1,SignalMessageIdx+1,TREE_PATH_TERMINATOR)),
"(RUN_TREE (process:RESPOND (SIGNAL_REF:/2/1/4) (process:fill_i_am)) (PARAMS))");
111 debug_disable(D_TREE);
112 debug_disable(D_PROTOCOL);
113 debug_disable(D_STEP);
114 debug_disable(D_REDUCE+D_REDUCEV);
116 spec_is_str_equal(_td(
self,self->pending_signals),
"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:backnforth) (IN_RESPONSE_TO_UUID)) (BODY:{(i_am (RECEPTOR_LABEL (ENGLISH_LABEL:super cept)) (RECEPTOR_IDENTIFIER:314159))}))))");
119 spec_is_str_equal(t2s(self->q->active->context->run_tree),
"(RUN_TREE (process:NOOP (i_am (RECEPTOR_LABEL (ENGLISH_LABEL:super cept)) (RECEPTOR_IDENTIFIER:314159))) (PARAMS))");
121 debug_disable(D_SIGNALS);
126 void testProtocolAlive() {
129 spec_is_str_equal(t2s(_sem_get_def(G_sem,ALIVE)),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:ALIVE)) (PROTOCOL_SEMANTICS (ROLE:SERVER) (ROLE:CLIENT) (GOAL:HANDLER)) (alive (EXPECT (ROLE:SERVER) (SOURCE (ROLE:CLIENT)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PING))) (ACTION:respond_with_yup)) (EXPECT (ROLE:CLIENT) (SOURCE (ROLE:SERVER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:YUP))) (SLOT (GOAL:HANDLER) (SLOT_IS_VALUE_OF:ACTION)))))");
136 spec_is_str_equal(_td(r,r->
flux),
"(FLUX (DEFAULT_ASPECT (EXPECTATIONS (EXPECTATION (CARRIER:alive) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:PING))) (ACTION:respond_with_yup) (PARAMS) (END_CONDITIONS (UNLIMITED)))) (SIGNALS)))");
140 _t_newi(noop,TEST_INT_SYMBOL,314);
143 T *bindings =
_t_build(G_sem,0,PROTOCOL_BINDINGS,RESOLUTION,WHICH_PROCESS,GOAL,HANDLER,ACTUAL_PROCESS,proc,NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL);
149 spec_is_str_equal(_td(r2,r2->
flux),
"(FLUX (DEFAULT_ASPECT (EXPECTATIONS (EXPECTATION (CARRIER:alive) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:YUP))) (ACTION:do nothing) (PARAMS) (END_CONDITIONS (UNLIMITED)) (SEMANTIC_MAP (SEMANTIC_LINK (GOAL:HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:do nothing)))))) (SIGNALS)))");
154 spec_is_str_equal(_td(r,r->
q->
active->context->
run_tree),
"(RUN_TREE (process:RESPOND (SIGNAL_REF:/2/1/4) (YUP)) (PARAMS))");
155 debug_disable(D_SIGNALS);
157 spec_is_str_equal(_td(r,r->
q->
completed->context->
run_tree),
"(RUN_TREE (SIGNAL_UUID) (PARAMS))");
158 spec_is_str_equal(_td(r,r->pending_signals),
"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:alive) (IN_RESPONSE_TO_UUID)) (BODY:{(YUP)}))))");
177 void _setupTestProtocols() {
183 T *action =
_t_build(G_sem,0,SLOT,GOAL,process,SLOT_IS_VALUE_OF,ACTION,NULL_SYMBOL);
184 T *pattern =
_t_build(G_sem,0,PATTERN,SEMTREX_SYMBOL_LITERAL,SLOT,USAGE,data,SLOT_IS_VALUE_OF,SEMTREX_SYMBOL,NULL_SYMBOL,NULL_SYMBOL);
188 simple_def =
_t_parse(G_sem,0,
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:\"do\")) (PROTOCOL_SEMANTICS (ROLE:agent) (GOAL:process) (USAGE:data)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:data) (REPLACEMENT_VALUE (USAGE:TEST_STR_SYMBOL))) (SEMANTIC_LINK (GOAL:process) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP)))) (act (EXPECT (ROLE:agent) (SOURCE (ROLE:agent)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:data) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (SLOT (GOAL:process) (SLOT_IS_VALUE_OF:ACTION)))))");
197 shake_def =
_t_parse(G_sem,0,
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:\"shake\")) (PROTOCOL_SEMANTICS (ROLE:mover) (ROLE:shaker)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:info) (REPLACEMENT_VALUE (USAGE:TEST_FLOAT_SYMBOL)))) (INCLUSION (PNAME:do) (LINKAGE (WHICH_ROLE (ROLE:agent) (ROLE:mover))) (LINKAGE (WHICH_GOAL (GOAL:process) (GOAL:shaking))) (LINKAGE (WHICH_USAGE (USAGE:data) (USAGE:info)))))");
201 void testProtocolResolve() {
204 _t_newi(noop,TEST_INT_SYMBOL,314);
207 T *bindings =
_t_parse(G_sem,0,
"(PROTOCOL_BINDINGS (RESOLUTION (WHICH_PROCESS (GOAL:process) (ACTUAL_PROCESS:do_nothing))) (RESOLUTION (WHICH_SYMBOL (USAGE:data) (ACTUAL_SYMBOL:TEST_INT_SYMBOL))))");
211 spec_is_str_equal(t2s(sem_map),
"(SEMANTIC_MAP (SEMANTIC_LINK (GOAL:process) (REPLACEMENT_VALUE (ACTUAL_PROCESS:do_nothing))) (SEMANTIC_LINK (USAGE:data) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:TEST_INT_SYMBOL))))");
213 spec_is_str_equal(t2s(unbound),
"(PROTOCOL_SEMANTICS (ROLE:agent))");
214 spec_is_str_equal(t2s(resolved),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:do)) (PROTOCOL_SEMANTICS (ROLE:agent) (GOAL:process) (USAGE:data)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:data) (REPLACEMENT_VALUE (USAGE:TEST_STR_SYMBOL))) (SEMANTIC_LINK (GOAL:process) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP)))) (act (EXPECT (ROLE:agent) (SOURCE (ROLE:agent)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_INT_SYMBOL))) (ACTION:do_nothing))))");
221 void testProtocolUnwrap() {
224 T *unwrapped =
_o_unwrap(G_sem,shake_def,sem_map);
226 spec_is_str_equal(t2s(sem_map),
"(SEMANTIC_MAP (SEMANTIC_LINK (ROLE:agent) (REPLACEMENT_VALUE (ROLE:mover))) (SEMANTIC_LINK (GOAL:process) (REPLACEMENT_VALUE (GOAL:shaking))) (SEMANTIC_LINK (USAGE:data) (REPLACEMENT_VALUE (USAGE:info))))");
229 spec_is_str_equal(t2s(unwrapped),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:shake)) (PROTOCOL_SEMANTICS (ROLE:mover) (ROLE:shaker) (GOAL:shaking) (USAGE:info)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:info) (REPLACEMENT_VALUE (USAGE:TEST_FLOAT_SYMBOL))) (SEMANTIC_LINK (GOAL:shaking) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP)))) (act (EXPECT (ROLE:mover) (SOURCE (ROLE:mover)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:info) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (SLOT (GOAL:shaking) (SLOT_IS_VALUE_OF:ACTION)))))");
233 void testProtocolDefaults() {
235 T *bindings =
_t_parse(G_sem,0,
"(PROTOCOL_BINDINGS (RESOLUTION (WHICH_SYMBOL (USAGE:data) (ACTUAL_SYMBOL:TEST_INT_SYMBOL))))");
236 T *defaults = _t_find(simple_def,PROTOCOL_DEFAULTS);
238 spec_is_str_equal(t2s(sem_map),
"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:data) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:TEST_INT_SYMBOL))) (SEMANTIC_LINK (GOAL:process) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))))");
267 void testProtocol() {
269 _setupTestProtocols();
270 testProtocolResolve();
271 testProtocolUnwrap();
272 testProtocolRequesting();
273 testProtocolRecognize();
275 testProtocolDefaults();
T * _t_new_root(Symbol symbol)
Process _d_define_process(SemTable *sem, T *code, char *name, char *intention, T *signature, T *link, Context c)
T * _o_bindings2sem_map(T *bindings, T *sem_map, T *defaults)
T * _t_detach_by_idx(T *t, int i)
void _r_free(Receptor *r)
ReceptorAddress addr
the address by which to get messages to this receptor instance
VMHost * _v_new()
Creates a new virtual machine host.
T * _o_unwrap(SemTable *sem, T *def, T *sem_map)
T * flux
pointer for quick access to the flux
void _v_activate(VMHost *v, Xaddr x)
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
Qe * active
active processes
void _o_initiate(Receptor *r, SemanticID protocol, SemanticID interaction, T *bindings)
Symbol _d_define_symbol(SemTable *sem, Structure s, char *label, Context c)
T * __r_make_signal(ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *signal_contents, UUIDt *in_response_to, T *until, T *cid)
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
void _o_express_role(Receptor *r, Protocol protocol, Symbol role, Aspect aspect, T *bindings)
Receptor * r
Receptor data for this vm host.
Qe * completed
completed processes (pending cleanup)
Protocol _d_define_protocol(SemTable *sem, T *def, Context c)
T * _t_parse(SemTable *sem, T *parent, char *s,...)
T * run_tree
pointer to the root of the run_tree
void _v_deliver_signals(VMHost *v, Receptor *sender)
Error _r_deliver(Receptor *r, T *signal)
Process _r_define_process(Receptor *r, T *code, char *name, char *intention, T *signature, T *link)
T * _t_build(SemTable *sem, T *parent,...)
T * _o_resolve(SemTable *sem, T *def, T *sem_map)