310 Commits

Author SHA1 Message Date
icy17
d1a90d09dc tests: Fix potential NULL pointer dereference 2024-08-12 10:02:04 +02:00
Cœur
5485887c47 Check against EVUTIL_INVALID_SOCKET 2024-07-08 10:20:47 +02:00
Andy Pan
ceb6551fa2 gcc: fix the -Wincompatible-pointer-types errors
---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-06-01 18:24:43 +02:00
icy17
74217832a8 Fix potential Null pointer dereference in regress.c 2024-04-15 10:26:11 +03:00
Azat Khuzhin
0dbd3eb3c9 tests: add test for EV_SIGNAL with timeout
Refs: https://github.com/libevent/libevent-book/issues/12
2024-02-19 22:07:32 +01:00
Azat Khuzhin
0ea2058252 test: add del_wait/del_notify tests for windows
Test manually, since CI is too slow
2023-02-12 21:54:45 +01:00
Dmitry Antipov
1af745d033 signal: new signal handling backend based on signalfd
Linux-specific signal handling backend based on signalfd(2)
system call, and public function event_base_get_signal_method()
to obtain an underlying kernel signal handling mechanism.

Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
2022-11-12 21:14:48 +01:00
Azat Khuzhin
6ad6afb646 test/regress: retry some signal rlated tests in darwin
CI: https://github.com/azat/libevent/runs/3643912290 # simplestsignal
CI: https://github.com/azat/libevent/runs/3643912296 # simplesignal
CI: https://github.com/azat/libevent/runs/3643912228 # multiplesignal
2021-09-19 12:26:14 +03:00
Nick Grifka
06a1192951 test: Fix test_simpleclose for Windows platform
Replace close with evutil_closesocket
Caught with PR #1006
2020-05-07 21:14:13 -07:00
Azat Khuzhin
972b456bf6 Fix EV_CLOSED detection/reporting (epoll only)
- EV_CLOSED is EPOLLRDHUP in epoll
- EPOLLRDHUP reported w/o EPOLLHUP if the socket closed with shutdown(SHUT_WR)
- EPOLLRDHUP reported w/  EPOLLHUP if the socket closed with close()
  so in this case epoll backend will detect this event as error
  (EV_READ|EV_WRITE), since the epoll_ctl() will return EPOLLRDHUP with
  EPOLLHUP set, but this is not correct, let's fix this.

Fixes: #984
2020-05-05 00:25:23 +03:00
Azat Khuzhin
ecb67f6189 test: cover EV_CLOSED with lots of possible scenarious
- trigger *RDHUP via close() <-- has issues
- trigger *RDHUP via shutdown()
- EV_CLOSED
- EV_CLOSED|EV_PERSIST
- EV_CLOSED|EV_ET <!-- has issues
- EV_CLOSED|EV_ET|EV_PERSIST
2020-05-04 23:58:28 +03:00
Azat Khuzhin
c81362b2ec test: rename simpleclose to simpleclose_rw (since it works via write/read) 2020-05-04 23:58:28 +03:00
Azat Khuzhin
f6d7992b05 test: mark common_timeout as retriable
Refs: https://github.com/libevent/libevent/pull/951#issuecomment-576711224
2020-01-24 07:52:06 +03:00
Azat Khuzhin
391003e9b7 test: use THREAD_* wrappers over pthread* in del_notify 2020-01-14 00:42:13 +03:00
Azat Khuzhin
4b72024b7f test: Use THREAD_* wrappers in del_notify/del_wait 2020-01-13 23:36:19 +03:00
Tobias Stoeckmann
9b2060c97a Added test for evmap slot validations.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2019-04-27 11:47:23 +02:00
John Ohl
62df1301ca
Add support for EV_TIMEOUT to event_base_active_by_fd
Closes: #194 (cherry-pick)
2019-03-03 23:42:03 +03:00
Azat Khuzhin
14eb903ba3
Revert "test: avoid regress hanging in macOS"
After we started to use kill() over raise() everything should work just
fine.

This reverts commit a86f89d333d870e6714bd28c695ba1774df3d7f5.

Fixed-in: 728c5dc1 ("Use kill() over raise() for raising the signal (fixes osx 10.14 with kqueue)")
Fixes: #747
2019-02-24 17:28:36 +03:00
Azat Khuzhin
728c5dc11f
Use kill() over raise() for raising the signal (fixes osx 10.14 with kqueue)
On OSX 10.14+ the raise() uses pthread_kill() (verified with dtruss) and
by some reason signals that has been raised with pthread_kill() do not
received by kqueue EVFILT_SIGNAL.

While on OSX 10.11 the raise()/pthread_kill() uses plain kill() and
everything work just fine (linux also does the same, but instead of
kill() it uses tgkill())

