tests: Add failmalloc tests
This commit is contained in:
parent
b0f76773e1
commit
49b8ea1bf3
|
@ -63,6 +63,11 @@ AC_ARG_ENABLE([examples],
|
|||
[Build example programs])],
|
||||
[request_examples=$enableval], [request_examples=yes])
|
||||
|
||||
AC_ARG_ENABLE([failmalloc],
|
||||
[AS_HELP_STRING([--enable-failmalloc],
|
||||
[Build failmalloc test program])],
|
||||
[request_failmalloc=$enableval], [request_failmalloc=no])
|
||||
|
||||
AC_ARG_WITH([libxml2],
|
||||
[AS_HELP_STRING([--without-libxml2],
|
||||
[disable support for libxml2])],
|
||||
|
@ -241,6 +246,9 @@ fi
|
|||
|
||||
AM_CONDITIONAL([ENABLE_HDTEST], [ test "x${enable_hdtest}" = "xyes" ])
|
||||
|
||||
# failmalloc tests
|
||||
AM_CONDITIONAL([ENABLE_FAILMALLOC], [ test "x${enable_failmalloc}" = "xyes" ])
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([ \
|
||||
arpa/inet.h \
|
||||
|
@ -344,4 +352,5 @@ AC_MSG_NOTICE([summary of build options:
|
|||
Src: ${enable_src}
|
||||
Examples: ${enable_examples}
|
||||
Hdtest: ${enable_hdtest}
|
||||
Failmalloc: ${request_failmalloc}
|
||||
])
|
||||
|
|
|
@ -25,7 +25,10 @@ SUBDIRS = testdata
|
|||
if HAVE_CUNIT
|
||||
|
||||
check_PROGRAMS = main
|
||||
# failmalloc
|
||||
|
||||
if ENABLE_FAILMALLOC
|
||||
check_PROGRAMS += failmalloc
|
||||
endif # ENABLE_FAILMALLOC
|
||||
|
||||
OBJECTS = main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c \
|
||||
nghttp2_buffer_test.c \
|
||||
|
@ -49,17 +52,22 @@ main_SOURCES = $(HFILES) $(OBJECTS)
|
|||
main_LDADD = ${top_builddir}/lib/libnghttp2.la
|
||||
main_LDFLAGS = -static @CUNIT_LIBS@ @TESTS_LIBS@
|
||||
|
||||
# failmalloc_SOURCES = failmalloc.c failmalloc_test.c failmalloc_test.h \
|
||||
# malloc_wrapper.c malloc_wrapper.h \
|
||||
# nghttp2_test_helper.c nghttp2_test_helper.h
|
||||
# failmalloc_LDADD = $(main_LDADD)
|
||||
# failmalloc_LDFLAGS = $(main_LDFLAGS)
|
||||
if ENABLE_FAILMALLOC
|
||||
failmalloc_SOURCES = failmalloc.c failmalloc_test.c failmalloc_test.h \
|
||||
malloc_wrapper.c malloc_wrapper.h \
|
||||
nghttp2_test_helper.c nghttp2_test_helper.h
|
||||
failmalloc_LDADD = $(main_LDADD)
|
||||
failmalloc_LDFLAGS = $(main_LDFLAGS)
|
||||
endif # ENABLE_FAILMALLOC
|
||||
|
||||
AM_CFLAGS = -Wall -I${top_srcdir}/lib -I${top_srcdir}/lib/includes -I${top_builddir}/lib/includes \
|
||||
@CUNIT_CFLAGS@ @DEFS@
|
||||
|
||||
TESTS = main
|
||||
# failmalloc
|
||||
|
||||
if ENABLE_FAILMALLOC
|
||||
TESTS += failmalloc
|
||||
endif # ENABLE_FAILMALLOC
|
||||
|
||||
if ENABLE_SRC
|
||||
|
||||
|
|
|
@ -36,18 +36,6 @@
|
|||
#include "malloc_wrapper.h"
|
||||
#include "nghttp2_test_helper.h"
|
||||
|
||||
static char* strcopy(const char* s)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
char *dest = malloc(len+1);
|
||||
if(dest == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(dest, s, len);
|
||||
dest[len] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t data[8192];
|
||||
uint8_t *datamark, *datalimit;
|
||||
|
@ -104,50 +92,6 @@ static ssize_t fixed_length_data_source_read_callback
|
|||
return wlen;
|
||||
}
|
||||
|
||||
static ssize_t get_credential_ncerts(nghttp2_session *session,
|
||||
const nghttp2_origin *origin,
|
||||
void *user_data)
|
||||
{
|
||||
if(strcmp("example.org", origin->host) == 0 &&
|
||||
strcmp("https", origin->scheme) == 0 &&
|
||||
443 == origin->port) {
|
||||
return 2;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t get_credential_cert(nghttp2_session *session,
|
||||
const nghttp2_origin *origin,
|
||||
size_t idx,
|
||||
uint8_t *cert, size_t certlen,
|
||||
void *user_data)
|
||||
{
|
||||
size_t len = strlen(origin->host);
|
||||
if(certlen == 0) {
|
||||
return len;
|
||||
} else {
|
||||
assert(certlen == len);
|
||||
memcpy(cert, origin->host, len);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t get_credential_proof(nghttp2_session *session,
|
||||
const nghttp2_origin *origin,
|
||||
uint8_t *proof, size_t prooflen,
|
||||
void *uer_data)
|
||||
{
|
||||
size_t len = strlen(origin->scheme);
|
||||
if(prooflen == 0) {
|
||||
return len;
|
||||
} else {
|
||||
assert(prooflen == len);
|
||||
memcpy(proof, origin->scheme, len);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define TEST_FAILMALLOC_RUN(FUN) \
|
||||
size_t nmalloc, i; \
|
||||
\
|
||||
|
@ -179,22 +123,16 @@ static void run_nghttp2_session_send(void)
|
|||
int rv;
|
||||
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
||||
callbacks.send_callback = null_send_callback;
|
||||
callbacks.get_credential_ncerts = get_credential_ncerts;
|
||||
callbacks.get_credential_cert = get_credential_cert;
|
||||
callbacks.get_credential_proof = get_credential_proof;
|
||||
|
||||
data_prd.read_callback = fixed_length_data_source_read_callback;
|
||||
ud.data_source_length = 64*1024;
|
||||
|
||||
iv[0].settings_id = NGHTTP2_SETTINGS_UPLOAD_BANDWIDTH;
|
||||
iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_PERSIST_VALUE;
|
||||
iv[0].value = 256;
|
||||
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
|
||||
iv[0].value = 4096;
|
||||
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
|
||||
iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE;
|
||||
iv[1].value = 100;
|
||||
|
||||
rv = nghttp2_session_client_new(&session, NGHTTP2_PROTO_SPDY3,
|
||||
&callbacks, &ud);
|
||||
rv = nghttp2_session_client_new(&session, &callbacks, &ud);
|
||||
if(rv != 0) {
|
||||
goto client_new_fail;
|
||||
}
|
||||
|
@ -202,8 +140,8 @@ static void run_nghttp2_session_send(void)
|
|||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = nghttp2_submit_syn_stream(session, NGHTTP2_CTRL_FLAG_NONE,
|
||||
0, 3, nv, NULL);
|
||||
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1,
|
||||
NGHTTP2_PRI_DEFAULT, nv, NULL);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -211,14 +149,14 @@ static void run_nghttp2_session_send(void)
|
|||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
/* The SYN_STREAM submitted by the previous
|
||||
nghttp2_submit_syn_stream will have stream ID 3. Send HEADERS to
|
||||
that stream. */
|
||||
rv = nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_NONE, 3, nv);
|
||||
/* The HEADERS submitted by the previous nghttp2_submit_headers will
|
||||
have stream ID 3. Send HEADERS to that stream. */
|
||||
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3,
|
||||
NGHTTP2_PRI_DEFAULT, nv, NULL);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = nghttp2_submit_data(session, 3, NGHTTP2_DATA_FLAG_FIN, &data_prd);
|
||||
rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -226,7 +164,8 @@ static void run_nghttp2_session_send(void)
|
|||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = nghttp2_submit_rst_stream(session, 3, NGHTTP2_CANCEL);
|
||||
rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 3,
|
||||
NGHTTP2_CANCEL);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -235,19 +174,20 @@ static void run_nghttp2_session_send(void)
|
|||
goto fail;
|
||||
}
|
||||
/* Sending against half-closed stream */
|
||||
rv = nghttp2_submit_headers(session, NGHTTP2_CTRL_FLAG_NONE, 3, nv);
|
||||
rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3,
|
||||
NGHTTP2_PRI_DEFAULT, nv, NULL);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = nghttp2_submit_data(session, 3, NGHTTP2_DATA_FLAG_FIN, &data_prd);
|
||||
rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = nghttp2_submit_ping(session);
|
||||
rv = nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_SETTINGS_NONE, iv, 2);
|
||||
rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -255,7 +195,8 @@ static void run_nghttp2_session_send(void)
|
|||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = nghttp2_submit_goaway(session, NGHTTP2_GOAWAY_OK);
|
||||
rv = nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, NGHTTP2_NO_ERROR,
|
||||
NULL, 0);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
@ -278,40 +219,38 @@ static void run_nghttp2_session_recv(void)
|
|||
{
|
||||
nghttp2_session *session;
|
||||
nghttp2_session_callbacks callbacks;
|
||||
nghttp2_zlib deflater;
|
||||
nghttp2_hd_context deflater;
|
||||
nghttp2_frame frame;
|
||||
uint8_t *buf = NULL, *nvbuf = NULL;
|
||||
size_t buflen = 0, nvbuflen = 0;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen = 0;
|
||||
ssize_t framelen;
|
||||
const char *nv[] = { ":host", "example.org",
|
||||
const char *nv[] = { ":authority", "example.org",
|
||||
":scheme", "https",
|
||||
NULL };
|
||||
nghttp2_settings_entry iv[2];
|
||||
nghttp2_mem_chunk proof;
|
||||
nghttp2_mem_chunk *certs;
|
||||
size_t ncerts;
|
||||
my_user_data ud;
|
||||
data_feed df;
|
||||
int rv;
|
||||
nghttp2_nv *nva;
|
||||
ssize_t nvlen;
|
||||
|
||||
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
|
||||
callbacks.recv_callback = data_feed_recv_callback;
|
||||
ud.df = &df;
|
||||
|
||||
nghttp2_failmalloc_pause();
|
||||
nghttp2_zlib_deflate_hd_init(&deflater, 1, NGHTTP2_PROTO_SPDY3);
|
||||
nghttp2_session_server_new(&session, NGHTTP2_PROTO_SPDY3, &callbacks, &ud);
|
||||
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
||||
nghttp2_session_server_new(&session, &callbacks, &ud);
|
||||
nghttp2_failmalloc_unpause();
|
||||
|
||||
/* SYN_STREAM */
|
||||
/* HEADERS */
|
||||
nghttp2_failmalloc_pause();
|
||||
nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY3,
|
||||
NGHTTP2_CTRL_FLAG_FIN, 1, 0, 2,
|
||||
nghttp2_frame_nv_copy(nv));
|
||||
framelen = nghttp2_frame_pack_syn_stream(&buf, &buflen,
|
||||
&nvbuf, &nvbuflen,
|
||||
&frame.syn_stream, &deflater);
|
||||
nghttp2_frame_syn_stream_free(&frame.syn_stream);
|
||||
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
|
||||
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM,
|
||||
1, NGHTTP2_PRI_DEFAULT, nva, nvlen);
|
||||
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame.headers,
|
||||
&deflater);
|
||||
nghttp2_frame_headers_free(&frame.headers);
|
||||
data_feed_init(&df, buf, framelen);
|
||||
nghttp2_failmalloc_unpause();
|
||||
|
||||
|
@ -322,7 +261,7 @@ static void run_nghttp2_session_recv(void)
|
|||
|
||||
/* PING */
|
||||
nghttp2_failmalloc_pause();
|
||||
nghttp2_frame_ping_init(&frame.ping, NGHTTP2_PROTO_SPDY3, 1);
|
||||
nghttp2_frame_ping_init(&frame.ping, NGHTTP2_FLAG_NONE, NULL);
|
||||
framelen = nghttp2_frame_pack_ping(&buf, &buflen, &frame.ping);
|
||||
nghttp2_frame_ping_free(&frame.ping);
|
||||
data_feed_init(&df, buf, framelen);
|
||||
|
@ -335,8 +274,7 @@ static void run_nghttp2_session_recv(void)
|
|||
|
||||
/* RST_STREAM */
|
||||
nghttp2_failmalloc_pause();
|
||||
nghttp2_frame_rst_stream_init(&frame.rst_stream, NGHTTP2_PROTO_SPDY3, 1,
|
||||
NGHTTP2_PROTOCOL_ERROR);
|
||||
nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_PROTOCOL_ERROR);
|
||||
framelen = nghttp2_frame_pack_rst_stream(&buf, &buflen, &frame.rst_stream);
|
||||
nghttp2_frame_rst_stream_free(&frame.rst_stream);
|
||||
nghttp2_failmalloc_unpause();
|
||||
|
@ -348,14 +286,11 @@ static void run_nghttp2_session_recv(void)
|
|||
|
||||
/* SETTINGS */
|
||||
nghttp2_failmalloc_pause();
|
||||
iv[0].settings_id = NGHTTP2_SETTINGS_UPLOAD_BANDWIDTH;
|
||||
iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_PERSIST_VALUE;
|
||||
iv[0].value = 256;
|
||||
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
|
||||
iv[0].value = 4096;
|
||||
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
|
||||
iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE;
|
||||
iv[1].value = 100;
|
||||
nghttp2_frame_settings_init(&frame.settings, NGHTTP2_PROTO_SPDY3,
|
||||
NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS,
|
||||
nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE,
|
||||
nghttp2_frame_iv_copy(iv, 2), 2);
|
||||
framelen = nghttp2_frame_pack_settings(&buf, &buflen, &frame.settings);
|
||||
nghttp2_frame_settings_free(&frame.settings);
|
||||
|
@ -366,32 +301,10 @@ static void run_nghttp2_session_recv(void)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
/* CREDENTIAL */
|
||||
nghttp2_failmalloc_pause();
|
||||
proof.data = (uint8_t*)strcopy("PROOF");
|
||||
proof.length = strlen("PROOF");
|
||||
ncerts = 2;
|
||||
certs = malloc(sizeof(nghttp2_mem_chunk)*ncerts);
|
||||
certs[0].data = (uint8_t*)strcopy("CERT0");
|
||||
certs[0].length = strlen("CERT0");
|
||||
certs[1].data = (uint8_t*)strcopy("CERT1");
|
||||
certs[1].length = strlen("CERT1");
|
||||
nghttp2_frame_credential_init(&frame.credential, NGHTTP2_PROTO_SPDY3,
|
||||
1, &proof, certs, ncerts);
|
||||
framelen = nghttp2_frame_pack_credential(&buf, &buflen, &frame.credential);
|
||||
nghttp2_frame_credential_free(&frame.credential);
|
||||
nghttp2_failmalloc_unpause();
|
||||
|
||||
rv = nghttp2_session_recv(session);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fail:
|
||||
free(buf);
|
||||
free(nvbuf);
|
||||
nghttp2_session_del(session);
|
||||
nghttp2_zlib_deflate_free(&deflater);
|
||||
nghttp2_hd_deflate_free(&deflater);
|
||||
}
|
||||
|
||||
void test_nghttp2_session_recv(void)
|
||||
|
@ -399,57 +312,54 @@ void test_nghttp2_session_recv(void)
|
|||
TEST_FAILMALLOC_RUN(run_nghttp2_session_recv);
|
||||
}
|
||||
|
||||
static void run_nghttp2_frame_pack_syn_stream(void)
|
||||
static void run_nghttp2_frame_pack_headers(void)
|
||||
{
|
||||
nghttp2_zlib deflater, inflater;
|
||||
nghttp2_hd_context deflater, inflater;
|
||||
nghttp2_frame frame, oframe;
|
||||
uint8_t *buf = NULL, *nvbuf = NULL;
|
||||
size_t buflen = 0, nvbuflen = 0;
|
||||
nghttp2_buffer inflatebuf;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen = 0;
|
||||
ssize_t framelen;
|
||||
const char *nv[] = { ":host", "example.org",
|
||||
":scheme", "https",
|
||||
NULL };
|
||||
char **nv_copy;
|
||||
int rv;
|
||||
nghttp2_nv *nva;
|
||||
ssize_t nvlen;
|
||||
|
||||
nghttp2_buffer_init(&inflatebuf, 4096);
|
||||
rv = nghttp2_zlib_deflate_hd_init(&deflater, 1, NGHTTP2_PROTO_SPDY3);
|
||||
rv = nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
||||
if(rv != 0) {
|
||||
goto deflate_init_fail;
|
||||
}
|
||||
rv = nghttp2_zlib_inflate_hd_init(&inflater, NGHTTP2_PROTO_SPDY3);
|
||||
rv = nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST);
|
||||
if(rv != 0) {
|
||||
goto inflate_init_fail;
|
||||
}
|
||||
nv_copy = nghttp2_frame_nv_copy(nv);
|
||||
if(nv_copy == NULL) {
|
||||
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
|
||||
if(nvlen < 0) {
|
||||
goto nv_copy_fail;
|
||||
}
|
||||
nghttp2_frame_syn_stream_init(&frame.syn_stream, NGHTTP2_PROTO_SPDY3,
|
||||
NGHTTP2_CTRL_FLAG_FIN, 1, 0, 2, nv_copy);
|
||||
framelen = nghttp2_frame_pack_syn_stream(&buf, &buflen,
|
||||
&nvbuf, &nvbuflen,
|
||||
&frame.syn_stream, &deflater);
|
||||
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_STREAM,
|
||||
1, NGHTTP2_PRI_DEFAULT, nva, nvlen);
|
||||
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame.headers,
|
||||
&deflater);
|
||||
if(framelen < 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = unpack_frame_with_nv_block(NGHTTP2_SYN_STREAM, NGHTTP2_PROTO_SPDY3,
|
||||
&oframe, &inflater, buf, framelen);
|
||||
rv = unpack_frame_with_nv_block(&oframe, NGHTTP2_HEADERS, &inflater,
|
||||
buf, framelen);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
nghttp2_frame_syn_stream_free(&oframe.syn_stream);
|
||||
nghttp2_frame_headers_free(&oframe.headers);
|
||||
fail:
|
||||
free(buf);
|
||||
free(nvbuf);
|
||||
nghttp2_frame_syn_stream_free(&frame.syn_stream);
|
||||
nghttp2_frame_headers_free(&frame.headers);
|
||||
nv_copy_fail:
|
||||
nghttp2_zlib_inflate_free(&inflater);
|
||||
nghttp2_hd_inflate_free(&inflater);
|
||||
inflate_init_fail:
|
||||
nghttp2_zlib_deflate_free(&deflater);
|
||||
nghttp2_hd_deflate_free(&deflater);
|
||||
deflate_init_fail:
|
||||
nghttp2_buffer_free(&inflatebuf);
|
||||
;
|
||||
}
|
||||
|
||||
static void run_nghttp2_frame_pack_ping(void)
|
||||
|
@ -457,7 +367,7 @@ static void run_nghttp2_frame_pack_ping(void)
|
|||
nghttp2_frame frame;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen = 0;
|
||||
nghttp2_frame_ping_init(&frame.ping, NGHTTP2_PROTO_SPDY3, 1);
|
||||
nghttp2_frame_ping_init(&frame.ping, NGHTTP2_FLAG_NONE, NULL);
|
||||
nghttp2_frame_pack_ping(&buf, &buflen, &frame.ping);
|
||||
free(buf);
|
||||
nghttp2_frame_ping_free(&frame.ping);
|
||||
|
@ -468,8 +378,8 @@ static void run_nghttp2_frame_pack_goaway(void)
|
|||
nghttp2_frame frame;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen = 0;
|
||||
nghttp2_frame_goaway_init(&frame.goaway, NGHTTP2_PROTO_SPDY3, 1000000007,
|
||||
NGHTTP2_GOAWAY_PROTOCOL_ERROR);
|
||||
nghttp2_frame_goaway_init(&frame.goaway, 1000000007, NGHTTP2_PROTOCOL_ERROR,
|
||||
NULL, 0);
|
||||
nghttp2_frame_pack_goaway(&buf, &buflen, &frame.goaway);
|
||||
free(buf);
|
||||
nghttp2_frame_goaway_free(&frame.goaway);
|
||||
|
@ -480,8 +390,7 @@ static void run_nghttp2_frame_pack_rst_stream(void)
|
|||
nghttp2_frame frame;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen = 0;
|
||||
nghttp2_frame_rst_stream_init(&frame.rst_stream, NGHTTP2_PROTO_SPDY3, 1,
|
||||
NGHTTP2_PROTOCOL_ERROR);
|
||||
nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_PROTOCOL_ERROR);
|
||||
nghttp2_frame_pack_rst_stream(&buf, &buflen, &frame.rst_stream);
|
||||
free(buf);
|
||||
nghttp2_frame_rst_stream_free(&frame.rst_stream);
|
||||
|
@ -492,7 +401,7 @@ static void run_nghttp2_frame_pack_window_update(void)
|
|||
nghttp2_frame frame;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen = 0;
|
||||
nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_PROTO_SPDY3,
|
||||
nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE,
|
||||
1000000007, 4096);
|
||||
nghttp2_frame_pack_window_update(&buf, &buflen,
|
||||
&frame.window_update);
|
||||
|
@ -509,20 +418,16 @@ static void run_nghttp2_frame_pack_settings(void)
|
|||
nghttp2_settings_entry iv[2], *iv_copy;
|
||||
int rv;
|
||||
|
||||
iv[0].settings_id = NGHTTP2_SETTINGS_UPLOAD_BANDWIDTH;
|
||||
iv[0].flags = NGHTTP2_ID_FLAG_SETTINGS_PERSIST_VALUE;
|
||||
iv[0].value = 256;
|
||||
iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
|
||||
iv[0].value = 4096;
|
||||
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
|
||||
iv[1].flags = NGHTTP2_ID_FLAG_SETTINGS_NONE;
|
||||
iv[1].value = 100;
|
||||
|
||||
iv_copy = nghttp2_frame_iv_copy(iv, 2);
|
||||
if(iv_copy == NULL) {
|
||||
goto iv_copy_fail;
|
||||
}
|
||||
nghttp2_frame_settings_init(&frame.settings, NGHTTP2_PROTO_SPDY3,
|
||||
NGHTTP2_FLAG_SETTINGS_CLEAR_SETTINGS,
|
||||
iv_copy, 2);
|
||||
nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, iv_copy, 2);
|
||||
framelen = nghttp2_frame_pack_settings(&buf, &buflen, &frame.settings);
|
||||
if(framelen < 0) {
|
||||
goto fail;
|
||||
|
@ -542,58 +447,14 @@ static void run_nghttp2_frame_pack_settings(void)
|
|||
;
|
||||
}
|
||||
|
||||
static void run_nghttp2_frame_pack_credential(void)
|
||||
{
|
||||
nghttp2_frame frame, oframe;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen = 0;
|
||||
ssize_t framelen;
|
||||
nghttp2_mem_chunk proof;
|
||||
nghttp2_mem_chunk *certs;
|
||||
size_t ncerts;
|
||||
int rv;
|
||||
|
||||
nghttp2_failmalloc_pause();
|
||||
|
||||
proof.data = (uint8_t*)strcopy("PROOF");
|
||||
proof.length = strlen("PROOF");
|
||||
ncerts = 2;
|
||||
certs = malloc(sizeof(nghttp2_mem_chunk)*ncerts);
|
||||
certs[0].data = (uint8_t*)strcopy("CERT0");
|
||||
certs[0].length = strlen("CERT0");
|
||||
certs[1].data = (uint8_t*)strcopy("CERT1");
|
||||
certs[1].length = strlen("CERT1");
|
||||
|
||||
nghttp2_failmalloc_unpause();
|
||||
|
||||
nghttp2_frame_credential_init(&frame.credential, NGHTTP2_PROTO_SPDY3,
|
||||
1, &proof, certs, ncerts);
|
||||
framelen = nghttp2_frame_pack_credential(&buf, &buflen, &frame.credential);
|
||||
if(framelen < 0) {
|
||||
goto fail;
|
||||
}
|
||||
rv = nghttp2_frame_unpack_credential(&oframe.credential,
|
||||
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
||||
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
||||
framelen-NGHTTP2_FRAME_HEAD_LENGTH);
|
||||
if(rv != 0) {
|
||||
goto fail;
|
||||
}
|
||||
nghttp2_frame_credential_free(&oframe.credential);
|
||||
fail:
|
||||
free(buf);
|
||||
nghttp2_frame_credential_free(&frame.credential);
|
||||
}
|
||||
|
||||
static void run_nghttp2_frame(void)
|
||||
{
|
||||
run_nghttp2_frame_pack_syn_stream();
|
||||
run_nghttp2_frame_pack_headers();
|
||||
run_nghttp2_frame_pack_ping();
|
||||
run_nghttp2_frame_pack_goaway();
|
||||
run_nghttp2_frame_pack_rst_stream();
|
||||
run_nghttp2_frame_pack_window_update();
|
||||
run_nghttp2_frame_pack_settings();
|
||||
run_nghttp2_frame_pack_credential();
|
||||
}
|
||||
|
||||
void test_nghttp2_frame(void)
|
||||
|
|
Loading…
Reference in New Issue