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

Unified · Split

test/api/DataGenerator.cpp+1−4
@@ -1,5 +1,4 @@
11 #include <string.h>//memset/memcpy
2−#include <time.h>
32 #include "utils/DataGenerator.h"
43 #include "utils/BufferedData.h"
54 #include "utils/FileInputStream.h"
@@ -27,7 +26,6 @@ bool YUVPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, · 21 unmodified lines
2726 return false;
2827 }
2928 if (fileStream.read (sBuf.data(), kiFrameSize) == kiFrameSize) {
30− srand ((uint32_t)time (NULL));
3129 int32_t iStartPosX = rand() % (SRC_FRAME_WIDTH - iWidth);
3230 int32_t iStartPosY = rand() % (SRC_FRAME_HEIGHT - iHeight);
3331 uint8_t* pSrcPointer = sBuf.data() + iStartPosX + iStartPosY * SRC_FRAME_WIDTH;
@@ -43,9 +41,8 @@ bool YUVPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, · 9 unmodified lines
4341 return false;
4442 }
4543
46−void RandomPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride, int32_t iIdx) {
44+void RandomPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride) {
4745 uint8_t* pLocalPointer = pPointer;
48− srand ((uint32_t) (time (NULL) + iIdx));
4946 for (int32_t j = 0; j < iHeight; j++) {
5047 for (int32_t i = 0; i < iWidth; i++) {
5148 pLocalPointer[i] = rand() % 256;

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