1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov#include <assert.h> 350aadb33SDmitri Tikhonov#include <inttypes.h> 450aadb33SDmitri Tikhonov#include <stdio.h> 550aadb33SDmitri Tikhonov#include <stdlib.h> 650aadb33SDmitri Tikhonov#include <string.h> 750aadb33SDmitri Tikhonov 8fb3e20e0SDmitri Tikhonov#ifdef WIN32 9fb3e20e0SDmitri Tikhonov#include "vc_compat.h" 10fb3e20e0SDmitri Tikhonov#endif 11fb3e20e0SDmitri Tikhonov 1250aadb33SDmitri Tikhonov#include "lsquic_int_types.h" 1350aadb33SDmitri Tikhonov#include "lsquic_rechist.h" 1450aadb33SDmitri Tikhonov#include "lsquic_util.h" 1550aadb33SDmitri Tikhonov 1650aadb33SDmitri Tikhonov 1750aadb33SDmitri Tikhonovstatic void 1850aadb33SDmitri Tikhonovtest4 (void) 1950aadb33SDmitri Tikhonov{ 2050aadb33SDmitri Tikhonov lsquic_rechist_t rechist; 2150aadb33SDmitri Tikhonov const struct lsquic_packno_range *range; 2250aadb33SDmitri Tikhonov lsquic_packno_t packno; 2350aadb33SDmitri Tikhonov 24f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 0, 0); 2550aadb33SDmitri Tikhonov 2650aadb33SDmitri Tikhonov for (packno = 11917; packno <= 11941; ++packno) 2750aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, packno, 0); 2850aadb33SDmitri Tikhonov for (packno = 11946; packno <= 11994; ++packno) 2950aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, packno, 0); 3050aadb33SDmitri Tikhonov 3150aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 3250aadb33SDmitri Tikhonov assert(range); 3350aadb33SDmitri Tikhonov assert(range->high == 11994); 3450aadb33SDmitri Tikhonov assert(range->low == 11946); 3550aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 3650aadb33SDmitri Tikhonov assert(range); 3750aadb33SDmitri Tikhonov assert(range->high == 11941); 3850aadb33SDmitri Tikhonov assert(range->low == 11917); 3950aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 4050aadb33SDmitri Tikhonov assert(!range); 4150aadb33SDmitri Tikhonov 4250aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 11995, 0); 4350aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 11996, 0); 4450aadb33SDmitri Tikhonov 4550aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 4650aadb33SDmitri Tikhonov assert(range); 4750aadb33SDmitri Tikhonov assert(range->high == 11996); 4850aadb33SDmitri Tikhonov assert(range->low == 11946); 4950aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 5050aadb33SDmitri Tikhonov assert(range); 5150aadb33SDmitri Tikhonov assert(range->high == 11941); 5250aadb33SDmitri Tikhonov assert(range->low == 11917); 5350aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 5450aadb33SDmitri Tikhonov assert(!range); 5550aadb33SDmitri Tikhonov 5650aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 11912, 0); 5750aadb33SDmitri Tikhonov lsquic_rechist_stop_wait(&rechist, 11860); 5850aadb33SDmitri Tikhonov 5950aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 6050aadb33SDmitri Tikhonov assert(range); 6150aadb33SDmitri Tikhonov assert(range->high == 11996); 6250aadb33SDmitri Tikhonov assert(range->low == 11946); 6350aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 6450aadb33SDmitri Tikhonov assert(range); 6550aadb33SDmitri Tikhonov assert(range->high == 11941); 6650aadb33SDmitri Tikhonov assert(range->low == 11917); 6750aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 6850aadb33SDmitri Tikhonov assert(range); 6950aadb33SDmitri Tikhonov assert(range->high == 11912); 7050aadb33SDmitri Tikhonov assert(range->low == 11912); 7150aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 7250aadb33SDmitri Tikhonov assert(!range); 7350aadb33SDmitri Tikhonov 7450aadb33SDmitri Tikhonov for (packno = 12169; packno <= 12193; ++packno) 7550aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, packno, 0); 7650aadb33SDmitri Tikhonov 7750aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 7850aadb33SDmitri Tikhonov assert(range); 7950aadb33SDmitri Tikhonov assert(range->high == 12193); 8050aadb33SDmitri Tikhonov assert(range->low == 12169); 8150aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 8250aadb33SDmitri Tikhonov assert(range); 8350aadb33SDmitri Tikhonov assert(range->high == 11996); 8450aadb33SDmitri Tikhonov assert(range->low == 11946); 8550aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 8650aadb33SDmitri Tikhonov assert(range); 8750aadb33SDmitri Tikhonov assert(range->high == 11941); 8850aadb33SDmitri Tikhonov assert(range->low == 11917); 8950aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 9050aadb33SDmitri Tikhonov assert(range); 9150aadb33SDmitri Tikhonov assert(range->high == 11912); 9250aadb33SDmitri Tikhonov assert(range->low == 11912); 9350aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 9450aadb33SDmitri Tikhonov assert(!range); 9550aadb33SDmitri Tikhonov 9650aadb33SDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 9750aadb33SDmitri Tikhonov} 9850aadb33SDmitri Tikhonov 9950aadb33SDmitri Tikhonov 10050aadb33SDmitri Tikhonovstatic void 10150aadb33SDmitri Tikhonovrechist2str (lsquic_rechist_t *rechist, char *buf, size_t bufsz) 10250aadb33SDmitri Tikhonov{ 10350aadb33SDmitri Tikhonov const struct lsquic_packno_range *range; 10450aadb33SDmitri Tikhonov size_t off; 10550aadb33SDmitri Tikhonov int n; 10650aadb33SDmitri Tikhonov 10750aadb33SDmitri Tikhonov for (off = 0, range = lsquic_rechist_first(rechist); 10850aadb33SDmitri Tikhonov range && off < bufsz; 10950aadb33SDmitri Tikhonov off += n, range = lsquic_rechist_next(rechist)) 11050aadb33SDmitri Tikhonov { 11150aadb33SDmitri Tikhonov n = snprintf(buf + off, bufsz - off, "[%"PRIu64"-%"PRIu64"]", 11250aadb33SDmitri Tikhonov range->high, range->low); 11350aadb33SDmitri Tikhonov if (n < 0 || (size_t) n >= bufsz - off) 11450aadb33SDmitri Tikhonov break; 11550aadb33SDmitri Tikhonov } 11650aadb33SDmitri Tikhonov} 11750aadb33SDmitri Tikhonov 11850aadb33SDmitri Tikhonov 11950aadb33SDmitri Tikhonovstatic void 1201a0003e3SDmitri Tikhonovtest_range_copy (struct lsquic_rechist *orig, int ietf) 1211a0003e3SDmitri Tikhonov{ 1221a0003e3SDmitri Tikhonov char orig_str[0x1000], new_str[0x1000]; 1231a0003e3SDmitri Tikhonov struct lsquic_rechist new; 124bbee242aSDmitri Tikhonov size_t len; 1251a0003e3SDmitri Tikhonov 1261a0003e3SDmitri Tikhonov rechist2str(orig, orig_str, sizeof(orig_str)); 1271a0003e3SDmitri Tikhonov 1281a0003e3SDmitri Tikhonov lsquic_rechist_init(&new, ietf, 0); 1291a0003e3SDmitri Tikhonov lsquic_rechist_copy_ranges(&new, orig, 1301a0003e3SDmitri Tikhonov (const struct lsquic_packno_range * (*) (void *)) lsquic_rechist_first, 1311a0003e3SDmitri Tikhonov (const struct lsquic_packno_range * (*) (void *)) lsquic_rechist_next); 1321a0003e3SDmitri Tikhonov rechist2str(&new, new_str, sizeof(new_str)); 1331a0003e3SDmitri Tikhonov assert(0 == strcmp(orig_str, new_str)); 134bbee242aSDmitri Tikhonov lsquic_rechist_cleanup(&new); 135bbee242aSDmitri Tikhonov 136bbee242aSDmitri Tikhonov /* This tests that lower-numbered ranges do not overwrite higher-numbered 137bbee242aSDmitri Tikhonov * ranges. 138bbee242aSDmitri Tikhonov */ 139bbee242aSDmitri Tikhonov lsquic_rechist_init(&new, ietf, 10); 140bbee242aSDmitri Tikhonov lsquic_rechist_copy_ranges(&new, orig, 141bbee242aSDmitri Tikhonov (const struct lsquic_packno_range * (*) (void *)) lsquic_rechist_first, 142bbee242aSDmitri Tikhonov (const struct lsquic_packno_range * (*) (void *)) lsquic_rechist_next); 143bbee242aSDmitri Tikhonov rechist2str(&new, new_str, sizeof(new_str)); 144bbee242aSDmitri Tikhonov len = strlen(new_str); 145bbee242aSDmitri Tikhonov assert(0 == strncmp(orig_str, new_str, len)); 146bbee242aSDmitri Tikhonov lsquic_rechist_cleanup(&new); 1471a0003e3SDmitri Tikhonov} 1481a0003e3SDmitri Tikhonov 1491a0003e3SDmitri Tikhonov 1501a0003e3SDmitri Tikhonovstatic void 15150aadb33SDmitri Tikhonovtest5 (void) 15250aadb33SDmitri Tikhonov{ 15350aadb33SDmitri Tikhonov lsquic_rechist_t rechist; 15450aadb33SDmitri Tikhonov char buf[100]; 15550aadb33SDmitri Tikhonov 156f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 0, 0); 15750aadb33SDmitri Tikhonov 15850aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 1, 0); 15950aadb33SDmitri Tikhonov /* Packet 2 omitted because it could not be decrypted */ 16050aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 3, 0); 16150aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 12, 0); 16250aadb33SDmitri Tikhonov 16350aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 16450aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][3-3][1-1]")); 16550aadb33SDmitri Tikhonov 16650aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 4, 0); 16750aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 10, 0); 16850aadb33SDmitri Tikhonov 16950aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 17050aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][10-10][4-3][1-1]")); 17150aadb33SDmitri Tikhonov 17250aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 6, 0); 17350aadb33SDmitri Tikhonov 17450aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 17550aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][10-10][6-6][4-3][1-1]")); 17650aadb33SDmitri Tikhonov 17750aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 7, 0); 17850aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 8, 0); 17950aadb33SDmitri Tikhonov 18050aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 18150aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][10-10][8-6][4-3][1-1]")); 18250aadb33SDmitri Tikhonov 18350aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 9, 0); 1841a0003e3SDmitri Tikhonov test_range_copy(&rechist, 0); 18550aadb33SDmitri Tikhonov 18650aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 18750aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][10-6][4-3][1-1]")); 18850aadb33SDmitri Tikhonov 18950aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 5, 0); 19050aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 11, 0); 19150aadb33SDmitri Tikhonov 19250aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 19350aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-3][1-1]")); 19450aadb33SDmitri Tikhonov 19550aadb33SDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 19650aadb33SDmitri Tikhonov} 19750aadb33SDmitri Tikhonov 19850aadb33SDmitri Tikhonov 199b62ec17fSDmitri Tikhonovstatic void 200f38b395aSDmitri Tikhonovtest_rand_sequence (unsigned seed, unsigned max) 201b62ec17fSDmitri Tikhonov{ 202b62ec17fSDmitri Tikhonov struct lsquic_rechist rechist; 203b62ec17fSDmitri Tikhonov const struct lsquic_packno_range *range; 204b62ec17fSDmitri Tikhonov lsquic_packno_t prev_low; 205b62ec17fSDmitri Tikhonov enum received_st st; 206f38b395aSDmitri Tikhonov unsigned i, count; 207b62ec17fSDmitri Tikhonov 208f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 1, max); 209b62ec17fSDmitri Tikhonov srand(seed); 210b62ec17fSDmitri Tikhonov 211b62ec17fSDmitri Tikhonov for (i = 0; i < 10000; ++i) 212b62ec17fSDmitri Tikhonov { 213b62ec17fSDmitri Tikhonov st = lsquic_rechist_received(&rechist, (unsigned) rand(), 0); 214b62ec17fSDmitri Tikhonov assert(st == REC_ST_OK || st == REC_ST_DUP); 215b62ec17fSDmitri Tikhonov } 216b62ec17fSDmitri Tikhonov 2171a0003e3SDmitri Tikhonov test_range_copy(&rechist, 1); 2181a0003e3SDmitri Tikhonov 219b62ec17fSDmitri Tikhonov range = lsquic_rechist_first(&rechist); 220b62ec17fSDmitri Tikhonov assert(range); 221b62ec17fSDmitri Tikhonov assert(range->high >= range->low); 222b62ec17fSDmitri Tikhonov prev_low = range->low; 223f38b395aSDmitri Tikhonov count = 1; 224b62ec17fSDmitri Tikhonov 225b62ec17fSDmitri Tikhonov while (range = lsquic_rechist_next(&rechist), range != NULL) 226b62ec17fSDmitri Tikhonov { 227f38b395aSDmitri Tikhonov ++count; 228b62ec17fSDmitri Tikhonov assert(range->high >= range->low); 229b62ec17fSDmitri Tikhonov assert(range->high < prev_low); 230b62ec17fSDmitri Tikhonov prev_low = range->low; 231b62ec17fSDmitri Tikhonov } 232f38b395aSDmitri Tikhonov if (max) 233f38b395aSDmitri Tikhonov assert(count <= max); 234b62ec17fSDmitri Tikhonov 235b62ec17fSDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 236b62ec17fSDmitri Tikhonov} 237b62ec17fSDmitri Tikhonov 238b62ec17fSDmitri Tikhonov 239b62ec17fSDmitri Tikhonovstruct shuffle_elem { 240b62ec17fSDmitri Tikhonov unsigned packno; 241b62ec17fSDmitri Tikhonov int rand; 242b62ec17fSDmitri Tikhonov}; 243b62ec17fSDmitri Tikhonov 244b62ec17fSDmitri Tikhonov 245b62ec17fSDmitri Tikhonovstatic int 246b62ec17fSDmitri Tikhonovcomp_els (const void *a_p, const void *b_p) 247b62ec17fSDmitri Tikhonov{ 248b62ec17fSDmitri Tikhonov const struct shuffle_elem *a = a_p, *b = b_p; 249b62ec17fSDmitri Tikhonov if (a->rand < b->rand) 250b62ec17fSDmitri Tikhonov return -1; 251b62ec17fSDmitri Tikhonov if (a->rand > b->rand) 252b62ec17fSDmitri Tikhonov return 1; 253b62ec17fSDmitri Tikhonov return (a->packno > b->packno) - (b->packno > a->packno); 254b62ec17fSDmitri Tikhonov} 255b62ec17fSDmitri Tikhonov 256b62ec17fSDmitri Tikhonov 257b62ec17fSDmitri Tikhonovstatic void 258b62ec17fSDmitri Tikhonovtest_shuffle_1000 (unsigned seed) 259b62ec17fSDmitri Tikhonov{ 260b62ec17fSDmitri Tikhonov struct lsquic_rechist rechist; 261b62ec17fSDmitri Tikhonov const struct lsquic_packno_range *range; 262b62ec17fSDmitri Tikhonov enum received_st st; 263b62ec17fSDmitri Tikhonov unsigned i; 264b62ec17fSDmitri Tikhonov struct shuffle_elem *els; 265b62ec17fSDmitri Tikhonov 266b62ec17fSDmitri Tikhonov els = malloc(sizeof(els[0]) * 10000); 267f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 1, 0); 268b62ec17fSDmitri Tikhonov srand(seed); 269b62ec17fSDmitri Tikhonov 270b62ec17fSDmitri Tikhonov for (i = 0; i < 10000; ++i) 271b62ec17fSDmitri Tikhonov { 272b62ec17fSDmitri Tikhonov els[i].packno = i; 273b62ec17fSDmitri Tikhonov els[i].rand = rand(); 274b62ec17fSDmitri Tikhonov } 275b62ec17fSDmitri Tikhonov 276b62ec17fSDmitri Tikhonov qsort(els, 10000, sizeof(els[0]), comp_els); 277b62ec17fSDmitri Tikhonov 278b62ec17fSDmitri Tikhonov for (i = 0; i < 10000; ++i) 279b62ec17fSDmitri Tikhonov { 280b62ec17fSDmitri Tikhonov st = lsquic_rechist_received(&rechist, els[i].packno, 0); 281b62ec17fSDmitri Tikhonov assert(st == REC_ST_OK || st == REC_ST_DUP); 282b62ec17fSDmitri Tikhonov } 2831a0003e3SDmitri Tikhonov test_range_copy(&rechist, 1); 284b62ec17fSDmitri Tikhonov 285b62ec17fSDmitri Tikhonov range = lsquic_rechist_first(&rechist); 286b62ec17fSDmitri Tikhonov assert(range); 287b62ec17fSDmitri Tikhonov assert(range->high == 9999); 288b62ec17fSDmitri Tikhonov assert(range->low == 0); 289b62ec17fSDmitri Tikhonov range = lsquic_rechist_next(&rechist); 290b62ec17fSDmitri Tikhonov assert(!range); 291b62ec17fSDmitri Tikhonov 292b62ec17fSDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 293b62ec17fSDmitri Tikhonov free(els); 294b62ec17fSDmitri Tikhonov} 295b62ec17fSDmitri Tikhonov 296b62ec17fSDmitri Tikhonov 29750aadb33SDmitri Tikhonovint 29850aadb33SDmitri Tikhonovmain (void) 29950aadb33SDmitri Tikhonov{ 30050aadb33SDmitri Tikhonov enum received_st st; 30150aadb33SDmitri Tikhonov lsquic_rechist_t rechist; 30250aadb33SDmitri Tikhonov unsigned i; 30350aadb33SDmitri Tikhonov const struct lsquic_packno_range *range; 30450aadb33SDmitri Tikhonov 305f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 0, 0); 30650aadb33SDmitri Tikhonov 307b62ec17fSDmitri Tikhonov lsquic_time_t now = 1234; 30850aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, 0, now); 30950aadb33SDmitri Tikhonov assert(("inserting packet number zero results in error", st == REC_ST_ERR)); 31050aadb33SDmitri Tikhonov 31150aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, 1, now); 31250aadb33SDmitri Tikhonov assert(("inserting packet number one is successful", st == REC_ST_OK)); 31350aadb33SDmitri Tikhonov 31450aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, 1, now); 31550aadb33SDmitri Tikhonov assert(("inserting packet number one again results in duplicate error", 31650aadb33SDmitri Tikhonov st == REC_ST_DUP)); 31750aadb33SDmitri Tikhonov 31850aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 31950aadb33SDmitri Tikhonov assert(("first range returned correctly", range)); 32050aadb33SDmitri Tikhonov assert(("first range low value checks out", range->low == 1)); 32150aadb33SDmitri Tikhonov assert(("first range high value checks out", range->high == 1)); 32250aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 32350aadb33SDmitri Tikhonov assert(("second range does not exist", !range)); 32450aadb33SDmitri Tikhonov 32550aadb33SDmitri Tikhonov for (i = 3; i <= 5; ++i) 32650aadb33SDmitri Tikhonov { 32750aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, i, now); 32850aadb33SDmitri Tikhonov assert(("inserting packet", st == REC_ST_OK)); 32950aadb33SDmitri Tikhonov } 33050aadb33SDmitri Tikhonov 33150aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 33250aadb33SDmitri Tikhonov assert(("first range returned correctly", range)); 33350aadb33SDmitri Tikhonov assert(("first range low value checks out", range->low == 3)); 33450aadb33SDmitri Tikhonov assert(("first range high value checks out", range->high == 5)); 33550aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 33650aadb33SDmitri Tikhonov assert(("second range returned correctly", range)); 33750aadb33SDmitri Tikhonov assert(("second range low value checks out", range->low == 1)); 33850aadb33SDmitri Tikhonov assert(("second range high value checks out", range->high == 1)); 33950aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 34050aadb33SDmitri Tikhonov assert(("third range does not exist", !range)); 34150aadb33SDmitri Tikhonov 34250aadb33SDmitri Tikhonov lsquic_rechist_stop_wait(&rechist, 3); 34350aadb33SDmitri Tikhonov 34450aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, 1, now); 34550aadb33SDmitri Tikhonov assert(("inserting packet number one is unsuccessful after cutoff 3", 34650aadb33SDmitri Tikhonov st == REC_ST_DUP)); 34750aadb33SDmitri Tikhonov 34850aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 34950aadb33SDmitri Tikhonov assert(("first range returned correctly", range)); 35050aadb33SDmitri Tikhonov assert(("first range low value checks out", range->low == 3)); 35150aadb33SDmitri Tikhonov assert(("first range high value checks out", range->high == 5)); 35250aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 35350aadb33SDmitri Tikhonov assert(("second range does not exist", !range)); 35450aadb33SDmitri Tikhonov 35550aadb33SDmitri Tikhonov for (i = 9; i >= 7; --i) 35650aadb33SDmitri Tikhonov { 35750aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, i, now); 35850aadb33SDmitri Tikhonov assert(("inserting packet", st == REC_ST_OK)); 35950aadb33SDmitri Tikhonov } 36050aadb33SDmitri Tikhonov 36150aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 36250aadb33SDmitri Tikhonov assert(("first range returned correctly", range)); 36350aadb33SDmitri Tikhonov assert(("first range low value checks out", range->low == 7)); 36450aadb33SDmitri Tikhonov assert(("first range high value checks out", range->high == 9)); 36550aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 36650aadb33SDmitri Tikhonov assert(("second range returned correctly", range)); 36750aadb33SDmitri Tikhonov assert(("second range low value checks out", range->low == 3)); 36850aadb33SDmitri Tikhonov assert(("second range high value checks out", range->high == 5)); 36950aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 37050aadb33SDmitri Tikhonov assert(("third range does not exist", !range)); 37150aadb33SDmitri Tikhonov 372b62ec17fSDmitri Tikhonov lsquic_rechist_stop_wait(&rechist, 5); 373b62ec17fSDmitri Tikhonov 374b62ec17fSDmitri Tikhonov range = lsquic_rechist_first(&rechist); 375b62ec17fSDmitri Tikhonov range = lsquic_rechist_next(&rechist); 376b62ec17fSDmitri Tikhonov assert(("second range returned correctly", range)); 377b62ec17fSDmitri Tikhonov assert(("second range low value checks out", range->low == 5)); 378b62ec17fSDmitri Tikhonov assert(("second range high value checks out", range->high == 5)); 379b62ec17fSDmitri Tikhonov range = lsquic_rechist_next(&rechist); 380b62ec17fSDmitri Tikhonov assert(("third range does not exist", !range)); 381b62ec17fSDmitri Tikhonov 382b62ec17fSDmitri Tikhonov lsquic_rechist_stop_wait(&rechist, 8); 383b62ec17fSDmitri Tikhonov 384b62ec17fSDmitri Tikhonov range = lsquic_rechist_first(&rechist); 385b62ec17fSDmitri Tikhonov assert(("first range returned correctly", range)); 386b62ec17fSDmitri Tikhonov assert(("first range low value checks out", range->low == 8)); 387b62ec17fSDmitri Tikhonov assert(("first range high value checks out", range->high == 9)); 388b62ec17fSDmitri Tikhonov range = lsquic_rechist_next(&rechist); 389b62ec17fSDmitri Tikhonov assert(("second range does not exist", !range)); 390b62ec17fSDmitri Tikhonov 39150aadb33SDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 39250aadb33SDmitri Tikhonov 39350aadb33SDmitri Tikhonov test4(); 39450aadb33SDmitri Tikhonov 39550aadb33SDmitri Tikhonov test5(); 39650aadb33SDmitri Tikhonov 397b62ec17fSDmitri Tikhonov for (i = 0; i < 10; ++i) 398f38b395aSDmitri Tikhonov test_rand_sequence(i, 0); 399f38b395aSDmitri Tikhonov 400f38b395aSDmitri Tikhonov for (i = 0; i < 10; ++i) 401f38b395aSDmitri Tikhonov test_rand_sequence(i, 111 + i * 3 /* Just something arbitrary */); 402b62ec17fSDmitri Tikhonov 403b62ec17fSDmitri Tikhonov for (i = 0; i < 10; ++i) 404b62ec17fSDmitri Tikhonov test_shuffle_1000(i); 405b62ec17fSDmitri Tikhonov 40650aadb33SDmitri Tikhonov return 0; 40750aadb33SDmitri Tikhonov} 408