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 @@
1#include<gtest/gtest.h>1#include<gtest/gtest.h>
2#include <stdlib.h>
3#include <time.h>
4 2
5#include "wels_common_basis.h"3#include "wels_common_basis.h"
6#include "mem_align.h"4#include "mem_align.h"
@@ -133,7 +131,6 @@ typedef struct TagWelsMvPred { · 126 unmodified lines
133//mok input data131//mok input data
134void AssignMvInputData (SAnchorMvPred* pAncMvPred) {132void AssignMvInputData (SAnchorMvPred* pAncMvPred) {
135 int32_t i, j, k;133 int32_t i, j, k;
136 srand ((uint32_t)time (NULL));
137 //fill MV data and refIdx134 //fill MV data and refIdx
138 for (i = 0; i < 2; ++i) {135 for (i = 0; i < 2; ++i) {
139 for (j = 0; j < 30; ++j) {136 for (j = 0; j < 30; ++j) {
@@ -182,7 +179,6 @@ TEST (PredMvTest, PredMv) { · 42 unmodified lines
182 iIndex = 0;179 iIndex = 0;
183 iBlockWidth = 4;180 iBlockWidth = 4;
184 i = 0;181 i = 0;
185 srand ((uint32_t)time (NULL));
186 while (i++ < kiRandTime) {182 while (i++ < kiRandTime) {
187 iRef = (rand() % 18) - 2; //-2~15183 iRef = (rand() % 18) - 2; //-2~15
188 INIT_MV_DATA;184 INIT_MV_DATA;
@@ -235,7 +231,6 @@ TEST (PredMvTest, PredInter16x8Mv) { · 46 unmodified lines
235 bool bOK = true;231 bool bOK = true;
236 232
237 i = 0;233 i = 0;
238 srand ((uint32_t)time (NULL));
239 while (i++ < kiRandTime) {234 while (i++ < kiRandTime) {
240 iIndex = (rand() & 1) << 3; //0, 8235 iIndex = (rand() & 1) << 3; //0, 8
241 iRef = (rand() % 18) - 2; //-2~15236 iRef = (rand() % 18) - 2; //-2~15
@@ -255,7 +250,6 @@ TEST (PredMvTest, PredInter8x16Mv) { · 13 unmodified lines
255 bool bOK = true;250 bool bOK = true;
256 251
257 i = 0;252 i = 0;
258 srand ((uint32_t)time (NULL));
259 while (i++ < kiRandTime) {253 while (i++ < kiRandTime) {
260 iIndex = (rand() & 1) << 2; //0, 4254 iIndex = (rand() & 1) << 2; //0, 4
261 iRef = (rand() % 18) - 2; //-2~15255 iRef = (rand() % 18) - 2; //-2~15
@@ -469,7 +463,6 @@ int32_t FreeLayerData (PDqLayer pDqLayer) { · 207 unmodified lines
469}463}
470 464
471void InitRandomLayerSliceIdc (PDqLayer pDqLayer) {465void InitRandomLayerSliceIdc (PDqLayer pDqLayer) {
472 srand ((uint32_t)time (NULL));
473 int32_t i = 0;466 int32_t i = 0;
474 int32_t iTotalMbNum = pDqLayer->iMbWidth * pDqLayer->iMbHeight;467 int32_t iTotalMbNum = pDqLayer->iMbWidth * pDqLayer->iMbHeight;
475 int32_t iMbFirstSliceEnd = rand() % (iTotalMbNum - 1); //assure 2 slices468 int32_t iMbFirstSliceEnd = rand() % (iTotalMbNum - 1); //assure 2 slices
@@ -482,14 +475,12 @@ void InitRandomLayerSliceIdc (PDqLayer pDqLayer) { · 6 unmodified lines
482}475}
483 476
484void InitRandomLayerMbType (PDqLayer pDqLayer) {477void InitRandomLayerMbType (PDqLayer pDqLayer) {
485 srand ((uint32_t)time (NULL));
486 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {478 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {
487 pDqLayer->pMbType[i] = (rand() & 0x0f) + 1; //1 ~ 16479 pDqLayer->pMbType[i] = (rand() & 0x0f) + 1; //1 ~ 16
488 }480 }
489}481}
490 482
491void InitRandomLayerMvData (PDqLayer pDqLayer) {483void InitRandomLayerMvData (PDqLayer pDqLayer) {
492 srand ((uint32_t)time (NULL));
493 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {484 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {
494 for (int32_t j = 0; j < MB_BLOCK4x4_NUM; ++j) {485 for (int32_t j = 0; j < MB_BLOCK4x4_NUM; ++j) {
495 for (int32_t k = 0; k < MV_A; ++k) {486 for (int32_t k = 0; k < MV_A; ++k) {
@@ -500,7 +491,6 @@ void InitRandomLayerMvData (PDqLayer pDqLayer) { · 4 unmodified lines
500}491}
501 492
502void InitRandomLayerRefIdxData (PDqLayer pDqLayer) {493void InitRandomLayerRefIdxData (PDqLayer pDqLayer) {
503 srand ((uint32_t)time (NULL));
504 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {494 for (int32_t i = 0; i < pDqLayer->iMbWidth * pDqLayer->iMbHeight; ++i) {
505 for (int32_t j = 0; j < MB_BLOCK4x4_NUM; ++j) {495 for (int32_t j = 0; j < MB_BLOCK4x4_NUM; ++j) {
506 pDqLayer->pRefIndex[0][i][j] = (rand() % 18 - 2); //-2 ~ 15496 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