History

[UT] add more condition to improve the coverage of DecoderCrashTest https://rbcommons.com/s/OpenH264/r/1132/

Sijia Chen committed 11 years ago

Commit 2c44dba1 parent 4048b971 file · +71 −20Browse files

Showing the changes to test/api/encode_decode_api_test.cpp (1 of 1 file). Show all

Unified · Split

test/api/encode_decode_api_test.cpp+71−20
@@ -2316,14 +2316,20 @@ struct EncodeDecodeParamBase { · 2315 unmodified lines
23162316 int iTarBitrate;
23172317 };
23182318
2319−
2319+#define NUM_OF_POSSIBLE_RESOLUTION (9)
23202320 static const EncodeDecodeParamBase kParamArray[] = {
23212321 {160, 90, 6.0f, 250000},
2322+ {90, 160, 6.0f, 250000},
23222323 {320, 180, 12.0f, 500000},
2324+ {180, 320, 12.0f, 500000},
2325+ {480, 270, 12.0f, 600000},
2326+ {270, 480, 12.0f, 600000},
23232327 {640, 360, 24.0f, 800000},
2328+ {360, 640, 24.0f, 800000},
2329+ {1280, 720, 24.0f, 1000000},
23242330 };
23252331
2326−//#define DEBUG_FILE_SAVE
2332+//#define DEBUG_FILE_SAVE_CRA
23272333 TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
23282334 uint32_t uiGet;
23292335 encoder_->Uninitialize();
@@ -2332,33 +2338,62 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 2 unmodified lines
23322338 unsigned int uiLoopRound = 0;
23332339 unsigned char* pucBuf = ucBuf_;
23342340 int iDecAuSize;
2335−#ifdef DEBUG_FILE_SAVE
2341+#ifdef DEBUG_FILE_SAVE_CRA
23362342 //open file to save tested BS
2337− FILE* f = fopen ("test_crash.264", "wb");
2343+ FILE* fDataFile = fopen ("test_crash.264", "wb");
2344+ FILE* fLenFile = fopen ("test_crash_len.log", "w");
23382345 int iFileSize = 0;
23392346 #endif
23402347
2348+ //set eCurStrategy for one test
2349+ EParameterSetStrategy eCurStrategy = CONSTANT_ID;
2350+ switch (rand() % 7) {
2351+ case 1:
2352+ eCurStrategy = INCREASING_ID;
2353+ break;
2354+ case 2:
2355+ eCurStrategy = SPS_LISTING;
2356+ break;
2357+ case 3:
2358+ eCurStrategy = SPS_LISTING_AND_PPS_INCREASING;
2359+ break;
2360+ case 6:
2361+ eCurStrategy = SPS_PPS_LISTING;
2362+ break;
2363+ default:
2364+ //using the initial value
2365+ break;
2366+ }
2367+
23412368 do {
23422369 int iTotalFrameNum = (rand() % 100) + 1;
2343− int iSeed = rand() % 3; //3 indicates the length of kParamArray[] used in the following
2370+ int iSeed = rand() % NUM_OF_POSSIBLE_RESOLUTION;
23442371 EncodeDecodeParamBase p = kParamArray[iSeed];
2372+#ifdef DEBUG_FILE_SAVE_CRA
2373+ printf ("using param set %d in loop %d\n", iSeed, uiLoopRound);
2374+#endif
23452375 //Initialize Encoder
23462376 prepareParam (1, 1, p.width, p.height, p.frameRate, &param_);
2347− param_.iRCMode = RC_BITRATE_MODE;
2377+ param_.iRCMode = RC_TIMESTAMP_MODE;
23482378 param_.iTargetBitrate = p.iTarBitrate;
23492379 param_.uiIntraPeriod = 0;
2350− param_.eSpsPpsIdStrategy = INCREASING_ID;
2380+ param_.eSpsPpsIdStrategy = eCurStrategy;
23512381 param_.bEnableBackgroundDetection = true;
2352− param_.bEnableSceneChangeDetect = true;
2353− param_.bPrefixNalAddingCtrl = true;
2382+ param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;
2383+ param_.bPrefixNalAddingCtrl = (rand() % 2) ? true : false;
23542384 param_.iEntropyCodingModeFlag = 0;
23552385 param_.bEnableFrameSkip = true;
2356− param_.uiMaxNalSize = 1400;
23572386 param_.iMultipleThreadIdc = 0;
23582387 param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;
23592388 param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;
2360− param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_DYN_SLICE;
2361− param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1000;
2389+ param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = (rand() % 2) ? SM_DYN_SLICE : SM_SINGLE_SLICE;
2390+ if (param_.sSpatialLayers[0].sSliceCfg.uiSliceMode == SM_DYN_SLICE) {
2391+ param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1400;
2392+ param_.uiMaxNalSize = 1400;
2393+ } else {
2394+ param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 0;
2395+ param_.uiMaxNalSize = 0;
2396+ }
23622397
23632398 int rv = encoder_->InitializeExt (&param_);
23642399 ASSERT_TRUE (rv == cmResultSuccess);
@@ -2379,11 +2414,11 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 14 unmodified lines
23792414 prepareEncDecParam (pInput);
23802415 while (iIdx++ < iTotalFrameNum) { // loop in frame
23812416 EncodeOneFrame();
2382−#ifdef DEBUG_FILE_SAVE
2417+#ifdef DEBUG_FILE_SAVE_CRA
23832418 //reset file if file size large
23842419 if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {
2385− fclose (f);
2386− f = fopen ("test_crash.264", "wb");
2420+ fclose (fDataFile);
2421+ fDataFile = fopen ("test_crash.264", "wb");
23872422 iFileSize = 0;
23882423 decoder_->Uninitialize();
23892424
@@ -2411,7 +2446,8 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 21 unmodified lines
24112446 for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL
24122447 int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];
24132448 //packet loss
2414− int iLossRate = (rand() % 11); //loss rate among 0 ~ 10%
2449+ int iLossRateRange = (uiLoopRound % 100) + 1; //1-100
2450+ int iLossRate = (rand() % iLossRateRange);
24152451 bool bPacketLost = (rand() % 101) > (100 -
24162452 iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS
24172453 if (!bPacketLost) { //no loss
@@ -2419,15 +2455,29 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 1 unmodified line
24192455 pucBuf += iPacketSize;
24202456 iDecAuSize += iPacketSize;
24212457 }
2458+#ifdef DEBUG_FILE_SAVE_CRA
2459+ else {
2460+ printf ("lost packet size=%d at frame-type=%d at loss rate %d (%d)\n", iPacketSize, info.eFrameType, iLossRate,
2461+ iLossRateRange);
2462+ }
2463+#endif
24222464 //update bs info
24232465 pBsBuf += iPacketSize;
24242466 } //nal
24252467 } //layer
24262468
2427−#ifdef DEBUG_FILE_SAVE
2469+#ifdef DEBUG_FILE_SAVE_CRA
24282470 //save to file
2429− fwrite (ucBuf_, 1, iDecAuSize, f);
2471+ fwrite (ucBuf_, 1, iDecAuSize, fDataFile);
2472+ fflush (fDataFile);
24302473 iFileSize += iDecAuSize;
2474+
2475+ //save to len file
2476+ unsigned long ulTmp[4];
2477+ ulTmp[0] = ulTmp[1] = ulTmp[2] = iIdx;
2478+ ulTmp[3] = iDecAuSize;
2479+ fwrite (ulTmp, sizeof (unsigned long), 4, fLenFile); // index, timeStamp, data size
2480+ fflush (fLenFile);
24312481 #endif
24322482
24332483 //decode
@@ -2443,11 +2493,12 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 9 unmodified lines
24432493 uiLoopRound ++;
24442494 if (uiLoopRound >= (1 << 30))
24452495 uiLoopRound = 0;
2446−#ifdef DEBUG_FILE_SAVE
2496+#ifdef DEBUG_FILE_SAVE_CRA
24472497 if (uiLoopRound % 100 == 0)
24482498 printf ("run %d times.\n", uiLoopRound);
24492499 } while (1); //while (iLoopRound<100);
2450− fclose (f);
2500+ fclose (fDataFile);
2501+ fclose (fLenFile);
24512502 #else
24522503 }
24532504 while (uiLoopRound < 10);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t