Showing the changes to test/encoder/EncUT_MemoryAlloc.cpp (1 of 85 files). Show all
Unified · Split
| @@ -6,54 +6,54 @@ · 5 unmodified lines | |||
| 6 | using namespace WelsSVCEnc; | 6 | using namespace WelsSVCEnc; |
| 7 | 7 | ||
| 8 | //Tests of WelsGetCacheLineSize Begin | 8 | //Tests of WelsGetCacheLineSize Begin |
| 9 | TEST(MemoryAlignTest, GetCacheLineSize_LoopWithin16K) { | 9 | TEST (MemoryAlignTest, GetCacheLineSize_LoopWithin16K) { |
| 10 | const unsigned int kuiTestBoundary16K = 16 * 1024; | 10 | const unsigned int kuiTestBoundary16K = 16 * 1024; |
| 11 | unsigned int uiTargetAlign = 1; | 11 | unsigned int uiTargetAlign = 1; |
| 12 | while (uiTargetAlign < kuiTestBoundary16K) { | 12 | while (uiTargetAlign < kuiTestBoundary16K) { |
| 13 | CMemoryAlign cTestMa(uiTargetAlign); | 13 | CMemoryAlign cTestMa (uiTargetAlign); |
| 14 | ASSERT_EQ( (uiTargetAlign & 0x0F)?16:uiTargetAlign, cTestMa.WelsGetCacheLineSize() ); | 14 | ASSERT_EQ ((uiTargetAlign & 0x0F) ? 16 : uiTargetAlign, cTestMa.WelsGetCacheLineSize()); |
| 15 | ++ uiTargetAlign; | 15 | ++ uiTargetAlign; |
| 16 | } | 16 | } |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | TEST(MemoryAlignTest, GetCacheLineSize_Zero) { | 19 | TEST (MemoryAlignTest, GetCacheLineSize_Zero) { |
| 20 | CMemoryAlign cTestMa(0); | 20 | CMemoryAlign cTestMa (0); |
| 21 | const uint32_t kuiSixteen = 16; | 21 | const uint32_t kuiSixteen = 16; |
| 22 | ASSERT_EQ( kuiSixteen, cTestMa.WelsGetCacheLineSize() ); | 22 | ASSERT_EQ (kuiSixteen, cTestMa.WelsGetCacheLineSize()); |
| 23 | } | 23 | } |
| 24 | TEST(MemoryAlignTest, GetCacheLineSize_MaxUINT) { | 24 | TEST (MemoryAlignTest, GetCacheLineSize_MaxUINT) { |
| 25 | CMemoryAlign cTestMa(0xFFFFFFFF); | 25 | CMemoryAlign cTestMa (0xFFFFFFFF); |
| 26 | const uint32_t kuiSixteen = 16; | 26 | const uint32_t kuiSixteen = 16; |
| 27 | ASSERT_EQ( kuiSixteen, cTestMa.WelsGetCacheLineSize() ); | 27 | ASSERT_EQ (kuiSixteen, cTestMa.WelsGetCacheLineSize()); |
| 28 | } | 28 | } |
| 29 | //Tests of WelsGetCacheLineSize End | 29 | //Tests of WelsGetCacheLineSize End |
| 30 | //Tests of WelsMallocAndFree Begin | 30 | //Tests of WelsMallocAndFree Begin |
| 31 | TEST(MemoryAlignTest, WelsMallocAndFreeOnceFunctionVerify) { | 31 | TEST (MemoryAlignTest, WelsMallocAndFreeOnceFunctionVerify) { |
| 32 | const uint32_t kuiTargetAlignSize[4] = {32, 16, 64, 8}; | 32 | const uint32_t kuiTargetAlignSize[4] = {32, 16, 64, 8}; |
| 33 | srand((uint32_t)time(NULL)); | 33 | srand ((uint32_t)time (NULL)); |
| 34 | const uint32_t kuiZero = 0; | 34 | const uint32_t kuiZero = 0; |
| 35 | for (int i=0; i<4; i++) { | 35 | for (int i = 0; i < 4; i++) { |
| 36 | const uint32_t kuiTestAlignSize = kuiTargetAlignSize[i]; | 36 | const uint32_t kuiTestAlignSize = kuiTargetAlignSize[i]; |
| 37 | const uint32_t kuiTestDataSize = abs(rand()); | 37 | const uint32_t kuiTestDataSize = abs (rand()); |
| 38 | 38 | ||
| 39 | CMemoryAlign cTestMa(kuiTestAlignSize); | 39 | CMemoryAlign cTestMa (kuiTestAlignSize); |
| 40 | const uint32_t uiSize = kuiTestDataSize; | 40 | const uint32_t uiSize = kuiTestDataSize; |
| 41 | const char strUnitTestTag[100] = "pUnitTestData"; | 41 | const char strUnitTestTag[100] = "pUnitTestData"; |
| 42 | const uint32_t kuiUsedCacheLineSize = ((kuiTestAlignSize == 0) || (kuiTestAlignSize & 0x0F)) ? (16) : (kuiTestAlignSize); | 42 | const uint32_t kuiUsedCacheLineSize = ((kuiTestAlignSize == 0) |
| 43 | const uint32_t kuiExtraAlignSize = kuiUsedCacheLineSize-1; | 43 | || (kuiTestAlignSize & 0x0F)) ? (16) : (kuiTestAlignSize); |
| 44 | const uint32_t kuiExpectedSize = sizeof( void ** ) + sizeof( int32_t ) + kuiExtraAlignSize + uiSize; | 44 | const uint32_t kuiExtraAlignSize = kuiUsedCacheLineSize - 1; |
| 45 | uint8_t *pUnitTestData = static_cast<uint8_t *>(cTestMa.WelsMalloc(uiSize, strUnitTestTag)); | 45 | const uint32_t kuiExpectedSize = sizeof (void**) + sizeof (int32_t) + kuiExtraAlignSize + uiSize; |
| 46 | if ( pUnitTestData != NULL ) { | 46 | uint8_t* pUnitTestData = static_cast<uint8_t*> (cTestMa.WelsMalloc (uiSize, strUnitTestTag)); |
| 47 | ASSERT_TRUE( (((uintptr_t)(pUnitTestData)) & kuiExtraAlignSize) == 0 ); | 47 | if (pUnitTestData != NULL) { |
| 48 | EXPECT_EQ( kuiExpectedSize, cTestMa.WelsGetMemoryUsage() ); | 48 | ASSERT_TRUE ((((uintptr_t) (pUnitTestData)) & kuiExtraAlignSize) == 0); |
| 49 | cTestMa.WelsFree( pUnitTestData, strUnitTestTag ); | 49 | EXPECT_EQ (kuiExpectedSize, cTestMa.WelsGetMemoryUsage()); |
| 50 | EXPECT_EQ( kuiZero, cTestMa.WelsGetMemoryUsage() ); | 50 | cTestMa.WelsFree (pUnitTestData, strUnitTestTag); |
| 51 | } | 51 | EXPECT_EQ (kuiZero, cTestMa.WelsGetMemoryUsage()); |
| 52 | else { | 52 | } else { |
| 53 | EXPECT_EQ( NULL, pUnitTestData ); | 53 | EXPECT_EQ (NULL, pUnitTestData); |
| 54 | EXPECT_EQ( kuiZero, cTestMa.WelsGetMemoryUsage() ); | 54 | EXPECT_EQ (kuiZero, cTestMa.WelsGetMemoryUsage()); |
| 55 | cTestMa.WelsFree( pUnitTestData, strUnitTestTag ); | 55 | cTestMa.WelsFree (pUnitTestData, strUnitTestTag); |
| 56 | EXPECT_EQ( kuiZero, cTestMa.WelsGetMemoryUsage() ); | 56 | EXPECT_EQ (kuiZero, cTestMa.WelsGetMemoryUsage()); |
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| 59 | } | 59 | } |