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
2316 int iTarBitrate;2316 int iTarBitrate;
2317};2317};
2318 2318
2319 2319#define NUM_OF_POSSIBLE_RESOLUTION (9)
2320static const EncodeDecodeParamBase kParamArray[] = {2320static const EncodeDecodeParamBase kParamArray[] = {
2321 {160, 90, 6.0f, 250000},2321 {160, 90, 6.0f, 250000},
2322 {90, 160, 6.0f, 250000},
2322 {320, 180, 12.0f, 500000},2323 {320, 180, 12.0f, 500000},
2324 {180, 320, 12.0f, 500000},
2325 {480, 270, 12.0f, 600000},
2326 {270, 480, 12.0f, 600000},
2323 {640, 360, 24.0f, 800000},2327 {640, 360, 24.0f, 800000},
2328 {360, 640, 24.0f, 800000},
2329 {1280, 720, 24.0f, 1000000},
2324};2330};
2325 2331
2326//#define DEBUG_FILE_SAVE2332//#define DEBUG_FILE_SAVE_CRA
2327TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {2333TEST_F (DecodeCrashTestAPI, DecoderCrashTest) {
2328 uint32_t uiGet;2334 uint32_t uiGet;
2329 encoder_->Uninitialize();2335 encoder_->Uninitialize();
@@ -2332,33 +2338,62 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 2 unmodified lines
2332 unsigned int uiLoopRound = 0;2338 unsigned int uiLoopRound = 0;
2333 unsigned char* pucBuf = ucBuf_;2339 unsigned char* pucBuf = ucBuf_;
2334 int iDecAuSize;2340 int iDecAuSize;
2335#ifdef DEBUG_FILE_SAVE2341#ifdef DEBUG_FILE_SAVE_CRA
2336 //open file to save tested BS2342 //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");
2338 int iFileSize = 0;2345 int iFileSize = 0;
2339#endif2346#endif
2340 2347
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
2341 do {2368 do {
2342 int iTotalFrameNum = (rand() % 100) + 1;2369 int iTotalFrameNum = (rand() % 100) + 1;
2343 int iSeed = rand() % 3; //3 indicates the length of kParamArray[] used in the following2370 int iSeed = rand() % NUM_OF_POSSIBLE_RESOLUTION;
2344 EncodeDecodeParamBase p = kParamArray[iSeed];2371 EncodeDecodeParamBase p = kParamArray[iSeed];
2372#ifdef DEBUG_FILE_SAVE_CRA
2373 printf ("using param set %d in loop %d\n", iSeed, uiLoopRound);
2374#endif
2345 //Initialize Encoder2375 //Initialize Encoder
2346 prepareParam (1, 1, p.width, p.height, p.frameRate, &param_);2376 prepareParam (1, 1, p.width, p.height, p.frameRate, &param_);
2347 param_.iRCMode = RC_BITRATE_MODE;2377 param_.iRCMode = RC_TIMESTAMP_MODE;
2348 param_.iTargetBitrate = p.iTarBitrate;2378 param_.iTargetBitrate = p.iTarBitrate;
2349 param_.uiIntraPeriod = 0;2379 param_.uiIntraPeriod = 0;
2350 param_.eSpsPpsIdStrategy = INCREASING_ID;2380 param_.eSpsPpsIdStrategy = eCurStrategy;
2351 param_.bEnableBackgroundDetection = true;2381 param_.bEnableBackgroundDetection = true;
2352 param_.bEnableSceneChangeDetect = true;2382 param_.bEnableSceneChangeDetect = (rand() % 3) ? true : false;
2353 param_.bPrefixNalAddingCtrl = true;2383 param_.bPrefixNalAddingCtrl = (rand() % 2) ? true : false;
2354 param_.iEntropyCodingModeFlag = 0;2384 param_.iEntropyCodingModeFlag = 0;
2355 param_.bEnableFrameSkip = true;2385 param_.bEnableFrameSkip = true;
2356 param_.uiMaxNalSize = 1400;
2357 param_.iMultipleThreadIdc = 0;2386 param_.iMultipleThreadIdc = 0;
2358 param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;2387 param_.sSpatialLayers[0].iSpatialBitrate = p.iTarBitrate;
2359 param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;2388 param_.sSpatialLayers[0].iMaxSpatialBitrate = p.iTarBitrate << 1;
2360 param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_DYN_SLICE;2389 param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = (rand() % 2) ? SM_DYN_SLICE : SM_SINGLE_SLICE;
2361 param_.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceSizeConstraint = 1000;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 }
2362 2397
2363 int rv = encoder_->InitializeExt (&param_);2398 int rv = encoder_->InitializeExt (&param_);
2364 ASSERT_TRUE (rv == cmResultSuccess);2399 ASSERT_TRUE (rv == cmResultSuccess);
@@ -2379,11 +2414,11 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 14 unmodified lines
2379 prepareEncDecParam (pInput);2414 prepareEncDecParam (pInput);
2380 while (iIdx++ < iTotalFrameNum) { // loop in frame2415 while (iIdx++ < iTotalFrameNum) { // loop in frame
2381 EncodeOneFrame();2416 EncodeOneFrame();
2382#ifdef DEBUG_FILE_SAVE2417#ifdef DEBUG_FILE_SAVE_CRA
2383 //reset file if file size large2418 //reset file if file size large
2384 if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {2419 if ((info.eFrameType == videoFrameTypeIDR) && (iFileSize >= (1 << 25))) {
2385 fclose (f);2420 fclose (fDataFile);
2386 f = fopen ("test_crash.264", "wb");2421 fDataFile = fopen ("test_crash.264", "wb");
2387 iFileSize = 0;2422 iFileSize = 0;
2388 decoder_->Uninitialize();2423 decoder_->Uninitialize();
2389 2424
@@ -2411,7 +2446,8 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 21 unmodified lines
2411 for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL2446 for (int iNalCnt = 0; iNalCnt < iTotalNalCnt; iNalCnt++) { //loop in NAL
2412 int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];2447 int iPacketSize = pLayerBsInfo->pNalLengthInByte[iNalCnt];
2413 //packet loss2448 //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);
2415 bool bPacketLost = (rand() % 101) > (100 -2451 bool bPacketLost = (rand() % 101) > (100 -
2416 iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS2452 iLossRate); // [0, (100-iLossRate)] indicates NO LOSS, (100-iLossRate, 100] indicates LOSS
2417 if (!bPacketLost) { //no loss2453 if (!bPacketLost) { //no loss
@@ -2419,15 +2455,29 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 1 unmodified line
2419 pucBuf += iPacketSize;2455 pucBuf += iPacketSize;
2420 iDecAuSize += iPacketSize;2456 iDecAuSize += iPacketSize;
2421 }2457 }
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
2422 //update bs info2464 //update bs info
2423 pBsBuf += iPacketSize;2465 pBsBuf += iPacketSize;
2424 } //nal2466 } //nal
2425 } //layer2467 } //layer
2426 2468
2427#ifdef DEBUG_FILE_SAVE2469#ifdef DEBUG_FILE_SAVE_CRA
2428 //save to file2470 //save to file
2429 fwrite (ucBuf_, 1, iDecAuSize, f);2471 fwrite (ucBuf_, 1, iDecAuSize, fDataFile);
2472 fflush (fDataFile);
2430 iFileSize += iDecAuSize;2473 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);
2431#endif2481#endif
2432 2482
2433 //decode2483 //decode
@@ -2443,11 +2493,12 @@ TEST_F (DecodeCrashTestAPI, DecoderCrashTest) { · 9 unmodified lines
2443 uiLoopRound ++;2493 uiLoopRound ++;
2444 if (uiLoopRound >= (1 << 30))2494 if (uiLoopRound >= (1 << 30))
2445 uiLoopRound = 0;2495 uiLoopRound = 0;
2446#ifdef DEBUG_FILE_SAVE2496#ifdef DEBUG_FILE_SAVE_CRA
2447 if (uiLoopRound % 100 == 0)2497 if (uiLoopRound % 100 == 0)
2448 printf ("run %d times.\n", uiLoopRound);2498 printf ("run %d times.\n", uiLoopRound);
2449 } while (1); //while (iLoopRound<100);2499 } while (1); //while (iLoopRound<100);
2450 fclose (f);2500 fclose (fDataFile);
2501 fclose (fLenFile);
2451#else2502#else
2452 }2503 }
2453 while (uiLoopRound < 10);2504 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