abc/src/base/abci/abcDebug.c
/**Function*************************************************************

  Synopsis    [Takes a network and a procedure to test.]

  Description [The network demonstrates the bug in the procedure.
  Procedure should return 1 if the bug is demonstrated.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Takes a network and a procedure to test.]

Description [The network demonstrates the bug in the procedure.
Procedure should return 1 if the bug is demonstrated.]




Function Synopsis [ Takes a network and a procedure to test . ] Description [ The network demonstrates the bug in the procedure . Procedure should return 1 if the bug is demonstrated . ]
void Abc_NtkAutoDebug( Abc_Ntk_t * pNtk, int (*pFuncError) (Abc_Ntk_t *) )
{
    Abc_Ntk_t * pNtkMod;
    char * pFileName = "bug_found.blif";
    int i, nSteps, nIter, ModNum, RandNum = 1;
    abctime clk, clkTotal = Abc_Clock();
    assert( Abc_NtkIsLogic(pNtk) );
    srand( 0x123123 );
    pNtk = Abc_NtkDup(pNtk);
    if ( !(*pFuncError)( pNtk ) )
    {
        printf( "The original network does not cause the bug. Quitting.\n" );
        Abc_NtkDelete( pNtk );
        return;
    }
    for ( nIter = 0; ; nIter++ )
    {
        clk = Abc_Clock();
        nSteps = 2 * Abc_NtkCountFaninsTotal(pNtk);
        RandNum ^= rand();
        for ( i = 0; i < nSteps; i++ )
        {
            ModNum = (i + RandNum) % nSteps;
            pNtkMod = Abc_NtkAutoDebugModify( pNtk, ModNum/2, ModNum%2 );
            Io_WriteBlifLogic( pNtk, "bug_temp.blif", 1 );   
            if ( (*pFuncError)( pNtkMod ) ) 
            {
                Abc_NtkDelete( pNtk );
                pNtk = pNtkMod;
                break;
            }
            else 
                Abc_NtkDelete( pNtkMod );
        }
        printf( "Iter %6d : Latches = %6d. Nodes = %6d. Steps = %6d. Error step = %3d.  ", 
            nIter, Abc_NtkLatchNum(pNtk), Abc_NtkNodeNum(pNtk), nSteps, i );
        ABC_PRT( "Time", Abc_Clock() - clk );
        if ( i == nSteps ) 
            break;
    }
    Io_WriteBlifLogic( pNtk, pFileName, 1 );
    printf( "Final network written into file \"%s\". ", pFileName );
    ABC_PRT( "Total time", Abc_Clock() - clkTotal );
    Abc_NtkDelete( pNtk );
}
void Abc_NtkAutoDebug ( Abc_Ntk_t * pNtk , int ( * pFuncError ) ( Abc_Ntk_t * ) ) { Abc_Ntk_t * pNtkMod ; char * pFileName = " " ; int i , nSteps , nIter , ModNum , RandNum = 1 ; abctime clk , clkTotal = Abc_Clock ( ) ; assert ( Abc_NtkIsLogic ( pNtk ) ) ; srand ( 0x123123 ) ; pNtk = Abc_NtkDup ( pNtk ) ; if ( ! ( * pFuncError ) ( pNtk ) ) { printf ( " \n " ) ; Abc_NtkDelete ( pNtk ) ; return ; } for ( nIter = 0 ; ; nIter ++ ) { clk = Abc_Clock ( ) ; nSteps = 2 * Abc_NtkCountFaninsTotal ( pNtk ) ; RandNum ^= rand ( ) ; for ( i = 0 ; i < nSteps ; i ++ ) { ModNum = ( i + RandNum ) % nSteps ; pNtkMod = Abc_NtkAutoDebugModify ( pNtk , ModNum / 2 , ModNum % 2 ) ; Io_WriteBlifLogic ( pNtk , " " , 1 ) ; if ( ( * pFuncError ) ( pNtkMod ) ) { Abc_NtkDelete ( pNtk ) ; pNtk = pNtkMod ; break ; } else Abc_NtkDelete ( pNtkMod ) ; } printf ( " " , nIter , Abc_NtkLatchNum ( pNtk ) , Abc_NtkNodeNum ( pNtk ) , nSteps , i ) ; ABC_PRT ( " " , Abc_Clock ( ) - clk ) ; if ( i == nSteps ) break ; } Io_WriteBlifLogic ( pNtk , pFileName , 1 ) ; printf ( " \" \" " , pFileName ) ; ABC_PRT ( " " , Abc_Clock ( ) - clkTotal ) ; Abc_NtkDelete ( pNtk ) ; }
Function
Synopsis    [Takes a network and a procedure to test.]
Function Synopsis [ Takes a network and a procedure to test . ]
// create internal copy of the network // perform incremental modifications // count how many ways of modifying the network exists // try modifying the network as many times // get the shifted number of bug // get the modified network // write the network // check if the bug is still there // bug is still there // no bug // could not modify it while preserving the bug // write out the final network