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 @@
1#include<gtest/gtest.h>1#include<gtest/gtest.h>
2#include<stdlib.h>
3#include<time.h>
4#include "ls_defines.h"2#include "ls_defines.h"
5#include "encode_mb_aux.h"3#include "encode_mb_aux.h"
6#include "wels_common_basis.h"4#include "wels_common_basis.h"
@@ -14,7 +12,6 @@ TEST (EncodeMbAuxTest, TestScan_4x4_ac_c) { · 7 unmodified lines
14 ALLOC_MEMORY (int16_t, iLevel, 16);12 ALLOC_MEMORY (int16_t, iLevel, 16);
15 ALLOC_MEMORY (int16_t, iDctA, 16);13 ALLOC_MEMORY (int16_t, iDctA, 16);
16 ALLOC_MEMORY (int16_t, iDctB, 16);14 ALLOC_MEMORY (int16_t, iDctB, 16);
17 srand ((unsigned int)time (NULL));
18 for (int i = 0; i < 16; i++) {15 for (int i = 0; i < 16; i++) {
19 iDctA[i] = rand() % 256 + 1;16 iDctA[i] = rand() % 256 + 1;
20 iDctB[i] = iDctA[i];17 iDctB[i] = iDctA[i];
@@ -47,7 +44,6 @@ TEST (EncodeMbAuxTest, TestScan_4x4_ac_sse2) { · 26 unmodified lines
47 ALLOC_MEMORY (int16_t, iLevelA, 16);44 ALLOC_MEMORY (int16_t, iLevelA, 16);
48 ALLOC_MEMORY (int16_t, iLevelB, 16);45 ALLOC_MEMORY (int16_t, iLevelB, 16);
49 ALLOC_MEMORY (int16_t, iDct, 16);46 ALLOC_MEMORY (int16_t, iDct, 16);
50 srand ((unsigned int)time (NULL));
51 for (int i = 0; i < 16; i++) {47 for (int i = 0; i < 16; i++) {
52 iDct[i] = rand() % 256 + 1;48 iDct[i] = rand() % 256 + 1;
53 }49 }
@@ -64,7 +60,6 @@ TEST (EncodeMbAuxTest, WelsScan4x4DcAc_sse2) { · 10 unmodified lines
64 ALLOC_MEMORY (int16_t, iLevelA, 32);60 ALLOC_MEMORY (int16_t, iLevelA, 32);
65 ALLOC_MEMORY (int16_t, iLevelB, 32);61 ALLOC_MEMORY (int16_t, iLevelB, 32);
66 ALLOC_MEMORY (int16_t, iDct, 32);62 ALLOC_MEMORY (int16_t, iDct, 32);
67 srand ((unsigned int)time (NULL));
68 for (int i = 0; i < 32; i++)63 for (int i = 0; i < 32; i++)
69 iDct[i] = (rand() & 32767) - 16384;64 iDct[i] = (rand() & 32767) - 16384;
70 WelsScan4x4DcAc_sse2 (iLevelA, iDct);65 WelsScan4x4DcAc_sse2 (iLevelA, iDct);
@@ -81,7 +76,6 @@ TEST (EncodeMbAuxTest, TestScan_4x4_dcc) { · 10 unmodified lines
81 ALLOC_MEMORY (int16_t, iLevel, 16);76 ALLOC_MEMORY (int16_t, iLevel, 16);
82 ALLOC_MEMORY (int16_t, iDctA, 16);77 ALLOC_MEMORY (int16_t, iDctA, 16);
83 ALLOC_MEMORY (int16_t, iDctB, 16);78 ALLOC_MEMORY (int16_t, iDctB, 16);
84 srand ((unsigned int)time (NULL));
85 for (int i = 0; i < 16; i++)79 for (int i = 0; i < 16; i++)
86 iDctA[i] = iDctB[i] = rand() % 256 + 1;80 iDctA[i] = iDctB[i] = rand() % 256 + 1;
87 WelsScan4x4Dc (iLevel, iDctA);81 WelsScan4x4Dc (iLevel, iDctA);
@@ -154,7 +148,6 @@ TEST (EncodeMbAuxTest, WelsDctT4_c) { · 66 unmodified lines
154 int16_t iDctRef[4][4];148 int16_t iDctRef[4][4];
155 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];149 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];
156 int16_t iDct[16];150 int16_t iDct[16];
157 srand ((unsigned int)time (NULL));
158 for (int i = 0; i < 4; i++)151 for (int i = 0; i < 4; i++)
159 for (int j = 0; j < 4; j++)152 for (int j = 0; j < 4; j++)
160 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;153 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;
@@ -168,7 +161,6 @@ TEST (EncodeMbAuxTest, WelsDctFourT4_c) { · 7 unmodified lines
168 int16_t iDctRef[4][4][4];161 int16_t iDctRef[4][4][4];
169 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];162 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];
170 int16_t iDct[16 * 4];163 int16_t iDct[16 * 4];
171 srand ((unsigned int)time (NULL));
172 for (int i = 0; i < 8; i++)164 for (int i = 0; i < 8; i++)
173 for (int j = 0; j < 8; j++)165 for (int j = 0; j < 8; j++)
174 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;166 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;
@@ -184,7 +176,6 @@ TEST (EncodeMbAuxTest, WelsDctFourT4_c) { · 9 unmodified lines
184TEST (EncodeMbAuxTest, WelsDctT4_mmx) {176TEST (EncodeMbAuxTest, WelsDctT4_mmx) {
185 int16_t iDctC[16], iDctM[16];177 int16_t iDctC[16], iDctM[16];
186 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];178 uint8_t uiPix1[16 * FENC_STRIDE], uiPix2[16 * FDEC_STRIDE];
187 srand ((unsigned int)time (NULL));
188 for (int i = 0; i < 4; i++)179 for (int i = 0; i < 4; i++)
189 for (int j = 0; j < 4; j++)180 for (int j = 0; j < 4; j++)
190 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;181 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;
@@ -200,7 +191,6 @@ TEST (EncodeMbAuxTest, WelsDctFourT4_sse2) { · 9 unmodified lines
200 ALLOC_MEMORY (uint8_t, uiPix2, 16 * FDEC_STRIDE);191 ALLOC_MEMORY (uint8_t, uiPix2, 16 * FDEC_STRIDE);
201 ALLOC_MEMORY (int16_t, iDctC, 16 * 4);192 ALLOC_MEMORY (int16_t, iDctC, 16 * 4);
202 ALLOC_MEMORY (int16_t, iDctS, 16 * 4);193 ALLOC_MEMORY (int16_t, iDctS, 16 * 4);
203 srand ((unsigned int)time (NULL));
204 for (int i = 0; i < 8; i++)194 for (int i = 0; i < 8; i++)
205 for (int j = 0; j < 8; j++)195 for (int j = 0; j < 8; j++)
206 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;196 uiPix1[i * FENC_STRIDE + j] = uiPix2[i * FDEC_STRIDE + j] = rand() & 255;
@@ -218,7 +208,6 @@ TEST (EncodeMbAuxTest, WelsCalculateSingleCtr4x4_sse2) { · 11 unmodified lines
218 CMemoryAlign cMemoryAlign (0);208 CMemoryAlign cMemoryAlign (0);
219 ALLOC_MEMORY (int16_t, iDctC, 16);209 ALLOC_MEMORY (int16_t, iDctC, 16);
220 ALLOC_MEMORY (int16_t, iDctS, 16);210 ALLOC_MEMORY (int16_t, iDctS, 16);
221 srand ((unsigned int)time (NULL));
222 for (int i = 0; i < 16; i++)211 for (int i = 0; i < 16; i++)
223 iDctC[i] = iDctS[i] = (rand() & 65535) - 32768;212 iDctC[i] = iDctS[i] = (rand() & 65535) - 32768;
224 WelsCalculateSingleCtr4x4_c (iDctC);213 WelsCalculateSingleCtr4x4_c (iDctC);
@@ -242,7 +231,6 @@ TEST(EncodeMbAuxTest, function) { \ · 17 unmodified lines
242 ENFORCE_STACK_ALIGN_1D (uint8_t, ref_src, iSStride*height, 16); \231 ENFORCE_STACK_ALIGN_1D (uint8_t, ref_src, iSStride*height, 16); \
243 ENFORCE_STACK_ALIGN_1D (uint8_t, ref_dst, iDStride*height, 16); \232 ENFORCE_STACK_ALIGN_1D (uint8_t, ref_dst, iDStride*height, 16); \
244 ENFORCE_STACK_ALIGN_1D (uint8_t, dst, iDStride*height, 16); \233 ENFORCE_STACK_ALIGN_1D (uint8_t, dst, iDStride*height, 16); \
245 srand((unsigned int)time(NULL)); \
246 for(int i = 0; i < height; i++) \234 for(int i = 0; i < height; i++) \
247 for(int j = 0; j < width; j++) \235 for(int j = 0; j < width; j++) \
248 ref_src[i*iSStride+j] = rand() & 255; \236 ref_src[i*iSStride+j] = rand() & 255; \
@@ -265,7 +253,6 @@ GENERATE_UT_FOR_COPY (16, 16, WelsCopy16x16_sse2); · 16 unmodified lines
265#endif253#endif
266TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_c) {254TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_c) {
267 ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16);255 ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16);
268 srand ((unsigned int)time (NULL));
269 int32_t result = 0;256 int32_t result = 0;
270 for (int i = 0; i < 16; i++) {257 for (int i = 0; i < 16; i++) {
271 pLevel[i] = (rand() & 0x07) - 4;258 pLevel[i] = (rand() & 0x07) - 4;
@@ -277,7 +264,6 @@ TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_c) { · 5 unmodified lines
277#ifdef X86_ASM264#ifdef X86_ASM
278TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_sse2) {265TEST (EncodeMbAuxTest, WelsGetNoneZeroCount_sse2) {
279 ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16);266 ENFORCE_STACK_ALIGN_1D (int16_t, pLevel, 16, 16);
280 srand ((unsigned int)time (NULL));
281 int32_t result = 0;267 int32_t result = 0;
282 for (int i = 0; i < 16; i++) {268 for (int i = 0; i < 16; i++) {
283 pLevel[i] = (rand() & 0x07) - 4;269 pLevel[i] = (rand() & 0x07) - 4;
@@ -310,7 +296,6 @@ TEST (EncodeMbAuxTest, WelsQuantFour4x4Max_c) { · 26 unmodified lines
310 int16_t ff[8], mf[8];296 int16_t ff[8], mf[8];
311 int16_t iDctA[64], iMaxA[16];297 int16_t iDctA[64], iMaxA[16];
312 int16_t iDctC[64], iMaxC[16];298 int16_t iDctC[64], iMaxC[16];
313 srand ((unsigned int)time (NULL));
314 for (int i = 0; i < 8; i++) {299 for (int i = 0; i < 8; i++) {
315 ff[i] = rand() & 32767;300 ff[i] = rand() & 32767;
316 mf[i] = rand() & 32767;301 mf[i] = rand() & 32767;
@@ -333,7 +318,6 @@ TEST (EncodeMbAuxTest, WelsQuantFour4x4Max_sse2) { · 16 unmodified lines
333 ALLOC_MEMORY (int16_t, iDctS, 64);318 ALLOC_MEMORY (int16_t, iDctS, 64);
334 ALLOC_MEMORY (int16_t, iMaxC, 16);319 ALLOC_MEMORY (int16_t, iMaxC, 16);
335 ALLOC_MEMORY (int16_t, iMaxS, 16);320 ALLOC_MEMORY (int16_t, iMaxS, 16);
336 srand ((unsigned int)time (NULL));
337 for (int i = 0; i < 8; i++) {321 for (int i = 0; i < 8; i++) {
338 ff[i] = rand() & 32767;322 ff[i] = rand() & 32767;
339 mf[i] = rand() & 32767;323 mf[i] = rand() & 32767;
@@ -372,7 +356,6 @@ int32_t WelsHadamardQuant2x2SkipAnchor (int16_t* rs, int16_t ff, int16_t mf) { · 32 unmodified lines
372TEST (EncodeMbAuxTest, WelsHadamardQuant2x2Skip_c) {356TEST (EncodeMbAuxTest, WelsHadamardQuant2x2Skip_c) {
373 int16_t iRS[64];357 int16_t iRS[64];
374 int16_t ff, mf;358 int16_t ff, mf;
375 srand ((unsigned int)time (NULL));
376 for (int i = 0; i < 64; i++)359 for (int i = 0; i < 64; i++)
377 iRS[i] = (rand() & 32767) - 16384;360 iRS[i] = (rand() & 32767) - 16384;
378 ff = rand() & 32767;361 ff = rand() & 32767;
@@ -417,7 +400,6 @@ TEST (EncodeMbAuxTest, WelsHadamardQuant2x2_c) { · 38 unmodified lines
417 int16_t iRsC[64], iRsA[64];400 int16_t iRsC[64], iRsA[64];
418 int16_t ff, mf;401 int16_t ff, mf;
419 int16_t iBlockA[16], iBlockC[16], iDctA[4], iDctC[4];402 int16_t iBlockA[16], iBlockC[16], iDctA[4], iDctC[4];
420 srand ((unsigned int)time (NULL));
421 for (int i = 0; i < 64; i++)403 for (int i = 0; i < 64; i++)
422 iRsA[i] = iRsC[i] = (rand() & 32767) - 16384;404 iRsA[i] = iRsC[i] = (rand() & 32767) - 16384;
423 for (int i = 0; i < 4; i++)405 for (int i = 0; i < 4; i++)
@@ -462,7 +444,6 @@ TEST (EncodeMbAuxTest, WelsHadamardT4Dc_c) { · 38 unmodified lines
462 ALLOC_MEMORY (int16_t, iDct, 128 * 16);444 ALLOC_MEMORY (int16_t, iDct, 128 * 16);
463 ALLOC_MEMORY (int16_t, iLumaDcR, 16);445 ALLOC_MEMORY (int16_t, iLumaDcR, 16);
464 ALLOC_MEMORY (int16_t, iLumaDcC, 16);446 ALLOC_MEMORY (int16_t, iLumaDcC, 16);
465 srand ((unsigned int)time (NULL));
466 for (int i = 0; i < 128 * 16; i++)447 for (int i = 0; i < 128 * 16; i++)
467 iDct[i] = (rand() & 32767) - 16384;448 iDct[i] = (rand() & 32767) - 16384;
468 WelsHadamardT4DcAnchor (iLumaDcR, iDct);449 WelsHadamardT4DcAnchor (iLumaDcR, iDct);
@@ -479,7 +460,6 @@ TEST (EncodeMbAuxTest, WelsHadamardT4Dc_sse2) { · 10 unmodified lines
479 ALLOC_MEMORY (int16_t, iDct, 128 * 16);460 ALLOC_MEMORY (int16_t, iDct, 128 * 16);
480 ALLOC_MEMORY (int16_t, iLumaDcC, 16);461 ALLOC_MEMORY (int16_t, iLumaDcC, 16);
481 ALLOC_MEMORY (int16_t, iLumaDcS, 16);462 ALLOC_MEMORY (int16_t, iLumaDcS, 16);
482 srand ((unsigned int)time (NULL));
483 for (int i = 0; i < 128 * 16; i++)463 for (int i = 0; i < 128 * 16; i++)
484 iDct[i] = (rand() & 32767) - 16384;464 iDct[i] = (rand() & 32767) - 16384;
485 WelsHadamardT4Dc_c (iLumaDcC, iDct);465 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