test_packet_out.c revision a74702c6
1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 2#include <assert.h> 3#include <errno.h> 4#include <stdio.h> 5#include <stdlib.h> 6#include <string.h> 7#include <sys/queue.h> 8#include <sys/types.h> 9#include <sys/stat.h> 10#ifndef WIN32 11#include <unistd.h> 12#endif 13#include <fcntl.h> 14 15#include <openssl/md5.h> 16 17#include "lsquic.h" 18 19#include "lsquic_int_types.h" 20#include "lsquic_packet_common.h" 21#include "lsquic_packet_gquic.h" 22#include "lsquic_packet_out.h" 23#include "lsquic_conn_flow.h" 24#include "lsquic_sfcw.h" 25#include "lsquic_varint.h" 26#include "lsquic_hq.h" 27#include "lsquic_hash.h" 28#include "lsquic_stream.h" 29#include "lsquic_types.h" 30#include "lsquic_malo.h" 31#include "lsquic_mm.h" 32#include "lsquic_engine_public.h" 33#include "lsquic_logger.h" 34 35 36int 37main (void) 38{ 39 struct lsquic_engine_public enpub; 40 struct packet_out_frec_iter pofi; 41 lsquic_packet_out_t *packet_out; 42 struct lsquic_stream streams[6]; 43 struct frame_rec *frec; 44 45 memset(&enpub, 0, sizeof(enpub)); 46 memset(&streams, 0, sizeof(streams)); 47 lsquic_mm_init(&enpub.enp_mm); 48 packet_out = lsquic_mm_get_packet_out(&enpub.enp_mm, NULL, GQUIC_MAX_PAYLOAD_SZ); 49 50 lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[0], QUIC_FRAME_STREAM, 7, 1); 51 lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[1], QUIC_FRAME_STREAM, 8, 1); 52 lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[2], QUIC_FRAME_STREAM, 9, 1); 53 lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[1], QUIC_FRAME_RST_STREAM, 10, 0); 54 lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[3], QUIC_FRAME_STREAM, 11, 1); 55 lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[4], QUIC_FRAME_STREAM, 12, 1); 56 lsquic_packet_out_add_stream(packet_out, &enpub.enp_mm, &streams[5], QUIC_FRAME_STREAM, 13, 1); 57 58 frec = lsquic_pofi_first(&pofi, packet_out); 59 assert(frec->fe_stream == &streams[0]); 60 assert(frec->fe_off == 7); 61 assert(frec->fe_frame_type == QUIC_FRAME_STREAM); 62 63 frec = lsquic_pofi_next(&pofi); 64 assert(frec->fe_stream == &streams[1]); 65 assert(frec->fe_off == 8); 66 assert(frec->fe_frame_type == QUIC_FRAME_STREAM); 67 68 frec = lsquic_pofi_next(&pofi); 69 assert(frec->fe_stream == &streams[2]); 70 assert(frec->fe_off == 9); 71 assert(frec->fe_frame_type == QUIC_FRAME_STREAM); 72 73 frec = lsquic_pofi_next(&pofi); 74 assert(frec->fe_stream == &streams[1]); 75 assert(frec->fe_off == 10); 76 assert(frec->fe_frame_type == QUIC_FRAME_RST_STREAM); 77 78 frec = lsquic_pofi_next(&pofi); 79 assert(frec->fe_stream == &streams[3]); 80 assert(frec->fe_off == 11); 81 assert(frec->fe_frame_type == QUIC_FRAME_STREAM); 82 83 frec = lsquic_pofi_next(&pofi); 84 assert(frec->fe_stream == &streams[4]); 85 assert(frec->fe_off == 12); 86 assert(frec->fe_frame_type == QUIC_FRAME_STREAM); 87 88 frec = lsquic_pofi_next(&pofi); 89 assert(frec->fe_stream == &streams[5]); 90 assert(frec->fe_off == 13); 91 assert(frec->fe_frame_type == QUIC_FRAME_STREAM); 92 93 assert((void *) 0 == lsquic_pofi_next(&pofi)); 94 95 lsquic_packet_out_destroy(packet_out, &enpub, NULL); 96 assert(!lsquic_malo_first(enpub.enp_mm.malo.frame_rec_arr)); 97 98 lsquic_mm_cleanup(&enpub.enp_mm); 99 return 0; 100} 101