summaryrefslogtreecommitdiffstats
path: root/perform
diff options
context:
space:
mode:
authorBill Wendling <wendling@ncsa.uiuc.edu>2002-06-17 20:01:17 (GMT)
committerBill Wendling <wendling@ncsa.uiuc.edu>2002-06-17 20:01:17 (GMT)
commit5e12a077ab139275108afe59e77bbaf7cbb9730a (patch)
treeaf836ed6971c0eec841cad6854581a1e9c4a8009 /perform
parent12e0c2e474d06cca46b44a229919c19f2d1a132c (diff)
downloadhdf5-5e12a077ab139275108afe59e77bbaf7cbb9730a.zip
hdf5-5e12a077ab139275108afe59e77bbaf7cbb9730a.tar.gz
hdf5-5e12a077ab139275108afe59e77bbaf7cbb9730a.tar.bz2
[svn-r5656] Purpose:
Feature Add Description: Use the /dev/urandom device for random data if it's available. (That is stat() doesn't return a -1 when ran on it). Use random() otherwise. Platforms tested: Linux, FreeBSD
Diffstat (limited to 'perform')
-rw-r--r--perform/zip_perf.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/perform/zip_perf.c b/perform/zip_perf.c
index c124997..910afdf 100644
--- a/perform/zip_perf.c
+++ b/perform/zip_perf.c
@@ -27,11 +27,11 @@
#include <stdarg.h>
#include <string.h>
#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/uio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
/* our header files */
@@ -411,6 +411,40 @@ parse_size_directive(const char *size)
}
static void
+fill_with_random_data(Bytef *src, uLongf src_len)
+{
+ register int i;
+ struct stat buf;
+
+ if (stat("/dev/urandom", &buf) == 0) {
+ int fd = open("/dev/urandom", O_RDONLY);
+
+ printf("Using /dev/urandom for random data\n");
+
+ if (fd < 0)
+ error(strerror(errno));
+
+ for (;;) {
+ ssize_t rc = read(fd, src, src_len);
+
+ if (rc == -1)
+ error(strerror(errno));
+
+ if (rc == src_len)
+ break;
+
+ src += rc;
+ src_len -= rc;
+ }
+ } else {
+ printf("Using random() for random data\n");
+
+ for (i = 0; i < src_len; ++i)
+ src[i] = 0xff & random();
+ }
+}
+
+static void
do_write_test(unsigned long file_size, unsigned long min_buf_size,
unsigned long max_buf_size)
{
@@ -433,9 +467,7 @@ do_write_test(unsigned long file_size, unsigned long min_buf_size,
compression_time = 0.0;
if (random_test)
- /* fill the buffer with random data */
- for (i = 0; i < src_len; ++i)
- src[i] = 0xff | (1 + (int)(255.0 * rand()/(RAND_MAX + 1.0)));
+ fill_with_random_data(src, src_len);
printf("Buffer size == ");
@@ -464,7 +496,7 @@ do_write_test(unsigned long file_size, unsigned long min_buf_size,
/* loop to make sure we write everything out that we want to write */
for (;;) {
- int rc = write(output, s_ptr, s_len);
+ ssize_t rc = write(output, s_ptr, s_len);
if (rc == -1)
error(strerror(errno));