2 * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 #include <parse_units.h>
52 struct timeval time1
, time2
;
55 starttesting(char *msg
)
57 printf("--------------------------------------------\n");
58 printf("testing %s...\n", msg
);
60 gettimeofday(&time1
, NULL
);
66 gettimeofday(&time2
, NULL
);
67 printf("-%s--------------------------------------\n",
68 !bool ? "ok --" : "fail ");
69 time2
.tv_usec
-= time1
.tv_usec
;
70 if (time2
.tv_usec
< 0) {
71 time2
.tv_usec
+= 10000;
74 time2
.tv_sec
-= time1
.tv_sec
;
75 printf("timing: %ld.%ld\n", (long)time2
.tv_sec
, (long)time2
.tv_usec
);
82 hash_cmp(void *foo
, void *bar
)
84 return strcmp((char *) foo
, (char *)bar
);
90 return hashcaseadd((char *) foo
);
94 hash_print(void *foo
, void *bar
)
96 printf("%s\n", (char *) foo
);
105 starttesting("hashtab");
107 h
= hashtabnew(100, hash_cmp
, hash_hash
);
109 return endtesting(1);
111 if (!hashtabadd(h
, "one")||
112 !hashtabadd(h
, "two")||
113 !hashtabadd(h
, "three")||
114 !hashtabadd(h
, "four"))
115 return endtesting(1);
117 printf("foreach ----\n");
118 hashtabforeach(h
, hash_print
, NULL
);
120 printf("search ----\none == %s\ntwo == %s\nthree == %s\nfour == %s\n",
121 (char *)hashtabsearch(h
, "one"),
122 (char *)hashtabsearch(h
, "two"),
123 (char *)hashtabsearch(h
, "three"),
124 (char *)hashtabsearch(h
, "four"));
128 return endtesting(0);
131 struct units u1_units
[] = {
139 struct units u2_units
[] = {
141 { "u2-hack2", 0x08 },
142 { "u2-hack1", 0x04 },
155 starttesting ("log");
157 m
= log_open ("util-tester", "/dev/stderr:notime");
159 return endtesting(1);
161 u1
= log_unit_init (m
, "u1", u1_units
, 0x3);
163 return endtesting(1);
165 u2
= log_unit_init (m
, "u2", u2_units
, 0x0);
167 return endtesting(1);
169 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
170 printf ("%s\n", buf
); fflush (stdout
);
171 log_set_mask_str (m
, NULL
, buf
);
172 log_log (u1
, 0x1, "1. this should show");
173 log_log (u2
, 0x1, "X. this should NOT show");
175 log_set_mask_str (m
, NULL
, "u1:-debug;u2:+debug");
176 log_log (u1
, 0x1, "X. now this should NOT show");
177 log_log (u2
, 0x1, "2. now this should show");
178 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
179 printf ("%s\n", buf
); fflush (stdout
);
180 log_set_mask_str (m
, NULL
, buf
);
182 log_set_mask_str (m
, NULL
, "u1:-debug;u2:-debug");
183 log_log (u1
, 0x1, "X. now this should NOT show");
184 log_log (u2
, 0x1, "X. now this should NOT show");
185 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
186 printf ("%s\n", buf
); fflush (stdout
);
187 log_set_mask_str (m
, NULL
, buf
);
189 log_set_mask_str (m
, NULL
, "+debug");
190 log_log (u1
, 0x1, "3. now this should show");
191 log_log (u2
, 0x1, "4. now this should show");
192 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
193 printf ("%s\n", buf
); fflush (stdout
);
194 log_set_mask_str (m
, NULL
, buf
);
196 log_set_mask_str (m
, NULL
, "-debug");
197 log_log (u1
, 0x1, "X. now this should NOT show");
198 log_log (u2
, 0x1, "X. now this should NOT show");
199 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
200 printf ("%s\n", buf
); fflush (stdout
);
201 log_set_mask_str (m
, NULL
, buf
);
203 log_set_mask_str (m
, NULL
, "+debug,+warning");
204 log_log (u1
, 0x1, "5. now this should show");
205 log_log (u2
, 0x1, "6. now this should show");
206 log_log (u1
, 0x2, "7. now this should show");
207 log_log (u2
, 0x2, "8. now this should show");
208 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
209 printf ("%s\n", buf
); fflush (stdout
);
210 log_set_mask_str (m
, NULL
, buf
);
212 log_set_mask_str (m
, u1
, "-debug,-warning");
213 log_log (u1
, 0x1, "X. now this should NOT show");
214 log_log (u2
, 0x1, "9. now this should show");
215 log_log (u1
, 0x2, "X. now this should NOT show");
216 log_log (u2
, 0x2, "10. now this should show");
218 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
219 printf ("%s\n", buf
); fflush (stdout
);
220 log_set_mask_str (m
, NULL
, buf
);
222 log_set_mask (u1
, 0x4 + 0x2 + 0x1);
223 log_set_mask (u2
, 0x8 + 0x4 + 0x2 + 0x1);
225 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
226 printf ("%s\n", buf
); fflush (stdout
);
227 log_set_mask_str (m
, NULL
, buf
);
229 log_set_mask_str (m
, NULL
, "all");
230 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
231 printf ("all: %s\n", buf
); fflush (stdout
);
233 log_set_mask_str (m
, NULL
, "-all");
234 log_mask2str (m
, NULL
, buf
, sizeof(buf
));
235 printf ("none: %s\n", buf
); fflush (stdout
);
239 return endtesting (0);
245 starttesting ("math");
247 if (arlautil_findprime(17) != 17)
248 return endtesting (1);
249 if (arlautil_findprime(18) != 19)
250 return endtesting (1);
251 if (arlautil_findprime(11412) != 11423)
252 return endtesting (1);
254 if (arlautil_findprime(11412) != 11423)
255 return endtesting (1);
257 if (arlautil_isprime(20897) == 0)
258 return endtesting (1);
259 if (arlautil_isprime(49037) == 0)
260 return endtesting (1);
262 return endtesting (0);
266 main(int argc
, char **argv
)