7 #include "../src/ceptr.h"
8 #include "../src/accumulator.h"
11 #include <sys/types.h>
15 void _testReceptorClockAddExpectation(
Receptor *r);
16 void testAccBootStrap() {
17 spec_is_ptr_equal(G_vm,NULL);
22 char *dname =
"tmp/test_vm";
25 system(
"rm -r tmp/test_vm");
28 spec_is_equal(stat(dname, &st),0);
30 spec_is_str_equal(t2s(G_vm->
r->
root),
"(RECEPTOR_INSTANCE (INSTANCE_OF:SYS_RECEPTOR) (CONTEXT_NUM:0) (PARENT_CONTEXT_NUM:-1) (RECEPTOR_STATE (FLUX (DEFAULT_ASPECT (EXPECTATIONS) (SIGNALS))) (PENDING_SIGNALS) (PENDING_RESPONSES) (CONVERSATIONS) (RECEPTOR_ELAPSED_TIME:0)))");
33 spec_is_equal(G_vm->active_receptor_count,1);
35 spec_is_str_equal(t2s(clock->
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)))");
38 T *tick = __r_make_tick();
56 spec_is_ptr_equal(G_vm,NULL);
64 Xaddr x = {CLOCK_RECEPTOR,1};
66 spec_is_false(ct == NULL);
86 void testAccInstances() {
88 T *t = _t_newi(0,TEST_INT_SYMBOL,1);
90 Xaddr x = _a_new_instance(&i,t);
91 spec_is_ptr_equal(t,_a_get_instance(&i,x));
93 t = _t_newi(0,TEST_INT_SYMBOL,2);
94 _a_set_instance(&i,x,t);
95 spec_is_ptr_equal(t,_a_get_instance(&i,x));
97 t = _t_new_str(0,TEST_STR_SYMBOL,
"fish");
98 x = _a_new_instance(&i,t);
100 t = _t_newi(0,TEST_INT_SYMBOL,3);
101 x = _a_new_instance(&i,t);
103 t = _t_newi(0,TEST_INT_SYMBOL,4);
104 _a_new_instance(&i,t);
105 _a_delete_instance(&i,x);
107 t = _a_get_instance(&i,x);
108 spec_is_ptr_equal(t,NULL);
110 spec_is_str_equal(t2s(i),
"(INSTANCE_STORE (INSTANCES (SYMBOL_INSTANCES:TEST_INT_SYMBOL (TEST_INT_SYMBOL:2) (DELETED_INSTANCE) (TEST_INT_SYMBOL:4)) (SYMBOL_INSTANCES:TEST_STR_SYMBOL (TEST_STR_SYMBOL:fish))))");
111 _a_free_instances(&i);
114 void testAccGetInstances() {
119 t = _t_newi(0,TEST_INT_SYMBOL,1);
120 x = _a_new_instance(&i,t);
121 t = _t_newi(0,TEST_INT_SYMBOL,2);
122 x = _a_new_instance(&i,t);
123 t = _t_newi(0,TEST_INT_SYMBOL,3);
124 x = _a_new_instance(&i,t);
125 t = _t_newi(0,TEST_INT_SYMBOL,4);
126 _a_new_instance(&i,t);
128 spec_is_str_equal(t2s(i),
"(INSTANCE_STORE (INSTANCES (SYMBOL_INSTANCES:TEST_INT_SYMBOL (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:2) (TEST_INT_SYMBOL:3) (TEST_INT_SYMBOL:4))))");
130 _a_delete_instance(&i,x);
133 _a_get_instances(&i,TEST_INT_SYMBOL,t);
134 spec_is_str_equal(t2s(t),
"(ITERATION_DATA (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:2) (TEST_INT_SYMBOL:4))");
137 _a_free_instances(&i);
141 void testAccPersistInstances() {
144 T *it = _t_newi(0,TEST_INT_SYMBOL,1);
145 _a_new_instance(&i,it);
147 it = _t_newi(0,TEST_INT_SYMBOL,2);
148 Xaddr z = _a_new_instance(&i,it);
151 _t_newi(t,TEST_INT_SYMBOL,314);
152 Xaddr x = _a_new_instance(&i,t);
156 Xaddr y = _a_new_instance(&i,ht);
158 S *s = __a_serialize_instances(&i);
159 _a_free_instances(&i);
160 __a_unserialize_instances(G_sem,&i,s);
162 spec_is_str_equal(t2s(_a_get_instance(&i,x)),
"(PARAMS (TEST_INT_SYMBOL:314))");
163 spec_is_str_equal(t2s(_a_get_instance(&i,y)),t2s(htc));
164 spec_is_str_equal(t2s(_a_get_instance(&i,z)),
"(TEST_INT_SYMBOL:2)");
167 _a_free_instances(&i);
171 void testAccToken() {
173 T *t,*token1,*token2,*d1,*d2;
176 t = _t_newi(0,TEST_INT_SYMBOL,1);
177 x = _a_new_instance(&i,t);
179 d1 = _t_newi(0,TEST_INT_SYMBOL,314);
180 d2 = _t_newi(0,TEST_INT_SYMBOL,123);
182 token1 = _a_gen_token(&i,x,d1);
183 token2 = _a_gen_token(&i,x,d2);
185 spec_is_str_equal(t2s(i),
"(INSTANCE_STORE (INSTANCES (SYMBOL_INSTANCES:TEST_INT_SYMBOL (TEST_INT_SYMBOL:1))) (INSTANCE_TOKENS (LAST_TOKEN:2) (INSTANCE_TOKEN:1 (TOKEN_XADDR:TEST_INT_SYMBOL.1) (DEPENDENCY_HASH:-1641288256)) (INSTANCE_TOKEN:2 (TOKEN_XADDR:TEST_INT_SYMBOL.1) (DEPENDENCY_HASH:1282387645))))");
188 xx = _a_get_token_xaddr(&i,token1,d1);
189 spec_is_xaddr_equal(G_sem,x,xx);
190 xx = _a_get_token_xaddr(&i,token2,d2);
191 spec_is_xaddr_equal(G_sem,x,xx);
194 xx = _a_get_token_xaddr(&i,token1,d2);
195 spec_is_true(is_null_xaddr(xx));
196 xx = _a_get_token_xaddr(&i,token2,d1);
197 spec_is_true(is_null_xaddr(xx));
200 T *d3 = _t_newi(0,TEST_INT_SYMBOL,999);
201 xx = _a_get_token_xaddr(&i,token1,d3);
202 spec_is_true(is_null_xaddr(xx));
203 _a_add_dependency(&i,token1,d3);
204 char *with_two_dependencies =
"(INSTANCE_STORE (INSTANCES (SYMBOL_INSTANCES:TEST_INT_SYMBOL (TEST_INT_SYMBOL:1))) (INSTANCE_TOKENS (LAST_TOKEN:2) (INSTANCE_TOKEN:1 (TOKEN_XADDR:TEST_INT_SYMBOL.1) (DEPENDENCY_HASH:-1641288256) (DEPENDENCY_HASH:-226474859)) (INSTANCE_TOKEN:2 (TOKEN_XADDR:TEST_INT_SYMBOL.1) (DEPENDENCY_HASH:1282387645))))";
205 spec_is_str_equal(t2s(i),with_two_dependencies);
207 _a_add_dependency(&i,token1,d3);
208 spec_is_str_equal(t2s(i),with_two_dependencies);
210 xx = _a_get_token_xaddr(&i,token1,d3);
211 spec_is_xaddr_equal(G_sem,x,xx);
212 xx = _a_get_token_xaddr(&i,token2,d3);
213 spec_is_true(is_null_xaddr(xx));
217 _a_delete_dependency(&i,token1,d3);
218 spec_is_str_equal(t2s(i),
"(INSTANCE_STORE (INSTANCES (SYMBOL_INSTANCES:TEST_INT_SYMBOL (TEST_INT_SYMBOL:1))) (INSTANCE_TOKENS (LAST_TOKEN:2) (INSTANCE_TOKEN:1 (TOKEN_XADDR:TEST_INT_SYMBOL.1) (DEPENDENCY_HASH:-1641288256)) (INSTANCE_TOKEN:2 (TOKEN_XADDR:TEST_INT_SYMBOL.1) (DEPENDENCY_HASH:1282387645))))");
219 xx = _a_get_token_xaddr(&i,token1,d3);
220 spec_is_true(is_null_xaddr(xx));
223 _a_delete_token(&i,token1);
224 spec_is_str_equal(t2s(i),
"(INSTANCE_STORE (INSTANCES (SYMBOL_INSTANCES:TEST_INT_SYMBOL (TEST_INT_SYMBOL:1))) (INSTANCE_TOKENS (LAST_TOKEN:2) (INSTANCE_TOKEN:2 (TOKEN_XADDR:TEST_INT_SYMBOL.1) (DEPENDENCY_HASH:1282387645))))");
231 _a_free_instances(&i);
235 void testAccumulator() {
236 struct stat st = {0};
237 char *temp_dir =
"tmp";
238 if (stat(temp_dir, &st) == -1) {
239 mkdir(temp_dir,0700);
244 testAccGetInstances();
245 testAccPersistInstances();
T * _t_new_root(Symbol symbol)
T * flux
pointer for quick access to the flux
T * root
RECEPTOR_INSTANCE semantic tree.
void _a_boot(char *dir_path)
ActiveReceptor active_receptors[MAX_ACTIVE_RECEPTORS]
pointer to array that holds all currently active receptors
T * _makeTestHTTPRequestTree()
[makeTestHTTPRequestTree]
T * _r_get_instance(Receptor *r, Xaddr x)
Receptor * r
Receptor data for this vm host.