3 char *key_u32
= "test_u32";
4 char *key_str
= "test_str";
5 char *key_mem
= "test_mem";
6 char *key_map
= "test_map";
7 char *key_label
= "test_label";
9 /*===========================================================================*
11 *===========================================================================*/
17 /* Publish and retrieve. */
18 r
= ds_publish_u32(key_u32
, 1234, 0);
20 r
= ds_retrieve_u32(key_u32
, &value
);
21 assert(r
== OK
&& value
== 1234);
23 /* If dstest deletes 'test_u32' immediately after publishing it,
24 * subs will catch the event, but it can't check it immediately.
25 * So dstest will sleep 2 seconds to wait for subs to complete. */
28 /* Publish again without DSF_OVERWRITE. */
29 r
= ds_publish_u32(key_u32
, 4321, 0);
32 /* Publish again with DSF_OVERWRITE to overwrite it. */
33 r
= ds_publish_u32(key_u32
, 4321, DSF_OVERWRITE
);
35 r
= ds_retrieve_u32(key_u32
, &value
);
36 assert(r
== OK
&& value
== 4321);
39 r
= ds_delete_u32(key_u32
);
41 r
= ds_retrieve_u32(key_u32
, &value
);
44 printf("DSTEST: U32 test successful!\n");
47 /*===========================================================================*
49 *===========================================================================*/
53 char *string
= "little";
54 char *longstring
= "verylooooooongstring";
57 r
= ds_publish_str(key_str
, string
, 0);
60 r
= ds_retrieve_str(key_str
, buf
, sizeof(buf
)-1);
61 assert(r
== OK
&& strcmp(string
, buf
) == 0);
63 r
= ds_delete_str(key_str
);
66 /* Publish a long string. */
67 r
= ds_publish_str(key_str
, longstring
, 0);
70 r
= ds_retrieve_str(key_str
, buf
, sizeof(buf
)-1);
71 assert(r
== OK
&& strcmp(string
, buf
) != 0
72 && strncmp(longstring
, buf
, sizeof(buf
)-1) == 0);
74 r
= ds_delete_str(key_str
);
77 printf("DSTEST: STRING test successful!\n");
80 /*===========================================================================*
82 *===========================================================================*/
85 char *string1
= "ok, this is a string";
86 char *string2
= "ok, this is a very looooong string";
87 size_t len1
= strlen(string1
) + 1;
88 size_t len2
= strlen(string2
) + 1;
93 /* Publish and retrieve. */
94 r
= ds_publish_mem(key_mem
, string1
, len1
, 0);
97 r
= ds_retrieve_mem(key_mem
, buf
, &get_len
);
98 assert(r
== OK
&& strcmp(string1
, buf
) == 0);
99 assert(get_len
== len1
);
101 /* Let get_len=8, which is less than strlen(string1). */
103 r
= ds_retrieve_mem(key_mem
, buf
, &get_len
);
104 assert(r
== OK
&& get_len
== 8);
106 /* Publish again to overwrite with a bigger memory range. */
107 r
= ds_publish_mem(key_mem
, string2
, len2
, DSF_OVERWRITE
);
111 r
= ds_retrieve_mem(key_mem
, buf
, &get_len
);
112 assert(r
== OK
&& strcmp(string2
, buf
) == 0);
113 assert(get_len
== len2
);
115 r
= ds_delete_mem(key_mem
);
118 printf("DSTEST: MEM test successful!\n");
121 /*===========================================================================*
123 *===========================================================================*/
124 void test_label(void)
127 char label
[DS_MAX_KEYLEN
];
130 /* Retrieve own label and endpoint. */
131 r
= ds_retrieve_label_name(label
, getprocnr());
133 r
= ds_retrieve_label_endpt(label
, &endpoint
);
134 assert(r
== OK
&& endpoint
== getprocnr());
136 /* Publish and delete. */
137 r
= ds_publish_label(label
, endpoint
, 0);
139 r
= ds_delete_label(label
);
142 printf("DSTEST: LABEL test successful!\n");
145 /*===========================================================================*
147 *===========================================================================*/
150 char buf_buf
[CLICK_SIZE
* 2];
151 char buf_buf2
[CLICK_SIZE
* 2];
153 char get_buf
[CLICK_SIZE
];
161 buf
= (char*) CLICK_CEIL(buf_buf
);
162 buf2
= (char*) CLICK_CEIL(buf_buf2
);
166 get_p
= (int *)get_buf
;
169 r
= ds_publish_map(key_map
, buf
, CLICK_SIZE
, 0);
172 r
= ds_snapshot_map(key_map
, &is
);
175 /* Copy the mapped memory range.
176 * Set *p=2, then the mapped memory range should change too
177 * and *get_p should be 2.
180 get_len
= CLICK_SIZE
;
181 r
= ds_retrieve_map(key_map
, get_buf
, &get_len
, 0, DSMF_COPY_MAPPED
);
182 assert(r
== OK
&& get_len
== CLICK_SIZE
&& *get_p
== 2);
184 /* Copy snapshot, where *get_p should still be 1. */
185 get_len
= CLICK_SIZE
;
186 r
= ds_retrieve_map(key_map
, get_buf
, &get_len
, is
, DSMF_COPY_SNAPSHOT
);
187 assert(r
== OK
&& get_len
== CLICK_SIZE
&& *get_p
== 1);
189 /* Map the mapped memory range to @buf2, then set *p=3, which
190 * in turn should let *p2=3.
192 get_len
= CLICK_SIZE
;
193 r
= ds_retrieve_map(key_map
, buf2
, &get_len
, 0, DSMF_MAP_MAPPED
);
194 assert(r
== OK
&& get_len
== CLICK_SIZE
);
198 r
= ds_delete_map(key_map
);
201 printf("DSTEST: MAP test successful!\n");
204 /*===========================================================================*
205 * sef_cb_init_fresh *
206 *===========================================================================*/
207 static int sef_cb_init_fresh(int UNUSED(type
), sef_init_info_t
*UNUSED(info
))
209 /* Run all the tests. */
219 /*===========================================================================*
220 * sef_local_startup *
221 *===========================================================================*/
222 static void sef_local_startup(void)
224 /* Let SEF perform startup. */
225 sef_setcb_init_fresh(sef_cb_init_fresh
);
230 /*===========================================================================*
232 *===========================================================================*/
235 /* SEF local startup. */