vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Thu Jun 15 22:27:19 2017 +0300| [d6ab70fc71a5d78f34ce4b5bf19ac216002037f0] | committer: Rémi Denis-Courmont
interrupt: extend test cases > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d6ab70fc71a5d78f34ce4b5bf19ac216002037f0 --- src/test/interrupt.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/test/interrupt.c b/src/test/interrupt.c index d58b52160c..6b1bffbdf0 100644 --- a/src/test/interrupt.c +++ b/src/test/interrupt.c @@ -30,12 +30,20 @@ #include <vlc_common.h> #include <vlc_threads.h> #include <vlc_interrupt.h> +#include <vlc_network.h> static vlc_sem_t sem; +static int fds[2]; + +static void interrupt_callback(void *data) +{ + vlc_sem_post(data); +} static void test_context_simple(vlc_interrupt_t *ctx) { vlc_interrupt_t *octx; + char c; vlc_interrupt_set(ctx); octx = vlc_interrupt_set(NULL); @@ -45,6 +53,11 @@ static void test_context_simple(vlc_interrupt_t *ctx) octx = vlc_interrupt_set(ctx); assert(octx == ctx); + vlc_interrupt_register(interrupt_callback, &sem); + vlc_interrupt_raise(ctx); + vlc_sem_wait(&sem); + vlc_interrupt_unregister(); + /* BIG FAT WARNING: This is only meant to test the vlc_cond_wait_i11e() * function. This is NOT a good example of how to use the function in * normal code. */ @@ -64,6 +77,34 @@ static void test_context_simple(vlc_interrupt_t *ctx) assert(vlc_sem_wait_i11e(&sem) == EINTR); assert(vlc_sem_wait_i11e(&sem) == 0); + assert(vlc_mwait_i11e(1) == 0); + vlc_interrupt_raise(ctx); + assert(vlc_mwait_i11e(CLOCK_FREQ * 10000000) == EINTR); + + assert(vlc_poll_i11e(NULL, 0, 1) == 0); + vlc_interrupt_raise(ctx); + assert(vlc_poll_i11e(NULL, 0, 1000000000) == -1); + assert(errno == EINTR); + + c = 12; + assert(vlc_write_i11e(fds[0], &c, 1) == 1); + c = 0; + assert(vlc_read_i11e(fds[1], &c, 1) == 1 && c == 12); + vlc_interrupt_raise(ctx); + assert(vlc_read_i11e(fds[1], &c, 1) == -1); + assert(errno == EINTR); + + c = 42; + assert(vlc_sendto_i11e(fds[0], &c, 1, 0, NULL, 0) == 1); + c = 0; + assert(vlc_recvfrom_i11e(fds[1], &c, 1, 0, NULL, 0) == 1 && c == 42); + vlc_interrupt_raise(ctx); + assert(vlc_recvfrom_i11e(fds[1], &c, 1, 0, NULL, 0) == -1); + assert(errno == EINTR); + + vlc_interrupt_raise(ctx); + assert(vlc_accept_i11e(fds[1], NULL, NULL, true) < 0); + octx = vlc_interrupt_set(NULL); assert(octx == ctx); octx = vlc_interrupt_set(NULL); @@ -109,6 +150,12 @@ static void *test_thread_cancel(void *data) vlc_assert_unreachable(); } +static void unreachable_callback(void *data) +{ + (void) data; + abort(); +} + int main (void) { vlc_interrupt_t *ctx; @@ -124,6 +171,8 @@ int main (void) ctx = vlc_interrupt_create(); assert(ctx != NULL); + assert(vlc_socketpair(PF_LOCAL, SOCK_STREAM, 0, fds, false) == 0); + test_context_simple(ctx); assert(!vlc_clone(&th, test_thread_simple, ctx, VLC_THREAD_PRIORITY_LOW)); @@ -140,6 +189,22 @@ int main (void) vlc_join(th, NULL); vlc_interrupt_destroy(ctx); + + /* Tests without interrupt context */ + vlc_sem_post(&sem); + assert(vlc_sem_wait_i11e(&sem) == 0); + assert(vlc_mwait_i11e(1) == 0); + assert(vlc_poll_i11e(NULL, 0, 1) == 0); + + vlc_interrupt_register(unreachable_callback, NULL); + vlc_interrupt_unregister(); + + void *data[2]; + vlc_interrupt_forward_start(ctx, data); + assert(vlc_interrupt_forward_stop(data) == 0); + + vlc_close(fds[1]); + vlc_close(fds[0]); vlc_sem_destroy(&sem); return 0; } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
