1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

Replace random() usage in test programs by av_lfg_*().

Originally committed as revision 18070 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Diego Biurrun 2009-03-20 11:48:27 +00:00
parent c7594e0764
commit 294eaa2643
9 changed files with 64 additions and 36 deletions

View File

@ -179,9 +179,9 @@ void ff_init_cabac_states(CABACContext *c){
}
#ifdef TEST
#undef random
#define SIZE 10240
#include "libavutil/lfg.h"
#include "avcodec.h"
#include "cabac.h"
@ -191,12 +191,14 @@ int main(void){
uint8_t r[9*SIZE];
int i;
uint8_t state[10]= {0};
AVLFG prn;
av_lfg_init(&prn, 1);
ff_init_cabac_encoder(&c, b, SIZE);
ff_init_cabac_states(&c);
for(i=0; i<SIZE; i++){
r[i]= random()%7;
r[i] = av_lfg_get(&prn) % 7;
}
for(i=0; i<SIZE; i++){

View File

@ -33,6 +33,7 @@
#include <math.h>
#include "libavutil/common.h"
#include "libavutil/lfg.h"
#include "simple_idct.h"
#include "aandcttab.h"
@ -41,7 +42,6 @@
#include "x86/idct_xvid.h"
#undef printf
#undef random
void *fast_memcpy(void *a, const void *b, size_t c){return memcpy(a,b,c);};
@ -208,8 +208,9 @@ void dct_error(const char *name, int is_idct,
int64_t sysErr[64], sysErrMax=0;
int maxout=0;
int blockSumErrMax=0, blockSumErr;
AVLFG prn;
srandom(0);
av_lfg_init(&prn, 1);
err_inf = 0;
err2 = 0;
@ -220,7 +221,7 @@ void dct_error(const char *name, int is_idct,
switch(test){
case 0:
for(i=0;i<64;i++)
block1[i] = (random() % 512) -256;
block1[i] = (av_lfg_get(&prn) % 512) -256;
if (is_idct){
fdct(block1);
@ -229,12 +230,12 @@ void dct_error(const char *name, int is_idct,
}
break;
case 1:{
int num= (random()%10)+1;
int num = av_lfg_get(&prn) % 10 + 1;
for(i=0;i<num;i++)
block1[random()%64] = (random() % 512) -256;
block1[av_lfg_get(&prn) % 64] = av_lfg_get(&prn) % 512 -256;
}break;
case 2:
block1[0]= (random()%4096)-2048;
block1[0] = av_lfg_get(&prn) % 4096 - 2048;
block1[63]= (block1[0]&1)^1;
break;
}
@ -334,7 +335,7 @@ void dct_error(const char *name, int is_idct,
switch(test){
case 0:
for(i=0;i<64;i++)
block1[i] = (random() % 512) -256;
block1[i] = av_lfg_get(&prn) % 512 -256;
if (is_idct){
fdct(block1);
@ -344,10 +345,10 @@ void dct_error(const char *name, int is_idct,
break;
case 1:{
case 2:
block1[0] = (random() % 512) -256;
block1[1] = (random() % 512) -256;
block1[2] = (random() % 512) -256;
block1[3] = (random() % 512) -256;
block1[0] = av_lfg_get(&prn) % 512 -256;
block1[1] = av_lfg_get(&prn) % 512 -256;
block1[2] = av_lfg_get(&prn) % 512 -256;
block1[3] = av_lfg_get(&prn) % 512 -256;
}break;
}
@ -471,7 +472,9 @@ void idct248_error(const char *name,
{
int it, i, it1, ti, ti1, err_max, v;
srandom(0);
AVLFG prn;
av_lfg_init(&prn, 1);
/* just one test to see if code is correct (precision is less
important here) */
@ -480,7 +483,7 @@ void idct248_error(const char *name,
/* XXX: use forward transform to generate values */
for(i=0;i<64;i++)
block1[i] = (random() % 256) - 128;
block1[i] = av_lfg_get(&prn) % 256 - 128;
block1[0] += 1024;
for(i=0; i<64; i++)

View File

@ -23,6 +23,7 @@
* FFT and MDCT tests.
*/
#include "libavutil/lfg.h"
#include "dsputil.h"
#include <math.h>
#include <unistd.h>
@ -31,7 +32,6 @@
#include <string.h>
#undef exit
#undef random
/* reference fft */
@ -131,7 +131,9 @@ void mdct_ref(float *output, float *input, int nbits)
float frandom(void)
{
return (float)((random() & 0xffff) - 32768) / 32768.0;
AVLFG prn;
av_lfg_init(&prn, 1);
return (float)((av_lfg_get(&prn) & 0xffff) - 32768) / 32768.0;
}
int64_t gettime(void)

View File

@ -30,10 +30,10 @@
#include <unistd.h>
#include "dsputil.h"
#include "libavutil/lfg.h"
#undef exit
#undef printf
#undef random
#define WIDTH 64
#define HEIGHT 64
@ -44,9 +44,12 @@ uint8_t img2[WIDTH * HEIGHT];
void fill_random(uint8_t *tab, int size)
{
int i;
AVLFG prn;
av_lfg_init(&prn, 1);
for(i=0;i<size;i++) {
#if 1
tab[i] = random() % 256;
tab[i] = av_lfg_get(&prn) % 256;
#else
tab[i] = i;
#endif
@ -142,7 +145,7 @@ int main(int argc, char **argv)
ctx = avcodec_alloc_context();
ctx->dsp_mask = FF_MM_FORCE;
dsputil_init(&cctx, ctx);
for (c = 0; c < 2; c++) {
for (c = 0; c < 1; c++) {
int x;
ctx->dsp_mask = FF_MM_FORCE | flags[c];
dsputil_init(&mmxctx, ctx);

View File

@ -111,13 +111,18 @@ int ff_rac_terminate(RangeCoder *c){
#ifdef TEST
#define SIZE 10240
#undef random
#include "libavutil/lfg.h"
int main(void){
RangeCoder c;
uint8_t b[9*SIZE];
uint8_t r[9*SIZE];
int i;
uint8_t state[10]= {0};
AVLFG prn;
av_lfg_init(&prn, 1);
ff_init_range_encoder(&c, b, SIZE);
ff_build_rac_states(&c, 0.05*(1LL<<32), 128+64+32+16);
@ -125,7 +130,7 @@ int main(void){
memset(state, 128, sizeof(state));
for(i=0; i<SIZE; i++){
r[i]= random()%7;
r[i] = av_lfg_get(&prn) % 7;
}
for(i=0; i<SIZE; i++){

View File

@ -4689,7 +4689,8 @@ AVCodec snow_encoder = {
#undef malloc
#undef free
#undef printf
#undef random
#include "libavutil/lfg.h"
int main(void){
int width=256;
@ -4699,10 +4700,13 @@ int main(void){
int i;
s.spatial_decomposition_count=6;
s.spatial_decomposition_type=1;
AVLFG prn;
av_lfg_init(&prn, 1);
printf("testing 5/3 DWT\n");
for(i=0; i<width*height; i++)
buffer[0][i]= buffer[1][i]= random()%54321 - 12345;
buffer[0][i] = buffer[1][i] = av_lfg_get(&prn) % 54321 - 12345;
ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
@ -4713,7 +4717,7 @@ int main(void){
printf("testing 9/7 DWT\n");
s.spatial_decomposition_type=0;
for(i=0; i<width*height; i++)
buffer[0][i]= buffer[1][i]= random()%54321 - 12345;
buffer[0][i] = buffer[1][i] = av_lfg_get(&prn) % 54321 - 12345;
ff_spatial_dwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);
ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count);

View File

@ -192,10 +192,9 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) {
}
#ifdef TEST
#include "lfg.h"
#include "log.h"
#undef random
int main(void){
int i,j;
AVAES ae, ad, b;
@ -209,10 +208,12 @@ int main(void){
{0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf},
{0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65}};
uint8_t temp[16];
AVLFG prn;
av_aes_init(&ae, "PI=3.141592654..", 128, 0);
av_aes_init(&ad, "PI=3.141592654..", 128, 1);
av_log_set_level(AV_LOG_DEBUG);
av_lfg_init(&prn, 1);
for(i=0; i<2; i++){
av_aes_init(&b, rkey[i], 128, 1);
@ -224,7 +225,7 @@ int main(void){
for(i=0; i<10000; i++){
for(j=0; j<16; j++){
pt[j]= random();
pt[j] = av_lfg_get(&prn);
}
{START_TIMER
av_aes_crypt(&ae, temp, pt, 1, NULL, 0);

View File

@ -164,9 +164,9 @@ int ff_pca(PCA *pca, double *eigenvector, double *eigenvalue){
#ifdef TEST
#undef printf
#undef random
#include <stdio.h>
#include <stdlib.h>
#include "lfg.h"
int main(void){
PCA *pca;
@ -174,15 +174,18 @@ int main(void){
#define LEN 8
double eigenvector[LEN*LEN];
double eigenvalue[LEN];
AVLFG prn;
av_lfg_init(&prn, 1);
pca= ff_pca_init(LEN);
for(i=0; i<9000000; i++){
double v[2*LEN+100];
double sum=0;
int pos= random()%LEN;
int v2= (random()%101) - 50;
v[0]= (random()%101) - 50;
int pos = av_lfg_get(&prn) % LEN;
int v2 = av_lfg_get(&prn) % 101 - 50;
v[0] = av_lfg_get(&prn) % 101 - 50;
for(j=1; j<8; j++){
if(j<=pos) v[j]= v[0];
else v[j]= v2;
@ -191,7 +194,7 @@ int main(void){
/* for(j=0; j<LEN; j++){
v[j] -= v[pos];
}*/
// sum += random()%10;
// sum += av_lfg_get(&prn) % 10;
/* for(j=0; j<LEN; j++){
v[j] -= sum/LEN;
}*/

View File

@ -144,7 +144,9 @@ void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*f)(void *opaque, void
#endif
#ifdef TEST
#undef random
#include "lfg.h"
static int check(AVTreeNode *t){
if(t){
int left= check(t->child[0]);
@ -179,9 +181,12 @@ int cmp(const void *a, const void *b){
int main(void){
int i,k;
AVTreeNode *root= NULL, *node=NULL;
AVLFG prn;
av_lfg_init(&prn, 1);
for(i=0; i<10000; i++){
int j= (random()%86294);
int j = av_lfg_get(&prn) % 86294;
if(check(root) > 999){
av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i);
print(root, 0);
@ -192,7 +197,7 @@ int main(void){
node= av_mallocz(av_tree_node_size);
av_tree_insert(&root, (void*)(j+1), cmp, &node);
j= (random()%86294);
j = av_lfg_get(&prn) % 86294;
{
AVTreeNode *node2=NULL;
av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j);