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