Fix Windows support

This commit is contained in:
Dmitri Tikhonov 2020-06-03 00:13:30 -04:00
parent 41d574f34c
commit fb3e20e0bc
72 changed files with 912 additions and 475 deletions

View file

@ -45,7 +45,6 @@ SET(TESTS
frame_writer
goaway_gquic_be
h3_framing
hcsi_reader
hkdf
lsquic_hash
packet_out
@ -82,6 +81,8 @@ ENDIF()
IF (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
# No regexes on Windows
SET(TESTS ${TESTS} ack_merge)
# No open_memstream() on Windows
SET(TESTS ${TESTS} hcsi_reader)
ENDIF()
@ -98,21 +99,27 @@ ADD_TEST(stream_hash test_stream -h)
ADD_TEST(stream_A test_stream -A)
ADD_TEST(stream_hash_A test_stream -A -h)
IF(NOT MSVC)
ADD_EXECUTABLE(graph_cubic graph_cubic.c ${ADDL_SOURCES})
TARGET_LINK_LIBRARIES(graph_cubic ${LIBS})
ADD_EXECUTABLE(mini_parse mini_parse.c ${ADDL_SOURCES})
TARGET_LINK_LIBRARIES(mini_parse ${LIBS})
ENDIF()
ADD_EXECUTABLE(test_min_heap test_min_heap.c ../src/liblsquic/lsquic_min_heap.c)
ADD_TEST(min_heap test_min_heap)
ADD_EXECUTABLE(test_malo_pooled test_malo.c ../src/liblsquic/lsquic_malo.c)
SET(MALO_SRC test_malo.c ../src/liblsquic/lsquic_malo.c)
IF(MSVC)
LIST(APPEND MALO_SRC ../wincompat/getopt.c)
ENDIF()
ADD_EXECUTABLE(test_malo_pooled ${MALO_SRC})
SET_TARGET_PROPERTIES(test_malo_pooled
PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLSQUIC_USE_POOLS=1")
ADD_TEST(malo_pooled test_malo_pooled)
ADD_EXECUTABLE(test_malo_nopool test_malo.c ../src/liblsquic/lsquic_malo.c)
ADD_EXECUTABLE(test_malo_nopool ${MALO_SRC})
SET_TARGET_PROPERTIES(test_malo_nopool
PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DLSQUIC_USE_POOLS=0")
ADD_TEST(malo_nopool test_malo_nopool)

View file

@ -10,12 +10,16 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
#include <fcntl.h>
#include <unistd.h>
#else
#include "getopt.h"
#endif
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "lsquic.h"
#include "lsquic_types.h"

View file

@ -9,6 +9,10 @@
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include "vc_compat.h"
#endif
#include "lsquic_types.h"
#include "lsquic_int_types.h"
#include "lsquic_rechist.h"

View file

@ -5,6 +5,8 @@
#include <string.h>
#ifndef WIN32
#include <sys/time.h>
#else
#include "vc_compat.h"
#endif
#include "lsquic_types.h"

View file

@ -5,6 +5,8 @@
#include <string.h>
#ifndef WIN32
#include <sys/time.h>
#else
#include "vc_compat.h"
#endif
#include "lsquic_types.h"

View file

@ -105,7 +105,8 @@ main (void)
unsigned const count = popcount(i);
unsigned const min_n = i % count;
unsigned const min_t = t++;
unsigned j, n, ids[2];
unsigned j, n;
enum alarm_id ids[2];
for (j = 0, n = 0; j < MAX_LSQUIC_ALARMS; ++j)
{
if ((1u << j) & i)

View file

@ -115,6 +115,9 @@ test_attq_ordering (enum sort_action sa)
}
}
#ifdef _MSC_VER
prev = 0;
#endif
for (i = 0; i < sizeof(curiosity); ++i)
{
next_attq = lsquic_attq_next(q);

View file

@ -38,7 +38,7 @@ test_post_quiescence_explosion (void)
struct lsquic_conn lconn = LSCONN_INITIALIZER_CIDLEN(lconn, 8);
struct lsquic_conn_public conn_pub = { .lconn = &lconn, };
int i;
struct lsquic_packet_out packet_out = {};
struct lsquic_packet_out packet_out; memset(&packet_out, 0, sizeof(packet_out));
cci->cci_init(&cubic, &conn_pub, 0);
cubic.cu_ssthresh = cubic.cu_cwnd = 32 * 1370;
@ -72,7 +72,7 @@ test_post_quiescence_explosion2 (void)
struct lsquic_conn lconn = LSCONN_INITIALIZER_CIDLEN(lconn, 8);
struct lsquic_conn_public conn_pub = { .lconn = &lconn, };
int i;
struct lsquic_packet_out packet_out = {};
struct lsquic_packet_out packet_out; memset(&packet_out, 0, sizeof(packet_out));
cci->cci_init(&cubic, &conn_pub, 0);
cubic.cu_ssthresh = cubic.cu_cwnd = 32 * 1370;

View file

@ -442,6 +442,8 @@ run_ekt_test (const struct export_key_test *test)
for (i = 0; i < 2; ++i)
{
if (i && !(test->ekt_ikm_sz == 32 && test->ekt_client_key_sz == 16 && test->ekt_server_key_sz == 16))
continue;
s = lsquic_export_key_material(test->ekt_ikm, (uint32_t)test->ekt_ikm_sz,
test->ekt_salt, (int)test->ekt_salt_sz,
test->ekt_context, (uint32_t)test->ekt_context_sz,

View file

@ -94,7 +94,7 @@ stream_write (struct lsquic_stream *stream, struct lsquic_reader *reader)
}
#define XHDR(name_, value_) .buf = value_, .name_ptr = name_, .val_len = sizeof(value_) - 1, .name_len = sizeof(name_) - 1
#define XHDR(name_, value_) .buf = name_ value_, .name_offset = 0, .name_len = sizeof(name_) - 1, .val_offset = sizeof(name_) - 1, .val_len = sizeof(value_) - 1,
static void

View file

@ -1136,7 +1136,7 @@ test_one_frt (const struct frame_reader_test *frt)
top:
lsquic_mm_init(&mm);
lshpack_dec_init(&hdec, LSHPACK_DEC_HTTP1X);
lshpack_dec_init(&hdec);
memset(&input, 0, sizeof(input));
memcpy(input.in_buf, frt->frt_buf, frt->frt_bufsz);
input.in_sz = frt->frt_bufsz;

View file

@ -225,7 +225,7 @@ test_rw (unsigned max_frame_sz)
lsquic_mm_init(&mm);
lshpack_enc_init(&henc);
lshpack_dec_init(&hdec, LSHPACK_DEC_HTTP1X);
lshpack_dec_init(&hdec);
stream = stream_new();
stream->sm_max_sz = 1;
@ -340,7 +340,7 @@ main (int argc, char **argv)
}
#define XHDR(name_, value_) .buf = value_, .name_ptr = name_, .val_len = sizeof(value_) - 1, .name_len = sizeof(name_) - 1
#define XHDR(name_, value_) .buf = name_ value_, .name_offset = 0, .name_len = sizeof(name_) - 1, .val_offset = sizeof(name_) - 1, .val_len = sizeof(value_) - 1,
/* This list is hardcoded to make the test deterministic */
static struct lsxpack_header header_arr[N_HEADERS] =

View file

@ -63,7 +63,7 @@ output_write (struct lsquic_stream *stream, struct lsquic_reader *reader)
#define IOV(v) { .iov_base = (v), .iov_len = sizeof(v) - 1, }
#define XHDR(name_, value_) .buf = value_, .name_ptr = name_, .val_len = sizeof(value_) - 1, .name_len = sizeof(name_) - 1
#define XHDR(name_, value_) .buf = name_ value_, .name_offset = 0, .name_len = sizeof(name_) - 1, .val_offset = sizeof(name_) - 1, .val_len = sizeof(value_) - 1,
static void
@ -162,6 +162,31 @@ test_one_header (void)
lsquic_mm_cleanup(&mm);
}
struct header_buf
{
unsigned off;
char buf[UINT16_MAX];
};
int
header_set_ptr (struct lsxpack_header *hdr, struct header_buf *header_buf,
const char *name, size_t name_len,
const char *val, size_t val_len)
{
if (header_buf->off + name_len + val_len <= sizeof(header_buf->buf))
{
memcpy(header_buf->buf + header_buf->off, name, name_len);
memcpy(header_buf->buf + header_buf->off + name_len, val, val_len);
lsxpack_header_set_offset2(hdr, header_buf->buf + header_buf->off,
0, name_len, name_len, val_len);
header_buf->off += name_len + val_len;
return 0;
}
else
return -1;
}
static void
test_oversize_header (void)
@ -172,6 +197,7 @@ test_oversize_header (void)
struct lsquic_mm mm;
const size_t big_len = LSXPACK_MAX_STRLEN - 20;
char *value;
struct header_buf hbuf;
lshpack_enc_init(&henc);
lsquic_mm_init(&mm);
@ -190,8 +216,9 @@ test_oversize_header (void)
{
{ XHDR(":status", "302") },
};
lsxpack_header_set_ptr(&header_arr[1], "some-header", 10, value, big_len);
lsxpack_header_set_ptr(&header_arr[2], "another-header", 10, value, big_len);
hbuf.off = 0;
header_set_ptr(&header_arr[1], &hbuf, "some-header", 10, value, big_len);
header_set_ptr(&header_arr[2], &hbuf, "another-header", 10, value, big_len);
struct lsquic_http_headers headers = {
.count = sizeof(header_arr) / sizeof(header_arr[0]),

View file

@ -493,6 +493,8 @@ static const struct lsquic_stream_if packetization_inside_many_stream_if = {
};
#define XHDR(name_, value_) .buf = name_ value_, .name_offset = 0, .name_len = sizeof(name_) - 1, .val_offset = sizeof(name_) - 1, .val_len = sizeof(value_) - 1,
static void
test_hq_framing (int sched_immed, int dispatch_once, unsigned wsize,
int flush_after_each_write, size_t conn_limit,
@ -509,8 +511,7 @@ test_hq_framing (int sched_immed, int dispatch_once, unsigned wsize,
* data-framing writer. This is simply so that we don't have to
* expose more stream things only for testing.
*/
struct lsxpack_header header;
lsxpack_header_set_ptr(&header, ":method", 7, "GET", 3);
struct lsxpack_header header = { XHDR(":method", "GET") };
struct lsquic_http_headers headers = { 1, &header, };
buf_in = malloc(buf_in_sz);
@ -739,8 +740,7 @@ test_frame_header_split (unsigned n_packets, unsigned extra_sz,
const unsigned wsize = 70;
const size_t buf_in_sz = wsize, buf_out_sz = 0x500000;
struct lsxpack_header header;
lsxpack_header_set_ptr(&header, ":method", 7, "GET", 3);
struct lsxpack_header header = { XHDR(":method", "GET") };
struct lsquic_http_headers headers = { 1, &header, };
buf_in = malloc(buf_in_sz);
@ -855,8 +855,7 @@ test_zero_size_frame (void)
const unsigned wsize = 7000;
const size_t buf_in_sz = wsize, buf_out_sz = 0x500000;
struct lsxpack_header header;
lsxpack_header_set_ptr(&header, ":method", 7, "GET", 3);
struct lsxpack_header header = { XHDR(":method", "GET") };
struct lsquic_http_headers headers = { 1, &header, };
buf_in = malloc(buf_in_sz);

View file

@ -35,7 +35,7 @@ main (int argc, char **argv)
else
nelems = 1000000;
widgets = malloc(sizeof(widgets[0]) * nelems);
widgets = calloc(nelems, sizeof(widgets[0]));
for (n = 0; n < nelems; ++n)
{

View file

@ -6,7 +6,7 @@
#ifndef WIN32
#include <unistd.h>
#else
#include <getopt.h>
#include "getopt.h"
#endif
#include "lsquic_malo.h"

View file

@ -46,6 +46,9 @@ test_min_heap (void)
for (i = 0; i < MAX_ELEMS; ++i)
lsquic_mh_insert(&heap, (void *) i, i);
verify_min_heap(&heap);
#ifdef _MSC_VER
prev_val = 0;
#endif
for (i = 0; i < MAX_ELEMS; ++i)
{
p = lsquic_mh_pop(&heap);

View file

@ -2,7 +2,11 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
#include <unistd.h>
#else
#include "getopt.h"
#endif
#include <openssl/rand.h>

View file

@ -38,7 +38,7 @@ main (void)
.sin_port = htons(443),
.sin_addr = peer_addr,
};
lsquic_cid_t cid = {};
lsquic_cid_t cid; memset(&cid, 0, sizeof(cid));
lsquic_qlog_create_connection(&cid, (const struct sockaddr *)&local,
(const struct sockaddr *)&peer);

View file

@ -5,6 +5,10 @@
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include "vc_compat.h"
#endif
#include "lsquic_types.h"
#include "lsquic_int_types.h"
#include "lsquic_rechist.h"

View file

@ -3,7 +3,12 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifndef WIN32
#include <unistd.h>
#else
#include "vc_compat.h"
#include <winbase.h>
#endif
#include "lsquic.h"
#include "lsquic_stock_shi.h"
@ -85,7 +90,11 @@ test_shi (const struct order *order)
assert(0 == s);
}
#ifndef WIN32
sleep(2); /* Let the thing expire */
#else
Sleep(2000); /* Let the thing expire */
#endif
for (i = 0; i < N_PAIRS; ++i)
{

View file

@ -10,7 +10,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
#include <unistd.h>
#else
#include "getopt.h"
#endif
#include "lsquic.h"
#include "lsquic_types.h"