Here is a simple reproducer that installs alarm to show that the signal
does not received by the kqueue backend:
  https://gist.github.com/azat/73638b8e3b0fa563a20dadcca9e652a1

Refs: #747
Fixes: #765
2019-02-24 17:18:11 +03:00
Azat Khuzhin
b29207dcee
Eliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows)
windows has intptr_t instead of regular int.

Also tt_fd_op() had been introduced, since we cannot use tt_int_op() for
comparing fd, since it is not always int.
2019-01-29 22:03:08 +03:00
Azat Khuzhin
91a2f1346e
test/nonpersist_readd: use assert helpers
To debug failure under win32 in appveyor:
  https://ci.appveyor.com/project/nmathewson/libevent/builds/21559140/job/dn16qdo1j6sr497t#L1620
2019-01-12 14:14:51 +03:00
Azat Khuzhin
fe5b07199d
Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)
This patch mark testcases that only fail under travis-ci/appveyor with
TT_RETRIABLE, since otherwise there is too much noise, other issues
(like failures under vagrant boxes) would be investigated separatelly.

linux (from travis-ci only):
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_by_host_ns_timeout
- http/cancel_by_host_ns_timeout_inactive_server
- thread/conditions_simple
- util/monotonic_prc_precise
- util/usleep
- main/del_wait

vagrant/ubuntu box (this is the only exception):
- thread/no_events

win32 (from appveyor only):
- main/active_later
- main/persistent_active_timeout

And we should use TT_RETRIABLE over TT_OFF_BY_DEFAULT/TT_SKIP when it
make sense.

But there is still "test-ratelim__group_lim" left.
2018-11-20 23:02:56 +03:00
Azat Khuzhin
4cbdb39c27
regress: use non blocking descriptors whenever it is possible
Next tests uses fds without O_NONBLOCK flag
- main/free_active_base
- main/many_events
- et/et (has some other bits cleaned up by using TT_* flags and test
  setup/cleanup callbacks)

And hence they will fail in debug mode (EVENT_DEBUG_MODE=):
  Assertion flags & O_NONBLOCK failed in event_debug_assert_socket_nonblocking_
2018-11-04 01:15:24 +03:00
Azat Khuzhin
23c2914f6b Notify event base if there are no more events, so it can exit without delay
Fixes: #623
2018-04-26 01:14:49 +03:00
Vincent JARDIN
56010f37ae test: fix warning
In function ‘send_a_byte_cb’:
test/regress.c:1853:2: warning: ignoring return value of ‘write’, declared with
attribute warn_unused_result [-Wunused-result]
  (void) write(*sockp, "A", 1);
2017-09-11 21:56:30 +02:00
Carlo Marcelo Arenas Belón
a86f89d333 test: avoid regress hanging in macOS
a backtrace of the process without this patch :
  * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    * frame #0: 0x00007fffb1fb7d96 libsystem_kernel.dylib`kevent + 10
      frame #1: 0x0000000108ed0a58 libevent-2.2.1.dylib`kq_dispatch + 696
      frame #2: 0x0000000108ec53d8 libevent-2.2.1.dylib`event_base_loop + 696
      frame #3: 0x0000000108e1763b regress`test_fork + 1931
      frame #4: 0x0000000108e5c7ad regress`run_legacy_test_fn + 45
      frame #5: 0x0000000108e690aa regress`testcase_run_one + 858
      frame #6: 0x0000000108e6954f regress`tinytest_main + 495
      frame #7: 0x0000000108e5c94b regress`main + 171
      frame #8: 0x00007fffb1e88235 libdyld.dylib`start + 1
      frame #9: 0x00007fffb1e88235 libdyld.dylib`start + 1

