shithub: openh264

Download patch

ref: 3b372806c06f10f634f6e8aa48aaab311422fde0
parent: beda2d8a02c7379aecb85832cf62116fea9baf73
parent: f7239b6bd2a4c4665088359247730396af54f35d
author: guangwei <GuangweiWang@users.noreply.github.com>
date: Thu Mar 16 09:42:34 EDT 2017

Merge pull request #2686 from huili2/low_mem_UT_improve

modify UT low memory cases

--- a/test/common/CWelsListTest.cpp
+++ b/test/common/CWelsListTest.cpp
@@ -9,7 +9,7 @@
   int a = 0;
 
   for (int i = 0; i < 60; i++) {
-    cTestList.push_back (&a);
+    ASSERT_TRUE (cTestList.push_back (&a));
     EXPECT_TRUE (1 == cTestList.size()) << "after push size=" << cTestList.size() ;
 
     cTestList.pop_front();
@@ -26,7 +26,7 @@
 
     for (int i = 0; i < 10; i++) {
       EXPECT_TRUE (i == cTestList.size()) << "before push size=" << cTestList.size() ;
-      EXPECT_TRUE (cTestList.push_back (pPointer));
+      ASSERT_TRUE (cTestList.push_back (pPointer));
     }
     EXPECT_TRUE (10 == cTestList.size()) << "after push size=" << cTestList.size() ;
 
@@ -44,7 +44,7 @@
   int a = 0;
   int* pPointer = &a;
 
-  EXPECT_TRUE (cTestList.push_back (pPointer));
+  ASSERT_TRUE (cTestList.push_back (pPointer));
 
   pPointer = NULL;
   EXPECT_FALSE (cTestList.push_back (pPointer));
@@ -53,7 +53,7 @@
 
   pPointer = &a;
   EXPECT_TRUE (cTestList.findNode (pPointer));
-  EXPECT_TRUE (cTestList.push_back (pPointer));
+  ASSERT_TRUE (cTestList.push_back (pPointer));
 }
 
 
@@ -68,7 +68,7 @@
   for (int j = 0; j < 10; j++) {
 
     for (int i = 0; i < kiIncreaseNum; i++) {
-      EXPECT_TRUE (cTestList.push_back (pPointer));
+      ASSERT_TRUE (cTestList.push_back (pPointer));
     }
     EXPECT_TRUE (kiIncreaseNum + j * (kiIncreaseNum - kiDecreaseNum) == cTestList.size()) << "after push size=" <<
         cTestList.size() ;
@@ -93,7 +93,7 @@
   EXPECT_TRUE (0 == cTestList.size());
 
   for (int i = 0; i < kiIncreaseNum; i++) {
-    EXPECT_TRUE (cTestList.push_back (pPointer));
+    ASSERT_TRUE (cTestList.push_back (pPointer));
   }
 
   for (int i = kiDecreaseNum; i > 0; i--) {
@@ -118,7 +118,7 @@
 
   for (int i = 0; i < TEST_LEN; i++) {
     a[i] = i;
-    cTestList.push_back (&a[i]);
+    ASSERT_TRUE (cTestList.push_back (&a[i]));
   }
 
   EXPECT_TRUE (cTestList.size() == TEST_LEN);
@@ -153,7 +153,7 @@
 
   for (int i = 0; i < TEST_LEN; i++) {
     data[i] = i;
-    cTestList.push_back (&data[i]);
+    ASSERT_TRUE (cTestList.push_back (&data[i]));
   }
   EXPECT_TRUE (cTestList.size() == TEST_LEN);
 
@@ -191,7 +191,7 @@
 
   for (int i = 0; i < TEST_LEN_10; i++) {
     data[i] = i;
-    cTestList.push_back (&data[i]);
+    ASSERT_TRUE (cTestList.push_back (&data[i]));
   }
   EXPECT_TRUE (cTestList.size() == TEST_LEN_10);
 
@@ -223,7 +223,7 @@
   //expand
   int iAddLen = rand() % 65535;
   for (int i = 0; i < iAddLen; i++) {
-    EXPECT_TRUE (cTestList.push_back (&data[0]));
+    ASSERT_TRUE (cTestList.push_back (&data[0]));
   }
   EXPECT_TRUE ((iCurrentLen + iAddLen) == cTestList.size());
   EraseOneInList (cTestList, &data[0]);
@@ -248,9 +248,9 @@
   int32_t* pObject3 = &c;
 
   //initial adding
-  EXPECT_TRUE (cNonDuplicatedIntList.push_back (pObject1));
-  EXPECT_TRUE (cNonDuplicatedIntList.push_back (pObject2));
-  EXPECT_TRUE (cNonDuplicatedIntList.push_back (pObject3));
+  ASSERT_TRUE (cNonDuplicatedIntList.push_back (pObject1));
+  ASSERT_TRUE (cNonDuplicatedIntList.push_back (pObject2));
+  ASSERT_TRUE (cNonDuplicatedIntList.push_back (pObject3));
   EXPECT_TRUE (3 == cNonDuplicatedIntList.size());
 
   //try failed adding
@@ -270,7 +270,7 @@
   EXPECT_TRUE (2 == cNonDuplicatedIntList.size());
 
   //add back
-  EXPECT_TRUE (cNonDuplicatedIntList.push_back (pObject1));
+  ASSERT_TRUE (cNonDuplicatedIntList.push_back (pObject1));
   EXPECT_TRUE (3 == cNonDuplicatedIntList.size());
 
   //another pop
@@ -282,7 +282,7 @@
   EXPECT_FALSE (cNonDuplicatedIntList.push_back (pObject1));
   EXPECT_TRUE (1 == cNonDuplicatedIntList.size());
 
-  EXPECT_TRUE (cNonDuplicatedIntList.push_back (pObject3));
+  ASSERT_TRUE (cNonDuplicatedIntList.push_back (pObject3));
   EXPECT_TRUE (2 == cNonDuplicatedIntList.size());
 
   //clean-up
@@ -303,9 +303,9 @@
   EXPECT_TRUE (NULL != pTaskThread3);
 
   //initial adding
-  EXPECT_TRUE (cThreadList.push_back (pTaskThread1));
-  EXPECT_TRUE (cThreadList.push_back (pTaskThread2));
-  EXPECT_TRUE (cThreadList.push_back (pTaskThread3));
+  ASSERT_TRUE (cThreadList.push_back (pTaskThread1));
+  ASSERT_TRUE (cThreadList.push_back (pTaskThread2));
+  ASSERT_TRUE (cThreadList.push_back (pTaskThread3));
   EXPECT_TRUE (3 == cThreadList.size());
 
   //try failed adding
@@ -325,7 +325,7 @@
   EXPECT_TRUE (2 == cThreadList.size());
 
   //add back
-  EXPECT_TRUE (cThreadList.push_back (pTaskThread1));
+  ASSERT_TRUE (cThreadList.push_back (pTaskThread1));
   EXPECT_TRUE (3 == cThreadList.size());
 
   //another pop
@@ -337,7 +337,7 @@
   EXPECT_FALSE (cThreadList.push_back (pTaskThread1));
   EXPECT_TRUE (1 == cThreadList.size());
 
-  EXPECT_TRUE (cThreadList.push_back (pTaskThread3));
+  ASSERT_TRUE (cThreadList.push_back (pTaskThread3));
   EXPECT_TRUE (2 == cThreadList.size());
 
   //clean-up
@@ -369,7 +369,7 @@
   for (int j = 0; j < 10; j++) {
     const int iBias = j * (kiIncreaseNum - kiDecreaseNum);
     for (int i = 0; i < kiIncreaseNum; i++) {
-      cThreadList.push_back (&pInput[i + kiIncreaseNum * j]);
+      ASSERT_TRUE (cThreadList.push_back (&pInput[i + kiIncreaseNum * j]));
     }
     EXPECT_TRUE (kiIncreaseNum + iBias == cThreadList.size()) << "after push size=" <<
         cThreadList.size() ;
--- a/test/decoder/DecUT_ParseSyntax.cpp
+++ b/test/decoder/DecUT_ParseSyntax.cpp
@@ -132,9 +132,9 @@
   //Uninit members
   void Uninit();
   //Decoder real bitstream
-  void DecodeBs (const char* sFileName);
+  bool DecodeBs (const char* sFileName);
   //Parse real bitstream
-  void ParseBs (const char* sFileName);
+  bool ParseBs (const char* sFileName);
   //Scalinglist
   void TestScalingList();
   //specific bitstream test
@@ -175,11 +175,16 @@
   m_iBufLength = 4;
   //
   m_pCtx = (PWelsDecoderContext)malloc (sizeof (SWelsDecoderContext));
-
+  if (m_pCtx == NULL)
+    return ERR_MALLOC_FAILED;
   memset (m_pCtx, 0, sizeof (SWelsDecoderContext));
   m_pWelsTrace = new welsCodecTrace();
   if (m_pWelsTrace != NULL) {
     m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
+  } else {
+    free (m_pCtx);
+    m_pCtx = NULL;
+    return ERR_MALLOC_FAILED;
   }
   CM_RETURN eRet = (CM_RETURN)Initialize (&m_sDecParam, m_pCtx, &m_pWelsTrace->m_sLogCtx);
   return (int32_t)eRet;
@@ -199,7 +204,7 @@
   m_iBufLength = 0;
 }
 
-void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) {
+bool DecoderParseSyntaxTest::DecodeBs (const char* sFileName) {
 
   uint8_t* pBuf = NULL;
   int32_t iBufPos = 0;
@@ -213,15 +218,28 @@
 
 #if defined(ANDROID_NDK)
   std::string filename = std::string ("/sdcard/") + sFileName;
-  ASSERT_TRUE ((pH264File = fopen (filename.c_str(), "rb")) != NULL);
+  if ((pH264File = fopen (filename.c_str(), "rb")) == NULL)
+    return false;
 #else
-  ASSERT_TRUE ((pH264File = fopen (sFileName, "rb")) != NULL);
+  if ((pH264File = fopen (sFileName, "rb")) == NULL)
+    return false;
 #endif
   fseek (pH264File, 0L, SEEK_END);
   iFileSize = (int32_t) ftell (pH264File);
   fseek (pH264File, 0L, SEEK_SET);
   pBuf = new uint8_t[iFileSize + 4];
-  ASSERT_EQ (fread (pBuf, 1, iFileSize, pH264File), (unsigned int) iFileSize);
+  if (pBuf == NULL) {
+    fclose (pH264File);
+    return false;
+  }
+  if ((fread (pBuf, 1, iFileSize, pH264File) != (unsigned int) iFileSize)) {
+    fclose (pH264File);
+    if (pBuf) {
+      delete[] pBuf;
+      pBuf = NULL;
+    }
+    return false;
+  }
   memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage
   while (true) {
     if (iBufPos >= iFileSize) {
@@ -250,9 +268,9 @@
     pBuf = NULL;
   }
 
-
+  return true;
 }
-void DecoderParseSyntaxTest::ParseBs (const char* sFileName) {
+bool DecoderParseSyntaxTest::ParseBs (const char* sFileName) {
 
   uint8_t* pBuf = NULL;
   int32_t iBufPos = 0;
@@ -267,15 +285,28 @@
 
 #if defined(ANDROID_NDK)
   std::string filename = std::string ("/sdcard/") + sFileName;
-  ASSERT_TRUE ((pH264File = fopen (filename.c_str(), "rb")) != NULL);
+  if ((pH264File = fopen (filename.c_str(), "rb")) == NULL)
+    return false;
 #else
-  ASSERT_TRUE ((pH264File = fopen (sFileName, "rb")) != NULL);
+  if ((pH264File = fopen (sFileName, "rb")) == NULL)
+    return false;
 #endif
   fseek (pH264File, 0L, SEEK_END);
   iFileSize = (int32_t)ftell (pH264File);
   fseek (pH264File, 0L, SEEK_SET);
   pBuf = new uint8_t[iFileSize + 4];
-  ASSERT_EQ (fread (pBuf, 1, iFileSize, pH264File), (unsigned int)iFileSize);
+  if (pBuf == NULL) {
+    fclose (pH264File);
+    return false;
+  }
+  if (fread (pBuf, 1, iFileSize, pH264File) != (unsigned int)iFileSize) {
+    fclose (pH264File);
+    if (pBuf) {
+      delete[] pBuf;
+      pBuf = NULL;
+    }
+    return false;
+  }
   memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage
   while (true) {
     if (iBufPos >= iFileSize) {
@@ -308,7 +339,7 @@
     pBuf = NULL;
   }
 
-
+  return true;
 }
 
 
@@ -335,7 +366,7 @@
   int32_t iRet = ERR_NONE;
   iRet = Init();
   ASSERT_EQ (iRet, ERR_NONE);
-  DecodeBs ("res/BA_MW_D.264");
+  ASSERT_TRUE (DecodeBs ("res/BA_MW_D.264"));
   ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag == false);
   EXPECT_EQ (0, memcmp (iScalingListZero, m_pCtx->sSpsBuffer[0].iScalingList4x4, 6 * 16 * sizeof (uint8_t)));
   ASSERT_TRUE (m_pCtx->sPpsBuffer[0].bPicScalingMatrixPresentFlag == false);
@@ -344,7 +375,7 @@
   //Scalinglist value just written into sps and pps
   iRet = Init();
   ASSERT_EQ (iRet, ERR_NONE);
-  DecodeBs ("res/test_scalinglist_jm.264");
+  ASSERT_TRUE (DecodeBs ("res/test_scalinglist_jm.264"));
   ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag);
   for (int i = 0; i < 6; i++) {
     EXPECT_EQ (0, memcmp (iScalingList[i], m_pCtx->sSpsBuffer[0].iScalingList4x4[i], 16 * sizeof (uint8_t)));
@@ -364,7 +395,7 @@
   m_sDecParam.eEcActiveIdc = ERROR_CON_DISABLE;
   iRet = m_pDec->Initialize (&m_sDecParam);
   ASSERT_EQ (iRet, ERR_NONE);
-  ParseBs ("res/jm_1080p_allslice.264");
+  ASSERT_TRUE (ParseBs ("res/jm_1080p_allslice.264"));
   m_pDec->Uninitialize();
   //Uninit();
 }