Merge pull request #1836 from sijchen/imp_ut4

[UT] add more condition to improve the coverage of DecoderCrashTest
This commit is contained in:
ruil2 2015-03-05 15:47:24 +08:00
commit 5921e5e7d3

View File

@ -2316,14 +2316,20 @@ struct EncodeDecodeParamBase {
int iTarBitrate; int iTarBitrate;
}; };
#define NUM_OF_POSSIBLE_RESOLUTION (9)
static const EncodeDecodeParamBase kParamArray[] = { static const EncodeDecodeParamBase kParamArray[] = {
{160, 90, 6.0f, 250000}, {160, 90, 6.0f, 250000},
{90, 160, 6.0f, 250000},
{320, 180, 12.0f, 500000}, {320, 180, 12.0f, 500000},
{180, 320, 12.0f, 500000},
{480, 270, 12.0f, 600000},
{270, 480, 12.0f, 600000},
{640, 360, 24.0f, 800000}, {640, 360, 24.0f, 800000},
{360, 640, 24.0f, 800000},
{1280, 720, 24.0f, 1000000},
}; };
//#define DEBUG_FILE_SAVE //#define DEBUG_FILE_SAVE_CRA
TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
uint32_t uiGet; uint32_t uiGet;
encoder_->Uninitialize(); encoder_->Uninitialize();
@ -2332,33 +2338,62 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
unsigned int uiLoopRound = 0; unsigned int uiLoopRound = 0;
unsigned char* pucBuf = ucBuf_; unsigned char* pucBuf = ucBuf_;
int iDecAuSize; int iDecAuSize;
#ifdef DEBUG_FILE_SAVE #ifdef DEBUG_FILE_SAVE_CRA
//open file to save tested BS //open file to save tested BS
FILE* f = fopen ("test_crash.264", "wb"); FILE* fDataFile = fopen ("test_crash.264", "wb");
FILE* fLenFile = fopen ("test_crash_len.log", "w");
int iFileSize = 0; int iFileSize = 0;
#endif #endif
//set eCurStrategy for one test
EParameterSetStrategy eCurStrategy = CONSTANT_ID;
switch (rand() % 7) {
case 1:
eCurStrategy = INCREASING_ID;
break;
case 2:
eCurStrategy = SPS_LISTING;
break;
case 3:
eCurStrategy = SPS_LISTING_AND_PPS_INCREASING;
break;
case 6:
eCurStrategy = SPS_PPS_LISTING;
break;
default:
//using the initial value
break;
}
do { do {
int iTotalFrameNum = (rand() % 100) + 1; int iTotalFrameNum = (rand() % 100) + 1;
int iSeed = rand() % 3; //3 indicates the length of kParamArray[] used in the following int iSeed = rand() % NUM_OF_POSSIBLE_RESOLUTION;
EncodeDecodeParamBase p = kParamArray[iSeed]; EncodeDecodeParamBase p = kParamArray[iSeed];
#ifdef DEBUG_FILE_SAVE_CRA
printf ("using param set %d in loop %d\n", iSeed, uiLoopRound);
#endif
//Initialize Encoder //Initialize Encoder
prepareParam (1, 1, p.width, p.height, p.frameRate, &param_); prepareParam (1, 1, p.width, p.height, p.frameRate, &param_);
param_.iRCMode = RC_BITRATE_MODE; param_.iRCMode = RC_TIMESTAMP_MODE;
param_.iTargetBitrate = p.iTarBitrate; param_.iTargetBitrate = p.iTarBitrate;
param_.uiIntraPeriod = 0; param_.uiIntraPeriod = 0;
param_.eSpsPpsIdStrategy = INCREASING_ID; param_.eSpsPpsIdStrategy = eCurStrategy;
param_.bEnableBackgroundDetection = true; param_.bEnableBackgroundDetection = true;
param_.bEnableSceneChangeDetect = true; param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;
param_.bPrefixNalAddingCtrl = true; param_.bPrefixNalAddingCtrl = (rand() % 2) ? true : false;
param_.iEntropyCodingModeFlag = 0; param_.iEntropyCodingModeFlag = 0;
param_.bEnableFrameSkip = true; param_.bEnableFrameSkip = true;
param_.uiMaxNalSize = 1400;
param_.iMultipleThreadIdc = 0; param_.iMultipleThreadIdc = 0;
param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate; param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;
param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1; param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;
param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_DYN_SLICE; param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = (rand() % 2) ? SM_DYN_SLICE : SM_SINGLE_SLICE;
param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1000; if (param_.sSpatialLayers[0].sSliceCfg.uiSliceMode == SM_DYN_SLICE) {
param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1400;
param_.uiMaxNalSize = 1400;
} else {
param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 0;
param_.uiMaxNalSize = 0;
}
int rv = encoder_->InitializeExt (&param_); int rv = encoder_->InitializeExt (&param_);
ASSERT_TRUE (rv == cmResultSuccess); ASSERT_TRUE (rv == cmResultSuccess);
@ -2379,11 +2414,11 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
prepareEncDecParam (pInput); prepareEncDecParam (pInput);
while (iIdx++ < iTotalFrameNum) { // loop in frame while (iIdx++ < iTotalFrameNum) { // loop in frame
EncodeOneFrame(); EncodeOneFrame();
#ifdef DEBUG_FILE_SAVE #ifdef DEBUG_FILE_SAVE_CRA
//reset file if file size large //reset file if file size large
if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) { if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {
fclose (f); fclose (fDataFile);
f = fopen ("test_crash.264", "wb"); fDataFile = fopen ("test_crash.264", "wb");
iFileSize = 0; iFileSize = 0;
decoder_->Uninitialize(); decoder_->Uninitialize();
@ -2411,7 +2446,8 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL
int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt]; int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];
//packet loss //packet loss
int iLossRate = (rand() % 11); //loss rate among 0 ~ 10% int iLossRateRange = (uiLoopRound % 100) + 1; //1-100
int iLossRate = (rand() % iLossRateRange);
bool bPacketLost = (rand() % 101) > (100 - bool bPacketLost = (rand() % 101) > (100 -
iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS
if (!bPacketLost) { //no loss if (!bPacketLost) { //no loss
@ -2419,15 +2455,29 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
pucBuf += iPacketSize; pucBuf += iPacketSize;
iDecAuSize += iPacketSize; iDecAuSize += iPacketSize;
} }
#ifdef DEBUG_FILE_SAVE_CRA
else {
printf ("lost packet size=%d at frame-type=%d at loss rate %d (%d)\n", iPacketSize, info.eFrameType, iLossRate,
iLossRateRange);
}
#endif
//update bs info //update bs info
pBsBuf += iPacketSize; pBsBuf += iPacketSize;
} //nal } //nal
} //layer } //layer
#ifdef DEBUG_FILE_SAVE #ifdef DEBUG_FILE_SAVE_CRA
//save to file //save to file
fwrite (ucBuf_, 1, iDecAuSize, f); fwrite (ucBuf_, 1, iDecAuSize, fDataFile);
fflush (fDataFile);
iFileSize += iDecAuSize; iFileSize += iDecAuSize;
//save to len file
unsigned long ulTmp[4];
ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx;
ulTmp[3] = iDecAuSize;
fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size
fflush (fLenFile);
#endif #endif
//decode //decode
@ -2443,11 +2493,12 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
uiLoopRound ++; uiLoopRound ++;
if (uiLoopRound >= (1 << 30)) if (uiLoopRound >= (1 << 30))
uiLoopRound = 0; uiLoopRound = 0;
#ifdef DEBUG_FILE_SAVE #ifdef DEBUG_FILE_SAVE_CRA
if (uiLoopRound % 100 == 0) if (uiLoopRound % 100 == 0)
printf ("run %d times.\n", uiLoopRound); printf ("run %d times.\n", uiLoopRound);
} while (1); //while (iLoopRound<100); } while (1); //while (iLoopRound<100);
fclose (f); fclose (fDataFile);
fclose (fLenFile);
#else #else
} }
while (uiLoopRound < 10); while (uiLoopRound < 10);