Commit a69bc2cb authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: robustify HTTP/2 connection test

parent c7a2b2bd
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment