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/encoder/EncUT_EncoderMbAux.cpp (1 of 16 files). Show all

Unified · Split

test/encoder/EncUT_EncoderMbAux.cpp+0−20
@@ -1,6 +1,4 @@
11 #include<gtest/gtest.h>
2−#include<stdlib.h>
3−#include<time.h>
42 #include "ls_defines.h"
53 #include "encode_mb_aux.h"
64 #include "wels_common_basis.h"
@@ -14,7 +12,6 @@ TEST (EncodeMbAuxTest, TestScan_4x4_ac_c) { · 7 unmodified lines
1412 ALLOC_MEMORY (int16_t, iLevel, 16);
1513 ALLOC_MEMORY (int16_t, iDctA, 16);
1614 ALLOC_MEMORY (int16_t, iDctB, 16);
17− srand ((unsigned int)time (NULL));
1815 for (int i = 0; i < 16; i++) {
1916 iDctA[i] = rand() % 256 + 1;
2017 iDctB[i] = iDctA[i];
@@ -47,7 +44,6 @@ TEST (EncodeMbAuxTest, TestScan_4x4_ac_sse2) { · 26 unmodified lines
4744 ALLOC_MEMORY (int16_t, iLevelA, 16);
4845 ALLOC_MEMORY (int16_t, iLevelB, 16);
4946 ALLOC_MEMORY (int16_t, iDct, 16);
50− srand ((unsigned int)time (NULL));
5147 for (int i = 0; i < 16; i++) {
5248 iDct[i] = rand() % 256 + 1;
5349 }
@@ -64,7 +60,6 @@ TEST (EncodeMbAuxTest, WelsScan4x4DcAc_sse2) { · 10 unmodified lines
6460 ALLOC_MEMORY (int16_t, iLevelA, 32);
6561 ALLOC_MEMORY (int16_t, iLevelB, 32);
6662 ALLOC_MEMORY (int16_t, iDct, 32);
67− srand ((unsigned int)time (NULL));
6863 for (int i = 0; i < 32; i++)
6964 iDct[i] = (rand() & 32767) - 16384;
7065 WelsScan4x4DcAc_sse2 (iLevelA, iDct);
@@ -81,7 +76,6 @@ TEST (EncodeMbAuxTest, TestScan_4x4_dcc) { · 10 unmodified lines
8176 ALLOC_MEMORY (int16_t, iLevel, 16);
8277 ALLOC_MEMORY (int16_t, iDctA, 16);
8378 ALLOC_MEMORY (int16_t, iDctB, 16);
84− srand ((unsigned int)time (NULL));
8579 for (int i = 0; i < 16; i++)
8680 iDctA[i] = iDctB[i] = rand() % 256 + 1;
8781 WelsScan4x4Dc (iLevel, iDctA);
@@ -154,7 +148,6 @@ TEST (EncodeMbAuxTest, WelsDctT4_c) { · 66 unmodified lines
154148 int16_t iDctRef[4][4];
155149 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];
156150 int16_t iDct[16];
157− srand ((unsigned int)time (NULL));
158151 for (int i = 0; i < 4; i++)
159152 for (int j = 0; j < 4; j++)
160153 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;
@@ -168,7 +161,6 @@ TEST (EncodeMbAuxTest, WelsDctFourT4_c) { · 7 unmodified lines
168161 int16_t iDctRef[4][4][4];
169162 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];
170163 int16_t iDct[16 * 4];
171− srand ((unsigned int)time (NULL));
172164 for (int i = 0; i < 8; i++)
173165 for (int j = 0; j < 8; j++)
174166 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;
@@ -184,7 +176,6 @@ TEST (EncodeMbAuxTest, WelsDctFourT4_c) { · 9 unmodified lines
184176 TEST (EncodeMbAuxTest, WelsDctT4_mmx) {
185177 int16_t iDctC[16], iDctM[16];
186178 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];
187− srand ((unsigned int)time (NULL));
188179 for (int i = 0; i < 4; i++)
189180 for (int j = 0; j < 4; j++)
190181 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;
@@ -200,7 +191,6 @@ TEST (EncodeMbAuxTest, WelsDctFourT4_sse2) { · 9 unmodified lines
200191 ALLOC_MEMORY (uint8_t, uiPix2, 16 * FDEC_STRIDE);
201192 ALLOC_MEMORY (int16_t, iDctC, 16 * 4);
202193 ALLOC_MEMORY (int16_t, iDctS, 16 * 4);
203− srand ((unsigned int)time (NULL));
204194 for (int i = 0; i < 8; i++)
205195 for (int j = 0; j < 8; j++)
206196 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;
@@ -218,7 +208,6 @@ TEST (EncodeMbAuxTest, WelsCalculateSingleCtr4x4_sse2) { · 11 unmodified lines
218208 CMemoryAlign cMemoryAlign (0);
219209 ALLOC_MEMORY (int16_t, iDctC, 16);
220210 ALLOC_MEMORY (int16_t, iDctS, 16);
221− srand ((unsigned int)time (NULL));
222211 for (int i = 0; i < 16; i++)
223212 iDctC[i] = iDctS[i] = (rand() & 65535) - 32768;
224213 WelsCalculateSingleCtr4x4_c (iDctC);
@@ -242,7 +231,6 @@ TEST(EncodeMbAuxTest, function) { \ · 17 unmodified lines
242231 ENFORCE_STACK_ALIGN_1D (uint8_t, ref_src, iSStride*height, 16); \
243232 ENFORCE_STACK_ALIGN_1D (uint8_t, ref_dst, iDStride*height, 16); \
244233 ENFORCE_STACK_ALIGN_1D (uint8_t, dst, iDStride*height, 16); \
245− srand((unsigned int)time(NULL)); \
246234 for(int i = 0; i < height; i++) \
247235 for(int j = 0; j < width; j++) \
248236 ref_src[i*iSStride+j] = rand() & 255; \
@@ -265,7 +253,6 @@ GENERATE_UT_FOR_COPY (16, 16, WelsCopy16x16_sse2); · 16 unmodified lines
265253 #endif
266254 TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_c) {
267255 ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16);
268− srand ((unsigned int)time (NULL));
269256 int32_t result = 0;
270257 for (int i = 0; i < 16; i++) {
271258 pLevel[i] = (rand() & 0x07) - 4;
@@ -277,7 +264,6 @@ TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_c) { · 5 unmodified lines
277264 #ifdef X86_ASM
278265 TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_sse2) {
279266 ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16);
280− srand ((unsigned int)time (NULL));
281267 int32_t result = 0;
282268 for (int i = 0; i < 16; i++) {
283269 pLevel[i] = (rand() & 0x07) - 4;
@@ -310,7 +296,6 @@ TEST (EncodeMbAuxTest, WelsQuantFour4x4Max_c) { · 26 unmodified lines
310296 int16_t ff[8], mf[8];
311297 int16_t iDctA[64], iMaxA[16];
312298 int16_t iDctC[64], iMaxC[16];
313− srand ((unsigned int)time (NULL));
314299 for (int i = 0; i < 8; i++) {
315300 ff[i] = rand() & 32767;
316301 mf[i] = rand() & 32767;
@@ -333,7 +318,6 @@ TEST (EncodeMbAuxTest, WelsQuantFour4x4Max_sse2) { · 16 unmodified lines
333318 ALLOC_MEMORY (int16_t, iDctS, 64);
334319 ALLOC_MEMORY (int16_t, iMaxC, 16);
335320 ALLOC_MEMORY (int16_t, iMaxS, 16);
336− srand ((unsigned int)time (NULL));
337321 for (int i = 0; i < 8; i++) {
338322 ff[i] = rand() & 32767;
339323 mf[i] = rand() & 32767;
@@ -372,7 +356,6 @@ int32_t WelsHadamardQuant2x2SkipAnchor (int16_t* rs, int16_t ff, int16_t mf) { · 32 unmodified lines
372356 TEST (EncodeMbAuxTest, WelsHadamardQuant2x2Skip_c) {
373357 int16_t iRS[64];
374358 int16_t ff, mf;
375− srand ((unsigned int)time (NULL));
376359 for (int i = 0; i < 64; i++)
377360 iRS[i] = (rand() & 32767) - 16384;
378361 ff = rand() & 32767;
@@ -417,7 +400,6 @@ TEST (EncodeMbAuxTest, WelsHadamardQuant2x2_c) { · 38 unmodified lines
417400 int16_t iRsC[64], iRsA[64];
418401 int16_t ff, mf;
419402 int16_t iBlockA[16], iBlockC[16], iDctA[4], iDctC[4];
420− srand ((unsigned int)time (NULL));
421403 for (int i = 0; i < 64; i++)
422404 iRsA[i] = iRsC[i] = (rand() & 32767) - 16384;
423405 for (int i = 0; i < 4; i++)
@@ -462,7 +444,6 @@ TEST (EncodeMbAuxTest, WelsHadamardT4Dc_c) { · 38 unmodified lines
462444 ALLOC_MEMORY (int16_t, iDct, 128 * 16);
463445 ALLOC_MEMORY (int16_t, iLumaDcR, 16);
464446 ALLOC_MEMORY (int16_t, iLumaDcC, 16);
465− srand ((unsigned int)time (NULL));
466447 for (int i = 0; i < 128 * 16; i++)
467448 iDct[i] = (rand() & 32767) - 16384;
468449 WelsHadamardT4DcAnchor (iLumaDcR, iDct);
@@ -479,7 +460,6 @@ TEST (EncodeMbAuxTest, WelsHadamardT4Dc_sse2) { · 10 unmodified lines
479460 ALLOC_MEMORY (int16_t, iDct, 128 * 16);
480461 ALLOC_MEMORY (int16_t, iLumaDcC, 16);
481462 ALLOC_MEMORY (int16_t, iLumaDcS, 16);
482− srand ((unsigned int)time (NULL));
483463 for (int i = 0; i < 128 * 16; i++)
484464 iDct[i] = (rand() & 32767) - 16384;
485465 WelsHadamardT4Dc_c (iLumaDcC, iDct);

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