tests: Add failmalloc HPACK test

This commit is contained in:
Tatsuhiro Tsujikawa 2014-05-10 21:14:25 +09:00
parent d46e13ae52
commit a93e04c6f8
4 changed files with 92 additions and 2 deletions

View File

@ -59,7 +59,8 @@ int main(int argc, char* argv[])
test_nghttp2_session_send) ||
!CU_add_test(pSuite, "failmalloc_session_recv",
test_nghttp2_session_recv) ||
!CU_add_test(pSuite, "failmalloc_frame", test_nghttp2_frame)) {
!CU_add_test(pSuite, "failmalloc_frame", test_nghttp2_frame) ||
!CU_add_test(pSuite, "failmalloc_hd", test_nghttp2_hd)) {
CU_cleanup_registry();
return CU_get_error();
}

View File

@ -445,3 +445,89 @@ void test_nghttp2_frame(void)
TEST_FAILMALLOC_RUN(run_nghttp2_frame_pack_headers);
TEST_FAILMALLOC_RUN(run_nghttp2_frame_pack_settings);
}
static int deflate_inflate(nghttp2_hd_deflater *deflater,
nghttp2_hd_inflater *inflater,
nghttp2_bufs *bufs,
nghttp2_nv *nva, size_t nvlen)
{
int rv;
rv = nghttp2_hd_deflate_hd(deflater, bufs, nva, nvlen);
if(rv != 0) {
return rv;
}
rv = inflate_hd(inflater, NULL, bufs, 0);
if(rv < 0) {
return rv;
}
nghttp2_bufs_reset(bufs);
return 0;
}
static void run_nghttp2_hd(void)
{
nghttp2_hd_deflater deflater;
nghttp2_hd_inflater inflater;
nghttp2_bufs bufs;
int rv;
nghttp2_nv nva1[] = {
MAKE_NV(":scheme", "https"),
MAKE_NV(":authority", "example.org"),
MAKE_NV(":path", "/slashdot"),
MAKE_NV("accept-encoding", "gzip, deflate")
};
nghttp2_nv nva2[] = {
MAKE_NV(":scheme", "https"),
MAKE_NV(":authority", "example.org"),
MAKE_NV(":path", "/style.css"),
MAKE_NV("cookie", "nghttp2=FTW")
};
rv = frame_pack_bufs_init(&bufs);
if(rv != 0) {
return;
}
rv = nghttp2_hd_deflate_init(&deflater);
if(rv != 0) {
goto deflate_init_fail;
}
rv = nghttp2_hd_inflate_init(&inflater);
if(rv != 0) {
goto inflate_init_fail;
}
rv = deflate_inflate(&deflater, &inflater, &bufs, nva1, ARRLEN(nva1));
if(rv != 0) {
goto deflate_hd_fail;
}
rv = deflate_inflate(&deflater, &inflater, &bufs, nva2, ARRLEN(nva2));
if(rv != 0) {
goto deflate_hd_fail;
}
deflate_hd_fail:
nghttp2_hd_inflate_free(&inflater);
inflate_init_fail:
nghttp2_hd_deflate_free(&deflater);
deflate_init_fail:
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_hd(void)
{
TEST_FAILMALLOC_RUN(run_nghttp2_hd);
}

View File

@ -28,5 +28,6 @@
void test_nghttp2_session_send(void);
void test_nghttp2_session_recv(void);
void test_nghttp2_frame(void);
void test_nghttp2_hd(void);
#endif /* FAILMALLOC_TEST_H */

View File

@ -207,7 +207,9 @@ ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out,
processed += rv;
if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) {
add_out(out, &nv);
if(out) {
add_out(out, &nv);
}
}
if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) {
break;