1 /*------------------------------------------------------------\
2 | |
3 | This file is part of the Alliance CAD System Copyright |
4 | (C) Laboratoire LIP6 - D�partement ASIM Universite P&M Curie|
5 | |
6 | Home page : http://www-asim.lip6.fr/alliance/ |
7 | E-mail : mailto:alliance-users@asim.lip6.fr |
8 | |
9 | This progam is free software; you can redistribute it |
10 | and/or modify it under the terms of the GNU Library General|
11 | Public License as published by the Free Software Foundation |
12 | either version 2 of the License, or (at your option) any |
13 | later version. |
14 | |
15 | Alliance VLSI CAD System is distributed in the hope that |
16 | it will be useful, but WITHOUT ANY WARRANTY; |
17 | without even the implied warranty of MERCHANTABILITY or |
18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
19 | Public License for more details. |
20 | |
21 | You should have received a copy of the GNU General Public |
22 | License along with the GNU C Library; see the file COPYING. |
23 | If not, write to the Free Software Foundation, Inc., |
24 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
25 | |
26 \------------------------------------------------------------*/
27 /*------------------------------------------------------------\
28 | |
29 | Tool : Aut |
30 | |
31 | File : auttest.c |
32 | |
33 | Date : 03.12.96 |
34 | |
35 | Author : Jacomme Ludovic |
36 | |
37 \------------------------------------------------------------*/
38 /*------------------------------------------------------------\
39 | |
40 | Include Files |
41 | |
42 \------------------------------------------------------------*/
43
44 # include <stdio.h>
45 # include <stdlib.h>
46 # include <string.h>
47
48 # include <mut.h>
49 # include "aut.h"
50
51 # include "auttest.h"
52
53 /*------------------------------------------------------------\
54 | |
55 | Variables |
56 | |
57 \------------------------------------------------------------*/
58
59 static char TestBuffer[ AUT_TEST_BUFFER_SIZE ];
60 static authtable *TestHashTable = (authtable *)0;
61 static auth2table *TestHashTable2 = (auth2table *)0;
62 static char TestExit = 0;
63 static char TestMode2 = 0;
64 static long TestIndex = 0;
65
66 static command TestCommandDefine[ AUT_TEST_MAX_COMMAND ] =
67 {
68 { "addelem" , TestCommandAddElement },
69 { "addelem2" , TestCommandAddElement2 },
70 { "delelem" , TestCommandDelElement },
71 { "delelem2" , TestCommandDelElement2 },
72 { "exit" , TestCommandExit },
73 { "help" , TestCommandHelp },
74 { "list" , TestCommandHelp },
75 { "quit" , TestCommandExit },
76 { "reset" , TestCommandReset },
77 { "reset2" , TestCommandReset2 },
78 { "viewelem" , TestCommandViewElement },
79 { "viewelem2" , TestCommandViewElement2 },
80 { "viewhash" , TestCommandViewHash },
81 { "viewhash2" , TestCommandViewHash2 }
82 };
83
84 /*------------------------------------------------------------\
85 | |
86 | Functions |
87 | |
88 \------------------------------------------------------------*/
89 /*------------------------------------------------------------\
90 | |
91 | Test Command Compare |
92 | |
93 \------------------------------------------------------------*/
94
TestCommandCompare(FirstKey,SecondKey)95 static int TestCommandCompare( FirstKey, SecondKey )
96
97 command *FirstKey;
98 command *SecondKey;
99 {
100 return( strcmp( FirstKey->NAME, SecondKey->NAME ) );
101 }
102
103 /*------------------------------------------------------------\
104 | |
105 | Test Get Command Value |
106 | |
107 \------------------------------------------------------------*/
108
TestGetCommand(String)109 static command *TestGetCommand( String )
110
111 char *String;
112 {
113 command Entry;
114
115 Entry.NAME = String;
116
117 return( (command *)bsearch( (char *)(&Entry),
118 (char *)TestCommandDefine,
119 AUT_TEST_MAX_COMMAND,
120 sizeof( command ),
121 TestCommandCompare ) );
122 }
123
124 /*------------------------------------------------------------\
125 | |
126 | Command Functions |
127 | |
128 \------------------------------------------------------------*/
129 /*------------------------------------------------------------\
130 | |
131 | Test Command Exit |
132 | |
133 \------------------------------------------------------------*/
134
TestCommandExit(String)135 static void TestCommandExit( String )
136
137 char *String;
138 {
139 fprintf( stdout, "--> exit\n" );
140 TestExit = 1;
141 }
142
143 /*------------------------------------------------------------\
144 | |
145 | Test Command Help |
146 | |
147 \------------------------------------------------------------*/
148
TestCommandHelp(String)149 static void TestCommandHelp( String )
150
151 char *String;
152 {
153 int Counter;
154
155 fprintf( stdout, "--> help" );
156
157 for ( Counter = 0; Counter < AUT_TEST_MAX_COMMAND; Counter++ )
158 {
159 if ( ( Counter & 0x3 ) == 0 )
160 {
161 fprintf( stdout, "\n" );
162 }
163
164 fprintf( stdout, " %-8s", TestCommandDefine[ Counter ].NAME );
165 }
166 }
167
168 /*------------------------------------------------------------\
169 | |
170 | Test Command Add Element |
171 | |
172 \------------------------------------------------------------*/
173
TestCommandAddElement(String)174 static void TestCommandAddElement( String )
175
176 char *String;
177 {
178 authelem *AutElement;
179 char *Scan;
180
181 if ( TestMode2 ) return;
182
183 if ( String != (char *)0 )
184 {
185 Scan = strchr( String, ' ' );
186
187 if ( Scan != (char *)0 )
188 {
189 *Scan = '\0';
190 }
191
192 String = namealloc( String );
193 fprintf( stdout, "--> addelem %s\n", String );
194
195 AutElement = addauthelem( TestHashTable, String, TestIndex++ );
196 viewauthelem( AutElement );
197 }
198 }
199
200 /*------------------------------------------------------------\
201 | |
202 | Test Command Add Element 2 |
203 | |
204 \------------------------------------------------------------*/
205
TestCommandAddElement2(String)206 static void TestCommandAddElement2( String )
207
208 char *String;
209 {
210 auth2elem *AutElement;
211 char *Scan;
212
213 if ( ! TestMode2 ) return;
214
215 if ( String != (char *)0 )
216 {
217 Scan = strchr( String, ' ' );
218
219 if ( Scan != (char *)0 )
220 {
221 *Scan = '\0';
222 }
223
224 String = namealloc( String );
225 Scan = namealloc( Scan + 1 );
226
227 fprintf( stdout, "--> addelem %s %s\n", String, Scan );
228
229 AutElement = addauth2elem( TestHashTable2, String, Scan, TestIndex++ );
230 viewauth2elem( AutElement );
231 }
232 }
233
234 /*------------------------------------------------------------\
235 | |
236 | Test Command View Element |
237 | |
238 \------------------------------------------------------------*/
239
TestCommandViewElement(String)240 static void TestCommandViewElement( String )
241
242 char *String;
243 {
244 authelem *AutElement;
245 char *Scan;
246
247 if ( TestMode2 ) return;
248
249 if ( String != (char *)0 )
250 {
251 Scan = strchr( String, ' ' );
252
253 if ( Scan != (char *)0 )
254 {
255 *Scan = '\0';
256 }
257
258 String = namealloc( String );
259 fprintf( stdout, "--> viewelem %s\n", String );
260
261 AutElement = searchauthelem( TestHashTable, String );
262
263 if ( AutElement != (authelem *)0 )
264 {
265 viewauthelem( AutElement );
266 }
267 else
268 {
269 fprintf( stderr, "Element %s doesn't exist\n", String );
270 }
271 }
272 else
273 {
274 viewauthtable( TestHashTable, viewauthelem );
275 }
276 }
277
278 /*------------------------------------------------------------\
279 | |
280 | Test Command View Element 2 |
281 | |
282 \------------------------------------------------------------*/
283
TestCommandViewElement2(String)284 static void TestCommandViewElement2( String )
285
286 char *String;
287 {
288 auth2elem *AutElement;
289 char *Scan;
290
291 if ( ! TestMode2 ) return;
292
293 if ( String != (char *)0 )
294 {
295 Scan = strchr( String, ' ' );
296
297 if ( Scan != (char *)0 )
298 {
299 *Scan = '\0';
300 }
301
302 String = namealloc( String );
303 Scan = namealloc( Scan + 1 );
304 fprintf( stdout, "--> viewelem2 %s %s\n", String, Scan );
305
306 AutElement = searchauth2elem( TestHashTable2, String, Scan );
307
308 if ( AutElement != (auth2elem *)0 )
309 {
310 viewauth2elem( AutElement );
311 }
312 else
313 {
314 fprintf( stderr, "Element %s %s doesn't exist\n", String, Scan );
315 }
316 }
317 else
318 {
319 viewauth2table( TestHashTable2, viewauth2elem );
320 }
321 }
322
323
324 /*------------------------------------------------------------\
325 | |
326 | Test Command Del Element |
327 | |
328 \------------------------------------------------------------*/
329
TestCommandDelElement(String)330 static void TestCommandDelElement( String )
331
332 char *String;
333 {
334 char *Scan;
335
336 if ( TestMode2 ) return;
337
338 if ( String != (char *)0 )
339 {
340 Scan = strchr( String, ' ' );
341
342 if ( Scan != (char *)0 )
343 {
344 *Scan = '\0';
345 }
346
347 String = namealloc( String );
348 if ( delauthelem( TestHashTable, String ) )
349 {
350 fprintf( stdout, "--> delelem %s\n", String );
351 }
352 }
353 }
354
355 /*------------------------------------------------------------\
356 | |
357 | Test Command Del Element 2 |
358 | |
359 \------------------------------------------------------------*/
360
TestCommandDelElement2(String)361 static void TestCommandDelElement2( String )
362
363 char *String;
364 {
365 char *Scan;
366
367 if ( ! TestMode2 ) return;
368
369 if ( String != (char *)0 )
370 {
371 Scan = strchr( String, ' ' );
372
373 if ( Scan != (char *)0 )
374 {
375 *Scan = '\0';
376 }
377
378 String = namealloc( String );
379 Scan = namealloc( Scan + 1 );
380 if ( delauth2elem( TestHashTable2, String, Scan ) )
381 {
382 fprintf( stdout, "--> delelem2 %s %s\n", String, Scan );
383 }
384 }
385 }
386
387 /*------------------------------------------------------------\
388 | |
389 | Test Command Reset |
390 | |
391 \------------------------------------------------------------*/
392
TestCommandReset(String)393 static void TestCommandReset( String )
394
395 char *String;
396 {
397 if ( TestMode2 ) return;
398
399 fprintf( stdout, "--> reset\n" );
400 resetauthtable( TestHashTable );
401 }
402
403 /*------------------------------------------------------------\
404 | |
405 | Test Command Reset 2 |
406 | |
407 \------------------------------------------------------------*/
408
TestCommandReset2(String)409 static void TestCommandReset2( String )
410
411 char *String;
412 {
413 if ( ! TestMode2 ) return;
414
415 fprintf( stdout, "--> reset2\n" );
416 resetauth2table( TestHashTable2 );
417 }
418
419 /*------------------------------------------------------------\
420 | |
421 | Test Command View Hash |
422 | |
423 \------------------------------------------------------------*/
424
TestCommandViewHash(String)425 static void TestCommandViewHash( String )
426
427 char *String;
428 {
429 if ( TestMode2 ) return;
430
431 fprintf( stdout, "--> viewhash\n" );
432 viewauthtable( TestHashTable, 0 );
433 }
434
435 /*------------------------------------------------------------\
436 | |
437 | Test Command View Hash 2 |
438 | |
439 \------------------------------------------------------------*/
440
TestCommandViewHash2(String)441 static void TestCommandViewHash2( String )
442
443 char *String;
444 {
445 if ( ! TestMode2 ) return;
446
447 fprintf( stdout, "--> viewhash2\n" );
448 viewauth2table( TestHashTable2, 0 );
449 }
450
451
452 /*------------------------------------------------------------\
453 | |
454 | Main Loop |
455 | |
456 \------------------------------------------------------------*/
457
TestMainLoop()458 static int TestMainLoop()
459 {
460 command *Command;
461 char *Scan;
462
463 TestExit = 0;
464 TestIndex = 0;
465
466 do
467 {
468 fprintf( stdout, "\ncommand > " );
469
470 if ( ! fgets( TestBuffer, AUT_TEST_BUFFER_SIZE, stdin ) )
471 {
472 fprintf( stderr, "Interrupt by user\n" );
473
474 return( 0 );
475 }
476
477 Scan = strchr( TestBuffer, '\n' );
478
479 if ( Scan != (char *)0 )
480 {
481 *Scan = '\0';
482 }
483
484 Scan = strchr( TestBuffer, ' ' );
485
486 if ( Scan != (char *)0 )
487 {
488 *Scan = '\0'; Scan = Scan + 1;
489 }
490
491 Command = TestGetCommand( TestBuffer );
492
493 if ( Command != (command *)0 )
494 {
495 (*Command->FUNCTION)( Scan );
496 }
497 else
498 {
499 fprintf( stderr, "syntax error\n" );
500 }
501 }
502 while ( TestExit == 0 );
503
504 return( 1 );
505 }
506
507 /*------------------------------------------------------------\
508 | |
509 | Test Aut Hash Table |
510 | |
511 \------------------------------------------------------------*/
512
testauthtable(HashTable)513 int testauthtable( HashTable )
514
515 authtable *HashTable;
516 {
517 TestHashTable = HashTable;
518 TestMode2 = 0;
519
520 return( TestMainLoop() );
521 }
522
523 /*------------------------------------------------------------\
524 | |
525 | Test Aut Hash Table 2 |
526 | |
527 \------------------------------------------------------------*/
528
testauth2table(HashTable)529 int testauth2table( HashTable )
530
531 auth2table *HashTable;
532 {
533 TestHashTable2 = HashTable;
534 TestMode2 = 1;
535
536 return( TestMainLoop() );
537 }
538