Issue: #546
2017-09-11 01:48:35 +03:00
Azat Khuzhin
5ff83989f3 test: cover that after event_del() callback will not be scheduled again
Refs: #236
Refs: #225
2017-04-30 01:35:03 +03:00
Azat Khuzhin
a4b1828d6d test: windows doesn't have WNOWAIT
Fixes: 66a4eb0c3ae3b1f22b084b2d3aeb5c872f37efbd ("Check for WNOWAIT in
waitpid() in runtime (not in cmake/configure)")
2017-03-14 00:04:26 +03:00
Azat Khuzhin
66a4eb0c3a Check for WNOWAIT in waitpid() in runtime (not in cmake/configure)
Because checking in cmake breaks cross-compiling.

Introduced-in: 43eb56c7c738e3642f0981e3dd6ab9e082eec798.
Fixes: #482
Fixes: #462
Refs: #475

v2: use waitid() with WNOWAIT
v3: use WNOWAIT only if it available in waitpid(), because not all netbsd
    supports it
2017-03-08 13:31:55 +03:00
Tim Hentenaar
cb0df5cfac test/regress: cover a polling of invalid fd
Test that an event's callback is called if the fd is closed prior to being
polled for activity.

azat: make it run only for poll backend/method, and do not close fd
twice
2016-11-04 03:28:42 +03:00
Azat Khuzhin
43eb56c7c7 tests: use waitpid(..., WNOWAIT) to fix failing of main/fork under solaris
According to solaris docs:
  "One instance of a SIGCHLD signal is queued for each child process whose
  status has changed. If waitpid() returns because the status of a child
  process is available, and WNOWAIT was not specified in options, any pending
  SIGCHLD signal associated with the process ID of that child process is
  discarded. Any other pending SIGCHLD signals remain pending."

And interesting thing that it works if you add sleep(1) before waitpid(), and
also if you run with --verbose (some race or what).

But linux doesn't support WNOWAIT in waitpid() so add detection into
cmake/autotools.

Fixes: #387
Link: https://bugzilla.redhat.com/show_bug.cgi?id=840782
2016-08-11 17:08:35 +03:00
Azat Khuzhin
16d220cb6f test: replace sleeping with syncing pair in main/fork
About this syncing pair:
- read endpoint, must be blocked, to make it a checkpoint or smth like this
- write endpoint, must be nonblocking, to avoid readcb hung

Refs: #387
2016-08-11 16:18:12 +03:00
Azat Khuzhin
04fc82f7ad test: use EVUTIL_SHUT_WR 2016-03-11 01:28:43 +03:00
Nick Mathewson
4f778ab6d7 Add missing return statement to del_wait_thread so libevent can build. 2016-01-22 11:16:05 -05:00
Azat Khuzhin
5b58b709b2 test/regress: cover event_del() waiting mechanism
Since we have some issues (see refs) for changing waiting order in event_del()
I wrote this simple test, so maybe this test can explain something or at least
cover what we have before and show it will be broken.

P.S. we really need avoid such stuff like lets-test-with-sleep/usleep.

Refs: #225
Refs: #226
Refs: #236
2016-01-03 00:46:47 +03:00
Azat Khuzhin
ceddc607ca test/regress: cover existing signal callbacks and fork() + event_reinit()
Regression-for: 88640aa ("event_reinit: make signals works after fork() without
evsig_add()")
2015-12-27 09:30:10 +03:00
Azat Khuzhin
b075b81cd3 test/regress: cover signals after fork() + event_reinit()
Regression-for: ad0c237 ("event_reinit: always re-init signal's socketpair")
2015-12-27 09:29:57 +03:00
Azat Khuzhin
088d8b39f9 test/regress: main/fork: rewrite assertions by just removing event in callback
Instead of assigning some variable value (got_child), and schedule exit from
loop from that callback, just remove event for that signal, and event loop will
exit automatically when there will be no events.
2015-12-27 09:28:07 +03:00
Ed Schouten
fd36647af1 Don't use BSD u_* types.
These types are not part of POSIX. As we only use them in a small number
of places, we'd better replace them by C standard types. This makes a
larger part of the code build for CloudABI.
2015-08-25 19:15:50 +03:00
Nick Mathewson
89c1a3b7fe Fix several memory leaks in the unit tests.
Also add a comment to buffer.c about why we call
evbuffer_file_segment_free on failure to add the segment.
2014-09-18 12:40:38 -04:00
Nick Mathewson
a677b72bd6 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.
2014-09-18 12:02:13 -04:00
Azat Khuzhin
b897beff6a test/regress: add simplestsignal: to track reorder bugs separately 2014-06-29 17:39:33 +04:00
Nick Mathewson
c2076824a3 Fix a c90 warning 2014-01-21 12:21:37 -05:00
Nick Mathewson
867f401f9b Fix a pile of coverity warnings in the unit tests
Most of these problems can only trigger when the tests fail, but it's
good hygiene to keep the code warning-free in any case.
2014-01-08 11:51:22 -05:00
Nick Mathewson
f9e091bf4e Merge remote-tracking branch 'asweeny86/event-count-max' 2014-01-06 12:11:30 -05:00
Andrew Sweeney
26230a2d21 Added unit test for max event counts 2014-01-05 16:30:35 -05:00
Nick Mathewson
87fa2b004a Unit tests for active_by_fd; unsupport active_by_fd(TIMEOUT)
[It turns out that event_base_active_by_fd(TIMEOUT) didn't actually
work right. Feel free to add it back in as a patch.]
2013-12-23 20:46:38 -05:00
Nick Mathewson
1104d0bee9 Fix a (failure-only) null dereference in the unit tests 2013-08-06 19:31:26 -04:00
Nick Mathewson
7080d55c49 Use void casts to suppress some "unchecked return value" warns 2013-08-06 19:28:53 -04:00
Mobai Zhang
0fa107d8cb Added event_base_get_num_events() 2013-07-02 16:01:02 -04:00