//--------------------------------------------------------------------------- // @function: // CTreeMapTest::EresUnittest_Count // // @doc: // Count and debug output of all counts at various nodes // //--------------------------------------------------------------------------- GPOS_RESULT CTreeMapTest::EresUnittest_Count() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); TestMap *ptmap = PtmapLoad(pmp); // debug print CWStringDynamic str(pmp); COstreamString oss(&str); ULLONG ullCount = ptmap->UllCount(); oss << "total number of trees: " << ullCount << std::endl; #ifdef GPOS_DEBUG for (ULONG ul = 0; ul < ulElems; ul++) { oss << "node: " << ul << " count: " << ptmap->UllCount(&rgul[ul]) << std::endl; } (void) ptmap->OsPrint(oss); #endif // GPOS_DEBUG GPOS_TRACE(str.Wsz()); GPOS_DELETE(ptmap); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CMessageTableTest::EresUnittest_Basic // // @doc: // Create message table and insert all standard messages; // //--------------------------------------------------------------------------- GPOS_RESULT CMessageTableTest::EresUnittest_Basic() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); CMessageTable *pmt = GPOS_NEW(pmp) CMessageTable(pmp, GPOS_MSGTAB_SIZE, ElocEnUS_Utf8); // insert all system messages for (ULONG ul = 0; ul < CException::ExmiSentinel; ul++) { CMessage *pmsg = CMessage::Pmsg(ul); if (CException::m_excInvalid != pmsg->m_exc) { pmt->AddMessage(pmsg); #ifdef GPOS_DEBUG CMessage *pmsgLookedup = pmt->PmsgLookup(pmsg->m_exc); GPOS_ASSERT(pmsg == pmsgLookedup && "Lookup failed"); #endif // GPOS_DEBUG } } GPOS_DELETE(pmt); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CBitSetTest::EresUnittest_Performance // // @doc: // Simple perf test -- simulates xform candidate sets // //--------------------------------------------------------------------------- GPOS_RESULT CBitSetTest::EresUnittest_Performance() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); ULONG cSizeBits = 512; CBitSet *pbsBase = GPOS_NEW(pmp) CBitSet(pmp, cSizeBits); for (ULONG i = 0; i < cSizeBits; i++) { (void) pbsBase->FExchangeSet(i); } CBitSet *pbsTest = GPOS_NEW(pmp) CBitSet(pmp, cSizeBits); for (ULONG j = 0; j < 100000; j++) { ULONG cRandomBits = 16; for (ULONG i = 0; i < cRandomBits; i += ((cSizeBits - 1) / cRandomBits)) { (void) pbsTest->FExchangeSet(i); } pbsTest->Intersection(pbsBase); } pbsTest->Release(); pbsBase->Release(); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CMemoryPoolBasicTest::EresLeakByException // // @doc: // Basic test for ignored leaks under exception // //--------------------------------------------------------------------------- GPOS_RESULT CMemoryPoolBasicTest::EresLeakByException ( CMemoryPoolManager::EAllocType eat ) { CAutoTraceFlag atfDump(EtracePrintMemoryLeakDump, true); CAutoTraceFlag atfStackTrace(EtracePrintMemoryLeakStackTrace, true); CAutoTimer at("LeakByException test", true /*fPrint*/); // scope for pool { // create memory pool CAutoMemoryPool amp ( CAutoMemoryPool::ElcExc, eat, false /*fThreadSafe*/, 4 * 1024 * 1024 /*ullMaxSize*/ ); IMemoryPool *pmp = amp.Pmp(); for (ULONG i = 0; i < 10; i++) { // use overloaded New operator ULONG *rgul = GPOS_NEW_ARRAY(pmp, ULONG, 3); rgul[2] = 1; } GPOS_ASSERT(!"Trigger leak with exception"); } return GPOS_FAILED; }
//--------------------------------------------------------------------------- // @function: // CTreeMapTest::EresUnittest_Unrank // // @doc: // Rehydrate all trees encoded in the map // //--------------------------------------------------------------------------- GPOS_RESULT CTreeMapTest::EresUnittest_Unrank() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); TestMap *ptmap = PtmapLoad(pmp); // debug print CWStringDynamic str(pmp); COstreamString oss(&str); ULLONG ullCount = ptmap->UllCount(); for (ULONG ulRank = 0; ulRank < ullCount; ulRank++) { oss << "=== tree rank: " << ulRank << " ===" << std::endl; BOOL fFlag = true; CNode *pnd = ptmap->PrUnrank(pmp, &fFlag, ulRank); (void) pnd->OsPrint(oss); pnd->Release(); } GPOS_TRACE(str.Wsz()); GPOS_DELETE(ptmap); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CMDProviderTest::EresUnittest_Basic // // @doc: // Test fetching existing metadata objects from a file-based provider // //--------------------------------------------------------------------------- GPOS_RESULT CMDProviderTest::EresUnittest_Basic() { // create memory pool CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); // test lookup with a file-based provider CMDProviderMemory *pmdpFile = GPOS_NEW(mp) CMDProviderMemory(mp, file_name); pmdpFile->AddRef(); TestMDLookup(mp, pmdpFile); pmdpFile->Release(); // test lookup with a memory-based provider CHAR *dxl_string = CDXLUtils::Read(mp, file_name); IMDCacheObjectArray *mdcache_obj_array = CDXLUtils::ParseDXLToIMDObjectArray(mp, dxl_string, NULL /*xsd_file_path*/); CMDProviderMemory *pmdpMemory = GPOS_NEW(mp) CMDProviderMemory(mp, mdcache_obj_array); pmdpMemory->AddRef(); TestMDLookup(mp, pmdpMemory); GPOS_DELETE_ARRAY(dxl_string); mdcache_obj_array->Release(); pmdpMemory->Release(); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CSyncHashtableTest::EresUnittest_AccessorDeadlock // // @doc: // Test for self-deadlock on hashtable accessor // //--------------------------------------------------------------------------- GPOS_RESULT CSyncHashtableTest::EresUnittest_AccessorDeadlock() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); // scope for hashtable { CSyncHashtable<SElem, ULONG, CSpinlockDummy> sht; sht.Init ( pmp, GPOS_SHT_SMALL_BUCKETS, GPOS_OFFSET(SElem, m_link), GPOS_OFFSET(SElem, m_ulKey), &(SElem::m_ulInvalid), SElem::UlHash, SElem::FEqualKeys ); SElem elem; elem.m_ulKey = 1; ULONG ulKey = elem.m_ulKey; CSyncHashtableAccessByKey<SElem, ULONG, CSpinlockDummy> shtacc0(sht, ulKey); // this must assert since we try to self-deadlock on a spinlock CSyncHashtableAccessByKey<SElem, ULONG, CSpinlockDummy> shtacc1(sht, ulKey); } return GPOS_FAILED; }
//--------------------------------------------------------------------------- // @function: // CEnumSetTest::EresUnittest_Basics // // @doc: // Testing ctors/dtor, accessors, iterator // //--------------------------------------------------------------------------- GPOS_RESULT CEnumSetTest::EresUnittest_Basics() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); typedef CEnumSet<eTest, eTestSentinel> CETestSet; typedef CEnumSetIter<eTest, eTestSentinel> CETestIter; CETestSet *pes = GPOS_NEW(pmp) CETestSet(pmp); (void) pes->FExchangeSet(eTestOne); (void) pes->FExchangeSet(eTestTwo); GPOS_ASSERT(pes->FExchangeClear(eTestTwo)); GPOS_ASSERT(!pes->FExchangeSet(eTestTwo)); CETestIter eti(*pes); while(eti.FAdvance()) { GPOS_ASSERT((BOOL)eti); GPOS_ASSERT(eTestSentinel > eti.TBit()); GPOS_ASSERT(pes->FBit(eti.TBit())); } pes->Release(); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CICGTest::EresUnittest_PenalizeIndexJoinVersusHashJoin // // @doc: // Test that hash join is preferred versus index join when estimation // risk is high // //--------------------------------------------------------------------------- GPOS_RESULT CICGTest::EresUnittest_PreferHashJoinVersusIndexJoinWhenRiskIsHigh() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); // enable (Redistribute, Broadcast) hash join plans CAutoTraceFlag atf(EopttraceEnableRedistributeBroadcastHashJoin, true /*fVal*/); // When the risk threshold is infinite, we should pick index join DrgPcp *pdrgpcpUnlimited = GPOS_NEW(pmp) DrgPcp(pmp); ICostModelParams::SCostParam *pcpUnlimited = GPOS_NEW(pmp) ICostModelParams::SCostParam ( CCostModelParamsGPDB::EcpIndexJoinAllowedRiskThreshold, ULONG_MAX, // dVal 0, // dLowerBound ULONG_MAX // dUpperBound ); pdrgpcpUnlimited->Append(pcpUnlimited); GPOS_RESULT eres = CTestUtils::EresCheckOptimizedPlan ( rgszPreferHashJoinVersusIndexJoin, GPOS_ARRAY_SIZE(rgszPreferHashJoinVersusIndexJoin), &m_ulTestCounterPreferIndexJoinToHashJoin, 1, // ulSessionId 1, // ulCmdId FHasIndexJoin, pdrgpcpUnlimited ); pdrgpcpUnlimited->Release(); if (GPOS_OK != eres) { return eres; } // When the risk threshold is zero, we should not pick index join DrgPcp *pdrgpcpNoIndexJoin = GPOS_NEW(pmp) DrgPcp(pmp); ICostModelParams::SCostParam *pcpNoIndexJoin = GPOS_NEW(pmp) ICostModelParams::SCostParam ( CCostModelParamsGPDB::EcpIndexJoinAllowedRiskThreshold, 0, // dVal 0, // dLowerBound 0 // dUpperBound ); pdrgpcpNoIndexJoin->Append(pcpNoIndexJoin); eres = CTestUtils::EresCheckOptimizedPlan ( rgszPreferHashJoinVersusIndexJoin, GPOS_ARRAY_SIZE(rgszPreferHashJoinVersusIndexJoin), &m_ulTestCounterPreferHashJoinToIndexJoin, 1, // ulSessionId 1, // ulCmdId FHasNoIndexJoin, pdrgpcpNoIndexJoin ); pdrgpcpNoIndexJoin->Release(); return eres; }
//--------------------------------------------------------------------------- // @function: // CListTest::EresUnittest_Cursor // // @doc: // Various cursor-based inserts // //--------------------------------------------------------------------------- GPOS_RESULT CListTest::EresUnittest_Cursor() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); CList<SElem> list; list.Init(GPOS_OFFSET(SElem, m_linkFwd)); ULONG cSize = 5; SElem *rgelem = GPOS_NEW_ARRAY(pmp, SElem, cSize); list.Append(&rgelem[0]); list.Prepend(&rgelem[1], list.PtFirst()); list.Append(&rgelem[2], list.PtLast()); GPOS_ASSERT(&rgelem[1] == list.PtFirst()); GPOS_ASSERT(&rgelem[2] == list.PtLast()); list.Prepend(&rgelem[3], list.PtLast()); list.Append(&rgelem[4], list.PtFirst()); GPOS_ASSERT(&rgelem[1] == list.PtFirst()); GPOS_ASSERT(&rgelem[2] == list.PtLast()); GPOS_DELETE_ARRAY(rgelem); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CCostTest::EresUnittest_Arithmetic // // @doc: // Test arithmetic operations // //--------------------------------------------------------------------------- GPOS_RESULT CCostTest::EresUnittest_Arithmetic() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); CCost cost1(2.5); CCost cost2(3.0); CCost cost3(5.49); CCost cost4(5.51); CCost cost5(7.49); CCost cost6(7.51); CCost costAdd(cost1 + cost2); CCost costMultiply(cost1 * cost2); GPOS_ASSERT(costAdd > cost3); GPOS_ASSERT(costAdd < cost4); GPOS_ASSERT(costMultiply > cost5); GPOS_ASSERT(costMultiply < cost6); CAutoTrace at(mp); IOstream &os(at.Os()); os << "Arithmetic operations: " << std::endl << cost1 << " + " << cost2 << " = " << costAdd << std::endl << cost1 << " * " << cost2 << " = " << costMultiply << std::endl; return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CMiniDumperTest::EresUnittest_Basic // // @doc: // Basic test for minidump handler // //--------------------------------------------------------------------------- GPOS_RESULT CMiniDumperTest::EresUnittest_Basic() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); CMiniDumperStream mdrs(mp); CWStringDynamic wstrMinidump(mp); COstreamString oss(&wstrMinidump); mdrs.Init(&oss); GPOS_TRY { (void) PvRaise(NULL); } GPOS_CATCH_EX(ex) { mdrs.Finalize(); GPOS_RESET_EX; GPOS_TRACE(wstrMinidump.GetBuffer()); } GPOS_CATCH_END; return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CWStringTest::EresUnittest_Initialize // // @doc: // Test string construction // //--------------------------------------------------------------------------- GPOS_RESULT CWStringTest::EresUnittest_Initialize() { #ifdef GPOS_DEBUG // run this test in debug mode only CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); CWStringDynamic *pstr1 = GPOS_NEW(pmp) CWStringDynamic(pmp, GPOS_WSZ_LIT("123")); CWStringConst cstr1(GPOS_WSZ_LIT("123")); GPOS_ASSERT(pstr1->FEquals(&cstr1)); // empty string initialization CWStringDynamic *pstr2 = GPOS_NEW(pmp) CWStringDynamic(pmp); WCHAR buffer[16]; CWStringStatic ss(buffer, GPOS_ARRAY_SIZE(buffer)); CWStringConst cstr2(GPOS_WSZ_LIT("")); GPOS_ASSERT(pstr2->FEquals(&cstr2)); GPOS_ASSERT(ss.FEquals(&cstr2)); GPOS_ASSERT(0 == pstr2->UlLength()); GPOS_ASSERT(0 == ss.UlLength()); // constant string initialization CWStringConst *pcstr1 = GPOS_NEW(pmp) CWStringConst(GPOS_WSZ_LIT("123")); GPOS_ASSERT(pcstr1->FEquals(&cstr1)); // cleanup GPOS_DELETE(pstr1); GPOS_DELETE(pstr2); GPOS_DELETE(pcstr1); #endif // #ifdef GPOS_DEBUG return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CNormalizer::FPushableThruSeqPrjChild // // @doc: // Check if a predicate can be pushed through the child of a sequence // project expression // //--------------------------------------------------------------------------- BOOL CNormalizer::FPushableThruSeqPrjChild ( CExpression *pexprSeqPrj, CExpression *pexprPred ) { GPOS_ASSERT(NULL != pexprSeqPrj); GPOS_ASSERT(NULL != pexprPred); GPOS_ASSERT(CLogical::EopLogicalSequenceProject == pexprSeqPrj->Pop()->Eopid()); CDistributionSpec *pds = CLogicalSequenceProject::PopConvert(pexprSeqPrj->Pop())->Pds(); BOOL fPushable = false; if (CDistributionSpec::EdtHashed == pds->Edt()) { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); CColRefSet *pcrsUsed = CDrvdPropScalar::Pdpscalar(pexprPred->PdpDerive())->PcrsUsed(); CColRefSet *pcrsPartCols = CUtils::PcrsExtractColumns(pmp, CDistributionSpecHashed::PdsConvert(pds)->Pdrgpexpr()); if (pcrsPartCols->FSubset(pcrsUsed)) { // predicate is pushable if used columns are included in partition-by expression fPushable = true; } pcrsPartCols->Release(); } return fPushable; }
// basic int4 point tests; GPOS_RESULT CPointTest::EresUnittest_CPointInt4() { // create memory pool CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); // generate integer points CPoint *point1 = CTestUtils::PpointInt4(mp, 1); CPoint *point2 = CTestUtils::PpointInt4(mp, 2); GPOS_RTL_ASSERT_MSG(point1->Equals(point1), "1 == 1"); GPOS_RTL_ASSERT_MSG(point1->IsLessThan(point2), "1 < 2"); GPOS_RTL_ASSERT_MSG(point2->IsGreaterThan(point1), "2 > 1"); GPOS_RTL_ASSERT_MSG(point1->IsLessThanOrEqual(point2), "1 <= 2"); GPOS_RTL_ASSERT_MSG(point2->IsGreaterThanOrEqual(point2), "2 >= 2"); CDouble dDistance = point2->Distance(point1); // should be 1.0 GPOS_RTL_ASSERT_MSG(0.99 < dDistance && dDistance < 1.01, "incorrect distance calculation"); point1->Release(); point2->Release(); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CColumnFactoryTest::EresUnittest_Basic // // @doc: // Basic array allocation test // //--------------------------------------------------------------------------- GPOS_RESULT CColumnFactoryTest::EresUnittest_Basic() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); CMDAccessor mda(pmp, CMDCache::Pcache()); mda.RegisterProvider(CTestUtils::m_sysidDefault, pmdp); const IMDTypeInt4 *pmdtypeint4 = mda.PtMDType<IMDTypeInt4>(); CColumnFactory cf; // typed colref CColRef *pcrOne = cf.PcrCreate(pmdtypeint4); GPOS_ASSERT(pcrOne == cf.PcrLookup(pcrOne->m_ulId)); cf.Destroy(pcrOne); // typed/named colref CWStringConst strName(GPOS_WSZ_LIT("C_CustKey")); CColRef *pcrTwo = cf.PcrCreate(pmdtypeint4, CName(&strName)); GPOS_ASSERT(pcrTwo == cf.PcrLookup(pcrTwo->m_ulId)); // clone previous colref CColRef *pcrThree = cf.PcrCreate(pcrTwo); GPOS_ASSERT(pcrThree != cf.PcrLookup(pcrTwo->m_ulId)); GPOS_ASSERT(!pcrThree->Name().FEquals(pcrTwo->Name())); cf.Destroy(pcrThree); cf.Destroy(pcrTwo); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CStackTest::EresUnittest_Pop // // @doc: // This test should assert. // //--------------------------------------------------------------------------- GPOS_RESULT CStackTest::EresUnittest_Pop() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); ULONG rgsz[] = {1, 2, 3, 4}; CStack<ULONG> *pstk = GPOS_NEW(pmp) CStack<ULONG> (pmp, 4); CAutoP<CStack<ULONG> > cAP; cAP = pstk; // add elements incl trigger resize of array for (ULONG i = 0; i < 4; i++) { pstk->Push(&rgsz[i]); GPOS_ASSERT( (* pstk->Peek()) == 4 - i); GPOS_ASSERT(pstk->Pop() == &rgsz[i]); } // now deliberately pop when the stack is empty pstk->Pop(); return GPOS_FAILED; }
//--------------------------------------------------------------------------- // @function: // CAutoTaskProxyTest::EresUnittest_Wait // // @doc: // Wait for task to complete. // //--------------------------------------------------------------------------- GPOS_RESULT CAutoTaskProxyTest::EresUnittest_Wait() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); CWorkerPoolManager *pwpm = CWorkerPoolManager::WorkerPoolManager(); // scope for ATP { CAutoTaskProxy atp(mp, pwpm); CTask *rgPtsk[2]; ULLONG rgRes[2]; // create tasks rgPtsk[0] = atp.Create(CAutoTaskProxyTest::PvUnittest_Short, &rgRes[0]); rgPtsk[1] = atp.Create(CAutoTaskProxyTest::PvUnittest_Long, &rgRes[1]); // start two tasks atp.Schedule(rgPtsk[0]); atp.Schedule(rgPtsk[1]); // wait until tasks complete atp.Wait(rgPtsk[0]); atp.Wait(rgPtsk[1]); GPOS_ASSERT(rgRes[0] == *(ULLONG *)rgPtsk[0]->GetRes()); GPOS_ASSERT(rgRes[1] == *(ULLONG *)rgPtsk[1]->GetRes()); } return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CHashMapTest::EresUnittest_Ownership // // @doc: // Basic hash map test with ownership // //--------------------------------------------------------------------------- GPOS_RESULT CHashMapTest::EresUnittest_Ownership() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); ULONG ulCnt = 256; typedef CHashMap<ULONG_PTR, CHAR, UlHashPtr<ULONG_PTR>, gpos::FEqual<ULONG_PTR>, CleanupDelete<ULONG_PTR>, CleanupDeleteRg<CHAR> > HMUlChar; HMUlChar *phm = GPOS_NEW(pmp) HMUlChar(pmp, 32); for (ULONG i = 0; i < ulCnt; ++i) { ULONG_PTR *pulp = GPOS_NEW(pmp) ULONG_PTR(i); CHAR *sz = GPOS_NEW_ARRAY(pmp, CHAR, 3); #ifdef GPOS_DEBUG BOOL fSuccess = #endif // GPOS_DEBUG phm->FInsert(pulp, sz); GPOS_ASSERT(fSuccess); GPOS_ASSERT(sz == phm->PtLookup(pulp)); // can't insert existing keys GPOS_ASSERT(!phm->FInsert(pulp, sz)); } phm->Release(); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CLoggerTest::EresUnittest_LoggerFile // // @doc: // Log to file // //--------------------------------------------------------------------------- GPOS_RESULT CLoggerTest::EresUnittest_LoggerFile() { CAutoMemoryPool am; IMemoryPool *pmp = am.Pmp(); GPOS_TRY { // "/foobar" directory does not exist - this will throw an IOError CLoggerFile ploggerFile("/foobar", 10 /*ulFiles*/, 1024/*ulRotateThreshold*/); return GPOS_FAILED; } GPOS_CATCH_EX(ex) { GPOS_ASSERT(GPOS_MATCH_EX(ex, CException::ExmaSystem, CException::ExmiIOError)); GPOS_RESET_EX; } GPOS_CATCH_END; // use one worker, small file size to check rotation Unittest_TestLoggerFile ( pmp, 10 /*ulFiles*/, 4096 /*ulRotateThreshold*/, 1 /*ulWorkers*/, 10000 /*ulIterations*/ ) ; return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // ConfigureTests // // @doc: // Configurations needed before running unittests // //--------------------------------------------------------------------------- void ConfigureTests() { // initialize DXL support InitDXL(); CMDCache::Init(); // load metadata objects into provider file { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); CTestUtils::InitProviderFile(pmp); // detach safety (void) amp.PmpDetach(); } #ifdef GPOS_DEBUG // reset xforms factory to exercise xforms ctors and dtors CXformFactory::Pxff()->Shutdown(); GPOS_RESULT eres = CXformFactory::EresInit(); GPOS_ASSERT(GPOS_OK == eres); #endif // GPOS_DEBUG }
//--------------------------------------------------------------------------- // @function: // CMDProviderTest::EresUnittest_Basic // // @doc: // Test fetching existing metadata objects from a file-based provider // //--------------------------------------------------------------------------- GPOS_RESULT CMDProviderTest::EresUnittest_Basic() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); // test lookup with a file-based provider CMDProviderMemory *pmdpFile = GPOS_NEW(pmp) CMDProviderMemory(pmp, szFileName); pmdpFile->AddRef(); TestMDLookup(pmp, pmdpFile); pmdpFile->Release(); // test lookup with a memory-based provider CHAR *szDXL = CDXLUtils::SzRead(pmp, szFileName); DrgPimdobj *pdrgpmdobj = CDXLUtils::PdrgpmdobjParseDXL(pmp, szDXL, NULL /*szXSDPath*/); CMDProviderMemory *pmdpMemory = GPOS_NEW(pmp) CMDProviderMemory(pmp, pdrgpmdobj); pmdpMemory->AddRef(); TestMDLookup(pmp, pmdpMemory); GPOS_DELETE_ARRAY(szDXL); pdrgpmdobj->Release(); pmdpMemory->Release(); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CTreeMapTest::EresUnittest_FailedPlanEnumerationTests // // @doc: // Run Minidump-based tests that fail during plan enumeration because // of large plan space // //--------------------------------------------------------------------------- GPOS_RESULT CTreeMapTest::EresUnittest_FailedPlanEnumerationTests() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); BOOL fMatchPlans = false; BOOL fTestSpacePruning = false; #if defined(GPOS_Darwin) || defined(GPOS_Linux) // restrict plan matching to OsX and Linux to avoid arithmetic operations differences // across systems fMatchPlans = true; fTestSpacePruning = true; #endif // GPOS_Darwin || GPOS_Linux // enable plan enumeration only if we match plans CAutoTraceFlag atf1(EopttraceEnumeratePlans, fMatchPlans); // enable stats derivation for DPE CAutoTraceFlag atf2(EopttraceDeriveStatsForDPE, true /*fVal*/); const ULONG ulTests = GPOS_ARRAY_SIZE(rgszFailedPlanEnumerationTests); GPOS_RESULT eres = GPOS_OK; for (ULONG ul = 0; eres == GPOS_OK && ul < ulTests; ul++) { GPOS_TRY { eres = CTestUtils::EresRunMinidumps ( pmp, &rgszFailedPlanEnumerationTests[ul], 1, // ulTests &m_ulTestCounter, 1, // ulSessionId 1, // ulCmdId fMatchPlans, fTestSpacePruning ); } GPOS_CATCH_EX(ex) { if (GPOS_MATCH_EX(ex, CException::ExmaSystem, CException::ExmiOverflow)) { eres = GPOS_OK; GPOS_RESET_EX; } else { GPOS_RETHROW(ex); eres = GPOS_FAILED; } } GPOS_CATCH_END; } return eres; }
//--------------------------------------------------------------------------- // @function: // CCNFConverterTest::EresUnittest_Basic // // @doc: // Basic test // //--------------------------------------------------------------------------- GPOS_RESULT CCNFConverterTest::EresUnittest_Basic() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); // setup a file-based provider CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); CMDAccessor mda(pmp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp); typedef CExpression *(*Pfpexpr)(IMemoryPool*); Pfpexpr rgpf[] = { CTestUtils::PexprLogicalSelectWithNestedAnd, CTestUtils::PexprLogicalSelectWithNestedOr, CTestUtils::PexprLogicalSelectWithEvenNestedNot, CTestUtils::PexprLogicalSelectWithOddNestedNot, CTestUtils::PexprLogicalSelectWithNestedAndOrNot }; for (ULONG i = 0; i < GPOS_ARRAY_SIZE(rgpf); i++) { // install opt context in TLS CAutoOptCtxt aoc ( pmp, &mda, NULL, /* pceeval */ CTestUtils::Pcm(pmp) ); // generate expression CExpression *pexpr = rgpf[i](pmp); CExpression *pexprPreprocessed = CExpressionPreprocessor::PexprPreprocess(pmp, pexpr); CWStringDynamic str(pmp); COstreamString oss(&str); oss << std::endl << "SCALAR EXPR:" << std::endl << *(*pexpr)[1] << std::endl; GPOS_TRACE(str.Wsz()); str.Reset(); if (1 < pexprPreprocessed->UlArity()) { CExpression *pexprCNF = CCNFConverter::Pexpr2CNF(pmp, (*pexprPreprocessed)[1]); oss << std::endl << "CNF REPRESENTATION:" << std::endl << *pexprCNF << std::endl; GPOS_TRACE(str.Wsz()); str.Reset(); pexprCNF->Release(); } pexpr->Release(); pexprPreprocessed->Release(); } return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CAutoTaskProxyTest::EresUnittest_TimedWait // // @doc: // Wait for task to complete with timeout. // //--------------------------------------------------------------------------- GPOS_RESULT CAutoTaskProxyTest::EresUnittest_TimedWait() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); CWorkerPoolManager *pwpm = CWorkerPoolManager::WorkerPoolManager(); // scope for ATP { CAutoTaskProxy atp(mp, pwpm); CTask *rgPtsk[2]; ULLONG rgRes[2]; // create tasks rgPtsk[0] = atp.Create(CAutoTaskProxyTest::PvUnittest_Short, &rgRes[0]); rgPtsk[1] = atp.Create(CAutoTaskProxyTest::PvUnittest_Infinite, &rgRes[1]); // start tasks atp.Schedule(rgPtsk[0]); atp.Schedule(rgPtsk[1]); // wait for first task - no timeout #ifdef GPOS_DEBUG GPOS_RESULT eres = #endif // GPOS_DEBUG atp.TimedWait(rgPtsk[0], gpos::ulong_max); GPOS_ASSERT(GPOS_OK == eres); // check second task - timeout immediately #ifdef GPOS_DEBUG eres = #endif // GPOS_DEBUG atp.TimedWait(rgPtsk[1], 0); GPOS_ASSERT(GPOS_TIMEOUT == eres); // wait for second task - timeout #ifdef GPOS_DEBUG eres = #endif // GPOS_DEBUG atp.TimedWait(rgPtsk[1], 10); GPOS_ASSERT(GPOS_TIMEOUT == eres); GPOS_ASSERT(!rgPtsk[0]->IsCanceled()); GPOS_ASSERT(!rgPtsk[1]->IsCanceled()); GPOS_ASSERT(CTask::EtsCompleted == rgPtsk[0]->GetStatus()); GPOS_ASSERT(rgPtsk[1]->IsScheduled() && !rgPtsk[1]->IsFinished()); GPOS_ASSERT(rgRes[0] == *(ULLONG *)rgPtsk[0]->GetRes()); GPOS_ASSERT(NULL == rgPtsk[1]->GetRes()); // ATP cancels running task } return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CWStringTest::EresUnittest_AppendFormat // // @doc: // Test formatting strings // //--------------------------------------------------------------------------- GPOS_RESULT CWStringTest::EresUnittest_AppendFormat() { CAutoMemoryPool amp ( CAutoMemoryPool::ElcExc, CMemoryPoolManager::EatTracker, false /*fThreadSafe*/, 1024 * 1024 /*ullSizeMax*/ ); IMemoryPool *pmp = amp.Pmp(); CWStringDynamic *pstr1 = GPOS_NEW(pmp) CWStringDynamic(pmp, GPOS_WSZ_LIT("Hello")); WCHAR buffer1[16]; WCHAR buffer2[12]; CWStringStatic ss1(buffer1, GPOS_ARRAY_SIZE(buffer1), GPOS_WSZ_LIT("Hello")); CWStringStatic ss2(buffer2, GPOS_ARRAY_SIZE(buffer2), GPOS_WSZ_LIT("Hello")); pstr1->AppendFormat(GPOS_WSZ_LIT(" world %d"), 123); ss1.AppendFormat(GPOS_WSZ_LIT(" world %d"), 123); ss2.AppendFormat(GPOS_WSZ_LIT(" world %d"), 123); CWStringConst cstr1(GPOS_WSZ_LIT("Hello world 123")); #ifdef GPOS_DEBUG CWStringConst cstr2(GPOS_WSZ_LIT("Hello world")); #endif GPOS_ASSERT(pstr1->FEquals(&cstr1)); GPOS_ASSERT(ss1.FEquals(&cstr1)); GPOS_ASSERT(ss2.FEquals(&cstr2)); GPOS_RESULT eres = GPOS_OK; GPOS_TRY { // exhaust memory pool for (ULONG i = 0; i < ULONG_MAX; i++) { pstr1->AppendFormat(GPOS_WSZ_LIT("%ls world %d"), cstr1.Wsz(), 123); } eres = GPOS_FAILED; } GPOS_CATCH_EX(ex) { GPOS_ASSERT(GPOS_MATCH_EX(ex, CException::ExmaSystem, CException::ExmiOOM)); GPOS_RESET_EX; } GPOS_CATCH_END; // cleanup GPOS_DELETE(pstr1); return eres; }
//--------------------------------------------------------------------------- // @function: // CParseHandlerTest::EresUnittest_MDRequest // // @doc: // Tests parsing of a metadata request // //--------------------------------------------------------------------------- GPOS_RESULT CParseHandlerTest::EresUnittest_MDRequest() { // create own memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); return EresParseAndSerializeMDRequest(pmp, m_szMDRequestFile, false /* fvalidate */); }
//--------------------------------------------------------------------------- // @function: // CAutoTaskProxyTest::EresUnittest_WaitAny // // @doc: // Wait for at least one task to complete. // //--------------------------------------------------------------------------- GPOS_RESULT CAutoTaskProxyTest::EresUnittest_WaitAny() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); CWorkerPoolManager *pwpm = CWorkerPoolManager::WorkerPoolManager(); // scope for ATP { CAutoTaskProxy atp(mp, pwpm); CTask *rgPtsk[3]; ULLONG rgRes[3]; // create tasks rgPtsk[0] = atp.Create(CAutoTaskProxyTest::PvUnittest_Infinite, &rgRes[0]); rgPtsk[1] = atp.Create(CAutoTaskProxyTest::PvUnittest_Infinite, &rgRes[1]); rgPtsk[2] = atp.Create(CAutoTaskProxyTest::PvUnittest_Short, &rgRes[2]); // start tasks atp.Schedule(rgPtsk[0]); atp.Schedule(rgPtsk[1]); atp.Schedule(rgPtsk[2]); // wait until last task completes - the other run until canceled CTask *ptsk = NULL; atp.WaitAny(&ptsk); GPOS_ASSERT(rgPtsk[0]->CheckStatus(false /*fCompleted*/)); GPOS_ASSERT(rgPtsk[1]->CheckStatus(false /*fCompleted*/)); GPOS_ASSERT(ptsk == rgPtsk[2]); // disable error propagation here atp.SetPropagateError(false /* fPropagateError */); // cancel task atp.Cancel(rgPtsk[0]); atp.WaitAny(&ptsk); GPOS_ASSERT(rgPtsk[1]->CheckStatus(false /*fCompleted*/)); GPOS_ASSERT(ptsk == rgPtsk[0]); GPOS_ASSERT(rgPtsk[0]->IsCanceled()); GPOS_ASSERT(CTask::EtsError == rgPtsk[0]->GetStatus()); GPOS_ASSERT(CTask::EtsCompleted == rgPtsk[2]->GetStatus()); GPOS_ASSERT(NULL == rgPtsk[0]->GetRes()); GPOS_ASSERT(NULL == rgPtsk[1]->GetRes()); GPOS_ASSERT(rgRes[2] == *(ULLONG *)rgPtsk[2]->GetRes()); // ATP cancels running task } return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CWStringTest::EresUnittest_Append // // @doc: // Test appending of strings // //--------------------------------------------------------------------------- GPOS_RESULT CWStringTest::EresUnittest_Append() { CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); CWStringDynamic *pstr1 = GPOS_NEW(pmp) CWStringDynamic(pmp, GPOS_WSZ_LIT("123")); CWStringDynamic *pstr2 = GPOS_NEW(pmp) CWStringDynamic(pmp, GPOS_WSZ_LIT("456")); CWStringDynamic *pstr3 = GPOS_NEW(pmp) CWStringDynamic(pmp); WCHAR buffer1[8]; WCHAR buffer2[8]; WCHAR buffer3[8]; CWStringStatic ss1(buffer1, GPOS_ARRAY_SIZE(buffer1), GPOS_WSZ_LIT("123")); CWStringStatic ss2(buffer2, GPOS_ARRAY_SIZE(buffer2), GPOS_WSZ_LIT("456")); CWStringStatic ss3(buffer3, GPOS_ARRAY_SIZE(buffer3)); pstr1->Append(pstr2); ss1.Append(&ss2); #ifdef GPOS_DEBUG CWStringConst cstr1(GPOS_WSZ_LIT("123456")); CWStringConst cstr2(GPOS_WSZ_LIT("1234564")); #endif GPOS_ASSERT(pstr1->FEquals(&cstr1)); GPOS_ASSERT(ss1.FEquals(&cstr1)); // append an empty string pstr1->Append(pstr3); ss1.Append(&ss3); // string should be the same as before GPOS_ASSERT(pstr1->FEquals(&cstr1)); GPOS_ASSERT(ss1.FEquals(&cstr1)); // append to an empty string pstr3->Append(pstr1); ss3.Append(&ss1); GPOS_ASSERT(pstr3->FEquals(pstr1)); GPOS_ASSERT(ss3.FEquals(&ss1)); // check truncation ss3.Append(&ss2); GPOS_ASSERT(ss3.FEquals(&cstr2)); // cleanup GPOS_DELETE(pstr1); GPOS_DELETE(pstr2); GPOS_DELETE(pstr3); return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // CSyncHashtableTest::EresUnittest_SameKeyIteration // // @doc: // Test iteration over elements with the same key // //--------------------------------------------------------------------------- GPOS_RESULT CSyncHashtableTest::EresUnittest_SameKeyIteration() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); const ULONG ulSize = GPOS_SHT_ELEMENTS * GPOS_SHT_ELEMENT_DUPLICATES; SElem *rgelem = GPOS_NEW_ARRAY(pmp, SElem, ulSize); SElemHashtable sht; sht.Init ( pmp, GPOS_SHT_SMALL_BUCKETS, GPOS_OFFSET(SElem, m_link), GPOS_OFFSET(SElem, m_ulKey), &(SElem::m_ulInvalid), SElem::UlHash, SElem::FEqualKeys ); // insert a mix of elements with duplicate keys for (ULONG j = 0; j < GPOS_SHT_ELEMENT_DUPLICATES; j++) { for (ULONG i = 0; i < GPOS_SHT_ELEMENTS; i++) { ULONG ulIndex = GPOS_SHT_ELEMENTS * j + i; rgelem[ulIndex] = SElem(ulIndex, i); sht.Insert(&rgelem[ulIndex]); } } // iterate over elements with the same key for (ULONG ulKey = 0; ulKey < GPOS_SHT_ELEMENTS; ulKey++) { SElemHashtableAccessor shtacc(sht, ulKey); ULONG ulCount = 0; SElem *pelem = shtacc.PtLookup(); while (NULL != pelem) { ulCount++; pelem = shtacc.PtNext(pelem); } GPOS_ASSERT(ulCount == GPOS_SHT_ELEMENT_DUPLICATES); } GPOS_DELETE_ARRAY(rgelem); return GPOS_OK; }