mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Use evutil_weakrand() in unit tests.
(Coverity doesn't like random() or rand(). We don't care; this is for unit tests.) Fixes CID 1239298, 1239296, 1239295, 1239293.
This commit is contained in:
parent
76643dd0e7
commit
a677b72bd6
@ -2296,7 +2296,7 @@ evtag_fuzz(void *ptr)
|
|||||||
|
|
||||||
for (j = 0; j < 100; j++) {
|
for (j = 0; j < 100; j++) {
|
||||||
for (i = 0; i < (int)sizeof(buffer); i++)
|
for (i = 0; i < (int)sizeof(buffer); i++)
|
||||||
buffer[i] = rand();
|
buffer[i] = test_weakrand();
|
||||||
evbuffer_drain(tmp, -1);
|
evbuffer_drain(tmp, -1);
|
||||||
evbuffer_add(tmp, buffer, sizeof(buffer));
|
evbuffer_add(tmp, buffer, sizeof(buffer));
|
||||||
|
|
||||||
|
@ -53,6 +53,10 @@ extern struct testcase_t listener_testcases[];
|
|||||||
extern struct testcase_t listener_iocp_testcases[];
|
extern struct testcase_t listener_iocp_testcases[];
|
||||||
extern struct testcase_t thread_testcases[];
|
extern struct testcase_t thread_testcases[];
|
||||||
|
|
||||||
|
extern struct evutil_weakrand_state test_weakrand_state;
|
||||||
|
|
||||||
|
#define test_weakrand() (evutil_weakrand_(&test_weakrand_state))
|
||||||
|
|
||||||
void regress_threads(void *);
|
void regress_threads(void *);
|
||||||
void test_bufferevent_zlib(void *);
|
void test_bufferevent_zlib(void *);
|
||||||
|
|
||||||
|
@ -90,6 +90,8 @@
|
|||||||
#include "../iocp-internal.h"
|
#include "../iocp-internal.h"
|
||||||
#include "../event-internal.h"
|
#include "../event-internal.h"
|
||||||
|
|
||||||
|
struct evutil_weakrand_state test_weakrand_state;
|
||||||
|
|
||||||
long
|
long
|
||||||
timeval_msec_diff(const struct timeval *start, const struct timeval *end)
|
timeval_msec_diff(const struct timeval *start, const struct timeval *end)
|
||||||
{
|
{
|
||||||
@ -452,6 +454,8 @@ main(int argc, const char **argv)
|
|||||||
|
|
||||||
tinytest_set_aliases(testaliases);
|
tinytest_set_aliases(testaliases);
|
||||||
|
|
||||||
|
evutil_weakrand_seed_(&test_weakrand_state, 0);
|
||||||
|
|
||||||
if (tinytest_main(argc,argv,testgroups))
|
if (tinytest_main(argc,argv,testgroups))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -30,12 +30,13 @@
|
|||||||
|
|
||||||
#include "tinytest.h"
|
#include "tinytest.h"
|
||||||
#include "tinytest_macros.h"
|
#include "tinytest_macros.h"
|
||||||
|
#include "regress.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_random_timeout(struct event *ev)
|
set_random_timeout(struct event *ev)
|
||||||
{
|
{
|
||||||
ev->ev_timeout.tv_sec = rand();
|
ev->ev_timeout.tv_sec = test_weakrand();
|
||||||
ev->ev_timeout.tv_usec = rand() & 0xfffff;
|
ev->ev_timeout.tv_usec = test_weakrand() & 0xfffff;
|
||||||
ev->ev_timeout_pos.min_heap_idx = -1;
|
ev->ev_timeout_pos.min_heap_idx = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#include "event2/listener.h"
|
#include "event2/listener.h"
|
||||||
#include "event2/thread.h"
|
#include "event2/thread.h"
|
||||||
|
|
||||||
|
static struct evutil_weakrand_state weakrand_state;
|
||||||
|
|
||||||
static int cfg_verbose = 0;
|
static int cfg_verbose = 0;
|
||||||
static int cfg_help = 0;
|
static int cfg_help = 0;
|
||||||
@ -113,11 +114,7 @@ loud_writecb(struct bufferevent *bev, void *ctx)
|
|||||||
struct client_state *cs = ctx;
|
struct client_state *cs = ctx;
|
||||||
struct evbuffer *output = bufferevent_get_output(bev);
|
struct evbuffer *output = bufferevent_get_output(bev);
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
#ifdef _WIN32
|
int r = evutil_weakrand_(&weakrand_state);
|
||||||
int r = rand() % 256;
|
|
||||||
#else
|
|
||||||
int r = random() % 256;
|
|
||||||
#endif
|
|
||||||
memset(buf, r, sizeof(buf));
|
memset(buf, r, sizeof(buf));
|
||||||
while (evbuffer_get_length(output) < 8192) {
|
while (evbuffer_get_length(output) < 8192) {
|
||||||
evbuffer_add(output, buf, sizeof(buf));
|
evbuffer_add(output, buf, sizeof(buf));
|
||||||
@ -553,6 +550,8 @@ main(int argc, char **argv)
|
|||||||
(void) WSAStartup(wVersionRequested, &wsaData);
|
(void) WSAStartup(wVersionRequested, &wsaData);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
evutil_weakrand_seed_(&weakrand_state, 0);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "event2/event.h"
|
#include "event2/event.h"
|
||||||
#include "event2/event_compat.h"
|
#include "event2/event_compat.h"
|
||||||
#include "event2/event_struct.h"
|
#include "event2/event_struct.h"
|
||||||
|
#include "util-internal.h"
|
||||||
|
|
||||||
int called = 0;
|
int called = 0;
|
||||||
|
|
||||||
@ -48,14 +49,12 @@ int called = 0;
|
|||||||
|
|
||||||
struct event *ev[NEVENT];
|
struct event *ev[NEVENT];
|
||||||
|
|
||||||
|
struct evutil_weakrand_state weakrand_state;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rand_int(int n)
|
rand_int(int n)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
return evutil_weakrand_(&weakrand_state);
|
||||||
return (int)(rand() % n);
|
|
||||||
#else
|
|
||||||
return (int)(random() % n);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -93,6 +92,8 @@ main(int argc, char **argv)
|
|||||||
(void) WSAStartup(wVersionRequested, &wsaData);
|
(void) WSAStartup(wVersionRequested, &wsaData);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
evutil_weakrand_seed_(&weakrand_state, 0);
|
||||||
|
|
||||||
/* Initalize the event library */
|
/* Initalize the event library */
|
||||||
event_init();
|
event_init();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user