vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Mon Dec 7 22:25:22 2015 +0200| [56c2ee0c098a2ab866ef9e16170b2b0dace04813] | committer: Rémi Denis-Courmont
HTTP/2 output queue test > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=56c2ee0c098a2ab866ef9e16170b2b0dace04813 --- modules/access/http/Makefile.am | 9 +- modules/access/http/h2output_test.c | 165 +++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 2 deletions(-) diff --git a/modules/access/http/Makefile.am b/modules/access/http/Makefile.am index 9b242c1..5ada7db 100644 --- a/modules/access/http/Makefile.am +++ b/modules/access/http/Makefile.am @@ -5,5 +5,10 @@ hpackenc_test_CFLAGS = -DENC_TEST h2frame_test_SOURCES = access/http/h2frame_test.c \ access/http/hpack.c access/http/hpack.h access/http/hpackenc.c \ access/http/h2frame.c access/http/h2frame.h -check_PROGRAMS += hpack_test hpackenc_test h2frame_test -TESTS += hpack_test hpackenc_test h2frame_test +h2output_test_SOURCES = access/http/h2output_test.c \ + access/http/hpack.c access/http/hpack.h access/http/hpackenc.c \ + access/http/h2frame.c access/http/h2frame.h \ + access/http/h2output.c access/http/h2output.h +h2output_test_LDADD = $(LIBPTHREAD) +check_PROGRAMS += hpack_test hpackenc_test h2frame_test h2output_test +TESTS += hpack_test hpackenc_test h2frame_test h2output_test diff --git a/modules/access/http/h2output_test.c b/modules/access/http/h2output_test.c new file mode 100644 index 0000000..6577801 --- /dev/null +++ b/modules/access/http/h2output_test.c @@ -0,0 +1,165 @@ +/***************************************************************************** + * h2output_test.c: HTTP/2 send queue test + ***************************************************************************** + * Copyright (C) 2015 Rémi Denis-Courmont + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#undef NDEBUG + +#include <assert.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdlib.h> +#include <vlc_common.h> +#include "h2frame.h" +#include "h2output.h" +#include "transport.h" + +#undef msleep + +static unsigned char counter = 0; +static bool send_failure = false; +static bool expect_hello = true; +static vlc_sem_t rx; + +/* Callback for sent frames */ +ssize_t vlc_https_send(struct vlc_tls *tls, const void *buf, size_t len) +{ + const uint8_t *p = buf; + + assert(tls == NULL); + + if (expect_hello) + { + assert(len >= 24); + assert(!memcmp(p, "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", 24)); + + expect_hello = false; + vlc_sem_post(&rx); + + if (len == 24) + return send_failure ? -1 : (ssize_t)len; + + p += 24; + len -= 24; + } + + assert(len == 9 + 1); + assert(p[9] == counter); + + counter++; + vlc_sem_post(&rx); + return send_failure ? -1 : (ssize_t)len; +} + +static struct vlc_h2_frame *frame(unsigned char c) +{ + struct vlc_h2_frame *f = vlc_h2_frame_data(1, &c, 1, false); + assert(f != NULL); + return f; +} + +static struct vlc_h2_frame *frame_list(struct vlc_h2_frame *first, ...) +{ + struct vlc_h2_frame **pp = &first; + va_list ap; + + va_start(ap, first); + for (struct vlc_h2_frame *f = first; + f != NULL; + f = va_arg(ap, struct vlc_h2_frame *)) + { + *pp = f; + pp = &f->next; + } + va_end(ap); + return first; +} + +int main(void) +{ + struct vlc_h2_output *out; + + /* Dummy */ + out = vlc_h2_output_create(NULL, false); + assert(out != NULL); + vlc_h2_output_destroy(out); + + vlc_sem_init(&rx, 0); + out = vlc_h2_output_create(NULL, expect_hello = true); + assert(out != NULL); + vlc_h2_output_destroy(out); + vlc_sem_destroy(&rx); + + /* Success */ + vlc_sem_init(&rx, 0); + out = vlc_h2_output_create(NULL, false); + assert(out != NULL); + assert(vlc_h2_output_send_prio(out, NULL) == -1); + assert(vlc_h2_output_send_prio(out, frame(0)) == 0); + assert(vlc_h2_output_send_prio(out, frame(1)) == 0); + assert(vlc_h2_output_send(out, NULL) == -1); + assert(vlc_h2_output_send(out, frame(2)) == 0); + assert(vlc_h2_output_send(out, frame(3)) == 0); + assert(vlc_h2_output_send(out, frame_list(frame(4), frame(5), + frame(6), NULL)) == 0); + assert(vlc_h2_output_send(out, frame(7)) == 0); + for (unsigned i = 0; i < 8; i++) + vlc_sem_wait(&rx); + + assert(vlc_h2_output_send_prio(out, frame(8)) == 0); + assert(vlc_h2_output_send(out, frame(9)) == 0); + + vlc_h2_output_destroy(out); + vlc_sem_destroy(&rx); + + /* Failure */ + send_failure = true; + + vlc_sem_init(&rx, 0); + counter = 10; + out = vlc_h2_output_create(NULL, false); + assert(out != NULL); + + assert(vlc_h2_output_send(out, frame(10)) == 0); + for (unsigned char i = 11; vlc_h2_output_send(out, frame(i)) == 0; i++) + msleep(CLOCK_FREQ/10); /* eventually, it should start failing */ + assert(vlc_h2_output_send(out, frame(0)) == -1); + assert(vlc_h2_output_send_prio(out, frame(0)) == -1); + vlc_h2_output_destroy(out); + vlc_sem_destroy(&rx); + + /* Failure during hello */ + vlc_sem_init(&rx, 0); + counter = 0; + out = vlc_h2_output_create(NULL, expect_hello = true); + assert(out != NULL); + vlc_sem_wait(&rx); + + for (unsigned char i = 1; vlc_h2_output_send_prio(out, frame(i)) == 0; i++) + msleep(CLOCK_FREQ/10); + assert(vlc_h2_output_send(out, frame(0)) == -1); + assert(vlc_h2_output_send_prio(out, frame(0)) == -1); + vlc_h2_output_destroy(out); + vlc_sem_destroy(&rx); + + return 0; +} _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
