170 Commits

Author SHA1 Message Date
Nick Mathewson
d84d8385cd Fix two use-after-free bugs in unit tests spoted by lock debugging 2009-11-27 17:36:51 -05:00
Nick Mathewson
9bf124bff6 Build correctly with mm replacement turned off.
svn:r1547
2009-11-18 21:16:47 +00:00
Nick Mathewson
b2fe4aedaa Unit tests for got_break and got_exit.
svn:r1521
2009-11-09 18:36:34 +00:00
Nick Mathewson
693c24ef9d Implement queued timeouts for case where many timeouts are the same.
Libevent's current timeout code is relatively optimized for the
randomly scattered timeout case, where events are added with their
timeouts in no particular order.  We add and remove timeouts with
O(lg n) behavior.

Frequently, however, an application will want to have many timeouts
of the same value.  For example, we might have 1000 bufferevents,
each with a 2 second timeout on reading or writing.  If we knew this
were always the case, we could just put timeouts in a queue and get
O(1) add and remove behavior.  Of course, a queue would give O(n)
performance for a scattered timeout pattern, so we don't want to
just switch the implementation.

This patch gives the user the ability to explicitly tag certain
timeout values as being "very common".  These timeout values have a
cookie encoded in the high bits of their tv_usec field to indicate
which queue they belong on.  The queues themselves are each
triggered by an entry in the minheap.

See the regress_main.c code for an example use.

svn:r1517
2009-11-09 17:16:30 +00:00
Nick Mathewson
784b8773a4 We do not work any more without an event-config.h; stop pretending that it is meaningful to check for HAVE_CONFIG_H
svn:r1516
2009-11-06 21:46:57 +00:00
Nick Mathewson
0fd0255fa4 Remove compat/sys/_time.h
I've gone through everything that it declared to see where it was used,
and it seems that we probably don't need it anywhere.

Here's what it declared, and why I think we're okay dropping it.

