History

Don't reset the random number generator within the unit tests

This makes sure we don't accidentally return the same sequence of random numbers multiple times within one test (which would be very non-random). Every time srand(time()) is called, the pseudo random number generator is initialized to the same value (as long as time() returned the same value). By initializing the random number generator once and for all before starting to run the unit tests, we are sure we don't need to reinitialize it within all the tests and all the functions that use random numbers. This fixes occasional errors in MotionEstimateTest. MotionEstimateTest was designed to allow the test to occasionally not succeed - if it didn't succeed, it tried again, up to 100 times. However, since the YUVPixelDataGenerator function reset the random seed to time(), every attempt actually ran with the same random data (as long as all 100 attempts ran within 1 second) - thus if one attempt in MotionEstimateTest failed, all 100 of them would fail. If the utility functions don't touch the random seed, this is not an issue.

Martin Storsjö committed 12 years ago

Commit 4f594de1 parent 806e59f16 files · +12 −114Browse files

Showing the changes to test/decoder/DecUT_PredMv.cpp (1 of 16 files). Show all

Unified · Split

test/decoder/DecUT_PredMv.cpp+0−10
@@ -1,6 +1,4 @@
11 #include<gtest/gtest.h>
2−#include <stdlib.h>
3−#include <time.h>
42
53 #include "wels_common_basis.h"
64 #include "mem_align.h"
@@ -133,7 +131,6 @@ typedef struct TagWelsMvPred { · 126 unmodified lines
133131 //mok input data
134132 void AssignMvInputData (SAnchorMvPred* pAncMvPred) {
135133 int32_t i, j, k;
136− srand ((uint32_t)time (NULL));
137134 //fill MV data and refIdx
138135 for (i = 0; i < 2; ++i) {
139136 for (j = 0; j < 30; ++j) {
@@ -182,7 +179,6 @@ TEST (PredMvTest, PredMv) { · 42 unmodified lines
182179 iIndex = 0;
183180 iBlockWidth = 4;
184181 i = 0;
185− srand ((uint32_t)time (NULL));
186182 while (i++ < kiRandTime) {
187183 iRef = (rand() % 18) - 2; //-2~15
188184 INIT_MV_DATA;
@@ -235,7 +231,6 @@ TEST (PredMvTest, PredInter16x8Mv) { · 46 unmodified lines
235231 bool bOK = true;
236232
237233 i = 0;
238− srand ((uint32_t)time (NULL));
239234 while (i++ < kiRandTime) {
240235 iIndex = (rand() & 1) << 3; //0, 8
241236 iRef = (rand() % 18) - 2; //-2~15
@@ -255,7 +250,6 @@ TEST (PredMvTest, PredInter8x16Mv) { · 13 unmodified lines
255250 bool bOK = true;
256251
257252 i = 0;
258− srand ((uint32_t)time (NULL));
259253 while (i++ < kiRandTime) {
260254 iIndex = (rand() & 1) << 2; //0, 4
261255 iRef = (rand() % 18) - 2; //-2~15
@@ -469,7 +463,6 @@ int32_t FreeLayerData (PDqLayer pDqLayer) { · 207 unmodified lines
469463 }
470464
471465 void InitRandomLayerSliceIdc (PDqLayer pDqLayer) {
472− srand ((uint32_t)time (NULL));
473466 int32_t i = 0;
474467 int32_t iTotalMbNum = pDqLayer->iMbWidth * pDqLayer->iMbHeight;
475468 int32_t iMbFirstSliceEnd = rand() % (iTotalMbNum - 1); //assure 2 slices
@@ -482,14 +475,12 @@ void InitRandomLayerSliceIdc (PDqLayer pDqLayer) { · 6 unmodified lines
482475 }
483476
484477 void InitRandomLayerMbType (PDqLayer pDqLayer) {
485− srand ((uint32_t)time (NULL));
486478 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {
487479 pDqLayer->pMbType[i] = (rand() & 0x0f) + 1; //1 ~ 16
488480 }
489481 }
490482
491483 void InitRandomLayerMvData (PDqLayer pDqLayer) {
492− srand ((uint32_t)time (NULL));
493484 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {
494485 for (int32_t j = 0; j < MB_BLOCK4x4_NUM; ++j) {
495486 for (int32_t k = 0; k < MV_A; ++k) {
@@ -500,7 +491,6 @@ void InitRandomLayerMvData (PDqLayer pDqLayer) { · 4 unmodified lines
500491 }
501492
502493 void InitRandomLayerRefIdxData (PDqLayer pDqLayer) {
503− srand ((uint32_t)time (NULL));
504494 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {
505495 for (int32_t j = 0; j < MB_BLOCK4x4_NUM; ++j) {
506496 pDqLayer->pRefIndex[0][i][j] = (rand() % 18 - 2); //-2 ~ 15

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