513 Commits

Author SHA1 Message Date
Nick Mathewson
b2c6202d65 Fix an assertion bug in test-ratelim
If the rate limit was low enough, then the echo_conns wouldn't finish
inside the 300 msec we allowed for them to close.  Instead, count the
number of connections we have, and keep waiting until they are all
closed.
2010-08-04 15:52:32 -04:00
Nick Mathewson
42f6b62414 Add option to test-ratelim to test min_share 2010-08-04 15:51:14 -04:00
Nick Mathewson
42a8c71112 Build more cleanly with NetBSDs that dislike toupper(char)
To be fair, when char can be signed, if toupper doesn't take negative
characters, toupper(char) is a very bad idea.  So let's just use the
nice safe EVUTIL_TOUPPER instead.  (It explicitly only upcases ASCII,
but we only use it for identifiers that we know to be ASCII anyway).
2010-07-31 17:10:04 -04:00
Joachim Bauch
840a72fbd5 Fix badly-behaved subtest of dns/bufferevent_connect_hostname
The bufferevent_connect_hostname test was specifying AF_INET, but the
gethostbyname test we were using to see what error to expect was using
PF_UNSPEC, leading to possible divergence of results.
2010-07-29 20:32:40 -04:00
Nick Mathewson
7c926916b2 Make test/test.sh call test-changelist
Eventually test-changelist should expand to try more cases, maybe
query the status of the actual changelist somehow, and integrate it
with the rest of the unit tests.

Also, add test-changelist to gitignore.
2010-07-19 15:16:29 +02:00
Nick Mathewson
cb927a5173 Fix whitespace. 2010-07-19 15:03:43 +02:00
Nick Mathewson
b00d4c0452 Remove unused variables in test/test-changelist.c 2010-07-19 14:58:08 +02:00
Mike Smellie
cf249e7d99 Possible fix to 100% cpu usage with epoll and openssl
I'm running a fairly simple bit of test code using libevent2 with epoll and
openssl bufferevents and I've run into a 100% cpu usage problem.

Looking into it 100% usage was caused by epoll_wait constantly
returning write events on the openssl socket when it shouldn't really have
been looking for write events at all (N_ACTIVE_CALLBACKS() was returning 0
also).

Looking a bit deeper eventbuffer_openssl socket seems to be requesting
that the EV_WRITE event be removed when it should, but the event isn't
actually being removed from epoll.

Continuing to follow this I think I've found a bug in
event_changelist_del.

For evpoll event_del calls event_changelist_del which caches the change
which is then actioned later when evpoll_dispatch is called.

In event_changlist_del there is a check so that if the currently changed
action is an add then the cached action is changed to a no-op rather than a
delete (which makes sense). The problem arises if there are more than
two add or delete operations between calls to dispatch, in this case it's
possible that the delete is turned into a no-op when it shouldn't have
been.

For example starting with the event on, a delete followed by an add and
then another delete results in a no-op when it should have been a delete (I
added a fair bit of debug output that seems to confirm this behaviour).

I've applied a small change that checks the original old_event stored with
the change and only converts the delete to a no-op if the event isn't on in
old_event. This seems to have fixed my problem.
2010-07-19 14:55:15 +02:00
Nick Mathewson
7510aac3b9 Unit test for event_get_struct_event_size() 2010-06-21 12:23:32 -04:00
Nick Mathewson
17a8e2d72b Add a function to retrieve the other side of a bufferevent pair 2010-06-07 12:06:43 -04:00
Nick Mathewson
44d57eee93 Add test for behavior on remote socket close
On all the backends on this little mac laptop, that behavior is to
report a remote socket close as both EV_READ and EV_WRITE.
Historically, we had problem for some of these behaviors on some
backends, so let's make sure that such behaviors don't come back.
2010-06-03 11:25:54 -04:00
Nick Mathewson
3689bd2d49 Have the unit tests report errors from test.sh
The default behavior of test.sh was to suppress all output from
test/regress, and say nothing but OKAY or FAILED.  This wasn't so good
for getting bugs reported, since lots of people didn't know to set
TEST_OUTPUT_FILE, or re-run ./test/regress on its own.

Now, when you don't specify an output file for test.sh, it runs
regress with the --quiet option.  This option makes the unit tests
only print output on failure, which is what we probably wanted.
2010-05-26 13:43:01 -04:00
Nick Mathewson
faf2a04fa5 Make test.sh exit with nonzero status if tests fail
This behavior makes "make verify" actually fail when the tests fail,
which is what it's supposed to do.
2010-05-26 13:43:01 -04:00
Nick Mathewson
8bc1e3d6d1 Remove all non-error prints from test/regress.c
Now, running ./test/regress --quiet will indeed only inform you
about errors.  Previously, it would also spew extra output.
2010-05-26 13:43:00 -04:00
Nick Mathewson
e73f1d792a Remove the now-obsolete setup_test() and cleanup_test() functions 2010-05-26 13:43:00 -04:00
Nick Mathewson
bda21e7ff9 Avoid close of uninitialized socket in evbuffer unit test
Attempts to fix a crash bug found by Brodie Thiesfield.
2010-05-17 11:58:07 -04:00
Nick Mathewson
75701e897b Add some missing includes to fix Linux build again 2010-05-14 14:30:09 -04:00
Nick Mathewson
b5bfc44d6b Make test-ratelim clean up after itself better. 2010-05-13 15:40:43 -04:00
Nick Mathewson
2b44dccaaf Add options to test-ratelim.c to check its results
The new options let you specify a maximum deviation of bandwidth used
from expected bandwidth used, and make test-ratelim.c exit with a
nonzero status when those deviations are violated.

