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 @@
1#include <string.h>//memset/memcpy1#include <string.h>//memset/memcpy
2#include <time.h>
3#include "utils/DataGenerator.h"2#include "utils/DataGenerator.h"
4#include "utils/BufferedData.h"3#include "utils/BufferedData.h"
5#include "utils/FileInputStream.h"4#include "utils/FileInputStream.h"
@@ -27,7 +26,6 @@ bool YUVPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, · 21 unmodified lines
27 return false;26 return false;
28 }27 }
29 if (fileStream.read (sBuf.data(), kiFrameSize) == kiFrameSize) {28 if (fileStream.read (sBuf.data(), kiFrameSize) == kiFrameSize) {
30 srand ((uint32_t)time (NULL));
31 int32_t iStartPosX = rand() % (SRC_FRAME_WIDTH - iWidth);29 int32_t iStartPosX = rand() % (SRC_FRAME_WIDTH - iWidth);
32 int32_t iStartPosY = rand() % (SRC_FRAME_HEIGHT - iHeight);30 int32_t iStartPosY = rand() % (SRC_FRAME_HEIGHT - iHeight);
33 uint8_t* pSrcPointer = sBuf.data() + iStartPosX + iStartPosY * SRC_FRAME_WIDTH;31 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
43 return false;41 return false;
44}42}
45 43
46void RandomPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride, int32_t iIdx) {44void RandomPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride) {
47 uint8_t* pLocalPointer = pPointer;45 uint8_t* pLocalPointer = pPointer;
48 srand ((uint32_t) (time (NULL) + iIdx));
49 for (int32_t j = 0; j < iHeight; j++) {46 for (int32_t j = 0; j < iHeight; j++) {
50 for (int32_t i = 0; i < iWidth; i++) {47 for (int32_t i = 0; i < iWidth; i++) {
51 pLocalPointer[i] = rand() % 256;48 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