Remove building with NOCRYPTO option
[minix.git] / minix / tests / ds / dstest.c
blobafd97624ce246200d089fe4eaf51a6a23b5d6749
1 #include "inc.h"
3 char *key_u32 = "test_u32";
4 char *key_str = "test_str";
5 char *key_mem = "test_mem";
6 char *key_label = "test_label";
8 /*===========================================================================*
9 * test_u32 *
10 *===========================================================================*/
11 void test_u32(void)
13 int r;
14 u32_t value;
16 /* Publish and retrieve. */
17 r = ds_publish_u32(key_u32, 1234, 0);
18 assert(r == OK);
19 r = ds_retrieve_u32(key_u32, &value);
20 assert(r == OK && value == 1234);
22 /* If dstest deletes 'test_u32' immediately after publishing it,
23 * subs will catch the event, but it can't check it immediately.
24 * So dstest will sleep 2 seconds to wait for subs to complete. */
25 sleep(2);
27 /* Publish again without DSF_OVERWRITE. */
28 r = ds_publish_u32(key_u32, 4321, 0);
29 assert(r == EEXIST);
31 /* Publish again with DSF_OVERWRITE to overwrite it. */
32 r = ds_publish_u32(key_u32, 4321, DSF_OVERWRITE);
33 assert(r == OK);
34 r = ds_retrieve_u32(key_u32, &value);
35 assert(r == OK && value == 4321);
37 /* Delete. */
38 r = ds_delete_u32(key_u32);
39 assert(r == OK);
40 r = ds_retrieve_u32(key_u32, &value);
41 assert(r == ESRCH);
43 printf("DSTEST: U32 test successful!\n");
46 /*===========================================================================*
47 * test_str *
48 *===========================================================================*/
49 void test_str(void)
51 int r;
52 char *string = "little";
53 char *longstring = "verylooooooongstring";
54 char buf[17];
56 r = ds_publish_str(key_str, string, 0);
57 assert(r == OK);
59 r = ds_retrieve_str(key_str, buf, sizeof(buf)-1);
60 assert(r == OK && strcmp(string, buf) == 0);
62 r = ds_delete_str(key_str);
63 assert(r == OK);
65 /* Publish a long string. */
66 r = ds_publish_str(key_str, longstring, 0);
67 assert(r == OK);
69 r = ds_retrieve_str(key_str, buf, sizeof(buf)-1);
70 assert(r == OK && strcmp(string, buf) != 0
71 && strncmp(longstring, buf, sizeof(buf)-1) == 0);
73 r = ds_delete_str(key_str);
74 assert(r == OK);
76 printf("DSTEST: STRING test successful!\n");
79 /*===========================================================================*
80 * test_mem *
81 *===========================================================================*/
82 void test_mem(void)
84 char *string1 = "ok, this is a string";
85 char *string2 = "ok, this is a very looooong string";
86 size_t len1 = strlen(string1) + 1;
87 size_t len2 = strlen(string2) + 1;
88 char buf[100];
89 size_t get_len;
90 int r;
92 /* Publish and retrieve. */
93 r = ds_publish_mem(key_mem, string1, len1, 0);
94 assert(r == OK);
95 get_len = 100;
96 r = ds_retrieve_mem(key_mem, buf, &get_len);
97 assert(r == OK && strcmp(string1, buf) == 0);
98 assert(get_len == len1);
100 /* Let get_len=8, which is less than strlen(string1). */
101 get_len = 8;
102 r = ds_retrieve_mem(key_mem, buf, &get_len);
103 assert(r == OK && get_len == 8);
105 /* Publish again to overwrite with a bigger memory range. */
106 r = ds_publish_mem(key_mem, string2, len2, DSF_OVERWRITE);
107 assert(r == OK);
109 get_len = 100;
110 r = ds_retrieve_mem(key_mem, buf, &get_len);
111 assert(r == OK && strcmp(string2, buf) == 0);
112 assert(get_len == len2);
114 r = ds_delete_mem(key_mem);
115 assert(r == OK);
117 printf("DSTEST: MEM test successful!\n");
120 /*===========================================================================*
121 * test_label *
122 *===========================================================================*/
123 void test_label(void)
125 int r;
126 char label[DS_MAX_KEYLEN];
127 endpoint_t endpoint;
129 /* Retrieve own label and endpoint. */
130 r = ds_retrieve_label_name(label, sef_self());
131 assert(r == OK);
132 r = ds_retrieve_label_endpt(label, &endpoint);
133 assert(r == OK && endpoint == sef_self());
135 /* Publish and delete. */
136 r = ds_publish_label(label, endpoint, 0);
137 assert(r == EPERM);
138 r = ds_delete_label(label);
139 assert(r == EPERM);
141 printf("DSTEST: LABEL test successful!\n");
144 /*===========================================================================*
145 * sef_cb_init_fresh *
146 *===========================================================================*/
147 static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
149 /* Run all the tests. */
150 test_u32();
151 test_str();
152 test_mem();
153 test_label();
155 return OK;
158 /*===========================================================================*
159 * sef_local_startup *
160 *===========================================================================*/
161 static void sef_local_startup(void)
163 /* Let SEF perform startup. */
164 sef_setcb_init_fresh(sef_cb_init_fresh);
166 sef_startup();
169 /*===========================================================================*
170 * main *
171 *===========================================================================*/
172 int main(void)
174 /* SEF local startup. */
175 sef_local_startup();
177 return 0;