nghttp2/tests/failmalloc_test.c

567 lines
16 KiB
C
Raw Normal View History

2012-04-24 15:51:06 +02:00
/*
2014-03-30 12:09:21 +02:00
* nghttp2 - HTTP/2 C Library
2012-04-24 15:51:06 +02:00
*
2014-05-10 12:38:37 +02:00
* Copyright (c) 2012, 2014 Tatsuhiro Tsujikawa
2012-04-24 15:51:06 +02:00
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "failmalloc_test.h"
#include <CUnit/CUnit.h>
#include <stdio.h>
#include <assert.h>
2013-07-12 17:19:03 +02:00
#include "nghttp2_session.h"
#include "nghttp2_stream.h"
#include "nghttp2_frame.h"
#include "nghttp2_helper.h"
2012-04-24 15:51:06 +02:00
#include "malloc_wrapper.h"
2013-07-12 17:19:03 +02:00
#include "nghttp2_test_helper.h"
2012-04-24 15:51:06 +02:00
typedef struct {
uint8_t data[8192];
uint8_t *datamark, *datalimit;
} data_feed;
typedef struct {
data_feed *df;
size_t data_source_length;
} my_user_data;
2014-11-27 15:39:04 +01:00
static void data_feed_init(data_feed *df, nghttp2_bufs *bufs) {
2014-05-10 12:38:37 +02:00
nghttp2_buf *buf;
size_t data_length;
buf = &bufs->head->buf;
data_length = nghttp2_buf_len(buf);
2012-04-24 15:51:06 +02:00
assert(data_length <= sizeof(df->data));
2014-05-10 12:38:37 +02:00
memcpy(df->data, buf->pos, data_length);
2012-04-24 15:51:06 +02:00
df->datamark = df->data;
2014-05-10 12:38:37 +02:00
df->datalimit = df->data + data_length;
2012-04-24 15:51:06 +02:00
}
static ssize_t null_send_callback(nghttp2_session *session, const uint8_t *data,
size_t len, int flags, void *user_data) {
(void)session;
(void)data;
(void)flags;
(void)user_data;
2015-09-23 07:41:53 +02:00
return (ssize_t)len;
2012-04-24 15:51:06 +02:00
}
static ssize_t data_feed_recv_callback(nghttp2_session *session, uint8_t *data,
size_t len, int flags, void *user_data) {
2014-11-27 15:39:04 +01:00
data_feed *df = ((my_user_data *)user_data)->df;
2015-09-23 07:41:53 +02:00
size_t avail = (size_t)(df->datalimit - df->datamark);
2013-07-12 17:19:03 +02:00
size_t wlen = nghttp2_min(avail, len);
(void)session;
(void)flags;
2012-04-24 15:51:06 +02:00
memcpy(data, df->datamark, wlen);
df->datamark += wlen;
2015-09-23 07:41:53 +02:00
return (ssize_t)wlen;
2012-04-24 15:51:06 +02:00
}
2014-11-27 15:39:04 +01:00
static ssize_t fixed_length_data_source_read_callback(
nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len,
uint32_t *data_flags, nghttp2_data_source *source, void *user_data) {
2014-11-27 15:39:04 +01:00
my_user_data *ud = (my_user_data *)user_data;
2012-04-24 15:51:06 +02:00
size_t wlen;
(void)session;
(void)stream_id;
(void)buf;
(void)source;
2014-11-27 15:39:04 +01:00
if (len < ud->data_source_length) {
2012-04-24 15:51:06 +02:00
wlen = len;
} else {
wlen = ud->data_source_length;
}
ud->data_source_length -= wlen;
2014-11-27 15:39:04 +01:00
if (ud->data_source_length == 0) {
2014-05-10 12:38:37 +02:00
*data_flags = NGHTTP2_DATA_FLAG_EOF;
2012-04-24 15:51:06 +02:00
}
2015-09-23 07:41:53 +02:00
return (ssize_t)wlen;
2012-04-24 15:51:06 +02:00
}
2014-11-27 15:39:04 +01:00
#define TEST_FAILMALLOC_RUN(FUN) \
do { \
int nmalloc, i; \
2014-11-27 15:39:04 +01:00
\
nghttp2_failmalloc = 0; \
nghttp2_nmalloc = 0; \
FUN(); \
nmalloc = nghttp2_nmalloc; \
\
nghttp2_failmalloc = 1; \
for (i = 0; i < nmalloc; ++i) { \
nghttp2_nmalloc = 0; \
nghttp2_failstart = i; \
/* printf("i=%zu\n", i); */ \
FUN(); \
/* printf("nmalloc=%d\n", nghttp2_nmalloc); */ \
} \
nghttp2_failmalloc = 0; \
} while (0)
static void run_nghttp2_session_send(void) {
2013-07-12 17:19:03 +02:00
nghttp2_session *session;
nghttp2_session_callbacks callbacks;
2014-11-27 15:39:04 +01:00
nghttp2_nv nv[] = {MAKE_NV(":host", "example.org"),
MAKE_NV(":scheme", "https")};
2013-07-12 17:19:03 +02:00
nghttp2_data_provider data_prd;
nghttp2_settings_entry iv[2];
2012-04-24 15:51:06 +02:00
my_user_data ud;
int rv;
2013-07-12 17:19:03 +02:00
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
2012-04-24 15:51:06 +02:00
callbacks.send_callback = null_send_callback;
data_prd.read_callback = fixed_length_data_source_read_callback;
2014-11-27 15:39:04 +01:00
ud.data_source_length = 64 * 1024;
2012-04-24 15:51:06 +02:00
2013-10-30 18:02:00 +01:00
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
iv[0].value = 4096;
2013-07-12 17:19:03 +02:00
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
2012-04-24 15:51:06 +02:00
iv[1].value = 100;
rv = nghttp2_session_client_new3(&session, &callbacks, &ud, NULL,
nghttp2_mem_fm());
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto client_new_fail;
}
2014-05-10 12:38:37 +02:00
rv = nghttp2_submit_request(session, NULL, nv, ARRLEN(nv), &data_prd, NULL);
2014-11-27 15:39:04 +01:00
if (rv < 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2014-11-27 15:39:04 +01:00
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, nv,
ARRLEN(nv), NULL);
if (rv < 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-07-12 17:19:03 +02:00
rv = nghttp2_session_send(session);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-10-30 18:02:00 +01:00
/* The HEADERS submitted by the previous nghttp2_submit_headers will
have stream ID 3. Send HEADERS to that stream. */
2014-11-27 15:39:04 +01:00
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, NULL, nv,
ARRLEN(nv), NULL);
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-10-30 18:02:00 +01:00
rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-07-12 17:19:03 +02:00
rv = nghttp2_session_send(session);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2014-11-27 15:39:04 +01:00
rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 3, NGHTTP2_CANCEL);
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-07-12 17:19:03 +02:00
rv = nghttp2_session_send(session);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-10-30 18:02:00 +01:00
rv = nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-10-30 18:02:00 +01:00
rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-07-12 17:19:03 +02:00
rv = nghttp2_session_send(session);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2014-06-18 08:12:54 +02:00
rv = nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 100, NGHTTP2_NO_ERROR,
2013-10-30 18:02:00 +01:00
NULL, 0);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2013-07-12 17:19:03 +02:00
rv = nghttp2_session_send(session);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2014-05-10 12:38:37 +02:00
2014-11-27 15:39:04 +01:00
fail:
2013-07-12 17:19:03 +02:00
nghttp2_session_del(session);
2016-10-15 11:36:04 +02:00
client_new_fail:;
2012-04-24 15:51:06 +02:00
}
2014-11-27 15:39:04 +01:00
void test_nghttp2_session_send(void) {
2013-07-12 17:19:03 +02:00
TEST_FAILMALLOC_RUN(run_nghttp2_session_send);
2012-04-24 15:51:06 +02:00
}
2016-04-03 12:07:46 +02:00
static void run_nghttp2_session_send_server(void) {
nghttp2_session *session;
nghttp2_session_callbacks *callbacks;
int rv;
const uint8_t *txdata;
ssize_t txdatalen;
const uint8_t origin[] = "nghttp2.org";
const uint8_t altsvc_field_value[] = "h2=\":443\"";
2016-04-03 12:07:46 +02:00
rv = nghttp2_session_callbacks_new(&callbacks);
if (rv != 0) {
return;
}
rv = nghttp2_session_server_new3(&session, callbacks, NULL, NULL,
nghttp2_mem_fm());
nghttp2_session_callbacks_del(callbacks);
if (rv != 0) {
return;
}
rv = nghttp2_submit_altsvc(session, NGHTTP2_FLAG_NONE, 0, origin,
sizeof(origin) - 1, altsvc_field_value,
sizeof(altsvc_field_value) - 1);
if (rv != 0) {
goto fail;
}
txdatalen = nghttp2_session_mem_send(session, &txdata);
if (txdatalen < 0) {
goto fail;
}
fail:
2016-04-24 06:49:57 +02:00
nghttp2_session_del(session);
2016-04-03 12:07:46 +02:00
}
void test_nghttp2_session_send_server(void) {
TEST_FAILMALLOC_RUN(run_nghttp2_session_send_server);
}
2014-11-27 15:39:04 +01:00
static void run_nghttp2_session_recv(void) {
2013-07-12 17:19:03 +02:00
nghttp2_session *session;
nghttp2_session_callbacks callbacks;
2014-05-10 12:38:37 +02:00
nghttp2_hd_deflater deflater;
2013-07-12 17:19:03 +02:00
nghttp2_frame frame;
2014-05-10 12:38:37 +02:00
nghttp2_bufs bufs;
2017-04-13 17:00:36 +02:00
nghttp2_nv nv[] = {
2017-11-23 06:19:12 +01:00
MAKE_NV(":method", "GET"),
MAKE_NV(":scheme", "https"),
MAKE_NV(":authority", "example.org"),
MAKE_NV(":path", "/"),
2017-04-13 17:00:36 +02:00
};
2013-07-12 17:19:03 +02:00
nghttp2_settings_entry iv[2];
2012-04-24 15:51:06 +02:00
my_user_data ud;
data_feed df;
int rv;
2013-10-30 18:02:00 +01:00
nghttp2_nv *nva;
2015-09-23 07:41:53 +02:00
size_t nvlen;
2012-04-24 15:51:06 +02:00
2014-05-10 12:38:37 +02:00
rv = frame_pack_bufs_init(&bufs);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 12:38:37 +02:00
return;
}
2013-07-12 17:19:03 +02:00
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
2012-04-24 15:51:06 +02:00
callbacks.recv_callback = data_feed_recv_callback;
ud.df = &df;
2013-07-12 17:19:03 +02:00
nghttp2_failmalloc_pause();
nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm());
nghttp2_session_server_new3(&session, &callbacks, &ud, NULL,
nghttp2_mem_fm());
2017-04-13 17:00:36 +02:00
/* Client preface */
nghttp2_bufs_add(&bufs, NGHTTP2_CLIENT_MAGIC, NGHTTP2_CLIENT_MAGIC_LEN);
data_feed_init(&df, &bufs);
nghttp2_bufs_reset(&bufs);
2013-07-12 17:19:03 +02:00
nghttp2_failmalloc_unpause();
2012-04-24 15:51:06 +02:00
2017-04-13 17:00:36 +02:00
rv = nghttp2_session_recv(session);
if (rv != 0) {
goto fail;
}
2013-07-12 17:19:03 +02:00
nghttp2_failmalloc_pause();
2017-04-13 17:00:36 +02:00
/* SETTINGS */
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
iv[0].value = 4096;
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
iv[1].value = 100;
nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE,
nghttp2_frame_iv_copy(iv, 2, nghttp2_mem_fm()),
2);
nghttp2_frame_pack_settings(&bufs, &frame.settings);
nghttp2_frame_settings_free(&frame.settings, nghttp2_mem_fm());
data_feed_init(&df, &bufs);
nghttp2_bufs_reset(&bufs);
nghttp2_failmalloc_unpause();
rv = nghttp2_session_recv(session);
if (rv != 0) {
goto fail;
}
nghttp2_failmalloc_pause();
/* HEADERS */
nvlen = ARRLEN(nv);
nghttp2_nv_array_copy(&nva, nv, nvlen, nghttp2_mem_fm());
2014-11-27 15:39:04 +01:00
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM, 1,
NGHTTP2_HCAT_REQUEST, NULL, nva, nvlen);
2014-05-10 12:38:37 +02:00
nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater);
nghttp2_frame_headers_free(&frame.headers, nghttp2_mem_fm());
2014-05-10 12:38:37 +02:00
data_feed_init(&df, &bufs);
nghttp2_bufs_reset(&bufs);
2013-07-12 17:19:03 +02:00
nghttp2_failmalloc_unpause();
2012-04-24 15:51:06 +02:00
2013-07-12 17:19:03 +02:00
rv = nghttp2_session_recv(session);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
/* PING */
2013-07-12 17:19:03 +02:00
nghttp2_failmalloc_pause();
2013-10-30 18:02:00 +01:00
nghttp2_frame_ping_init(&frame.ping, NGHTTP2_FLAG_NONE, NULL);
2014-05-10 12:38:37 +02:00
nghttp2_frame_pack_ping(&bufs, &frame.ping);
2013-07-12 17:19:03 +02:00
nghttp2_frame_ping_free(&frame.ping);
2014-05-10 12:38:37 +02:00
data_feed_init(&df, &bufs);
nghttp2_bufs_reset(&bufs);
2013-07-12 17:19:03 +02:00
nghttp2_failmalloc_unpause();
2012-04-24 15:51:06 +02:00
2013-07-12 17:19:03 +02:00
rv = nghttp2_session_recv(session);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
/* RST_STREAM */
2013-07-12 17:19:03 +02:00
nghttp2_failmalloc_pause();
2013-10-30 18:02:00 +01:00
nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_PROTOCOL_ERROR);
2014-05-10 12:38:37 +02:00
nghttp2_frame_pack_rst_stream(&bufs, &frame.rst_stream);
2013-07-12 17:19:03 +02:00
nghttp2_frame_rst_stream_free(&frame.rst_stream);
2014-05-10 12:38:37 +02:00
nghttp2_bufs_reset(&bufs);
2013-07-12 17:19:03 +02:00
nghttp2_failmalloc_unpause();
rv = nghttp2_session_recv(session);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2014-11-27 15:39:04 +01:00
fail:
2014-05-10 12:38:37 +02:00
nghttp2_bufs_free(&bufs);
2013-07-12 17:19:03 +02:00
nghttp2_session_del(session);
2013-10-30 18:02:00 +01:00
nghttp2_hd_deflate_free(&deflater);
2012-04-24 15:51:06 +02:00
}
2014-11-27 15:39:04 +01:00
void test_nghttp2_session_recv(void) {
2013-07-12 17:19:03 +02:00
TEST_FAILMALLOC_RUN(run_nghttp2_session_recv);
2012-04-24 15:51:06 +02:00
}
2014-11-27 15:39:04 +01:00
static void run_nghttp2_frame_pack_headers(void) {
2014-05-10 12:38:37 +02:00
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
2013-07-12 17:19:03 +02:00
nghttp2_frame frame, oframe;
2014-05-10 12:38:37 +02:00
nghttp2_bufs bufs;
2014-11-27 15:39:04 +01:00
nghttp2_nv nv[] = {MAKE_NV(":host", "example.org"),
MAKE_NV(":scheme", "https")};
2012-04-24 15:51:06 +02:00
int rv;
2013-10-30 18:02:00 +01:00
nghttp2_nv *nva;
2015-09-23 07:41:53 +02:00
size_t nvlen;
2012-04-24 15:51:06 +02:00
2014-05-10 12:38:37 +02:00
rv = frame_pack_bufs_init(&bufs);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 12:38:37 +02:00
return;
}
rv = nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm());
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto deflate_init_fail;
}
rv = nghttp2_hd_inflate_init(&inflater, nghttp2_mem_fm());
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto inflate_init_fail;
}
nvlen = ARRLEN(nv);
rv = nghttp2_nv_array_copy(&nva, nv, nvlen, nghttp2_mem_fm());
2014-11-27 15:39:04 +01:00
if (rv < 0) {
2012-04-24 15:51:06 +02:00
goto nv_copy_fail;
}
2014-11-27 15:39:04 +01:00
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM, 1,
NGHTTP2_HCAT_REQUEST, NULL, nva, nvlen);
2014-05-10 12:38:37 +02:00
rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2014-05-10 12:38:37 +02:00
rv = unpack_framebuf(&oframe, &bufs);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
nghttp2_frame_headers_free(&oframe.headers, nghttp2_mem_fm());
2014-05-10 12:38:37 +02:00
2014-11-27 15:39:04 +01:00
fail:
nghttp2_frame_headers_free(&frame.headers, nghttp2_mem_fm());
2014-11-27 15:39:04 +01:00
nv_copy_fail:
2013-10-30 18:02:00 +01:00
nghttp2_hd_inflate_free(&inflater);
2014-11-27 15:39:04 +01:00
inflate_init_fail:
2013-10-30 18:02:00 +01:00
nghttp2_hd_deflate_free(&deflater);
2014-11-27 15:39:04 +01:00
deflate_init_fail:
2014-05-10 12:38:37 +02:00
nghttp2_bufs_free(&bufs);
2012-04-24 15:51:06 +02:00
}
2014-11-27 15:39:04 +01:00
static void run_nghttp2_frame_pack_settings(void) {
2013-07-12 17:19:03 +02:00
nghttp2_frame frame, oframe;
2014-05-10 12:38:37 +02:00
nghttp2_bufs bufs;
nghttp2_buf *buf;
2013-07-12 17:19:03 +02:00
nghttp2_settings_entry iv[2], *iv_copy;
2012-04-24 15:51:06 +02:00
int rv;
2014-05-10 12:38:37 +02:00
rv = frame_pack_bufs_init(&bufs);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 12:38:37 +02:00
return;
}
2013-10-30 18:02:00 +01:00
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
iv[0].value = 4096;
2013-07-12 17:19:03 +02:00
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
2012-04-24 15:51:06 +02:00
iv[1].value = 100;
iv_copy = nghttp2_frame_iv_copy(iv, 2, nghttp2_mem_fm());
2014-05-10 12:38:37 +02:00
2014-11-27 15:39:04 +01:00
if (iv_copy == NULL) {
2012-04-24 15:51:06 +02:00
goto iv_copy_fail;
}
2014-05-10 12:38:37 +02:00
2013-10-30 18:02:00 +01:00
nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, iv_copy, 2);
2014-05-10 12:38:37 +02:00
rv = nghttp2_frame_pack_settings(&bufs, &frame.settings);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
2014-05-10 12:38:37 +02:00
buf = &bufs.head->buf;
2014-11-27 15:39:04 +01:00
rv = nghttp2_frame_unpack_settings_payload2(
&oframe.settings.iv, &oframe.settings.niv, buf->pos + NGHTTP2_FRAME_HDLEN,
nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN, nghttp2_mem_fm());
2014-05-10 12:38:37 +02:00
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2012-04-24 15:51:06 +02:00
goto fail;
}
nghttp2_frame_settings_free(&oframe.settings, nghttp2_mem_fm());
2014-05-10 12:38:37 +02:00
2014-11-27 15:39:04 +01:00
fail:
nghttp2_frame_settings_free(&frame.settings, nghttp2_mem_fm());
2014-11-27 15:39:04 +01:00
iv_copy_fail:
2014-05-10 12:38:37 +02:00
nghttp2_bufs_free(&bufs);
2012-04-24 15:51:06 +02:00
}
2014-11-27 15:39:04 +01:00
void test_nghttp2_frame(void) {
2014-05-10 12:38:37 +02:00
TEST_FAILMALLOC_RUN(run_nghttp2_frame_pack_headers);
TEST_FAILMALLOC_RUN(run_nghttp2_frame_pack_settings);
2012-04-24 15:51:06 +02:00
}
2014-05-10 14:14:25 +02:00
static int deflate_inflate(nghttp2_hd_deflater *deflater,
2014-11-27 15:39:04 +01:00
nghttp2_hd_inflater *inflater, nghttp2_bufs *bufs,
nghttp2_nv *nva, size_t nvlen, nghttp2_mem *mem) {
2014-05-10 14:14:25 +02:00
int rv;
2014-05-13 16:42:55 +02:00
rv = nghttp2_hd_deflate_hd_bufs(deflater, bufs, nva, nvlen);
2014-05-10 14:14:25 +02:00
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 14:14:25 +02:00
return rv;
}
rv = (int)inflate_hd(inflater, NULL, bufs, 0, mem);
2014-05-10 14:14:25 +02:00
2014-11-27 15:39:04 +01:00
if (rv < 0) {
2014-05-10 14:14:25 +02:00
return rv;
}
nghttp2_bufs_reset(bufs);
return 0;
}
2014-11-27 15:39:04 +01:00
static void run_nghttp2_hd(void) {
2014-05-10 14:14:25 +02:00
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
nghttp2_bufs bufs;
int rv;
2015-05-22 16:36:34 +02:00
nghttp2_nv nva1[] = {
MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"),
MAKE_NV(":path", "/slashdot"),
MAKE_NV("accept-encoding", "gzip, deflate"), MAKE_NV("foo", "bar")};
2014-05-10 14:14:25 +02:00
nghttp2_nv nva2[] = {
2014-11-27 15:39:04 +01:00
MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"),
2015-05-22 16:36:34 +02:00
MAKE_NV(":path", "/style.css"), MAKE_NV("cookie", "nghttp2=FTW"),
MAKE_NV("foo", "bar2")};
2014-05-10 14:14:25 +02:00
rv = frame_pack_bufs_init(&bufs);
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 14:14:25 +02:00
return;
}
rv = nghttp2_hd_deflate_init(&deflater, nghttp2_mem_fm());
2014-05-10 14:14:25 +02:00
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 14:14:25 +02:00
goto deflate_init_fail;
}
rv = nghttp2_hd_inflate_init(&inflater, nghttp2_mem_fm());
2014-05-10 14:14:25 +02:00
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 14:14:25 +02:00
goto inflate_init_fail;
}
rv = deflate_inflate(&deflater, &inflater, &bufs, nva1, ARRLEN(nva1),
nghttp2_mem_fm());
2014-05-10 14:14:25 +02:00
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 14:14:25 +02:00
goto deflate_hd_fail;
}
rv = deflate_inflate(&deflater, &inflater, &bufs, nva2, ARRLEN(nva2),
nghttp2_mem_fm());
2014-05-10 14:14:25 +02:00
2014-11-27 15:39:04 +01:00
if (rv != 0) {
2014-05-10 14:14:25 +02:00
goto deflate_hd_fail;
}
2014-11-27 15:39:04 +01:00
deflate_hd_fail:
2014-05-10 14:14:25 +02:00
nghttp2_hd_inflate_free(&inflater);
2014-11-27 15:39:04 +01:00
inflate_init_fail:
2014-05-10 14:14:25 +02:00
nghttp2_hd_deflate_free(&deflater);
2014-11-27 15:39:04 +01:00
deflate_init_fail:
2014-05-10 14:14:25 +02:00
nghttp2_bufs_free(&bufs);
}
2014-11-27 15:39:04 +01:00
void test_nghttp2_hd(void) { TEST_FAILMALLOC_RUN(run_nghttp2_hd); }