ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
protocol_spec.h
Go to the documentation of this file.
1 
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)))))");
11 
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)))))");
13 
14  //@todo trying to express request protocol should fail because it's not concrete enough
15 
16 }
17 
18 void testProtocolRecognize() {
19 
20  T *recog = _sem_get_def(G_sem,RECOGNIZE);
21 
22  // check the recognize protocol definition
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)))))");
24 
25  T *sem_map = _t_new_root(SEMANTIC_MAP);
26  T *t = _o_unwrap(G_sem,recog,sem_map);
27  // and also check how it gets unwrapped because it's defined in terms of REQUESTING
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))))");
29 
30  // the unwrapping should build up a semantic map
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))))");
32  _t_free(sem_map);
33 
34  // create a receptor to express the proctocl
35  Receptor *self = _r_new(G_sem,TEST_RECEPTOR);
36 
37  // and a noop-action to run as the result of recognizing
38  T *noop = _t_new_root(NOOP);
39  _t_newi(noop,TEST_INT_SYMBOL,314);
40  Process proc = _r_define_process(self,noop,"do nothing","long desc...",NULL,NULL);
41 
42  // which we add to the bindings
43  T *bindings = _t_new_root(PROTOCOL_BINDINGS);
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);
48 
49  // that get used to express the RECOGNIZER half of the protocol
50  _o_express_role(self,RECOGNIZE,RECOGNIZER,DEFAULT_ASPECT,bindings);
51  _t_free(bindings);
52 
53  //recognizer doesn't add expectations
54  spec_is_str_equal(_td(self,self->flux),"(FLUX (DEFAULT_ASPECT (EXPECTATIONS) (SIGNALS)))");
55 
56  // recognizee doesn't need any bindings because that role's completed by unwrapping
57  _o_express_role(self,RECOGNIZE,RECOGNIZEE,DEFAULT_ASPECT,NULL);
58  // however it does add expectation
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)))");
60 
61  VMHost *v = G_vm;
62  Xaddr x = _v_new_receptor(v,v->r,TEST_RECEPTOR,self);
63  _v_activate(v,x);
64 
65  // now create bindings for the RECONIZEE half of the protocols
66  bindings = _t_new_root(PROTOCOL_BINDINGS);
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);
81 
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))))))");
83 
84  /* debug_enable(D_PROTOCOL); */
85  /* debug_enable(D_TREE); */
86  /* debug_enable(D_SIGNALS); */
87  // now initiate recognition
88  _o_initiate(self,RECOGNIZE,backnforth,bindings);
89  _p_reduceq(self->q);
90  debug_disable(D_SIGNALS);
91 
92  // which should produce signals on the flux
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)");
96 
97  _v_deliver_signals(v,self);
98  // check the signal's envelope, body, and run-tree
99  T *signals = __r_get_signals(self,DEFAULT_ASPECT);
100  T *h = _t_clone(_t_getv(signals,1,SignalMessageIdx,MessageHeadIdx,TREE_PATH_TERMINATOR));
101  _t_free(_t_detach_by_idx(h,HeadOptionalsIdx)); // get rid of the end conditions which are variable so we can't test them!
102  spec_is_str_equal(t2s(h),"(HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:backnforth))");
103  _t_free(h);
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))");
106 
107  // debug_enable(D_REDUCE+D_REDUCEV);
108 
109  // which when get reduced, return the i_am result
110  _p_reduceq(self->q);
111  debug_disable(D_TREE);
112  debug_disable(D_PROTOCOL);
113  debug_disable(D_STEP);
114  debug_disable(D_REDUCE+D_REDUCEV);
115 
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))}))))");
117  _v_deliver_signals(v,self);
118 
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))");
120 
121  debug_disable(D_SIGNALS);
122 
123  //@todo cleanup! which we can't do yet because we haven't written code to remove installed receptors
124 }
125 
126 void testProtocolAlive() {
127  SemTable *sem = G_vm->r->sem;
128 
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)))))");
130 
131  Receptor *r = _r_new(sem,TEST_RECEPTOR);
132 
133  _o_express_role(r,ALIVE,SERVER,DEFAULT_ASPECT,NULL);
134 
135  // check that it was expressed
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)))");
137 
138  Receptor *r2 = _r_new(sem,TEST_RECEPTOR);
139  T *noop = _t_new_root(NOOP);
140  _t_newi(noop,TEST_INT_SYMBOL,314);
141  Process proc = _r_define_process(r2,noop,"do nothing","long desc...",NULL,NULL);
142 
143  T *bindings = _t_build(G_sem,0,PROTOCOL_BINDINGS,RESOLUTION,WHICH_PROCESS,GOAL,HANDLER,ACTUAL_PROCESS,proc,NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL);
144 
145  _o_express_role(r2,ALIVE,CLIENT,DEFAULT_ASPECT,bindings);
146  _t_free(bindings);
147 
148  // check that the expressed expectation is bound correctly to the handler
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)))");
150 
151  T *s = __r_make_signal(r->addr,r->addr,DEFAULT_ASPECT,alive,_t_new_root(PING),0,0,0);
152  //debug_enable(D_SIGNALS);
153  spec_is_equal(_r_deliver(r,s),noDeliveryErr);
154  spec_is_str_equal(_td(r,r->q->active->context->run_tree),"(RUN_TREE (process:RESPOND (SIGNAL_REF:/2/1/4) (YUP)) (PARAMS))"); // responds on the carrier in the signal envelope
155  debug_disable(D_SIGNALS);
156  spec_is_equal(_p_reduceq(r->q),noReductionErr);
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)}))))");
159 
160  _r_free(r);
161  _r_free(r2);
162 }
163 
164 Protocol simple;
165 Symbol agent;
166 Symbol process;
167 Symbol data;
168 T *simple_def;
169 
170 Protocol shake;
171 Symbol mover;
172 Symbol shaker;
173 Symbol shaking;
174 Symbol info;
175 T *shake_def;
176 
177 void _setupTestProtocols() {
178 
179  // a simple abstract protocol with an agent a process and some data
180  agent = _d_define_symbol(G_sem,RECEPTOR_ADDRESS,"agent",TEST_CONTEXT);
181  process = _d_define_symbol(G_sem,PROCESS,"process",TEST_CONTEXT);
182  data = _d_define_symbol(G_sem,SYMBOL,"data",TEST_CONTEXT);
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);
185 
186  Symbol act = _d_define_symbol(G_sem,INTERACTION,"act",TEST_CONTEXT);
187 
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)))))");
189  simple = _d_define_protocol(G_sem,simple_def,TEST_CONTEXT);
190 
191  // a protocol that's a wrapping of the simple protocol
192  mover = _d_define_symbol(G_sem,RECEPTOR_ADDRESS,"mover",TEST_CONTEXT);
193  shaker = _d_define_symbol(G_sem,RECEPTOR_ADDRESS,"shaker",TEST_CONTEXT);
194  shaking = _d_define_symbol(G_sem,PROCESS,"shaking",TEST_CONTEXT);
195  info = _d_define_symbol(G_sem,SYMBOL,"info",TEST_CONTEXT);
196 
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)))))");
198  shake = _d_define_protocol(G_sem,shake_def,TEST_CONTEXT);
199 }
200 
201 void testProtocolResolve() {
202 
203  T *noop = _t_new_root(NOOP);
204  _t_newi(noop,TEST_INT_SYMBOL,314);
205  Process proc = _d_define_process(G_sem,noop,"do_nothing","long desc...",NULL,NULL,TEST_CONTEXT);
206 
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))))");
208 
209  T *resolved = _t_clone(simple_def);
210  T *sem_map = _o_bindings2sem_map(bindings,NULL,NULL);
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))))");
212  T *unbound = _o_resolve(G_sem,resolved,sem_map);
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))))");
215 
216  _t_free(bindings);
217  _t_free(sem_map);
218  _t_free(resolved);
219 }
220 
221 void testProtocolUnwrap() {
222  T *sem_map = _t_new_root(SEMANTIC_MAP);
223  //debug_enable(D_PROTOCOL);
224  T *unwrapped = _o_unwrap(G_sem,shake_def,sem_map);
225  //debug_disable(D_PROTOCOL);
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))))");
227  _t_free(sem_map);
228 
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)))))");
230  _t_free(unwrapped);
231 }
232 
233 void testProtocolDefaults() {
234  // protocol defaults should get added into to the semantic map for items not in the bindings
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);
237  T *sem_map = _o_bindings2sem_map(bindings,NULL,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))))");
239  _t_free(sem_map);
240  _t_free(bindings);
241 }
242 
243 /* Symbol wrapper [(token,conversationbody)]; */
244 /* Symbol open_request,close_notice ; */
245 /* T *def = _o_make_protocol_def */
246 /* (sem,"connect", // establish a session connection */
247 /* ROLE,connector, // TCP socket client stack */
248 /* ROLE,connectee, // TCP socket server stack */
249 /* ROLE,source, // mail client */
250 /* ROLE,destination,// mail server */
251 /* USAGE,session_token, // new higher port given in open negotiation */
252 /* CARRYING,conversation, // SMTP */
253 
254 /* INTERACTION,"open", // receive on port 25 negotiate new port (as token) */
255 /* INITIATE,connector,connectee, send open_request,bind response token to source. */
256 /* EXPECT,connectee,connector,pattern=open_request, generate token/connector, bind pair with destination, return token, ENABLE "converse","close" */
257 /* INTERACTION,"converse", */
258 /* INITIATE,connector,connectee send conversation inside wrapper */
259 /* EXPECT,connectee,connector,pattern=wrapper,unwrap and map source & */
260 /* INTERACTION,"close", */
261 /* EXPECT,connector,connectee,pattern=close_notice, tell source about closing, */
262 /* EXPECT,connectee,connector,pattern=close_notice, tell destination about closing, cleanup token. */
263 /* NULL_SYMBOL); */
264 
265 
266 
267 void testProtocol() {
268  G_vm = _v_new();
269  _setupTestProtocols();
270  testProtocolResolve();
271  testProtocolUnwrap();
272  testProtocolRequesting();
273  testProtocolRecognize();
274  testProtocolAlive();
275  testProtocolDefaults();
276  _v_free(G_vm);
277 }
T * _t_new_root(Symbol symbol)
Definition: tree.c:160
Definition: ceptr_types.h:114
Process _d_define_process(SemTable *sem, T *code, char *name, char *intention, T *signature, T *link, Context c)
Definition: def.c:336
T * _o_bindings2sem_map(T *bindings, T *sem_map, T *defaults)
Definition: protocol.c:234
T * _t_detach_by_idx(T *t, int i)
Definition: tree.c:278
T * _t_clone(T *t)
Definition: tree.c:589
void _r_free(Receptor *r)
Definition: receptor.c:186
Error _p_reduceq(Q *q)
Definition: process.c:2126
void _v_free(VMHost *v)
Definition: vmhost.c:71
ReceptorAddress addr
the address by which to get messages to this receptor instance
Definition: ceptr_types.h:241
VMHost * _v_new()
Creates a new virtual machine host.
Definition: vmhost.c:41
Q * q
process queue
Definition: ceptr_types.h:250
T * _o_unwrap(SemTable *sem, T *def, T *sem_map)
Definition: protocol.c:262
T * flux
pointer for quick access to the flux
Definition: ceptr_types.h:243
void _v_activate(VMHost *v, Xaddr x)
Definition: vmhost.c:172
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
Definition: receptor.c:88
Qe * active
active processes
Definition: ceptr_types.h:209
void _o_initiate(Receptor *r, SemanticID protocol, SemanticID interaction, T *bindings)
Definition: protocol.c:506
Symbol _d_define_symbol(SemTable *sem, Structure s, char *label, Context c)
Definition: def.c:83
Definition: vmhost.h:40
T * __r_make_signal(ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *signal_contents, UUIDt *in_response_to, T *until, T *cid)
Definition: receptor.c:515
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
Definition: ceptr_types.h:242
void _o_express_role(Receptor *r, Protocol protocol, Symbol role, Aspect aspect, T *bindings)
Definition: protocol.c:409
Receptor * r
Receptor data for this vm host.
Definition: vmhost.h:43
Qe * completed
completed processes (pending cleanup)
Definition: ceptr_types.h:210
Protocol _d_define_protocol(SemTable *sem, T *def, Context c)
Definition: def.c:357
T * _t_parse(SemTable *sem, T *parent, char *s,...)
Definition: tree.c:919
T * run_tree
pointer to the root of the run_tree
Definition: ceptr_types.h:172
void _v_deliver_signals(VMHost *v, Receptor *sender)
Definition: vmhost.c:235
Error _r_deliver(Receptor *r, T *signal)
Definition: receptor.c:954
Process _r_define_process(Receptor *r, T *code, char *name, char *intention, T *signature, T *link)
Definition: receptor.c:275
void _t_free(T *t)
Definition: tree.c:526
T * _t_build(SemTable *sem, T *parent,...)
Definition: tree.c:635
T * _t_getv(T *t,...)
Definition: tree.c:1470
T * _o_resolve(SemTable *sem, T *def, T *sem_map)
Definition: protocol.c:372