This patch also adds a test-ratelim.sh script to run test-ratelim with
a few sensible options for testing.
2010-05-13 15:40:43 -04:00
Nick Mathewson
33bbbed9dd Mark the event_err() functions as __attribute__((noreturn))
This attribute tells gcc (and anything else that understands gcc
attributes) that the functions will never return control, and helps
the optimizer a little.  With luck, it will also tell
less-than-full-program dataflow analysis tools that they don't need to
worry about any code path that involves calling one of these functions
and then returning.

This patch also forces event_exit() to always exit, no matter what the
user-supplied fatal_callback does.  This means that the old unit tests
for the event_err* functions don't work any more, since they assume it
is safe to call event_err* if you've given it a bogus fatal_callback
that doesn't exit.  Instead, we have to make the unit tests fork
before calling event_err(), and have the main unit test process wait
for the event_err() test to exit with a sane exit code.  On unix,
that's trivial.  On windows, let's not bother and just assume that
event_err* works.
2010-05-13 15:39:02 -04:00
Nick Mathewson
dfb75ab207 Test the unlocked-deferred callback case of bufferevents 2010-05-12 15:38:28 -04:00
Nick Mathewson
3d9e05b174 Fix test.sh on freebsd
It turns out that in all conformant shells, "unset FOO" removes FOO
both from the shell's variables and from the exported environment.
(I've tested this on msys, opensolaris, linux, osx, and freebsd.)

And in nearly every shell I can find, "unset FOO; export FOO" does
the same as unset FOO... except in my FreeBSD VM, where the "export
FOO" sets the exported value of FOO equal to "".  This broke test.sh
for us.

The fix is simple: remove the needless exports!
2010-05-08 19:56:25 -04:00
Nick Mathewson
0ee6f6ce80 Make test.sh support mingw/msys on win32
This required:
   - Adding another WIN32 section in test.sh
   - not running "touch /dev/null"
   - calling WSAStartup in all the test binaries
   - Fixing a dumb windows-only bug in test-time.c
2010-05-08 19:38:30 -04:00
Nick Mathewson
f89168e7ea Make test for bufferevent_connect_hostname system-neutral
Previously, the be5_outcome field for the dns error would be set to
something dependent on our system resolver.  It turns out that you
can't rely on nameservers to really give you an NEXIST answer for
xyz.example.com nowadays: too many of them are annoyingly broken and
like to redirect you to their locked-in portals.  This patch changes
the bufferevent_connect_hostname test so that it makes sure that the
dns_error of be5_outcome is "whatever you would get from resolving
the target hostname"
2010-05-08 19:15:35 -04:00
Nick Mathewson
88a543fc19 Make unit test for add_file able to tell "error" from "done"
Importantly, we don't actually want to call evbuffer_write() when
the buffer is empty.  This makes it an error to ever get a -1 return
value from evbuffer_add_file(), which makes it safe for us to test
the return value.
2010-05-08 19:15:35 -04:00
Nick Mathewson
384d124581 Fix bench_http build on win32. 2010-05-08 17:15:52 -04:00
Nick Mathewson
05de45d63f add more (currently skipped) add_file tests on win32 2010-05-08 16:47:17 -04:00
Nick Mathewson
dcdae6b743 Make evbuffer_add_file() work on windows
Right now only the add_file() mode is supported, when it would be
nicer to have mmap support.  Perhaps for Libevent 2.1.x.
2010-05-08 16:34:18 -04:00
Nick Mathewson
b4f12a17aa Implement regress_make_tempfile on win32 to test evbuffer_add_file
(Conclusion: evbuffer_add_file is broken on win32, since it
uses recv on a file.)
2010-05-08 16:14:20 -04:00
Nick Mathewson
f37cd4c227 Detect broken unsetenv at unit-test runtime
If we have an unsetenv function that doesn't work, we can't run the
main/base_environ unit test, so we should skip it.
2010-05-08 14:36:59 -04:00
Nick Mathewson
a62c843340 Merge commit 'chrisd/connect-hostname-report-err' 2010-05-06 14:16:50 -04:00
Nick Mathewson
c16e68448c Rename current_base symbol to event_global_current_base_
The "current_base" symbol was never actually declared in an exported
header; it's hideously deprecated, and it was the one remaining
exported symbol (fwict) that was prefixed with neither ev nor
bufferevent nor _ev nor _bufferevent.

codesearch.google.com turns up no actual attempts to use our
current_base from outside libevent.
2010-05-04 13:27:36 -04:00
Nick Mathewson
cb6707405c Make debug mode catch mixed ET and non-ET events on an fd
Of the backends that support edge-triggered IO, most (all?) do not
support attempts to mix edge-triggered and level-triggered IO on the
same FD.  With debugging mode enabled, we now detect and refuse attempts
to add a level-triggered IO event to an fd that already has an
edge-triggered IO event, and vice versa.
2010-04-28 12:20:18 -04:00
Christopher Davis
0ef407065e Report DNS error when lookup fails during bufferevent_socket_connect_hostname. 2010-04-24 00:06:38 -07:00
Nick Mathewson
96730d3191 Make http_base_test stop leaking an event_base. 2010-04-23 23:13:26 -04:00
Nick Mathewson
b1c795007f Make evdns logging threadsafe
The old logging code was littered with places where we stored messages in
static char[] fields.  This is fine in a single-threaded program, but if you
ever tried to log evdns messages from two threads at once, you'd hit a race.

This patch also refactors evdns's debug_ntop function into a more useful
evutil_sockaddr_port_format() function, with unit tests.
2010-04-23 14:42:25 -04:00
Christopher Davis
39b870b8a0 Add dns/search_cancel unit test. 2010-04-22 21:49:05 -07:00
Sebastian Sjöberg
899c1dcc98 Replace EVUTIL_CLOSESOCKET macro with a function
The EVUTIL_CLOSESOCKET() macro required you to include unistd.h in your
source for POSIX.  We might as well turn it into a function: an extra
function call is going to be cheap in comparison with the system call.

We retain the EVUTIL_CLOSESOCKET() macro as an alias for the new
evutil_closesocket() function.

(commit message from email by Nick and Sebastian)
2010-04-14 15:42:57 -04:00
Giuseppe Scrivano
10c4c90450 Do not inhibit automake dependencies generation
It fixes make parallel builds.
2010-04-13 02:01:04 -04:00
Nick Mathewson
1234b95a75 Test another case of evbuffer_prepend 2010-04-09 17:19:39 -04:00
Nick Mathewson
8c83e99579 Add more unit tests for evbuffer_expand 2010-04-09 16:40:53 -04:00
Nick Mathewson
06a4443abe Unit-test every evbuffer_add_file() implementation.
Previously, we'd only test the default one, even if the others were still
compiled in.
2010-04-09 15:28:26 -04:00
Nick Mathewson
d5ebcf370d Rewrite evbuffer_expand and its users
The previous evbuffer_expand was not only incorrect; it was
inefficient too.  On all questions of time vs memory tradeoffs, it
chose to burn time in order to avoid wasting memory.  The new code
tries to be a little more balanced: it only resizes an existing chain
when doing so doesn't require too much copying, and when failing to do
so would waste a lot of the chain's space.

This patch also rewrites evbuffer_chain_insert to work properly with
last_with_datap, and adds a few convenience functions to buffer.c.
2010-03-31 12:53:20 -04:00
Nick Mathewson
b7442f8e83 Replace last_with_data with a slightly smarter version
To implement evbuffer_expand() properly, you need to be able to
replace the last chunk that has data, which means that we need to keep
track of the the next pointer pointing to the last_with_data chunk,
not the last_with_data chunk itself.
2010-03-31 12:50:32 -04:00
Nick Mathewson
7960af5113 Merge branch 'build' 2010-03-22 13:37:39 -04:00
Nick Mathewson
b557b175c0 Detect and refuse reentrant event_base_loop() calls
Calling event_base_loop on a base from inside a callback invoked by
that same base, or from two threads at once, has long been a way to
get exceedingly hard-to-diagnose errors.  This patch adds code to
detect such reentrant invocatinos, and exit quickly with a warning
that should explain what went wrong.
2010-03-21 13:28:48 -04:00
Nick Mathewson
33874b0528 Make 'main/many_events' test 70 fds, not 64.
This is mainly intended to ensure that we don't get hung up on
the 64-handle limit that lots of O(n) Windows functions (but FWICT
not select) like to enforce.
2010-03-16 13:37:15 -04:00
Nick Mathewson
274a7bd9a1 Fix some memory leaks in the unit tests
These don't matter except inasmuch as they give real memory leaks
a place to hide.

Found with valgrind
2010-03-13 00:56:07 -05:00
Nick Mathewson
68dc742bf1 Fix a write of uninitialized RAM in regression tests
Not actually harmful, but not something we should be doing.

Found by valgrind.
2010-03-13 00:31:14 -05:00
Nick Mathewson
0d047c3f11 Fix an obnoxious typo in the bufferevent_timeout_filter test
We were using the same bufferevent as the child of two filtering parents,
orphaning another.  This made one get freed twice, and the other not at all.

Possible fix for bug 2963306 spotted by Doug Cuthbertson.
2010-03-13 00:29:15 -05:00