diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2012-11-25 08:12:08 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2012-11-25 08:12:08 +0100 |
commit | 40330dd43d9fccac396e61ec0fb5df32b6530b57 (patch) | |
tree | e4503ed831c8f7a9d6a2f6d20889cd74292b2fa5 | |
parent | 933e63eaac669c9b235a7619e8d9aae058090a77 (diff) | |
download | fwbench-40330dd43d9fccac396e61ec0fb5df32b6530b57.tar.gz fwbench-40330dd43d9fccac396e61ec0fb5df32b6530b57.tar.bz2 fwbench-40330dd43d9fccac396e61ec0fb5df32b6530b57.tar.xz fwbench-40330dd43d9fccac396e61ec0fb5df32b6530b57.zip |
Generate random data to check way too clever controllers
-rw-r--r-- | fwbench.c | 55 | ||||
-rwxr-xr-x | fwbench.sh | 2 |
2 files changed, 44 insertions, 13 deletions
@@ -21,6 +21,7 @@ #include "config.h" //#define USE_FIFO +#define WRITE_RANDOM "/dev/frandom" #define WRITE_INTERVAL 1 #define WRITE_SUMMARY 5 #define DELTA_TOLERANCE 5 @@ -34,6 +35,7 @@ const char *fifo_name = ".fifo"; struct setup_s { + size_t uc; size_t width; size_t height; size_t bpp; @@ -81,6 +83,7 @@ typedef enum { OPT_FPF = 'f', OPT_MISSING = 'm', OPT_QUIET = 'q', + OPT_UC = 'u', OPT_HELP = 'h' } options_t; @@ -111,7 +114,8 @@ void Usage(int argc, char* const argv[], const char *format, ...) { " -n frames - Number of frames to write\n" " -g <width>x<height> - Geometry [1024]\n" " -g <pixels> - Number of megapixels [0.7]\n" -" -m <percent> - Tolerable missing frames [100%%]\n" +" -m <percent> - Tolerable missing frames [100%%]\n" +" -u <size> - Use uncompressable data, repeating block (MB)\n" " -q - Quiete\n" " -h - Help\n" "\n\n", @@ -184,6 +188,9 @@ static void set_fail_tolerance(setup_t *setup, double fail_rate) { setup->tolerance = fail_rate; } +static void request_uncompressable_data(setup_t *setup, size_t uc) { + setup->uc = uc; +} static int callback(setup_t *s, size_t result, void *buffer); @@ -230,28 +237,46 @@ static void *run(setup_t *setup) { size_t i; struct timeval tv; size_t size = setup->width * setup->height * setup->bpp; - char buffer[size]; + size_t pos = 0, mult = setup->uc / size; + char *buffer = malloc((mult + 1) * size); double interval = 1000000. / setup->fps, nextus; ssize_t tmp; size_t nexts; + g_assert(buffer); + + if (!mult) mult = 1; + +# ifdef WRITE_RANDOM + if (setup->uc) { + printf("Generating %zu MB of randomness...\n", mult * size / 1024 / 1024); + int rfd = open(WRITE_RANDOM, O_RDONLY); + g_assert(rfd >= 0); + read(rfd, buffer, mult * size); + close(rfd); + } +# endif /* WRITE_RANDOM */ + setup->run_started = 1; -#ifdef USE_FIFO +# ifdef USE_FIFO int fd = open(fifo_name, O_WRONLY); g_assert(fd >= 0); -#endif /* USE_FIFO */ +# endif /* USE_FIFO */ + gettimeofday(&tv, NULL); nexts = tv.tv_sec; nextus = tv.tv_usec + interval; for (i = 0; i < setup->iters; i++) { -#ifdef USE_FIFO - ssize_t res = write(fd, buffer, size); +# ifdef USE_FIFO + ssize_t res = write(fd, buffer + pos * size, size); g_assert(res == size); -#else /* USE_FIFO */ - callback(setup, size, buffer); -#endif /* USE_FIFO */ +# else /* USE_FIFO */ + callback(setup, size, buffer + pos * size); +# endif /* USE_FIFO */ + if ((++pos) == mult) pos = 0; + tmp = ((size_t)round(nextus)) / 1000000; nexts += tmp; nextus -= tmp * 1000000; @@ -263,10 +288,11 @@ static void *run(setup_t *setup) { nextus += interval; } -#ifdef USE_FIFO +# ifdef USE_FIFO close(fd); -#endif /* USE_FIFO */ +# endif /* USE_FIFO */ + free(buffer); #endif /* USE_UFO_GENERATOR */ return NULL; @@ -400,6 +426,7 @@ int main(int argc, char* const argv[]) size_t height = 768; size_t speed = 850; size_t size = 0; + size_t uc = 0; size_t run_time = 0; size_t iters = 0x7FFFFFFF; size_t fw_buffer = 0; @@ -418,7 +445,7 @@ int main(int argc, char* const argv[]) - while ((c = getopt(argc, argv, "hqo:s:t:r:n:g:f:m:b:")) != (unsigned char)-1) { + while ((c = getopt(argc, argv, "hqo:s:u:t:r:n:g:f:m:b:")) != (unsigned char)-1) { switch (c) { case OPT_OUTPUT: out = optarg; @@ -429,6 +456,9 @@ int main(int argc, char* const argv[]) case OPT_SIZE: size = atol(optarg); break; + case OPT_UC: + uc = atol(optarg); + break; case OPT_TIME: run_time = atol(optarg); break; @@ -484,6 +514,7 @@ int main(int argc, char* const argv[]) set_fail_tolerance(&setup, fail_rate); set_frames_per_file(&setup, fpf); + request_uncompressable_data(&setup, uc * 1024 * 1024); setup.fw = fastwriter_init(setup.fs, FASTWRITER_FLAGS_OVERWRITE); g_assert(setup.fw); @@ -34,7 +34,7 @@ speed=$((speed + 50)) res=1 while [ $res -ne 0 ]; do speed=$((speed - 50)) - fwbench -b 1024 -m 0 -r $speed -s $size -o $out + fwbench -b 1024 -m 0 -u 512 -r $speed -s $size -o $out res=$? usleep 500000 done |