projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use srand rather than less portable srandom
[yaz-moved-to-github.git]
/
ztest
/
ztest.c
diff --git
a/ztest/ztest.c
b/ztest/ztest.c
index
6d806b2
..
bbbb402
100644
(file)
--- a/
ztest/ztest.c
+++ b/
ztest/ztest.c
@@
-11,9
+11,19
@@
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
+
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+#ifdef WIN32
+#include <windows.h>
+#endif
#include <yaz/log.h>
#include <yaz/backend.h>
#include <yaz/log.h>
#include <yaz/backend.h>
@@
-188,18
+198,27
@@
static int parse_delay(struct delay *delayp, const char *value)
return 0;
}
return 0;
}
+static void ztest_sleep(double d)
+{
+#ifdef WIN32
+ Sleep( (DWORD) (d * 1000));
+#else
+ struct timeval tv;
+ tv.tv_sec = floor(d);
+ tv.tv_usec = (d - floor(d)) * 1000000;
+ select(0, 0, 0, 0, &tv);
+#endif
+}
+
static void do_delay(const struct delay *delayp)
{
double d = delayp->d1;
if (d > 0.0)
{
static void do_delay(const struct delay *delayp)
{
double d = delayp->d1;
if (d > 0.0)
{
- struct timeval tv;
if (delayp->d2 > d)
d += (rand()) * (delayp->d2 - d) / RAND_MAX;
if (delayp->d2 > d)
d += (rand()) * (delayp->d2 - d) / RAND_MAX;
- tv.tv_sec = floor(d);
- tv.tv_usec = (d - floor(d)) * 1000000;
- select(0, 0, 0, 0, &tv);
+ ztest_sleep(d);
}
}
}
}
@@
-268,7
+287,7
@@
int ztest_search(void *handle, bend_search_rr *rr)
const char *name = names[i];
const char *value = values[i];
if (!strcmp(name, "seed"))
const char *name = names[i];
const char *value = values[i];
if (!strcmp(name, "seed"))
- srandom(atoi(value));
+ srand(atoi(value));
else if (!strcmp(name, "search-delay"))
parse_delay(&new_set->search_delay, value);
else if (!strcmp(name, "present-delay"))
else if (!strcmp(name, "search-delay"))
parse_delay(&new_set->search_delay, value);
else if (!strcmp(name, "present-delay"))