7 #include "../src/ceptr.h"
8 #include "../src/receptor.h"
9 #include "../src/def.h"
10 #include "../src/accumulator.h"
11 #include "../src/vmhost.h"
12 #include "../src/protocol.h"
20 r =
_r_new(G_sem,TEST_RECEPTOR);
27 t = __r_get_expectations(r,DEFAULT_ASPECT);
28 spec_is_symbol_equal(r,
_t_symbol(t),EXPECTATIONS);
29 t = __r_get_signals(r,DEFAULT_ASPECT);
30 spec_is_symbol_equal(r,
_t_symbol(t),SIGNALS);
33 int p[] = {ReceptorInstanceStateIdx,ReceptorFluxIdx,TREE_PATH_TERMINATOR};
36 spec_is_ptr_equal(t,r->
flux);
38 spec_is_symbol_equal(r,
_t_symbol(t),DEFAULT_ASPECT);
40 spec_is_str_equal(t2s(r->
root),
"(RECEPTOR_INSTANCE (INSTANCE_OF:TEST_RECEPTOR) (CONTEXT_NUM:3) (PARENT_CONTEXT_NUM:0) (RECEPTOR_STATE (FLUX (DEFAULT_ASPECT (EXPECTATIONS) (SIGNALS))) (PENDING_SIGNALS) (PENDING_RESPONSES) (CONVERSATIONS) (RECEPTOR_ELAPSED_TIME:0)))");
46 void testReceptorAddRemoveExpectation() {
48 r =
_r_new(G_sem,TEST_RECEPTOR);
54 T *a = _t_news(0,ACTION,NULL_PROCESS);
57 T *es = __r_get_expectations(r,DEFAULT_ASPECT);
59 spec_is_str_equal(_td(r,e),
"(EXPECTATION (CARRIER:TEST_INT_SYMBOL) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_INT_SYMBOL))) (ACTION:NULL_PROCESS) (PARAMS) (END_CONDITIONS (UNLIMITED)))");
61 _r_remove_expectation(r,e);
63 spec_is_str_equal(_td(r,es),
"(EXPECTATIONS)");
67 void testReceptorSignal() {
69 T *sc,*signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
75 spec_is_symbol_equal(r,
_t_symbol(s),SIGNAL);
77 T *envelope =
_t_child(s,SignalEnvelopeIdx);
78 spec_is_str_equal(t2s(envelope),
"(ENVELOPE (SIGNAL_UUID))");
80 T *message =
_t_child(s,SignalMessageIdx);
82 T *head =
_t_child(message,MessageHeadIdx);
83 spec_is_str_equal(t2s(head),
"(HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:4)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING))");
84 T *body =
_t_child(message,MessageBodyIdx);
85 spec_is_str_equal(t2s(body),
"(BODY:{(TEST_INT_SYMBOL:314)})");
87 spec_is_ptr_equal(sc,contents);
90 UUIDt u = __uuid_gen();
92 spec_is_str_equal(t2s(s),
"(SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:4)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (IN_RESPONSE_TO_UUID)) (BODY:{(TEST_INT_SYMBOL:314)})))");
93 int p[] = {SignalMessageIdx,MessageHeadIdx,HeadOptionalsIdx,TREE_PATH_TERMINATOR};
98 T *ec = defaultRequestUntil();
100 spec_is_ptr_equal(ec,
_t_get(s,p));
106 void testReceptorSignalDeliver() {
108 T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
116 T *signals = __r_get_signals(r,DEFAULT_ASPECT);
117 spec_is_str_equal(_td(r,signals),
"(SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:4)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING)) (BODY:{(TEST_INT_SYMBOL:314)}))))");
121 void testReceptorDeliverConversation() {
123 T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
128 UUIDt cuuid = __uuid_gen();
129 T *cu = __cid_new(0,&cuuid,0);
133 spec_is_str_equal(_td(r,r->conversations),
"(CONVERSATIONS)");
136 spec_is_str_equal(_td(r,r->conversations),
"(CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS)))");
141 void testReceptorConversations() {
143 spec_is_str_equal(_td(r,r->conversations),
"(CONVERSATIONS)");
145 UUIDt u = __uuid_gen();
146 T *c = _r_add_conversation(r,0,&u,0,0);
147 spec_is_str_equal(_td(r,c),
"(CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS))");
148 spec_is_str_equal(_td(r,r->conversations),
"(CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS)))");
150 spec_is_ptr_equal(_r_find_conversation(r,&u),c);
153 UUIDt u2 = __uuid_gen();
154 T *c2 = _r_add_conversation(r,&u,&u2,0,0);
156 spec_is_str_equal(_td(r,r->conversations),
"(CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS)))))");
158 spec_is_ptr_equal(_r_find_conversation(r,&u2),c2);
161 UUIDt u3 = __uuid_gen();
162 T *c3 = _r_add_conversation(r,0,&u3,0,0);
164 spec_is_str_equal(_td(r,r->conversations),
"(CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS)))) (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS)))");
166 spec_is_ptr_equal(_r_find_conversation(r,&u3),c3);
171 extern int G_next_process_id;
172 void testReceptorResponseDeliver() {
175 G_next_process_id = 0;
182 T *req = _t_newr(p,REQUEST);
183 __r_make_addr(req,TO_ADDRESS,tt);
184 _t_news(req,ASPECT_IDENT,DEFAULT_ASPECT);
185 _t_news(req,CARRIER,TESTING);
186 _t_newi(req,TEST_INT_SYMBOL,98789);
187 _t_news(req,RESPONSE_CARRIER,TESTING);
199 spec_is_str_equal(_td(r,rt),
"(RUN_TREE (process:NOOP (SIGNAL_UUID)))");
200 T *pr =
_t_child(r->pending_responses,1);
201 spec_is_str_equal(_td(r,
_t_child(pr,1)),
"(SIGNAL_UUID)");
202 spec_is_str_equal(_td(r,
_t_child(pr,2)),
"(CARRIER:TESTING)");
203 spec_is_str_equal(_td(r,
_t_child(pr,3)),
"(WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1/1))");
205 spec_is_sem_equal(
_t_symbol(ec),END_CONDITIONS);
213 T *s =
__r_make_signal(from,to,DEFAULT_ASPECT,TESTING,_t_new_str(0,TEST_STR_SYMBOL,
"foo"),&response_id,0,0);
220 spec_is_ptr_equal(r->
q->
blocked,NULL);
225 spec_is_str_equal(_td(r,rt),
"(RUN_TREE (process:NOOP (TEST_STR_SYMBOL:foo)))");
228 spec_is_str_equal(_td(r,r->pending_responses),
"(PENDING_RESPONSES)");
233 void testReceptorEndCondition() {
235 _t_newr(until,UNLIMITED);
237 evaluateEndCondition(until,&cleanup,&allow);
238 spec_is_false(cleanup);spec_is_true(allow);
242 _t_newi(until,COUNT,2);
243 evaluateEndCondition(until,&cleanup,&allow);
244 spec_is_false(cleanup);spec_is_true(allow);
245 spec_is_str_equal(t2s(until),
"(END_CONDITIONS (COUNT:1))");
246 evaluateEndCondition(until,&cleanup,&allow);
247 spec_is_true(cleanup);spec_is_true(allow);
248 spec_is_str_equal(t2s(until),
"(END_CONDITIONS (COUNT:0))");
252 T *ts = __r_make_timestamp(TIMEOUT_AT,-2);
254 evaluateEndCondition(until,&cleanup,&allow);
255 spec_is_true(cleanup);spec_is_false(allow);
259 ts = __r_make_timestamp(TIMEOUT_AT,+2);
261 evaluateEndCondition(until,&cleanup,&allow);
262 spec_is_false(cleanup);spec_is_true(allow);
264 debug_disable(D_SIGNALS);
278 T *signal =
__r_make_signal(f,t,DEFAULT_ASPECT,HTTP_REQUEST,signal_contents,0,0,0);
283 char *stx =
"/HTTP_REQUEST_LINE/(.,.,HTTP_REQUEST_PATH/HTTP_REQUEST_PATH_SEGMENTS/<HTTP_REQUEST_PATH_SEGMENT:HTTP_REQUEST_PATH_SEGMENT>)";
303 spec_is_true(
_t_matchr(req,signal_contents,&result));
306 spec_is_str_equal(_td(r,m),
"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:HTTP_REQUEST_PATH_SEGMENT) (SEMTREX_MATCH_PATH:/3/1/1) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
318 _t_newi(until,COUNT,1);
322 _r_add_expectation(r,DEFAULT_ASPECT,HTTP_REQUEST,pattern,act,params,until,
using,NULL);
325 spec_is_equal(err,noDeliveryErr);
329 spec_is_str_equal(_td(r,__r_get_signals(r,DEFAULT_ASPECT)),
330 "(SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:4)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:HTTP_REQUEST)) (BODY:{(HTTP_REQUEST_LINE (HTTP_REQUEST_VERSION (VERSION_MAJOR:1) (VERSION_MINOR:1)) (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:groups) (HTTP_REQUEST_PATH_SEGMENT:5)) (HTTP_REQUEST_PATH_FILE (FILE_NAME:users) (FILE_EXTENSION:json)) (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:sort_by) (PARAM_VALUE:last_name)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:page) (PARAM_VALUE:2))))))})) (RUN_TREE (process:RESPOND (CARRIER:HTTP_RESPONSE) (PARAM_REF:/2/1)) (PARAMS (HTTP_RESPONSE (HTTP_RESPONSE_STATUS (STATUS_VALUE:200) (STATUS_TEXT:OK)) (HTTP_HEADERS (CONTENT_TYPE (MEDIA_TYPE_IDENT:TEXT_MEDIA_TYPE) (MEDIA_SUBTYPE_IDENT:CEPTR_TEXT_MEDIA_SUBTYPE))) (HTTP_RESPONSE_BODY (HTTP_REQUEST_PATH_SEGMENT:groups)))))))"
337 spec_is_str_equal(_td(r,r->pending_signals),
"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:4)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:HTTP_RESPONSE) (IN_RESPONSE_TO_UUID)) (BODY:{(HTTP_RESPONSE (HTTP_RESPONSE_STATUS (STATUS_VALUE:200) (STATUS_TEXT:OK)) (HTTP_HEADERS (CONTENT_TYPE (MEDIA_TYPE_IDENT:TEXT_MEDIA_TYPE) (MEDIA_SUBTYPE_IDENT:CEPTR_TEXT_MEDIA_SUBTYPE))) (HTTP_RESPONSE_BODY (HTTP_REQUEST_PATH_SEGMENT:groups)))}))))");
341 spec_is_str_equal(_td(r,result),
"(SIGNAL_UUID)");
347 T *es = __r_get_expectations(r,DEFAULT_ASPECT);
348 spec_is_str_equal(_td(r,es),
"(EXPECTATIONS)");
354 void testReceptorDef() {
362 T *def = _sem_get_def(r->
sem,lat);
363 spec_is_str_equal(t2s(def),
"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:Latitude)) (SYMBOL_STRUCTURE:FLOAT))");
364 def = _sem_get_def(r->
sem,lon);
365 spec_is_str_equal(t2s(def),
"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:Longitude)) (SYMBOL_STRUCTURE:FLOAT))");
369 __sem_get_by_label(G_sem,
"Latitude",&sid,r->
context);
370 spec_is_sem_equal(sid,lat);
374 def = _sem_get_def(r->
sem,latlong);
375 spec_is_str_equal(t2s(def),
"(STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:Latlong)) (STRUCTURE_SEQUENCE (STRUCTURE_SYMBOL:Latitude) (STRUCTURE_SYMBOL:Longitude)))");
390 char surface[] ={1,2,3,4,5,6,7,8,
'b',
'o',
'b',
'b',
'y',0};
395 def = _sem_get_def(r->
sem,p);
397 spec_is_str_equal(_td(r,def),
"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:do nothing)) (PROCESS_INTENTION:long version of doing nothing) (process:NOOP) (PROCESS_SIGNATURE))");
425 T *t_lat = _t_new(t,lat,&x,
sizeof(x));
426 T *t_lon = _t_new(t,lon,&x,
sizeof(x));
430 spec_is_str_equal(
_dump_semtrex(r->
sem,stx,buf),
"/house location/(latitude,longitude)");
431 __t_dump(r->
sem,stx,0,buf);
432 spec_is_str_equal(buf,
"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:house location) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:latitude)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:longitude))))");
438 t_lon->contents.symbol = lat;
461 float ll[] = {132.5,92.3};
462 T *t_lat = _t_new(t,lat,&ll[0],
sizeof(
float));
463 T *t_lon = _t_new(t,lon,&ll[1],
sizeof(
float));
466 spec_is_equal(x.addr,1);
467 spec_is_sem_equal(x.symbol,house_loc);
472 wjson(r->
sem,i,
"houseloc",-1);
473 spec_is_ptr_equal(i,t);
477 spec_is_ptr_equal(i,NULL);
496 float ll[] = {132.5,92.3};
497 T *t_lat = _t_new(t,lat,&ll[0],
sizeof(
float));
498 T *t_lon = _t_new(t,lon,&ll[1],
sizeof(
float));
507 T *t2 = _t_newi(0,TEST_INT_SYMBOL,314);
515 T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
520 T *s =
__r_make_signal(from,to,DEFAULT_ASPECT,TESTING,signal_contents,0,0,0);
527 S *s1 = (
S *)surface;
528 S *s2 = (
S *)(surface + s1->total_size);
529 spec_is_long_equal(length,s1->total_size+s2->total_size);
539 __t_dump(r->
sem,r->
root,0,buf);
540 __t_dump(ru->
sem,ru->
root,0,buf1);
541 spec_is_str_equal(buf1,buf);
545 spec_is_sem_equal(
_t_symbol(ru->pending_signals),PENDING_SIGNALS);
546 spec_is_sem_equal(
_t_symbol(ru->pending_responses),PENDING_RESPONSES);
554 buf[0] = buf1[0] = 0;
555 __t_dump(r->
sem,t,0,buf);
556 __t_dump(ru->
sem,t1,0,buf1);
557 spec_is_str_equal(buf1,buf);
560 spec_is_true(t1 != NULL);
562 buf[0] = buf1[0] = 0;
563 __t_dump(r->
sem,ir,0,buf);
564 __t_dump(ru->
sem,t1,0,buf1);
565 spec_is_str_equal(buf1,buf);
593 sprintf(buf,
"exp%d",i);
596 integer =
_r_define_structure(r,
"integer",16,exps[0],exps[1],exps[2],exps[3],exps[4],exps[5],exps[6],exps[7],exps[8],exps[9],exps[10],exps[11],exps[12],exps[13],exps[14],exps[15]);
606 void makeInt(
T *t,
int v) {
609 _t_newi(t,exps[i],(v>>i)&1);
612 void testReceptorNums() {
618 T *lat = _t_newr(t,latitude);
619 T *lon = _t_newr(t,longitude);
620 T *m = _t_newr(lat,mantissa);
621 T *e = _t_newr(lat,exponent);
624 m = _t_newr(lon,mantissa);
625 e = _t_newr(lon,exponent);
628 spec_is_str_equal(_td(r,t),
"(home_location (latitude (mantissa (exp0:0) (exp1:1) (exp2:1) (exp3:0) (exp4:1) (exp5:0) (exp6:0) (exp7:0) (exp8:0) (exp9:0) (exp10:0) (exp11:0) (exp12:0) (exp13:0) (exp14:0) (exp15:0)) (exponent (exp0:1) (exp1:0) (exp2:0) (exp3:0) (exp4:0) (exp5:0) (exp6:0) (exp7:0) (exp8:0) (exp9:0) (exp10:0) (exp11:0) (exp12:0) (exp13:0) (exp14:0) (exp15:0))) (longitude (mantissa (exp0:1) (exp1:0) (exp2:0) (exp3:0) (exp4:0) (exp5:0) (exp6:0) (exp7:0) (exp8:0) (exp9:0) (exp10:0) (exp11:0) (exp12:0) (exp13:0) (exp14:0) (exp15:0)) (exponent (exp0:0) (exp1:1) (exp2:0) (exp3:0) (exp4:0) (exp5:0) (exp6:0) (exp7:0) (exp8:0) (exp9:0) (exp10:0) (exp11:0) (exp12:0) (exp13:0) (exp14:0) (exp15:0))))");
629 wjson(r->
sem,t,
"homeloc",-1);
635 void testReceptorEdgeStream() {
637 char buffer[] =
"line1\nline2\n";
639 rs = fmemopen(buffer, strlen (buffer),
"r");
640 Stream *reader_stream = _st_new_unix_stream(rs,1);
646 ws = open_memstream(&output_data,&size);
647 Stream *writer_stream = _st_new_unix_stream(ws,0);
650 Xaddr edge = _v_new_receptor(v,v->
r,STREAM_EDGE,r);
651 _r_addWriter(r,writer_stream,DEFAULT_ASPECT);
652 _r_addReader(r,reader_stream,r->
addr,DEFAULT_ASPECT,LINE,LINE,
false);
654 spec_is_str_equal(_td(r,__r_get_expectations(r,DEFAULT_ASPECT)),
"(EXPECTATIONS (EXPECTATION (CARRIER:NULL_SYMBOL) (PATTERN (SEMTREX_SYMBOL_ANY)) (ACTION:echo2stream) (PARAMS (EDGE_STREAM) (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (UNLIMITED))))");
659 Stream *st = reader_stream;
661 while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
663 while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
665 while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
668 spec_is_false(_st_is_alive(st));
672 spec_is_equal(r->
q->
completed->context->
err,deadStreamReadReductionErr);
679 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:LINE)) (BODY:{(LINE:line1)}))) (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE)) (BODY:{(LINE:line2)}))))");
685 spec_is_str_equal(_td(r,__r_get_signals(r,DEFAULT_ASPECT)),
"(SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE)) (BODY:{(LINE:line1)})) (RUN_TREE (process:STREAM_WRITE (PARAM_REF:/2/1) (process:TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINES)) (TRANSCODE_ITEMS (PARAM_REF:/2/2)))) (PARAMS (EDGE_STREAM) (LINE:line1)))) (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE)) (BODY:{(LINE:line2)})) (RUN_TREE (process:STREAM_WRITE (PARAM_REF:/2/1) (process:TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINES)) (TRANSCODE_ITEMS (PARAM_REF:/2/2)))) (PARAMS (EDGE_STREAM) (LINE:line2)))))");
688 spec_is_str_equal(_td(r,r->pending_signals),
"(PENDING_SIGNALS)");
690 spec_is_str_equal(_td(r,r->
q->
active->context->
run_tree),
"(RUN_TREE (process:STREAM_WRITE (PARAM_REF:/2/1) (process:TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINES)) (TRANSCODE_ITEMS (PARAM_REF:/2/2)))) (PARAMS (EDGE_STREAM) (LINE:line1)))");
695 debug_disable(D_REDUCE+D_STEP);
697 spec_is_str_equal(_td(r,r->
q->
completed->context->
run_tree),
"(RUN_TREE (REDUCTION_ERROR_SYMBOL:NULL_SYMBOL) (PARAMS (EDGE_STREAM) (LINE:line2)))");
699 spec_is_str_equal(output_data,
"line1\nline2\n");
707 void *_ltester(
void *arg) {
708 char *result = doSys(
"echo 'testing!\nfish\n' | nc localhost 8888");
709 spec_is_str_equal(result,
"testing!\nfish\n\n");
715 void testReceptorEdgeListener() {
718 Xaddr edge = _v_new_receptor(v,v->
r,STREAM_EDGE,r);
753 T *code =
_t_parse(r->
sem,0,
"(CONVERSE (SCOPE (LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE) (PATTERN (SEMTREX_SYMBOL_ANY)) (ACTION:echo2stream) (PARAMS (PARAM_REF:/2/1) (SLOT (USAGE:NULL_SYMBOL)))) (ITERATE (PARAMS) (STREAM_ALIVE (PARAM_REF:/2/1)) (SAY % (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE) (STREAM_READ (PARAM_REF:/2/1) (RESULT_SYMBOL:LINE)))) (STREAM_CLOSE (PARAM_REF:/2/1))) (BOOLEAN:1))",__r_make_addr(0,TO_ADDRESS,r->
addr));
754 T *err_handler =
_t_parse(r->
sem,0,
"(CONTINUE (POP_PATH (PARAM_REF:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:2)) (CONTINUE_VALUE (BOOLEAN:0)))");
756 SocketListener *l = _r_addListener(r,8888,code,0,err_handler,DELIM_LF);
760 spec_is_str_equal(_t2s(v->
sem,r->
edge),
"(PARAMS (EDGE_LISTENER) (process:CONVERSE (SCOPE (process:LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE) (PATTERN (SEMTREX_SYMBOL_ANY)) (ACTION:echo2stream) (PARAMS (PARAM_REF:/2/1) (SLOT (USAGE:NULL_SYMBOL)))) (process:ITERATE (PARAMS) (process:STREAM_ALIVE (PARAM_REF:/2/1)) (process:SAY (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE) (process:STREAM_READ (PARAM_REF:/2/1) (RESULT_SYMBOL:LINE)))) (process:STREAM_CLOSE (PARAM_REF:/2/1))) (BOOLEAN:1)) (PARAMS) (process:CONTINUE (process:POP_PATH (PARAM_REF:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:2)) (CONTINUE_VALUE (BOOLEAN:0))))");
767 rc = pthread_create(&thread,0,_ltester,NULL);
769 raise_error(
"ERROR; return code from pthread_create() is %d\n", rc);
771 pthread_detach(thread);
773 raise_error(
"Error detaching tester thread; return code from pthread_detach() is %d\n", rc);
775 while(!G_done) sleepms(1);
777 _v_join_thread(&v->vm_thread);
779 debug_disable(D_STREAM+D_SOCKET+D_SIGNALS+D_STEP+D_REDUCE+D_REDUCEV);
780 spec_is_str_equal(t2s(r->
flux),
"(FLUX (DEFAULT_ASPECT (EXPECTATIONS (EXPECTATION (CARRIER:LINE) (PATTERN (SEMTREX_SYMBOL_ANY)) (ACTION:echo2stream) (PARAMS (EDGE_STREAM) (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (UNLIMITED)) (CONVERSATION_IDENT (CONVERSATION_UUID)))) (SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(LINE:testing!)})) (RUN_TREE (REDUCTION_ERROR_SYMBOL:NULL_SYMBOL) (PARAMS (EDGE_STREAM) (LINE:testing!)))) (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(LINE:fish)})) (RUN_TREE (REDUCTION_ERROR_SYMBOL:NULL_SYMBOL) (PARAMS (EDGE_STREAM) (LINE:fish)))) (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:LINE) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(LINE:)})) (RUN_TREE (REDUCTION_ERROR_SYMBOL:NULL_SYMBOL) (PARAMS (EDGE_STREAM) (LINE:)))))))");
786 void testReceptorClock() {
787 Receptor *r = _r_makeClockReceptor(G_sem);
788 spec_is_str_equal(_td(r,r->
root),
"(RECEPTOR_INSTANCE (INSTANCE_OF:CLOCK_RECEPTOR) (CONTEXT_NUM:4) (PARENT_CONTEXT_NUM:0) (RECEPTOR_STATE (FLUX (DEFAULT_ASPECT (EXPECTATIONS (EXPECTATION (CARRIER:tell_time) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:CLOCK_TELL_TIME))) (ACTION:respond with current time) (PARAMS) (END_CONDITIONS (UNLIMITED)))) (SIGNALS))) (PENDING_SIGNALS) (PENDING_RESPONSES) (CONVERSATIONS) (RECEPTOR_ELAPSED_TIME:0)))");
795 __sem_get_by_label(G_sem,
"time",&time,r->
context);
796 T *def = _sem_get_def(G_sem,time);
797 spec_is_str_equal(_td(r,def),
"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:time)) (PROTOCOL_SEMANTICS (ROLE:TIME_TELLER) (ROLE:TIME_HEARER) (GOAL:RESPONSE_HANDLER)) (tell_time (INITIATE (ROLE:TIME_HEARER) (DESTINATION (ROLE:TIME_TELLER)) (ACTION:time_request)) (EXPECT (ROLE:TIME_TELLER) (SOURCE (ROLE:TIME_HEARER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:CLOCK_TELL_TIME))) (ACTION:respond with current time))))");
804 T *res = _t_newr(bindings,RESOLUTION);
805 T *w = _t_newr(res,WHICH_RECEPTOR);
806 _t_news(w,ROLE,TIME_TELLER);
807 __r_make_addr(w,ACTUAL_RECEPTOR,r->
addr);
808 res = _t_newr(bindings,RESOLUTION);
809 w = _t_newr(res,WHICH_RECEPTOR);
810 _t_news(w,ROLE,TIME_HEARER);
811 __r_make_addr(w,ACTUAL_RECEPTOR,r->
addr);
812 res = _t_newr(bindings,RESOLUTION);
813 w = _t_newr(res,WHICH_PROCESS);
814 _t_news(w,GOAL,RESPONSE_HANDLER);
819 _t_newi(noop,TEST_INT_SYMBOL,314);
821 _t_news(w,ACTUAL_PROCESS,proc);
825 spec_is_str_equal(_td(r,r->
q->
active->context->
run_tree),
"(RUN_TREE (process:do nothing (process:REQUEST (TO_ADDRESS (RECEPTOR_ADDR:4)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:tell_time) (CLOCK_TELL_TIME) (RESPONSE_CARRIER:tell_time))) (PARAMS))");
827 _test_reduce_signals(r);
831 spec_is_str_equal(_td(r,r->pending_signals),
"(PENDING_SIGNALS)");
832 spec_is_str_equal(_td(r,r->pending_responses),
"(PENDING_RESPONSES)");
834 debug_disable(D_SIGNALS);
849 raise_error(
"ERROR; return code from pthread_create() is %d\n", rc);
854 int p[] = {2,3,TREE_PATH_TERMINATOR};
862 rc = pthread_join(thread, &status);
865 raise_error(
"ERROR; return code from pthread_join() is %d\n", rc);
868 debug_disable(D_SIGNALS);
873 void testReceptor() {
875 testReceptorAddRemoveExpectation();
876 testReceptorSignal();
877 testReceptorSignalDeliver();
878 testReceptorResponseDeliver();
879 testReceptorDeliverConversation();
880 testReceptorConversations();
881 testReceptorEndCondition();
888 testReceptorEdgeStream();
889 testReceptorEdgeListener();
T * _t_new_root(Symbol symbol)
T * edge
data store for edge receptors
Structure __r_get_symbol_structure(Receptor *r, Symbol s)
find a symbol's structure
void _r_serialize(Receptor *r, void **surfaceP, size_t *lengthP)
void testReceptorCreate()
T * _t_detach_by_idx(T *t, int i)
void testReceptorDefMatch()
[defineHouseLocation]
void testReceptorInstances()
T * _t_new_receptor(T *parent, Symbol symbol, Receptor *r)
void testReceptorSerialize()
void _r_free(Receptor *r)
T * _t_child(T *t, int i)
Receptor * __r_get_receptor(T *installed_receptor)
T * _t_newp(T *parent, Symbol symbol, Process surface)
int err
process error value
Context context
the context this receptor's definition creates
ReceptorAddress addr
the address by which to get messages to this receptor instance
Structure _r_define_structure(Receptor *r, char *label, int num_params,...)
void _r_add_expectation(Receptor *r, Aspect aspect, Symbol carrier, T *pattern, T *action, T *with, T *until, T *using, T *cid)
Adds an expectation to a receptor's aspect.
VMHost * _v_new()
Creates a new virtual machine host.
T * _t_get_match(T *match, Symbol group)
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.
void testReceptorExpectation()
SemTable * sem
Semantic Table for definitions on this host.
void _makeTestHTTPResponseProcess(Receptor *r, T **paramsP, Process *pP)
[makeTestHTTPRequestTree]
Receptor * _r_unserialize(SemTable *sem, void *surface)
Qe * active
active processes
Symbol _r_get_sem_by_label(Receptor *r, char *label)
int contexts_count
number of active processes
void _st_free(Stream *st)
void _o_initiate(Receptor *r, SemanticID protocol, SemanticID interaction, T *bindings)
int _t_matchr(T *semtrex, T *t, T **rP)
T * __r_make_signal(ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *signal_contents, UUIDt *in_response_to, T *until, T *cid)
T * _r_build_def_semtrex(Receptor *r, Symbol s)
void defineHouseLocation(Receptor *r, Symbol *lat, Symbol *lon, Structure *latlong, Symbol *house_loc)
[defineHouseLocation]
T * root
RECEPTOR_INSTANCE semantic tree.
Qe * blocked
blocked processes
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
size_t __r_get_symbol_size(Receptor *r, Symbol s, void *surface)
T * _makeTestHTTPRequestTree()
[makeTestHTTPRequestTree]
T * _r_get_instance(Receptor *r, Xaddr x)
void * ___clock_thread(void *arg)
Receptor * r
Receptor data for this vm host.
#define _sl(t, s)
macro to add a single symbol literal to semtrex tree
T * parseSemtrex(SemTable *sem, char *stx)
Qe * completed
completed processes (pending cleanup)
T * _t_parse(SemTable *sem, T *parent, char *s,...)
T * run_tree
pointer to the root of the run_tree
Symbol _r_define_symbol(Receptor *r, Structure s, char *label)
void _v_deliver_signals(VMHost *v, Receptor *sender)
Error _r_deliver(Receptor *r, T *signal)
char * _dump_semtrex(SemTable *sem, T *s, char *buf)
Process _r_define_process(Receptor *r, T *code, char *name, char *intention, T *signature, T *link)
T * _r_delete_instance(Receptor *r, Xaddr x)
int _r_def_match(Receptor *r, Symbol s, T *t)
Xaddr _r_new_instance(Receptor *r, T *t)