1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate * diagcode library unit test
29*0Sstevel@tonic-gate *
30*0Sstevel@tonic-gate * usually run from "make test" target. takes a single argument
31*0Sstevel@tonic-gate * which is the directory where the test dictionaries are found.
32*0Sstevel@tonic-gate * this test driver scans the dictionaries for comments of the form:
33*0Sstevel@tonic-gate * #TEST:<routine>:<errno>:<input>:<output>
34*0Sstevel@tonic-gate * and executes that test.
35*0Sstevel@tonic-gate *
36*0Sstevel@tonic-gate * exit 0 and an "All tests passed" message means no failures. otherwise
37*0Sstevel@tonic-gate * error messages are spewed as appropriate and exit value is non-zero.
38*0Sstevel@tonic-gate */
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate #include <stdio.h>
43*0Sstevel@tonic-gate #include <stdlib.h>
44*0Sstevel@tonic-gate #include <string.h>
45*0Sstevel@tonic-gate #include <ctype.h>
46*0Sstevel@tonic-gate #include <alloca.h>
47*0Sstevel@tonic-gate #include <errno.h>
48*0Sstevel@tonic-gate #include <sys/types.h>
49*0Sstevel@tonic-gate #include <dirent.h>
50*0Sstevel@tonic-gate #include <stdarg.h>
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate #include <fm/diagcode.h>
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate #define MAXLINE 10240
55*0Sstevel@tonic-gate #define MAXARG 10
56*0Sstevel@tonic-gate #define MAXKEY 100
57*0Sstevel@tonic-gate #define MAXCODE 100
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate static char *Myname;
60*0Sstevel@tonic-gate static char *Dict;
61*0Sstevel@tonic-gate static int Line;
62*0Sstevel@tonic-gate static int Errcount;
63*0Sstevel@tonic-gate static fm_dc_handle_t *Dhp;
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate /*PRINTFLIKE1*/
66*0Sstevel@tonic-gate static void
err(const char * fmt,...)67*0Sstevel@tonic-gate err(const char *fmt, ...)
68*0Sstevel@tonic-gate {
69*0Sstevel@tonic-gate va_list ap;
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate va_start(ap, fmt);
72*0Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s:%d ", Myname, Dict, Line);
73*0Sstevel@tonic-gate (void) vfprintf(stderr, fmt, ap);
74*0Sstevel@tonic-gate (void) fprintf(stderr, "\n");
75*0Sstevel@tonic-gate Errcount++;
76*0Sstevel@tonic-gate }
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate /* parse an expected errno value from test line (numeric or some symbolic) */
79*0Sstevel@tonic-gate static int
geterrno(const char * s)80*0Sstevel@tonic-gate geterrno(const char *s)
81*0Sstevel@tonic-gate {
82*0Sstevel@tonic-gate if (*s == '\0' || isspace(*s))
83*0Sstevel@tonic-gate return (0);
84*0Sstevel@tonic-gate else if (isdigit(*s))
85*0Sstevel@tonic-gate return (atoi(s));
86*0Sstevel@tonic-gate else if (strcmp(s, "EPERM") == 0)
87*0Sstevel@tonic-gate return (EPERM);
88*0Sstevel@tonic-gate else if (strcmp(s, "ENOENT") == 0)
89*0Sstevel@tonic-gate return (ENOENT);
90*0Sstevel@tonic-gate else if (strcmp(s, "ESRCH") == 0)
91*0Sstevel@tonic-gate return (ESRCH);
92*0Sstevel@tonic-gate else if (strcmp(s, "ENOMEM") == 0)
93*0Sstevel@tonic-gate return (ENOMEM);
94*0Sstevel@tonic-gate else if (strcmp(s, "EACCES") == 0)
95*0Sstevel@tonic-gate return (EACCES);
96*0Sstevel@tonic-gate else if (strcmp(s, "EINVAL") == 0)
97*0Sstevel@tonic-gate return (EINVAL);
98*0Sstevel@tonic-gate else if (strcmp(s, "ERANGE") == 0)
99*0Sstevel@tonic-gate return (ERANGE);
100*0Sstevel@tonic-gate else if (strcmp(s, "ENOMSG") == 0)
101*0Sstevel@tonic-gate return (ENOMSG);
102*0Sstevel@tonic-gate else if (strcmp(s, "ENOTSUP") == 0)
103*0Sstevel@tonic-gate return (ENOTSUP);
104*0Sstevel@tonic-gate else {
105*0Sstevel@tonic-gate err("geterrno: don't know errno \"%s\"", s);
106*0Sstevel@tonic-gate Errcount++;
107*0Sstevel@tonic-gate return (0);
108*0Sstevel@tonic-gate }
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate
111*0Sstevel@tonic-gate /* call fm_dc_opendict() as part of a test */
112*0Sstevel@tonic-gate static void
do_open(const char * dirpath,const char * dictname,char * argv[],int argc)113*0Sstevel@tonic-gate do_open(const char *dirpath, const char *dictname, char *argv[], int argc)
114*0Sstevel@tonic-gate {
115*0Sstevel@tonic-gate int reterrno;
116*0Sstevel@tonic-gate int experrno;
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate if (argc != 2) {
119*0Sstevel@tonic-gate err("argc != 2");
120*0Sstevel@tonic-gate return;
121*0Sstevel@tonic-gate }
122*0Sstevel@tonic-gate experrno = geterrno(argv[1]);
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate if ((Dhp = fm_dc_opendict(FM_DC_VERSION, dirpath, dictname)) == NULL)
125*0Sstevel@tonic-gate reterrno = errno;
126*0Sstevel@tonic-gate else
127*0Sstevel@tonic-gate reterrno = 0;
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate if (reterrno != experrno)
130*0Sstevel@tonic-gate err("opendict errno %d, expected %d", reterrno, experrno);
131*0Sstevel@tonic-gate }
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate /* call fm_dc_closedict() as part of a test */
134*0Sstevel@tonic-gate static void
do_close(const char * dirpath,const char * dictname,char * argv[],int argc)135*0Sstevel@tonic-gate do_close(const char *dirpath, const char *dictname, char *argv[], int argc)
136*0Sstevel@tonic-gate {
137*0Sstevel@tonic-gate if (Dhp) {
138*0Sstevel@tonic-gate fm_dc_closedict(Dhp);
139*0Sstevel@tonic-gate Dhp = NULL;
140*0Sstevel@tonic-gate }
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate /* call fm_dc_codelen() as part of a test */
144*0Sstevel@tonic-gate static void
do_codelen(const char * dirpath,const char * dictname,char * argv[],int argc)145*0Sstevel@tonic-gate do_codelen(const char *dirpath, const char *dictname, char *argv[], int argc)
146*0Sstevel@tonic-gate {
147*0Sstevel@tonic-gate int retcodelen;
148*0Sstevel@tonic-gate int expcodelen;
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate if (argc != 3) {
151*0Sstevel@tonic-gate err("argc != 3");
152*0Sstevel@tonic-gate return;
153*0Sstevel@tonic-gate }
154*0Sstevel@tonic-gate expcodelen = geterrno(argv[2]);
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate if (Dhp == NULL) {
157*0Sstevel@tonic-gate err("codelen NULL handle");
158*0Sstevel@tonic-gate return;
159*0Sstevel@tonic-gate }
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate retcodelen = fm_dc_codelen(Dhp);
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate if (retcodelen != expcodelen)
164*0Sstevel@tonic-gate err("codelen %d, expected %d", retcodelen, expcodelen);
165*0Sstevel@tonic-gate }
166*0Sstevel@tonic-gate
167*0Sstevel@tonic-gate /* call fm_dc_maxkey() as part of a test */
168*0Sstevel@tonic-gate static void
do_maxkey(const char * dirpath,const char * dictname,char * argv[],int argc)169*0Sstevel@tonic-gate do_maxkey(const char *dirpath, const char *dictname, char *argv[], int argc)
170*0Sstevel@tonic-gate {
171*0Sstevel@tonic-gate int retmaxkey;
172*0Sstevel@tonic-gate int expmaxkey;
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate if (argc != 3) {
175*0Sstevel@tonic-gate err("argc != 3");
176*0Sstevel@tonic-gate return;
177*0Sstevel@tonic-gate }
178*0Sstevel@tonic-gate expmaxkey = geterrno(argv[2]);
179*0Sstevel@tonic-gate
180*0Sstevel@tonic-gate if (Dhp == NULL) {
181*0Sstevel@tonic-gate err("maxkey NULL handle");
182*0Sstevel@tonic-gate return;
183*0Sstevel@tonic-gate }
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate retmaxkey = fm_dc_maxkey(Dhp);
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gate if (retmaxkey != expmaxkey)
188*0Sstevel@tonic-gate err("maxkey %d, expected %d", retmaxkey, expmaxkey);
189*0Sstevel@tonic-gate }
190*0Sstevel@tonic-gate
191*0Sstevel@tonic-gate /* call fm_dc_key2code() as part of a test */
192*0Sstevel@tonic-gate static void
do_key2code(const char * dirpath,const char * dictname,char * argv[],int argc)193*0Sstevel@tonic-gate do_key2code(const char *dirpath, const char *dictname, char *argv[], int argc)
194*0Sstevel@tonic-gate {
195*0Sstevel@tonic-gate int reterrno;
196*0Sstevel@tonic-gate int experrno;
197*0Sstevel@tonic-gate const char *key[MAXKEY];
198*0Sstevel@tonic-gate char code[MAXCODE];
199*0Sstevel@tonic-gate int nel;
200*0Sstevel@tonic-gate char *beginp;
201*0Sstevel@tonic-gate char *endp;
202*0Sstevel@tonic-gate
203*0Sstevel@tonic-gate if (argc < 3) {
204*0Sstevel@tonic-gate err("argc < 3");
205*0Sstevel@tonic-gate return;
206*0Sstevel@tonic-gate }
207*0Sstevel@tonic-gate if (argc > 4) {
208*0Sstevel@tonic-gate err("argc > 4");
209*0Sstevel@tonic-gate return;
210*0Sstevel@tonic-gate }
211*0Sstevel@tonic-gate experrno = geterrno(argv[1]);
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gate /* convert key into array */
214*0Sstevel@tonic-gate nel = 0;
215*0Sstevel@tonic-gate beginp = argv[2];
216*0Sstevel@tonic-gate while (nel < MAXKEY - 1) {
217*0Sstevel@tonic-gate key[nel++] = beginp;
218*0Sstevel@tonic-gate if ((endp = strchr(beginp, ' ')) != NULL) {
219*0Sstevel@tonic-gate *endp++ = '\0';
220*0Sstevel@tonic-gate beginp = endp;
221*0Sstevel@tonic-gate } else
222*0Sstevel@tonic-gate break;
223*0Sstevel@tonic-gate }
224*0Sstevel@tonic-gate key[nel] = NULL;
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gate if (Dhp == NULL) {
227*0Sstevel@tonic-gate err("key2code NULL handle");
228*0Sstevel@tonic-gate return;
229*0Sstevel@tonic-gate }
230*0Sstevel@tonic-gate
231*0Sstevel@tonic-gate if (fm_dc_key2code(Dhp, key, code, MAXCODE) < 0)
232*0Sstevel@tonic-gate reterrno = errno;
233*0Sstevel@tonic-gate else
234*0Sstevel@tonic-gate reterrno = 0;
235*0Sstevel@tonic-gate
236*0Sstevel@tonic-gate if (reterrno != experrno) {
237*0Sstevel@tonic-gate err("key2code errno %d, expected %d", reterrno, experrno);
238*0Sstevel@tonic-gate return;
239*0Sstevel@tonic-gate }
240*0Sstevel@tonic-gate
241*0Sstevel@tonic-gate if (reterrno == 0 && argc > 3 && strcmp(code, argv[3]))
242*0Sstevel@tonic-gate err("code \"%s\", expected \"%s\"", code, argv[3]);
243*0Sstevel@tonic-gate }
244*0Sstevel@tonic-gate
245*0Sstevel@tonic-gate /* call fm_dc_code2key() as part of a test */
246*0Sstevel@tonic-gate static void
do_code2key(const char * dirpath,const char * dictname,char * argv[],int argc)247*0Sstevel@tonic-gate do_code2key(const char *dirpath, const char *dictname, char *argv[], int argc)
248*0Sstevel@tonic-gate {
249*0Sstevel@tonic-gate int reterrno;
250*0Sstevel@tonic-gate int experrno;
251*0Sstevel@tonic-gate char keystr[MAXLINE];
252*0Sstevel@tonic-gate char *key[MAXKEY];
253*0Sstevel@tonic-gate int nel;
254*0Sstevel@tonic-gate
255*0Sstevel@tonic-gate if (argc < 3) {
256*0Sstevel@tonic-gate err("argc < 3");
257*0Sstevel@tonic-gate return;
258*0Sstevel@tonic-gate }
259*0Sstevel@tonic-gate if (argc > 4) {
260*0Sstevel@tonic-gate err("argc > 4");
261*0Sstevel@tonic-gate return;
262*0Sstevel@tonic-gate }
263*0Sstevel@tonic-gate experrno = geterrno(argv[1]);
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gate if (Dhp == NULL) {
266*0Sstevel@tonic-gate err("code2key NULL handle");
267*0Sstevel@tonic-gate return;
268*0Sstevel@tonic-gate }
269*0Sstevel@tonic-gate
270*0Sstevel@tonic-gate if (fm_dc_code2key(Dhp, argv[2], key, fm_dc_maxkey(Dhp)) < 0)
271*0Sstevel@tonic-gate reterrno = errno;
272*0Sstevel@tonic-gate else
273*0Sstevel@tonic-gate reterrno = 0;
274*0Sstevel@tonic-gate
275*0Sstevel@tonic-gate if (reterrno != experrno) {
276*0Sstevel@tonic-gate err("errno %d, expected %d", reterrno, experrno);
277*0Sstevel@tonic-gate return;
278*0Sstevel@tonic-gate }
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate if (reterrno)
281*0Sstevel@tonic-gate return;
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate if (argc > 3) {
284*0Sstevel@tonic-gate /* convert key into string */
285*0Sstevel@tonic-gate keystr[0] = '\0';
286*0Sstevel@tonic-gate for (nel = 0; key[nel]; nel++) {
287*0Sstevel@tonic-gate if (nel)
288*0Sstevel@tonic-gate (void) strcat(keystr, " ");
289*0Sstevel@tonic-gate (void) strcat(keystr, key[nel]);
290*0Sstevel@tonic-gate }
291*0Sstevel@tonic-gate
292*0Sstevel@tonic-gate if (strcmp(keystr, argv[3]))
293*0Sstevel@tonic-gate err("key \"%s\", expected \"%s\"", keystr, argv[3]);
294*0Sstevel@tonic-gate }
295*0Sstevel@tonic-gate for (nel = 0; key[nel]; nel++)
296*0Sstevel@tonic-gate free(key[nel]);
297*0Sstevel@tonic-gate }
298*0Sstevel@tonic-gate
299*0Sstevel@tonic-gate /* call fm_dc_getprop() as part of a test */
300*0Sstevel@tonic-gate static void
do_getprop(const char * dirpath,const char * dictname,char * argv[],int argc)301*0Sstevel@tonic-gate do_getprop(const char *dirpath, const char *dictname, char *argv[], int argc)
302*0Sstevel@tonic-gate {
303*0Sstevel@tonic-gate int reterrno;
304*0Sstevel@tonic-gate int experrno;
305*0Sstevel@tonic-gate const char *val;
306*0Sstevel@tonic-gate
307*0Sstevel@tonic-gate if (argc != 4) {
308*0Sstevel@tonic-gate err("argc != 4");
309*0Sstevel@tonic-gate return;
310*0Sstevel@tonic-gate }
311*0Sstevel@tonic-gate experrno = geterrno(argv[1]);
312*0Sstevel@tonic-gate
313*0Sstevel@tonic-gate if (Dhp == NULL) {
314*0Sstevel@tonic-gate err("getprop NULL handle");
315*0Sstevel@tonic-gate return;
316*0Sstevel@tonic-gate }
317*0Sstevel@tonic-gate
318*0Sstevel@tonic-gate if ((val = fm_dc_getprop(Dhp, argv[2])) == NULL)
319*0Sstevel@tonic-gate reterrno = errno;
320*0Sstevel@tonic-gate else
321*0Sstevel@tonic-gate reterrno = 0;
322*0Sstevel@tonic-gate
323*0Sstevel@tonic-gate if (reterrno != experrno) {
324*0Sstevel@tonic-gate err("getprop errno %d, expected %d", reterrno, experrno);
325*0Sstevel@tonic-gate return;
326*0Sstevel@tonic-gate }
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate if (reterrno == 0 && strcmp(val, argv[3]))
329*0Sstevel@tonic-gate err("val \"%s\", expected \"%s\"", val, argv[3]);
330*0Sstevel@tonic-gate }
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate /* scan a dictionary, looking for test directives embedded in the comments */
333*0Sstevel@tonic-gate static void
testdict(const char * dirpath,const char * dictname)334*0Sstevel@tonic-gate testdict(const char *dirpath, const char *dictname)
335*0Sstevel@tonic-gate {
336*0Sstevel@tonic-gate char linebuf[MAXLINE];
337*0Sstevel@tonic-gate char fname[MAXLINE];
338*0Sstevel@tonic-gate FILE *fp;
339*0Sstevel@tonic-gate
340*0Sstevel@tonic-gate (void) snprintf(fname, MAXLINE, "%s/%s.dict", dirpath, dictname);
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate if ((fp = fopen(fname, "r")) == NULL) {
343*0Sstevel@tonic-gate perror(fname);
344*0Sstevel@tonic-gate Errcount++;
345*0Sstevel@tonic-gate return;
346*0Sstevel@tonic-gate }
347*0Sstevel@tonic-gate
348*0Sstevel@tonic-gate Line = 0;
349*0Sstevel@tonic-gate Dict = fname;
350*0Sstevel@tonic-gate
351*0Sstevel@tonic-gate while (fgets(linebuf, MAXLINE, fp) != NULL) {
352*0Sstevel@tonic-gate char *argv[MAXARG];
353*0Sstevel@tonic-gate int argc;
354*0Sstevel@tonic-gate char *beginp;
355*0Sstevel@tonic-gate char *endp;
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gate Line++;
358*0Sstevel@tonic-gate if (strncmp(linebuf, "#TEST:", 6))
359*0Sstevel@tonic-gate continue;
360*0Sstevel@tonic-gate
361*0Sstevel@tonic-gate if ((endp = strchr(linebuf, '\n')) != NULL)
362*0Sstevel@tonic-gate *endp = '\0';
363*0Sstevel@tonic-gate argc = 0;
364*0Sstevel@tonic-gate beginp = &linebuf[6];
365*0Sstevel@tonic-gate while (argc < MAXARG - 1) {
366*0Sstevel@tonic-gate argv[argc++] = beginp;
367*0Sstevel@tonic-gate if ((endp = strchr(beginp, ':')) != NULL) {
368*0Sstevel@tonic-gate *endp++ = '\0';
369*0Sstevel@tonic-gate beginp = endp;
370*0Sstevel@tonic-gate } else
371*0Sstevel@tonic-gate break;
372*0Sstevel@tonic-gate }
373*0Sstevel@tonic-gate argv[argc] = NULL;
374*0Sstevel@tonic-gate
375*0Sstevel@tonic-gate if (strcmp(argv[0], "open") == 0)
376*0Sstevel@tonic-gate do_open(dirpath, dictname, argv, argc);
377*0Sstevel@tonic-gate else if (strcmp(argv[0], "close") == 0)
378*0Sstevel@tonic-gate do_close(dirpath, dictname, argv, argc);
379*0Sstevel@tonic-gate else if (strcmp(argv[0], "codelen") == 0)
380*0Sstevel@tonic-gate do_codelen(dirpath, dictname, argv, argc);
381*0Sstevel@tonic-gate else if (strcmp(argv[0], "maxkey") == 0)
382*0Sstevel@tonic-gate do_maxkey(dirpath, dictname, argv, argc);
383*0Sstevel@tonic-gate else if (strcmp(argv[0], "key2code") == 0)
384*0Sstevel@tonic-gate do_key2code(dirpath, dictname, argv, argc);
385*0Sstevel@tonic-gate else if (strcmp(argv[0], "code2key") == 0)
386*0Sstevel@tonic-gate do_code2key(dirpath, dictname, argv, argc);
387*0Sstevel@tonic-gate else if (strcmp(argv[0], "getprop") == 0)
388*0Sstevel@tonic-gate do_getprop(dirpath, dictname, argv, argc);
389*0Sstevel@tonic-gate else {
390*0Sstevel@tonic-gate err("unknown TEST command: \"%s\"", argv[0]);
391*0Sstevel@tonic-gate Errcount++;
392*0Sstevel@tonic-gate }
393*0Sstevel@tonic-gate }
394*0Sstevel@tonic-gate
395*0Sstevel@tonic-gate (void) fclose(fp);
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate if (Dhp) {
398*0Sstevel@tonic-gate fm_dc_closedict(Dhp);
399*0Sstevel@tonic-gate Dhp = NULL;
400*0Sstevel@tonic-gate }
401*0Sstevel@tonic-gate }
402*0Sstevel@tonic-gate
403*0Sstevel@tonic-gate /* scan a directory, looking for dictionaries to test against */
404*0Sstevel@tonic-gate int
main(int argc,char * argv[])405*0Sstevel@tonic-gate main(int argc, char *argv[])
406*0Sstevel@tonic-gate {
407*0Sstevel@tonic-gate DIR *dirp;
408*0Sstevel@tonic-gate struct dirent *dp;
409*0Sstevel@tonic-gate
410*0Sstevel@tonic-gate if ((Myname = strrchr(argv[0], '/')) == NULL)
411*0Sstevel@tonic-gate Myname = argv[0];
412*0Sstevel@tonic-gate else
413*0Sstevel@tonic-gate Myname++;
414*0Sstevel@tonic-gate
415*0Sstevel@tonic-gate if (argc != 2) {
416*0Sstevel@tonic-gate (void) fprintf(stderr, "usage: %s test-directory\n", argv[0]);
417*0Sstevel@tonic-gate exit(1);
418*0Sstevel@tonic-gate }
419*0Sstevel@tonic-gate
420*0Sstevel@tonic-gate if ((dirp = opendir(argv[1])) == NULL) {
421*0Sstevel@tonic-gate perror(argv[1]);
422*0Sstevel@tonic-gate exit(1);
423*0Sstevel@tonic-gate }
424*0Sstevel@tonic-gate
425*0Sstevel@tonic-gate while ((dp = readdir(dirp)) != NULL) {
426*0Sstevel@tonic-gate char *ptr;
427*0Sstevel@tonic-gate
428*0Sstevel@tonic-gate if (dp->d_name[0] == '.')
429*0Sstevel@tonic-gate continue;
430*0Sstevel@tonic-gate
431*0Sstevel@tonic-gate if ((ptr = strrchr(dp->d_name, '.')) == NULL ||
432*0Sstevel@tonic-gate strcmp(ptr, ".dict"))
433*0Sstevel@tonic-gate continue;
434*0Sstevel@tonic-gate
435*0Sstevel@tonic-gate *ptr = '\0'; /* remove the extension */
436*0Sstevel@tonic-gate testdict(argv[1], dp->d_name);
437*0Sstevel@tonic-gate }
438*0Sstevel@tonic-gate (void) closedir(dirp);
439*0Sstevel@tonic-gate
440*0Sstevel@tonic-gate if (Errcount == 0)
441*0Sstevel@tonic-gate (void) printf("%s: All tests passed.\n", Myname);
442*0Sstevel@tonic-gate
443*0Sstevel@tonic-gate return (Errcount);
444*0Sstevel@tonic-gate }
445