33 #define FFTEST_MAX_VARS 2
34 #define FFTEST_MAX_PARS 8
80 assert( iVar >= 0 && iVar < nVars );
101 int i, status, nVars = 7;
112 for ( i = 0; i < nVars; i++ )
236 int i, iFuncVars = 0;
281 int i, iFuncVars = 0;
320 int i, iCtrl0, iCtrl1, iCtrl2, iCtrl3, iMuxA, iMuxB, iFuncVars = 0;
385 if ( pStr[0] !=
'(' )
387 printf(
"The first symbol should be the opening paranthesis \"(\".\n" );
390 if ( pStr[
strlen(pStr)-1] !=
')' )
392 printf(
"The last symbol should be the closing paranthesis \")\".\n" );
395 for ( i = 0; pStr[i]; i++ )
396 if ( pStr[i] ==
'(' )
398 else if ( pStr[i] ==
')' )
402 printf(
"The number of opening and closing parantheses is not equal.\n" );
407 for ( i = 0; pStr[i]; i++ )
409 if ( pStr[i] >=
'a' && pStr[i] <=
'b' )
410 *pnVars =
Abc_MaxInt( *pnVars, pStr[i] -
'a' + 1 );
411 else if ( pStr[i] >=
'p' && pStr[i] <=
's' )
412 *pnPars =
Abc_MaxInt( *pnPars, pStr[i] -
'p' + 1 );
413 else if ( pStr[i] ==
'(' || pStr[i] ==
')' )
415 else if ( pStr[i] ==
'&' || pStr[i] ==
'|' || pStr[i] ==
'^' )
417 else if ( pStr[i] ==
'?' || pStr[i] ==
':' )
419 else if ( pStr[i] ==
'~' )
421 if ( pStr[i+1] <
'a' || pStr[i+1] >
'z' )
423 printf(
"Expecting alphabetic symbol (instead of \"%c\") after negation (~)\n", pStr[i+1] );
429 printf(
"Unknown symbol (%c) in the formula (%s)\n", pStr[i], pStr );
434 { printf(
"The number of input variables (%d) should be 2\n", *pnVars );
return 1; }
436 { printf(
"The number of parameters should be between 1 and %d\n", *pnPars );
return 1; }
442 for ( k = i = 0; pForm[i]; i++ )
444 if ( pForm[i] ==
'~' )
447 assert( pForm[i] >=
'a' && pForm[i] <=
'z' );
448 pStr[k++] =
'A' + pForm[i] -
'a';
451 pStr[k++] = pForm[i];
472 for ( pThis = pForm; *pThis; pThis++ )
477 else if ( *pThis ==
')' )
487 int iFans[3], Oper = -1;
489 if ( pBeg + 1 == pEnd )
491 if ( pBeg[0] >=
'a' && pBeg[0] <=
'b' )
492 return pVars[pBeg[0] -
'a'];
493 if ( pBeg[0] >=
'A' && pBeg[0] <=
'B' )
495 if ( pBeg[0] >=
'p' && pBeg[0] <=
'w' )
496 return pPars[pBeg[0] -
'p'];
497 if ( pBeg[0] >=
'P' && pBeg[0] <=
'W' )
502 if ( pBeg[0] ==
'(' )
505 if ( pEndNew == pEnd )
508 assert( pBeg[pEnd-pBeg-1] ==
')' );
529 assert( pEndNew[0] ==
':' );
558 for ( k = 0; k < nPars; k++ )
624 FILE * pFile = fopen( pFileName,
"wb" );
627 for ( v = i = 0; i < nIter; i++, fprintf(pFile,
"\n") )
628 for ( k = 0; k < nVars; k++ )
646 FILE * pTable = fopen(
"fault_stats.txt",
"a+" );
658 fprintf( pTable,
"%d ", nIter );
659 fprintf( pTable,
"%.2f", 1.0*clk/CLOCKS_PER_SEC );
660 fprintf( pTable,
"\n" );
689 for ( i = 0; i < pCnf2->
nClauses; i++ )
709 if ( i >= nFuncVars )
730 FILE * pFile = fopen( pFileName,
"wb" );
733 int nItersMax = 10000;
734 int i, nIters, status, Value, Count = 0;
736 for ( nIters = 0; nIters < nItersMax; nIters++ )
738 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
740 printf(
"Timeout reached after dumping %d untestable faults.\n", nIters );
748 if ( i >= nFuncVars )
758 printf(
"Untestable fault %4d : ", ++Count );
766 fprintf( pFile,
"%d ", i );
767 fprintf( pFile,
"\n" );
791 FILE * pFile = fopen( pFileName,
"rb" );
795 printf(
"Cannot open input file \"%s\".\n", pFileName );
799 while ( (c = fgetc(pFile)) != EOF )
801 if ( c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n' )
803 if ( c !=
'0' && c !=
'1' )
805 printf(
"Wring symbol (%c) in the input file.\n", c );
830 for ( i = 0; i < nPisNew; i++ )
848 int nConfLimit = 100;
849 int status, i, v, iVar, Lit;
850 int nUnsats = 0, nRuns = 0;
863 status =
sat_solver_solve( pSat, &Lit, &Lit+1, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
897 int Gia_ManFaultPrepare(
Gia_Man_t *
p,
Gia_Man_t * pG,
Bmc_ParFf_t * pPars,
int nFuncVars,
Vec_Int_t * vMap,
Vec_Int_t * vTests,
Vec_Int_t * vLits,
Gia_Man_t ** ppMiter,
Cnf_Dat_t ** ppCnf,
sat_solver ** ppSat,
int fWarmUp )
899 Gia_Man_t * p0 = NULL, * p1 = NULL, * pM;
908 printf(
"The number of symbols in the input patterns (%d) does not divide evenly on the number of test variables (%d).\n",
Vec_IntSize(vTests), nFuncVars );
914 if ( pPars->
Algo == 0 )
916 else if ( pPars->
Algo == 1 )
922 else if ( pPars->
Algo == 2 )
924 else if ( pPars->
Algo == 3 )
926 else if ( pPars->
Algo == 4 )
928 if ( pPars->
Algo != 1 )
944 for ( i = 0; i < pCnf->
nClauses; i++ )
959 if ( i >= nFuncVars )
970 printf(
"Reading %d pre-computed test patterns from file \"%s\".\n",
Vec_IntSize(vTests) / nFuncVars, pPars->
pFileName );
972 printf(
"Reading %d pre-computed test patterns from previous rounds.\n",
Vec_IntSize(vTests) / nFuncVars );
973 for ( Iter = 0; Iter < nTests; Iter++ )
978 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
984 printf(
"Timeout reached after %d seconds and adding %d tests.\n", pPars->
nTimeOut, Iter );
991 printf(
"The problem is UNSAT after adding %d tests.\n", Iter );
997 for ( i = 0; i < nFuncVars; i++ )
1003 printf(
"The problem is UNSAT after adding %d tests.\n", Iter );
1008 printf(
"Iter%6d : ", Iter );
1019 for ( Iter = 0; Iter < 2; Iter++ )
1021 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1026 printf(
"Timeout reached after %d seconds and %d iterations.\n", pPars->
nTimeOut, Iter );
1033 printf(
"The problem is UNSAT after %d iterations.\n", Iter );
1043 printf(
"The problem is UNSAT after adding %d tests.\n", Iter );
1049 printf(
"Using miter with: AIG nodes = %6d. CNF variables = %6d. CNF clauses = %8d.\n",
Gia_ManAndNum(pM), pCnf->
nVars, pCnf->
nClauses );
1070 int nIterMax = 1000000, nVars, nPars;
1071 int i, Iter, Iter2, status, nFuncVars = -1;
1073 Vec_Int_t * vLits, * vMap = NULL, * vTests, * vPars = NULL;
1083 if ( pPars->
Algo == 0 )
1084 printf(
"FFTEST is computing test patterns for fault model \"%s\"...\n", pPars->
pFormStr );
1085 else if ( pPars->
Algo == 1 )
1086 printf(
"FFTEST is computing test patterns for %sdelay faults...\n", pPars->
fBasic ?
"single " :
"" );
1087 else if ( pPars->
Algo == 2 )
1088 printf(
"FFTEST is computing test patterns for %sstuck-at faults...\n", pPars->
fBasic ?
"single " :
"" );
1089 else if ( pPars->
Algo == 3 )
1090 printf(
"FFTEST is computing test patterns for %scomplement faults...\n", pPars->
fBasic ?
"single " :
"" );
1091 else if ( pPars->
Algo == 4 )
1092 printf(
"FFTEST is computing test patterns for %sfunctionally observable faults...\n", pPars->
fBasic ?
"single " :
"" );
1095 printf(
"Unrecognized algorithm (%d).\n", pPars->
Algo );
1100 if ( pPars->
Algo == 0 )
1102 else if ( pPars->
Algo == 1 )
1104 else if ( pPars->
Algo == 2 )
1106 else if ( pPars->
Algo == 3 )
1108 else if ( pPars->
Algo == 4 )
1116 if ( vTests == NULL )
1121 if ( pPars->
Algo == 2 )
1123 else if ( pPars->
Algo == 3 )
1125 else if ( pPars->
Algo == 4 )
1130 if ( !
Gia_ManFaultPrepare(p, pG, pPars, nFuncVars, vMap, vTests, vLits, &pM, &pCnf, &pSat, 1) )
1141 if ( i >= nFuncVars )
1154 if ( !
Gia_ManFaultPrepare(p, pG, pPars, nFuncVars, vMap, vTests, vLits, &pM, &pCnf, &pSat, 0) )
1156 printf(
"This should never happen.\n" );
1163 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1167 printf(
"Iter%6d : ", Iter );
1178 printf(
"Timeout reached after %d seconds and %d iterations.\n", pPars->
nTimeOut, Iter );
1185 printf(
"The problem is UNSAT after %d iterations. ", Iter );
1192 if ( i < nFuncVars )
1200 printf(
"The problem is UNSAT after adding %d tests.\n", Iter );
1213 char * pFileName =
"tests.txt";
1215 printf(
"Dumping %d computed test patterns into file \"%s\".\n",
Vec_IntSize(vTests) / nFuncVars, pFileName );
1228 for ( i = 0; i < pCnf->
nClauses; i++ )
1236 if ( i >= nFuncVars )
1245 if ( i >= nFuncVars )
1261 for ( Iter2 = 0; ; Iter2++ )
1264 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
1268 printf(
"Iter%6d : ", Iter2 );
1279 printf(
"Timeout reached after %d seconds and %d iterations.\n", pPars->
nTimeOut, Iter2 );
1282 if ( Iter2 == Iter )
1287 for ( i = 0; i < nFuncVars; i++ )
1291 printf(
"The problem is UNSAT after adding %d tests.\n", Iter2 );
1301 printf(
"There are untestable faults. " );
1303 printf(
"There is no untestable faults. " );
1310 printf(
"The circuit is rectifiable. " );
1312 printf(
"The circuit is not rectifiable (or equivalent to the golden one). " );
1320 char * pFileName =
"untest.txt";
1323 printf(
"Dumped %d untestable multiple faults into file \"%s\". ", nUntests, pFileName );
1325 printf(
"Dumped %d ways of rectifying the circuit into file \"%s\". ", nUntests, pFileName );
static int Vec_IntCountPositive(Vec_Int_t *p)
static abctime sat_solver_set_runtime_limit(sat_solver *s, abctime Limit)
Gia_Man_t * Gia_ManFormulaUnfold(Gia_Man_t *p, char *pForm)
static int * Vec_IntArray(Vec_Int_t *p)
static void Cnf_DataLiftGia(Cnf_Dat_t *p, Gia_Man_t *pGia, int nVarsPlus)
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Gia_Man_t * Gia_ManDeriveDup(Gia_Man_t *p, int nPisNew)
void Gia_ManStop(Gia_Man_t *p)
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
#define Gia_ManForEachCo(p, pObj, i)
void Gia_ManDumpTests(Vec_Int_t *vTests, int nIter, char *pFileName)
Gia_Man_t * Gia_ManStuckAtUnfold(Gia_Man_t *p, Vec_Int_t *vMap)
static int Gia_ManPoNum(Gia_Man_t *p)
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
void Aig_ManStop(Aig_Man_t *p)
int Gia_ManFaultAnalyze(sat_solver *pSat, Vec_Int_t *vPars, Vec_Int_t *vMap, Vec_Int_t *vLits, int Iter)
static char * Gia_ManName(Gia_Man_t *p)
void Cnf_AddCardinConstrTest()
void Gia_ParFfSetDefault(Bmc_ParFf_t *p)
FUNCTION DEFINITIONS ///.
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
int Gia_ManRealizeFormula(Gia_Man_t *p, int *pVars, int *pPars, char *pStr, int nPars)
static int Gia_ManAppendCi(Gia_Man_t *p)
void sat_solver_delete(sat_solver *s)
static int Abc_Var2Lit(int Var, int fCompl)
Gia_Man_t * Gia_ManFOFUnfold(Gia_Man_t *p, Vec_Int_t *vMap)
int sat_solver_nconflicts(sat_solver *s)
char * Gia_ManFormulaEndToken(char *pForm)
static abctime Abc_Clock()
int Gia_ManRealizeFormula_rec(Gia_Man_t *p, int *pVars, int *pPars, char *pBeg, char *pEnd, int nPars)
static int Abc_MaxInt(int a, int b)
static Vec_Int_t * Vec_IntStartNatural(int nSize)
static int Cnf_AddCardinConstr(sat_solver *p, Vec_Int_t *vVars)
static int sat_solver_var_value(sat_solver *s, int v)
static int sat_solver_add_buffer(sat_solver *pSat, int iVarA, int iVarB, int fCompl)
#define FFTEST_MAX_VARS
DECLARATIONS ///.
Gia_Man_t * Gia_ManFaultCofactor(Gia_Man_t *p, Vec_Int_t *vValues)
void Gia_FormStrTransform(char *pStr, char *pForm)
#define Gia_ManForEachCi(p, pObj, i)
static void Abc_PrintTime(int level, const char *pStr, abctime time)
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
static int Gia_ManAndNum(Gia_Man_t *p)
static int Aig_ManCoNum(Aig_Man_t *p)
static Cnf_Dat_t * Cnf_DeriveGiaRemapped(Gia_Man_t *p)
static int Abc_LitIsCompl(int Lit)
static Gia_Obj_t * Gia_ManPi(Gia_Man_t *p, int v)
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
static int Gia_ObjFanin1Copy(Gia_Obj_t *pObj)
int Gia_ManDumpUntests(Gia_Man_t *pM, Cnf_Dat_t *pCnf, sat_solver *pSat, int nFuncVars, char *pFileName, int fVerbose)
void Gia_ManFaultTest(Gia_Man_t *p, Gia_Man_t *pG, Bmc_ParFf_t *pPars)
Gia_Man_t * Gia_ManFaultUnfold(Gia_Man_t *p, int fUseMuxes)
static Gia_Obj_t * Gia_ObjRoToRi(Gia_Man_t *p, Gia_Obj_t *pObj)
void sat_solver_setnvars(sat_solver *s, int n)
static int Vec_IntEntry(Vec_Int_t *p, int i)
int sat_solver_nvars(sat_solver *s)
#define ABC_NAMESPACE_IMPL_END
int Gia_ManHashMux(Gia_Man_t *p, int iCtrl, int iData1, int iData0)
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
#define Gia_ManForEachAnd(p, pObj, i)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
void Gia_ManPrintResults(Gia_Man_t *p, sat_solver *pSat, int nIter, abctime clk)
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
static void Vec_IntFreeP(Vec_Int_t **p)
#define Gia_ManForEachPi(p, pObj, i)
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
int sat_solver_nclauses(sat_solver *s)
#define ABC_NAMESPACE_IMPL_START
static int Gia_ManCiNum(Gia_Man_t *p)
static int Vec_IntEntryLast(Vec_Int_t *p)
static int Abc_LitNot(int Lit)
int sat_solver_simplify(sat_solver *s)
sat_solver * sat_solver_new(void)
static int Vec_IntSize(Vec_Int_t *p)
static void Vec_IntShrink(Vec_Int_t *p, int nSizeNew)
Vec_Int_t * Gia_ManGetTestPatterns(char *pFileName)
int Gia_ManFaultPrepare(Gia_Man_t *p, Gia_Man_t *pG, Bmc_ParFf_t *pPars, int nFuncVars, Vec_Int_t *vMap, Vec_Int_t *vTests, Vec_Int_t *vLits, Gia_Man_t **ppMiter, Cnf_Dat_t **ppCnf, sat_solver **ppSat, int fWarmUp)
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Gia_Man_t * Gia_ManFlipUnfold(Gia_Man_t *p, Vec_Int_t *vMap)
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
void Cnf_DataFree(Cnf_Dat_t *p)
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
int Gia_FormStrCount(char *pStr, int *pnVars, int *pnPars)
#define Gia_ManForEachRo(p, pObj, i)
void Gia_ManHashAlloc(Gia_Man_t *p)
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
static void Vec_IntFree(Vec_Int_t *p)
static int Gia_ManPiNum(Gia_Man_t *p)
static void Vec_IntClear(Vec_Int_t *p)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
char * Abc_UtilStrsav(char *s)
#define Gia_ManForEachPo(p, pObj, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Gia_Man_t * Gia_ManMiter(Gia_Man_t *pAig0, Gia_Man_t *pAig1, int nInsDup, int fDualOut, int fSeq, int fImplic, int fVerbose)
static int Gia_ManObjNum(Gia_Man_t *p)
int Gia_ManFaultAddOne(Gia_Man_t *pM, Cnf_Dat_t *pCnf, sat_solver *pSat, Vec_Int_t *vLits, int nFuncVars)
static int Gia_ManCoNum(Gia_Man_t *p)
static int sat_solver_add_and(sat_solver *pSat, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl)
static int Gia_ManRegNum(Gia_Man_t *p)