vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Fri Dec 18 21:19:55 2015 +0200| [a69bc2cb8ee0f042ea914c265f1514be5073e258] | committer: Rémi Denis-Courmont
https: robustify HTTP/2 connection test > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a69bc2cb8ee0f042ea914c265f1514be5073e258 --- modules/access/http/h2conn_test.c | 67 +++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/modules/access/http/h2conn_test.c b/modules/access/http/h2conn_test.c index fec5fcc..2d9c117 100644 --- a/modules/access/http/h2conn_test.c +++ b/modules/access/http/h2conn_test.c @@ -55,9 +55,44 @@ static void conn_send(struct vlc_h2_frame *f) free(f); } +enum { + DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS, PUSH_PROMISE, PING, GOAWAY, + WINDOW_UPDATE, CONTINUATION, +}; + +static void conn_expect(uint_fast8_t wanted) +{ + size_t len; + ssize_t val; + uint8_t hdr[9]; + uint8_t got; + + do { + val = recv(external_fd, hdr, 9, MSG_WAITALL); + assert(val == 9); + assert(hdr[0] == 0); + + /* Check type. We do not currently validate WINDOW_UPDATE. */ + got = hdr[3]; + assert(wanted == got || WINDOW_UPDATE == got); + + len = (hdr[1] << 8) | hdr[2]; + if (len > 0) + { + char buf[len]; + + val = recv(external_fd, buf, len, MSG_WAITALL); + assert(val == (ssize_t)len); + } + } + while (got != wanted); +} + static void conn_create(void) { + ssize_t val; int fds[2]; + char hello[24]; if (socketpair(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC, 0, fds)) assert(!"socketpair"); @@ -70,6 +105,12 @@ static void conn_create(void) conn = vlc_h2_conn_create(tls); assert(conn != NULL); conn_send(vlc_h2_frame_settings()); + + val = recv(external_fd, hello, 24, MSG_WAITALL); + assert(val == 24); + assert(!memcmp(hello, "PRI * HTTP/2.0\r\n", 16)); + conn_expect(SETTINGS); + conn_expect(SETTINGS); } static void conn_destroy(void) @@ -128,17 +169,20 @@ int main(void) conn_create(); conn_send(vlc_h2_frame_ping(42)); + conn_expect(PING); /* Test rejected stream */ sid += 2; s = stream_open(); assert(s != NULL); + conn_expect(HEADERS); conn_send(vlc_h2_frame_rst_stream(sid, VLC_H2_REFUSED_STREAM)); m = vlc_http_stream_read_headers(s); assert(m == NULL); b = vlc_http_stream_read(s); assert(b == NULL); vlc_http_stream_close(s, false); + conn_expect(RST_STREAM); /* Test accepted stream */ sid += 2; @@ -149,10 +193,14 @@ int main(void) assert(m != NULL); vlc_http_msg_destroy(m); - /* Test late data */ - stream_data(3, "Hello ", false); + stream_data(3, "Hello ", false); /* late data */ stream_data(3, "world!", true); + conn_expect(HEADERS); + conn_expect(RST_STREAM); + conn_expect(RST_STREAM); + conn_expect(RST_STREAM); + /* Test continuation then accepted stream */ sid += 2; s = stream_open(); @@ -177,6 +225,10 @@ int main(void) assert(b == NULL); vlc_http_msg_destroy(m); + conn_expect(HEADERS); + conn_expect(RST_STREAM); + conn_expect(RST_STREAM); + /* Test accepted stream after continuation */ sid += 2; s = stream_open(); @@ -197,6 +249,11 @@ int main(void) assert(b == NULL); vlc_http_msg_destroy(m); + conn_expect(HEADERS); + conn_expect(HEADERS); + conn_expect(RST_STREAM); + conn_expect(RST_STREAM); + /* Test multiple streams in non-LIFO order */ sid += 2; s = stream_open(); @@ -214,6 +271,12 @@ int main(void) assert(m != NULL); vlc_http_msg_destroy(m); + conn_expect(HEADERS); + conn_expect(HEADERS); + conn_expect(RST_STREAM); + conn_expect(RST_STREAM); + /* might or might not seen one or two extra RST_STREAM now */ + /* Test graceful connection termination */ sid += 2; s = stream_open(); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
