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