//--------------------------------------------------------------------------- // @function: // CUnittest::FSimulated // // @doc: // Check if exception was injected by simulation // //--------------------------------------------------------------------------- BOOL CUnittest::FSimulated ( CException ex ) { ITask *ptsk = ITask::PtskSelf(); GPOS_ASSERT(NULL != ptsk); return (ptsk->FTrace(EtraceSimulateOOM) && GPOS_MATCH_EX(ex, CException::ExmaSystem, CException::ExmiOOM)) || (ptsk->FTrace(EtraceSimulateAbort) && GPOS_MATCH_EX(ex, CException::ExmaSystem, CException::ExmiAbort)) || (ptsk->FTrace(EtraceSimulateIOError) && GPOS_MATCH_EX(ex, CException::ExmaSystem, CException::ExmiIOError)) || (ptsk->FTrace(EtraceSimulateNetError) && GPOS_MATCH_EX(ex, CException::ExmaSystem, CException::ExmiNetError)); }
//--------------------------------------------------------------------------- // @function: // FSimulateIOErrorInternal // // @doc: // Inject I/O exception // //--------------------------------------------------------------------------- static BOOL FSimulateIOErrorInternal ( INT iErrno, const CHAR *szFile, ULONG ulLine ) { BOOL fRes = false; ITask *ptsk = ITask::PtskSelf(); if (NULL != ptsk && ptsk->FTrace(EtraceSimulateIOError) && CFSimulator::Pfsim()->FNewStack(CException::ExmaSystem, CException::ExmiIOError) && !GPOS_MATCH_EX(ptsk->Perrctxt()->Exc(), CException::ExmaSystem, CException::ExmiIOError)) { // disable simulation temporarily to log injection CAutoTraceFlag(EtraceSimulateIOError, false); CLogger *plogger = dynamic_cast<CLogger*>(ITask::PtskSelf()->Ptskctxt()->PlogErr()); if (!plogger->FLogging()) { GPOS_TRACE_FORMAT_ERR("Simulating I/O error at %s:%d", szFile, ulLine); } errno = iErrno; if (ptsk->Perrctxt()->FPending()) { ptsk->Perrctxt()->Reset(); } // inject I/O error fRes = true; } return fRes; }
//--------------------------------------------------------------------------- // @function: // netutils::FSimulateNetError // // @doc: // Inject networking exception // //--------------------------------------------------------------------------- BOOL gpos::netutils::FSimulateNetError ( INT iErrno, const CHAR *szFile, ULONG ulLine ) { GPOS_ASSERT(0 < iErrno); ITask *ptsk = ITask::PtskSelf(); if (NULL != ptsk && ptsk->FTrace(EtraceSimulateNetError) && CFSimulator::Pfsim()->FNewStack(CException::ExmaSystem, CException::ExmiNetError) && !GPOS_MATCH_EX(ptsk->Perrctxt()->Exc(), CException::ExmaSystem, CException::ExmiNetError)) { // disable simulation temporarily to log injection CAutoTraceFlag(EtraceSimulateNetError, false); CLogger *plogger = dynamic_cast<CLogger*>(ITask::PtskSelf()->Ptskctxt()->PlogErr()); if (!plogger->FLogging()) { GPOS_TRACE_FORMAT_ERR("Simulating networking error at %s:%d", szFile, ulLine); } errno = iErrno; if (ptsk->Perrctxt()->FPending()) { ptsk->Perrctxt()->Reset(); } return true; } return false; }