-
Notifications
You must be signed in to change notification settings - Fork 35
/
define_fault_list.cpp
1164 lines (1065 loc) · 27.8 KB
/
define_fault_list.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************
Copyright (C) 1991,
Virginia Polytechnic Institute & State University
This program was originally written by Mr. Hyung K. Lee
under the supervision of Dr. Dong S. Ha, in the Bradley
Department of Electrical Engineering, VPI&SU, in 1991.
This program is released for research use only. This program,
or any derivative thereof, may not be reproduced nor used
for any commercial product without the written permission
of the authors.
For detailed information, please contact to
Dr. Dong S. Ha
Bradley Department of Electrical Engineering
Virginia Polytechnic Institute & State University
Blacksburg, VA 24061
Ph.: (540) 231-4942
Fax: (540) 231-3362
E-Mail: [email protected]
Web: http://www.ee.vt.edu/ha
REFERENCE:
H. K. Lee and D. S. Ha, "On the Generation of Test Patterns
for Combinational Circuits," Technical Report No. 12_93,
Dep't of Electrical Eng., Virginia Polytechnic Institute
and State University.
***********************************************************************/
/**************************** HISTORY **********************************
atalanta: version 1.0 H. K. Lee, 8/15/1991
atalanta: version 1.1 H. K. Lee, 10/5/1992
atalanta: version 2.0 H. K. Lee, 6/30/1997
***********************************************************************/
/*-----------------------------------------------------------------
file name: define_fault_list.c
This file constructs fault list after collapsing equivalent
faults.
-------------------------------------------------------------------*/
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include "error.h"
#include "hash.h"
#include "define_fault_list.h"
#include "parameter.h"
#include "define.h"
#include "macro.h"
extern GATEPTR *g_net;
extern STACKTYPE g_stack;
extern struct FAULT **g_pFaultList;
extern char rptmode;
extern HASHPTR pArrSymbolTable[];
// extern HASHPTR FindHash();
// extern void fatalerror();
/* set_all_fault_list
Sets up the fault list data structure.
Equivalent faults are collapsed.
*/
int initStemFaultsAndFaultList(int iNoGate, int iNoStemGates, GATEPTR *pStemGates) //set_all_fault_list
{
//OUTPUT: iNoFault
register GATEPTR pGate;
register FAULTPTR pFault;
register int i, j;
FAULTPTR pPreFault;
fault_type iFaultType;
int iNoFault, iNoStemFaultAdd1, iNoFaultTemp;
/**********************************
//int *piTest, size;
//FAULTTYPE *curr;
//piTest = (int*) malloc(sizeof(int));
//size = sizeof(FAULTTYPE);
//curr = (FAULTTYPE *)calloc(1, sizeof(FAULTTYPE));
//Never Used !
**********************************/
iNoFault = 0;
pPreFault = (FAULTPTR)malloc(sizeof(FAULTTYPE));
pPreFault->next = NULL;
for (i = 0; i < iNoGate; i++)
{
/* input line faults */
pGate = g_net[i];
pGate->pfault = pPreFault;
pGate->nfault = 0; // 0 also has a pPreFault object !!!
/* if the input of the gate has more than one fanouts,
add a s-a-1 for each AND/NAND,
a s-a-0 for each OR/NOR and
a s-a-0 and s-a-1 for other gates. */
if (pGate->inCount > 1) //>= 2 inputs !!
{
iFaultType = (pGate->type == AND || pGate->type == NAND) ? SA1 :
/*(pGate->type == OR || pGate->type == NOR)*/ SA0;
for (j = 0; j< pGate->inCount; j++)
{
if (pGate->inList[j]->outCount > 1) //FANOUT !!
{
pFault = (FAULTPTR)malloc(sizeof(FAULTTYPE));
pFault->gate = pGate;
pFault->type = iFaultType;
pFault->line = j;
pFault->next = NULL;
iNoFault++;
pGate->nfault++;
pPreFault->next = pFault;
//(pGate->pfault) ---> ... ---> ... ---> pPreFault ---> pFault
if (pPreFault == pGate->pfault) //For 1st time !!
{
pFault->previous = pFault; //don't point to pPreFault for 1st time
}
else
{
pFault->previous = pPreFault;
}
pPreFault = pFault;
/* case of high level gates */
if (pGate->type > PI) //XOR XNOR PO, add both SA1 & SA0 faults !!
{
ALLOCATE(pFault, FAULTTYPE, 1);
pFault->gate = pGate;
pFault->type = (iFaultType == SA1) ? SA0 : SA1;
pFault->line = j;
pFault->next = NULL;
iNoFault++;
pGate->nfault++;
pPreFault->next = pFault;
//(pGate->pfault) ---> ... ---> ... ---> pPreFault ---> pFault
if (pPreFault == pGate->pfault)
{
pFault->previous = pFault;
}
else
{
pFault->previous = pPreFault;
}
pPreFault = pFault;
}
}
}
}
/* output fault assignment:
add s-a-1 and s-a-0 faults for each fanout stem or
primary output. */
//(output==1) & (CoInput || PO)
if ((pGate->outCount == 1) && (pGate->outList[0]->inCount > 1 || pGate->outList[0]->type == PO))
{
//1)CoInput
//pGate ----------------->pGate->outList[0]
//Other Gates ------------>pGate->outList[0]
//2)PO
//pGate ----------------->pGate->outList[0] (PO)
iFaultType = (pGate->outList[0]->type == OR || pGate->outList[0]->type == NOR) ? SA0 :
/*(pGate->outList[0]->type == AND || pGate->outList[0]->type == NAND)*/ SA1;
ALLOCATE(pFault, FAULTTYPE, 1);
pFault->gate = pGate;
pFault->type = iFaultType;
pFault->line = OUTFAULT;
pFault->next = NULL;
iNoFault++;
pGate->nfault++;
pPreFault->next = pFault;
//(pGate->pfault) ---> ... ---> ... ---> pPreFault ---> pFault
if (pPreFault == pGate->pfault)
{
pFault->previous = pFault;
}
else
{
pFault->previous = pPreFault;
}
pPreFault = pFault;
/* case of high level gates */
if (pGate->outList[0]->type > PI) //XOR XNOR NOT PO, add both SA1 & SA0 faults !!
{
pFault = (FAULTPTR)malloc(sizeof(FAULTTYPE));
pFault->gate = pGate;
pFault->type = (iFaultType == SA1) ? SA0 : SA1;
pFault->line = OUTFAULT;
pFault->next = NULL;
iNoFault++;
pGate->nfault++;
pPreFault->next = pFault;
//(pGate->pfault) ---> ... ---> ... ---> pPreFault ---> pFault
if (pPreFault == pGate->pfault)
{
pFault->previous = pFault;
}
else
{
pFault->previous = pPreFault;
}
pPreFault = pFault;
}
}
//FANOUT
//add both SA0 & SA1 !!!
else if (pGate->outCount > 1)
{
pFault = (FAULTPTR)malloc(sizeof(FAULTTYPE));
pFault->gate = pGate;
pFault->type = SA1;
pFault->line = OUTFAULT;
pFault->next = NULL;
iNoFault++;
pGate->nfault++;
pPreFault->next = pFault;
//(pGate->pfault) ---> ... ---> ... ---> pPreFault ---> pFault
if (pPreFault == pGate->pfault)
{
pFault->previous = pFault;
}
else
{
pFault->previous = pPreFault;
}
pPreFault = pFault;
pFault = (FAULTPTR)malloc(sizeof(FAULTTYPE));
pFault->gate = pGate;
pFault->type = SA0;
pFault->line = OUTFAULT;
pFault->next = NULL;
iNoFault++;
pGate->nfault++;
pPreFault->next = pFault;
//(pGate->pfault) ---> ... ---> ... ---> pPreFault ---> pFault
if (pPreFault == pGate->pfault)
{
pFault->previous = pFault;
}
else
{
pFault->previous = pPreFault;
}
pPreFault = pFault;
}
//PO & CoInput
//add both SA0 & SA1 !!!
else if (pGate->type == PO && pGate->inList[0]->outCount > 1)
{
//pGate->inList[0] --------------> pGate (PO)
//pGate->inList[0] --------------> Other Gates
pFault = (FAULTPTR)malloc(sizeof(FAULTTYPE));
pFault->gate = pGate;
pFault->type = SA1;
pFault->line = 0;
pFault->next = NULL;
iNoFault++;
pGate->nfault++;
pPreFault->next = pFault;
//(pGate->pfault) ---> ... ---> ... ---> pPreFault ---> pFault
if (pPreFault == pGate->pfault)
{
pFault->previous = pFault;
}
else
{
pFault->previous = pPreFault;
}
pPreFault = pFault;
ALLOCATE(pFault, FAULTTYPE, 1);
pFault->gate = pGate;
pFault->type = SA0;
pFault->line = 0;
pFault->next = NULL;
iNoFault++;
pGate->nfault++;
pPreFault->next = pFault;
//(pGate->pfault) ---> ... ---> ... ---> pPreFault ---> pFault
if (pPreFault == pGate->pfault)
{
pFault->previous = pFault;
}
else
{
pFault->previous = pPreFault;
}
pPreFault = pFault;
}
//get pPreFault back !! So MAGIC !!
pPreFault = pGate->pfault;
if (pGate->pfault->next == NULL) //NO Fault generated!!
{
pGate->pfault = NULL; //Still the pPreFault object !!
}
else //New Fault !!
{
pGate->pfault = pPreFault->next;
}
pPreFault->next = NULL;
} /* end for */
free((char*)pPreFault);
/* create the fault_list and
enumerate faults in each fanout free region */
g_pFaultList = (FAULTPTR *)malloc((unsigned)(sizeof(FAULTPTR) * iNoFault));
clear(g_stack);
iNoFaultTemp = 0;
for (i = iNoStemGates - 1; i >= 0; i--)
{
push(g_stack, pStemGates[i]);
iNoStemFaultAdd1 = 1;
while (!is_empty(g_stack))
{
pGate = pop(g_stack);
for (pFault = pGate->pfault; pFault != NULL; pFault = pFault->next)
{
//Spread within the FFR !!
g_pFaultList[iNoFaultTemp++] = pFault; //Core sentence
iNoStemFaultAdd1++; //Core sentence
}
for (j = 0; j< pGate->inCount; j++)
{
if (pGate->inList[j]->outCount == 1) //With FFR
{
push(g_stack, pGate->inList[j]);
}
}
}
pStemGates[i]->dfault = (FAULTPTR *)malloc((unsigned)(iNoStemFaultAdd1 * sizeof(FAULTPTR)));
}
//OUTPUT: pStemGates[i]->dfault && g_pFaultList
if (iNoFault == iNoFaultTemp)
{
return(iNoFault);
}
else
{
//ERROR !!
return(-1);
}
}
/* add_fault
Add a fault to the linked list of each gate.
*/
void addFaultToGate(FAULTPTR pFault) //add_fault
{
//add pGate->pfault!!!
GATEPTR pGate; FAULTPTR pOldFault;
pGate = pFault->gate;
if (pGate->pfault == NULL) //The first fault
{
pGate->pfault = pFault;
pFault->previous = pFault;
pGate->nfault = 1;
}
else //Not the first
{
pOldFault = pGate->pfault;
while (pOldFault->next != NULL)
pOldFault = pOldFault->next;
pOldFault->next = pFault;
pFault->previous = pOldFault;
pGate->nfault++;
}
pFault->next = NULL;
}
/* restore_detected_fault_list
Restores the fault list for test compaction.
Does not restore redundant faults.
*/
int restoreUndetectedState_FSIM(int iNoFault) //restore_detected_fault_list
{
register FAULTPTR pFault;
register int i, iNoRestored;
iNoRestored = 0;
for (i = 0; i < iNoFault; i++)
{
pFault = g_pFaultList[i];
if (pFault->detected == DETECTED)
{
pFault->detected = UNDETECTED;
addFaultToGate(pFault);
iNoRestored++;
}
}
return(iNoRestored);
}
/* check_redundant_faults
Identifies redundant faults in which more than two inputs of
a gate are connected to one gate simultaneously and deletes
the faults from the fault list.
Input: nog, the number of gates of the circuit
Output: number of identified redundant faults
Note: changed flags of all gates should be reset to 0
prior to call this function.
*/
/* macro to delete a fault */
#define delete_fault(pFault) \
if (pFault->previous == pFault) \
{ \
pFault->gate->pfault = pFault->next; \
if(pFault->next != NULL) \
{ \
pFault->next->previous = pFault->next; \
} \
} \
else \
{ \
pFault->previous->next = pFault->next; \
if(pFault->next != NULL) \
{ \
pFault->next->previous = pFault->previous; \
} \
}
int deleteRedundantFaults(int iNoGate) //check_redundant_faults
{
register int i, j;
int iNoRedundant;
register GATEPTR pFanoutGate;
FAULTPTR pFault;
iNoRedundant = 0;
for (i = 0; i < iNoGate; i++)
{
if (g_net[i]->outCount > 1) //for every FANOUT pFanoutGate !!!
{
pFanoutGate = g_net[i]; //FANOUT
for (j = 0; j< pFanoutGate->outCount; j++)
{
//changed = 0
(pFanoutGate->outList[j]->changed)++;
}
for (j = 0; j< pFanoutGate->outCount; j++)
{
if (pFanoutGate->outList[j]->changed > 1) //for every pFanoutGate->outList[j] && changed > 1
{
for (pFault = pFanoutGate->outList[j]->pfault; pFault != NULL; pFault = pFault->next)
{
if (pFault->line >= 0)
//pFanoutGate->outList[j] == (pFault->gate)
//(pFault->gate->inList[pFault->line]) ----> pFault ----> (pFault->gate)
//pFanoutGate ------------------------------> pFault ----> pFanoutGate->outList[j]
//Other Gates ------------------------->pFault ----> pFanoutGate->outList[j]
{
if (pFault->gate->inList[pFault->line] == pFanoutGate) //pFanoutGate is 2rd gate which faults!!
{
pFault->detected = REDUNDANT;
if (--pFault->gate->nfault > 0) //At least 1 fault remains !!
{
//ALWAYS !!
delete_fault(pFault);
}
iNoRedundant++;
}
}
}
}
reset(pFanoutGate->outList[j]->changed); //change to 0 instead of 1 !!
}
}
}
return(iNoRedundant);
}
/*******************************************************************
The following routines are used to read fault directory.
The file format is the same as that of ISCAS89 fault list file.
**********************************************************************/
#define is_white_space(c) (c==' ' || c=='-' || c=='\t' || c=='\n')
#define is_head_symbol(c) (c=='/' || c=='>')
#define is_valid(c) ((c>='0' && c<='9') || \
(c>='A' && c<='Z') || \
(c>='a' && c<='z') || \
(c=='[' || c==']') || \
(c=='_'))
/*------getfaultsymbol-------------------------------------------------
reads next symbol from the given fault file
inputs : file the name of input file
outputs: s symbol string output
returns head character of s unless EOF is encountered.
-------------------------------------------------------------------*/
#define EOS '\0'
char getfaultsymbol(FILE *file, char s[])
{
char c;
int n = 0;
status valid = FALSE;
while ((c = getc(file)) != EOF)
{
if (is_white_space(c))
{
if (valid)
{
break;
}
else
{
continue;
}
}
if (is_head_symbol(c))
{
s[n++] = c; continue;
}
if (is_valid(c))
{
s[n++] = c; set(valid);
}
else
{
printFatalError(FAULTERROR);
}
}
s[n] = EOS;
if (c == EOF)
{
return(c);
}
else
{
return(s[0]);
}
}
/*------readfaults------------------------------------------------
reads fault list and constructs fault list data structure
inputs: file fault directory file
outputs: fault list
------------------------------------------------------------------*/
int readFaults(FILE *fpFaultFile, int g_iNoGate, int iStem, GATEPTR *pStem) //readfaults
{
//OUTPUT: g_pFaultList
GATEPTR gut;
FAULTPTR f;
int from, to, line, type;
HASHPTR h;
int i, j;
//char c;
char s[MAXSTRING];
int nfault, n, nof;
nfault = 0;
for (i = 0; i < g_iNoGate; i++)
{
gut = g_net[i];
gut->pfault = (FAULTPTR)NULL;
gut->nfault = 0;
}
while (getfaultsymbol(fpFaultFile, s) != EOF)
{
if (is_valid(s[0]))
{
if ((h = FindHash(pArrSymbolTable, HASHSIZE, s, 0)) == NULL)
{
fprintf(stderr, "Error in fault file:");
fprintf(stderr, "%s is not defined\n", s);
printFatalError(FAULTERROR);
}
if ((to = h->gate->index) < 0)
{
printFatalError(FAULTERROR);
}
gut = g_net[to];
line = (-1);
}
else if (s[0] == '>')
{
from = to;
if ((h = FindHash(pArrSymbolTable, HASHSIZE, &s[1], 0)) == NULL)
{
fprintf(stderr, "Error in fault file:");
fprintf(stderr, "%s is not defined\n", s);
printFatalError(FAULTERROR);
}
if ((to = h->gate->index) < 0)
{
printFatalError(FAULTERROR);
}
gut = g_net[to];
for (i = 0; i< gut->inCount; i++)
if (gut->inList[i]->index == from)
{
line = i; break;
}
}
else if (s[0] == '/')
{
if (s[1] == '1')
{
type = SA1;
}
else
{
type = SA0;
}
if (line >= 0)
{
type = (type == SA1) ? SA1 : SA0;
}
ALLOCATE(f, FAULTTYPE, 1);
f->gate = gut;
f->line = line;
f->type = type;
f->previous = f;
if ((f->next = gut->pfault) != NULL)
{
f->next->previous = f;
}
gut->pfault = f;
nfault++;
gut->nfault++;
/* while((c=getc(file)) != '\n') if(c==EOF) break; */
}
else
{
printFatalError(FAULTERROR);
}
}
/* create the fault_list and
enumerate faults in each fanout free region */
g_pFaultList = (FAULTPTR *)malloc((unsigned)(sizeof(FAULTPTR) * nfault));
nof = 0;
clear(g_stack);
for (i = iStem - 1; i >= 0; i--)
{
push(g_stack, pStem[i]);
n = 1;
while (!is_empty(g_stack))
{
gut = pop(g_stack);
for (f = gut->pfault; f != NULL; f = f->next)
{
g_pFaultList[nof++] = f; n++;
}
for (j = 0; j< gut->inCount; j++)
if (gut->inList[j]->outCount == 1)
{
push(g_stack, gut->inList[j]);
}
}
pStem[i]->dfault = (FAULTPTR *)malloc((unsigned)(n * sizeof(FAULTPTR)));
}
if (nfault == nof)
{
return(nfault);
}
else
{
return(-1);
}
}
#ifdef INCLUDE_HOPE
/*-----------------------------------------------------------------
The following routines creates the fault list for HOPE
-------------------------------------------------------------------*/
extern int g_iNoGate, g_iNoPI, g_iNoPO, g_iNoFF, g_iMaxLevel, g_iNoFault;
extern int *g_PrimaryIn, *g_PrimaryOut, *g_FlipFlop;
extern GATEPTR *g_net;
extern STACKTYPE g_stack1, g_stack2, *g_pEventListStack;
extern FAULTPTR g_pHeadFault, g_pCurrentFault, g_pTailFault, *g_pFaultList;
extern HASHPTR pArrSymbolTable[];
// extern HASHPTR FindHash();
// extern void fatalerror();
FAULTPTR g_pEvenHeadFault, g_pEvenTailFault, g_pOddHeadFault, g_pOddTailFault;
int g_parityForGate[MAXGTYPE] =
{
0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1,
}; //AND NAND OR NOR PI XOR XNOR DFF DUMMY BUFF NOT
int inverseParity[2][2] =
{
{0,1}, {1,0}
};
/*------init_fault_list--------------------------------------------
initializes fault list including headfault,tailfault
headfault indicates one dummy fault
-------------------------------------------------------------------*/
void initFaultList() //init_fault_list
{
ALLOCATE(g_pHeadFault, FAULTTYPE, 1);
g_pHeadFault->gate = NULL;
g_pHeadFault->next = NULL;
g_pHeadFault->event = NULL;
g_pEvenHeadFault = g_pEvenTailFault = g_pOddHeadFault = g_pOddTailFault = NULL;
g_pTailFault = g_pHeadFault;
}
/*------insert_fault------------------------------------------------
inserts a fault at the end of the fault list
used for fault ordering. Parity of each fault is
checked and stored in even and odd fault list.
inputs: gut; faulty gate
line; faulty line, if (-1), output fault
type; fault type
outputs: evenhead,eventail,oddhead,oddtail
-------------------------------------------------------------------*/
void insertFaultForGate(GATEPTR pGate, int iLineType, fault_type iFaultType) //insert_fault
{
int iParity;
FAULTPTR pFault;
iParity = (pGate->changed >= 2) ? pGate->changed - 2 : pGate->changed;
if (iLineType < 0)
{
iParity = inverseParity[g_parityForGate[pGate->type]][iParity];
}
ALLOCATE(pFault, FAULTTYPE, 1);
pFault->gate = pGate;
pFault->line = iLineType;
pFault->type = iFaultType;
pFault->next = NULL;
pFault->event = NULL;
pFault->npot = 0;
g_iNoFault++;
if ((iParity == 0 && iFaultType == SA0) || (iParity == 1 && iFaultType == SA1))
{
if (g_pEvenTailFault == NULL)
{
g_pEvenHeadFault = g_pEvenTailFault = pFault;
}
else
{
g_pEvenTailFault->next = pFault;
g_pEvenTailFault = pFault;
}
}
else //(iParity == 0 && iFaultType == SA1) || (iParity == 1 && iFaultType == SA0)
{
if (g_pOddTailFault == NULL)
{
g_pOddHeadFault = g_pOddTailFault = pFault;
}
else
{
g_pOddTailFault->next = pFault;
g_pOddTailFault = pFault;
}
}
}
/*------default_line_fault-----------------------------------------
defines default stuck-at faults for the given line
inputs: gut; gate under consideration
line; faulty line of the gate, if (-1), output fault
outputs: none
-------------------------------------------------------------------*/
void insertFaultsForGateByLine(GATEPTR pGate, int iLineType) //default_line_fault
{
GATEPTR pInGate, pOutGate;
if (iLineType < 0)
{
/* output iLineType fault */
if (pGate->type == DUMMY || pGate->type == PO)
{
return; //PO Eliminated !!
}
if (pGate->outCount != 1) //FANOUT
{
insertFaultForGate(pGate, OUTFAULT, SA0);
insertFaultForGate(pGate, OUTFAULT, SA1);
}
else //NORMAL Gate
{
//pGate ------------> pOutGate
//Other Gates --------> pOutGate
pOutGate = pGate->outList[0];
if (pOutGate->type == DUMMY)
{
//STOP***************************STOP
pOutGate = pOutGate->outList[0];
}
switch (pOutGate->type)
{
case AND:
case NAND:
if (pOutGate->inCount > 1)
{
insertFaultForGate(pGate, OUTFAULT, SA1);
}
break;
case OR:
case NOR:
if (pOutGate->inCount > 1)
{
insertFaultForGate(pGate, OUTFAULT, SA0);
}
break;
case XOR:
case XNOR:
case DFF:
case PO:
insertFaultForGate(pGate, OUTFAULT, SA0);
insertFaultForGate(pGate, OUTFAULT, SA1);
break;
default:
break; /* dummy, not, buff */
}
}
}
else
{
//STOP*****************************************STOP
/* input iLineType fault */
//pInGate ------------> pGate
//pInGate ------------->Other Gates
pInGate = pGate->inList[iLineType];
if (pInGate->type == DUMMY || pInGate->type == PO)
{
//STOP***************************STOP
pInGate = pInGate->inList[0];
}
if (pInGate->outCount > 1)
{
switch (pGate->type)
{
case AND:
case NAND:
if (pGate->inCount > 1)
{
insertFaultForGate(pGate, iLineType, SA1);
}
break;
case OR:
case NOR:
if (pGate->inCount > 1)
{
insertFaultForGate(pGate, iLineType, SA0);
}
break;
case XOR:
case XNOR:
case DFF:
case PO:
insertFaultForGate(pGate, iLineType, SA0);
insertFaultForGate(pGate, iLineType, SA1);
break;
default:
break; /* dummy, not, buffer */
}
}
}
}
#define setParity(pGate, iParity) \
pGate->changed = inverseParity[g_parityForGate[pGate->type]][iParity]
#define mark(pGate) pGate->changed += 2
#define isNotMarked(pGate) pGate->changed < 2
#define isStem(pGate) \
((pGate->outCount != 1) || (pGate->outList[0]->type == DFF))
/*------ Sets fault list for the given FFRs ------*/
void initFFRFaults(GATEPTR pGate) //FFR_Fault
{
//pGate == [STEM Gate]
//OUTPUT: g_pEvenHeadFault etc.. && g_iNoFault
register GATEPTR pInGate;
register int i;
clear(g_stack1);
g_pEvenHeadFault = g_pEvenTailFault = g_pOddHeadFault = g_pOddTailFault = NULL;
push(g_stack1, pGate);
while (!is_empty(g_stack1))
{
pGate = pop(g_stack1);
insertFaultsForGateByLine(pGate, OUTFAULT); //Core sentence g_pEvenHeadFault etc. updated !!
for (i = 0; i< pGate->inCount; i++)
{
pInGate = pGate->inList[i];
if (isStem(pInGate))
{
insertFaultsForGateByLine(pGate, i); //Core sentence
}
else
{
push(g_stack1, pInGate); //Within FFR !!
}
}
}
//g_pTailFault ---> g_pEvenHeadFault ---> g_pEvenTailFault ---> g_pOddHeadFault ---> g_pOddTailFault
if (g_pEvenTailFault == NULL)
{
g_pEvenHeadFault = g_pOddHeadFault;
g_pEvenTailFault = g_pOddTailFault;
}
else
{
g_pEvenTailFault->next = g_pOddHeadFault;
}
if ((g_pEvenTailFault = (g_pOddTailFault == NULL) ? g_pEvenTailFault : g_pOddTailFault) != NULL)
{
//g_pEvenTailFault = g_pOddTailFault (if g_pOddTailFault != NULL)
g_pTailFault->next = g_pEvenHeadFault;
g_pTailFault = g_pEvenTailFault;
//g_pTailFault ---> g_pEvenHeadFault ---> g_pEvenTailFault ---> g_pOddHeadFault ---> g_pOddTailFault
}
}
/*------DFS_po--------------------------------------------------------
Subroutine of DFS search from primary outputs
---------------------------------------------------------------------*/
void initFaultsForPOByDFS(GATEPTR pParentGate, GATEPTR pGate) //DFS_po
{
//ALWAYS: pParentGate == NULL
//Initially: pGate == PO Gate (Every PO executes this method)
int i;
/* preWORK */
setParity(pGate, (pParentGate == NULL ? 0 : pParentGate->changed - 2)); //The same as:
//pGate->changed = parity_of_gate[pGate->type]; //NAND & NOR & NOT ---> changed = TRUE
mark(pGate); //pGate->changed += 2
if (isStem(pGate)) //PO & FANOUT
{
initFFRFaults(pGate);
}
/* Go into children */
for (i = 0; i< pGate->inCount; i++)
{
/* preWORK for input lines */
if (isNotMarked(pGate->inList[i]))
{
initFaultsForPOByDFS(pGate, pGate->inList[i]);
}
}
}
/*------DFS_faults----------------------------------------------------
defines fault list in the order of DFS from primary outputs
use recursive version DFS routines.
main of DFS_po.
---------------------------------------------------------------------*/
void initFaultList_HOPE() //FWD_faults
{
register int i;
register GATEPTR pGate;
for (i = 0; i < g_iNoGate; i++)
{
reset(g_net[i]->changed);
}
initFaultList();
/* Primary Outputs */
for (i = 0; i < g_iNoPO; i++)
{