o struct timeval {}
  (Used all over, and we can't really get away with declaring it ourselves;
  we need the same definition the system uses.  If we can't find struct
  timeval, we're pretty much sunk.)

o struct timespec {}
  (Used in event.c, evdns.c, kqueue.c, evport.c.  Of these,
   kqueue.c and event.c include sys/_time.h.  event.c conditions its use on
   _EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.)

o TIMEVAL_TO_TIMESPEC
  (Used in kqueue.c, but every place with kqueue has sys/time.h)

o struct timezone {}
  (event2/util.h has a forward declaration; only evutil.c references it and
   doesn't look at its contents.)

o timerclear, timerisset, timercmp, timeradd, timersub
  (Everything now uses the evutil_timer* variants.)

o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval
  (These are only used in test/regress.c, which does not include _time.h)

o CLOCK_REALTIME
  (Only used in evdns.c, which does not include _time.h)

o TIMESPEC_TO_TIMEVAL
o DST_*
o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub
o struct clockinfo {}
o CLOCK_VIRTUAL, CLOCK_PROF
o TIMER_RELTIME, TIMER_ABSTIME
  (unused)

svn:r1494
2009-11-03 19:54:56 +00:00
Nick Mathewson
96c6956e02 Add a "many events" regression test.
This is a glass-box test to get more coverage on the event loop
backends.  We've run into bugs here before with fencepost errors, and
it turns out that none of our unit tests had enough events to
exercise the resize code.

Most of the backends have some kind of logic that resizes an array
when:
    - The highest fd is too high
    - The number of events added since the last iteration of the loop
      is too high
    - The number of active events is too high.

This test hits all 3 cases, and increases coverage in select.c by 7%,
in poll by 1%, and in kqueue by 9%.

svn:r1482
2009-10-30 22:43:30 +00:00
Nick Mathewson
5b3fb5bfa5 More documentation and unit tests for event_tagging.
svn:r1476
2009-10-29 16:35:20 +00:00
Nick Mathewson
904b5721cb Avoid calling exit() during event_base_new*()
Previously, each of the three make-an-event-base functions would exit
under different, weird circumstances, but return NULL on others.
  - All three would exit on OOM sometimes.
  - event_base_new() and event_init() would die	if all backends	were
    disabled.
  - None of them would die if the socketpair() call failed.

Now, only event_init() exits on failure, and it exits on every kind of
failure.  event_base_new() and event_base_new_with_config() never do.

svn:r1472
2009-10-27 06:47:25 +00:00
Nick Mathewson
e9ee1057e6 Give event_assign a return value, and make it less inclined to exit().
We also refactor event_assign so that it is the core function, and
event_set() is only the wrapper.

svn:r1469
2009-10-27 04:25:45 +00:00
Nick Mathewson
ba8a17714e Do not notify the main thread more than needed.
Basically, we suppress the notification when an event is added or deleted
and:
  - The event has no fd, or there is no change in whether we are
    reading/writing on the event's fd.
  - The event has no timeout, or adding the event did not make the earliest
    timeout become earlier.

This should be a big efficiency win in applications with multiple threads and
lots of timeouts.

svn:r1439
2009-10-02 03:03:58 +00:00
Nick Mathewson
8cc6883524 Fix the main/methods unit test to pass from "make verify".
The problem was introduced when we changed the semantics of
get_supported_methods() to reflect all the methods that exist.
Previously, it had not returned methods disabled from the environment,
but the test didn't know that.

svn:r1379
2009-07-25 03:35:32 +00:00
Nick Mathewson
49de08ef35 Push coverage of event.c a little higher
svn:r1373
2009-07-21 19:20:44 +00:00
Nick Mathewson
f4775918cd Refactor evtag tests into their own suite.
svn:r1366
2009-07-20 14:55:51 +00:00
Nick Mathewson
e8400a43ca Rename encode_int(64) to avoid polluting the global namespace.
They're now called evtag_encode_int(64).  The old names are available
as macros in event2/tag_compat.h.

Also, add unit tests for encode/decode_int64.

svn:r1365
2009-07-20 14:55:35 +00:00
Nick Mathewson
5d71b25b51 Remove all trailing whitespace from end-of-line.
svn:r1350
2009-07-17 18:38:38 +00:00
Nick Mathewson
d4e3671fb4 Add a test to free_active_base to free a base with an active event.
svn:r1349
2009-07-17 18:38:21 +00:00
Nick Mathewson
e224321c64 Convert and expand free_active_base/event_base_new tests to avoid dbl-free. Patch from Zack Weinberg
svn:r1342
2009-07-14 18:49:42 +00:00
Nick Mathewson
b45cead762 Make environment-variable tests work on win32, which has only one method and lacks (un)setenv.
svn:r1253
2009-04-30 18:05:33 +00:00
Nick Mathewson
586aa46886 Unit test for disabling events with EVENT_NO*, and for EVENT_BASE_FLAG_IGNORE_ENV.
svn:r1247
2009-04-28 19:08:27 +00:00
Nick Mathewson
d70b080488 Make main/methods test pass on systems where only one backend exists.
svn:r1235
2009-04-23 18:08:42 +00:00
Nick Mathewson
0068c98ad2 Make version test ignore the bottom byte of the version number.
svn:r1225
2009-04-23 00:01:14 +00:00
Nick Mathewson
b21be24545 Somehow free_active_base was using the socketpair, but not saying it needed it. How did this ever work?
svn:r1223
2009-04-23 00:00:55 +00:00
Nick Mathewson
1f9c9e5137 Add a missing "static".
svn:r1219
2009-04-22 15:38:50 +00:00
Nick Mathewson
133a015dba Make sure the test case for mem_functions hits strdup too.
svn:r1218
2009-04-21 18:48:05 +00:00
Nick Mathewson
7f1855d064 Add a basic test for set_mem_functions
svn:r1216
2009-04-21 18:47:35 +00:00
Nick Mathewson
386279d051 Add a test for event_pending; especially the timeout part.
svn:r1214
2009-04-21 18:47:02 +00:00
Nick Mathewson
ff1f429510 Unit tests for event_base_once.
svn:r1213
2009-04-21 18:46:43 +00:00
Nick Mathewson
ea664bf29a Refactor test wrappers to divide legacy items from useful stuff.
svn:r1212
2009-04-21 18:46:30 +00:00
Nick Mathewson
122e934e92 Add unit tests for version methods and feature-based backend selection
svn:r1211
2009-04-21 18:46:11 +00:00
Nick Mathewson
7cf8a7b0e0 Call the main testcases "main", not "legacy".
svn:r1210
2009-04-21 18:45:59 +00:00
Nick Mathewson
a8f6d961eb Actually stop using EVBUFFER_LENGTH/DATA, and move them to buffer_compat.h
svn:r1183
2009-04-17 06:56:09 +00:00
Nick Mathewson
68d0139f19 Refactor the zlib and pthreads tests to appear in the regular tinytest tree structure.
svn:r1141
2009-04-07 04:49:25 +00:00
Nick Mathewson
71604d85be Remove some needless includes
svn:r1104
2009-02-10 19:38:25 +00:00
Nick Mathewson
f9e4e0f98e Move bufferevent tests to regress_bufferevent.c file.
svn:r1101
2009-02-03 18:28:53 +00:00
Nick Mathewson
ea4b8724c0 checkpoint work on big bufferevent refactoring
svn:r1095
2009-02-02 19:22:13 +00:00
Nick Mathewson
a30c9eb1ac Move evbuffer tests into their own file.
svn:r1087
2009-02-01 01:07:12 +00:00
Nick Mathewson
12e8db5b23 Convert evtag test.
svn:r1085
2009-01-31 18:36:47 +00:00
Nick Mathewson
5831d11a42 Move rpc_test to regress_rpc.
svn:r1084
2009-01-31 18:36:37 +00:00
Nick Mathewson
fa6ae16992 Convert RPC suite. There are still some places it can exit(1), but those always run forked, so no big deal.
svn:r1083
2009-01-31 18:36:24 +00:00
Nick Mathewson
eac75f91e4 Port DNS tests.
svn:r1081
2009-01-31 07:32:14 +00:00
Nick Mathewson
153093ecc3 Port the HTTP unit tests. Most are still legacy (since they use test_ok so much), but at least they no longer exit(1) on failure
svn:r1076
2009-01-30 17:44:13 +00:00
Nick Mathewson
241690b230 Move util tests to regress_util.c
svn:r1075
2009-01-30 17:43:59 +00:00
Nick Mathewson
4e9470b481 Convert test_evutil_strtoll to new framework.
svn:r1074
2009-01-30 17:43:48 +00:00
Nick Mathewson
a8203b3490 Refactor unit tests using my spiffy new "tinytest" framework.
The big win here is that we can get process-level isolation.

This has been tested to work okay on at least Linux and Win32.  Only
the tests in regress.c have been converted wrapped in the new wrapper
functions; the others are still on the old system.

svn:r1073
2009-01-29 23:19:57 +00:00
Nick Mathewson
cc7a53c152 fix signed/unsigned warning in unit tests. can we just use "char*" on all new APIs? this void/unsigned char*/char* business is awful.
svn:r1071
2009-01-29 18:15:36 +00:00
Nick Mathewson
7dd362b158 Have util-internal.h define socklen_t if we need it, and include it appropriately. This fixes win32 compilation.
svn:r1070
2009-01-29 15:09:24 +00:00
Niels Provos
66b2a7ffb7 test evbuffer_add_reference
svn:r1068
2009-01-29 03:20:40 +00:00
Nick Mathewson
b85b710cf5 Update copyright statements to reflect the facts that:
a) this is 2009
b) niels and nick have been comaintainers for a while
c) saying "all rights reserved" when you then go on to explicitly
   disclaim some rights is sheer cargo-cultism.

svn:r1065
2009-01-27 22:34:36 +00:00
Nick Mathewson
8889a77039 Replace all use of config.h with event-config.h.
svn:r1064
2009-01-27 22:30:46 +00:00