test_rechist.c revision 1a0003e3
106b2a236SDmitri Tikhonov/* Copyright (c) 2017 - 2021 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; 1241a0003e3SDmitri Tikhonov 1251a0003e3SDmitri Tikhonov rechist2str(orig, orig_str, sizeof(orig_str)); 1261a0003e3SDmitri Tikhonov 1271a0003e3SDmitri Tikhonov lsquic_rechist_init(&new, ietf, 0); 1281a0003e3SDmitri Tikhonov lsquic_rechist_copy_ranges(&new, orig, 1291a0003e3SDmitri Tikhonov (const struct lsquic_packno_range * (*) (void *)) lsquic_rechist_first, 1301a0003e3SDmitri Tikhonov (const struct lsquic_packno_range * (*) (void *)) lsquic_rechist_next); 1311a0003e3SDmitri Tikhonov rechist2str(&new, new_str, sizeof(new_str)); 1321a0003e3SDmitri Tikhonov assert(0 == strcmp(orig_str, new_str)); 1331a0003e3SDmitri Tikhonov} 1341a0003e3SDmitri Tikhonov 1351a0003e3SDmitri Tikhonov 1361a0003e3SDmitri Tikhonovstatic void 13750aadb33SDmitri Tikhonovtest5 (void) 13850aadb33SDmitri Tikhonov{ 13950aadb33SDmitri Tikhonov lsquic_rechist_t rechist; 14050aadb33SDmitri Tikhonov char buf[100]; 14150aadb33SDmitri Tikhonov 142f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 0, 0); 14350aadb33SDmitri Tikhonov 14450aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 1, 0); 14550aadb33SDmitri Tikhonov /* Packet 2 omitted because it could not be decrypted */ 14650aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 3, 0); 14750aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 12, 0); 14850aadb33SDmitri Tikhonov 14950aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 15050aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][3-3][1-1]")); 15150aadb33SDmitri Tikhonov 15250aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 4, 0); 15350aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 10, 0); 15450aadb33SDmitri Tikhonov 15550aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 15650aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][10-10][4-3][1-1]")); 15750aadb33SDmitri Tikhonov 15850aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 6, 0); 15950aadb33SDmitri Tikhonov 16050aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 16150aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][10-10][6-6][4-3][1-1]")); 16250aadb33SDmitri Tikhonov 16350aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 7, 0); 16450aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 8, 0); 16550aadb33SDmitri Tikhonov 16650aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 16750aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][10-10][8-6][4-3][1-1]")); 16850aadb33SDmitri Tikhonov 16950aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 9, 0); 1701a0003e3SDmitri Tikhonov test_range_copy(&rechist, 0); 17150aadb33SDmitri Tikhonov 17250aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 17350aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-12][10-6][4-3][1-1]")); 17450aadb33SDmitri Tikhonov 17550aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 5, 0); 17650aadb33SDmitri Tikhonov lsquic_rechist_received(&rechist, 11, 0); 17750aadb33SDmitri Tikhonov 17850aadb33SDmitri Tikhonov rechist2str(&rechist, buf, sizeof(buf)); 17950aadb33SDmitri Tikhonov assert(0 == strcmp(buf, "[12-3][1-1]")); 18050aadb33SDmitri Tikhonov 18150aadb33SDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 18250aadb33SDmitri Tikhonov} 18350aadb33SDmitri Tikhonov 18450aadb33SDmitri Tikhonov 185b62ec17fSDmitri Tikhonovstatic void 186f38b395aSDmitri Tikhonovtest_rand_sequence (unsigned seed, unsigned max) 187b62ec17fSDmitri Tikhonov{ 188b62ec17fSDmitri Tikhonov struct lsquic_rechist rechist; 189b62ec17fSDmitri Tikhonov const struct lsquic_packno_range *range; 190b62ec17fSDmitri Tikhonov lsquic_packno_t prev_low; 191b62ec17fSDmitri Tikhonov enum received_st st; 192f38b395aSDmitri Tikhonov unsigned i, count; 193b62ec17fSDmitri Tikhonov 194f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 1, max); 195b62ec17fSDmitri Tikhonov srand(seed); 196b62ec17fSDmitri Tikhonov 197b62ec17fSDmitri Tikhonov for (i = 0; i < 10000; ++i) 198b62ec17fSDmitri Tikhonov { 199b62ec17fSDmitri Tikhonov st = lsquic_rechist_received(&rechist, (unsigned) rand(), 0); 200b62ec17fSDmitri Tikhonov assert(st == REC_ST_OK || st == REC_ST_DUP); 201b62ec17fSDmitri Tikhonov } 202b62ec17fSDmitri Tikhonov 2031a0003e3SDmitri Tikhonov test_range_copy(&rechist, 1); 2041a0003e3SDmitri Tikhonov 205b62ec17fSDmitri Tikhonov range = lsquic_rechist_first(&rechist); 206b62ec17fSDmitri Tikhonov assert(range); 207b62ec17fSDmitri Tikhonov assert(range->high >= range->low); 208b62ec17fSDmitri Tikhonov prev_low = range->low; 209f38b395aSDmitri Tikhonov count = 1; 210b62ec17fSDmitri Tikhonov 211b62ec17fSDmitri Tikhonov while (range = lsquic_rechist_next(&rechist), range != NULL) 212b62ec17fSDmitri Tikhonov { 213f38b395aSDmitri Tikhonov ++count; 214b62ec17fSDmitri Tikhonov assert(range->high >= range->low); 215b62ec17fSDmitri Tikhonov assert(range->high < prev_low); 216b62ec17fSDmitri Tikhonov prev_low = range->low; 217b62ec17fSDmitri Tikhonov } 218f38b395aSDmitri Tikhonov if (max) 219f38b395aSDmitri Tikhonov assert(count <= max); 220b62ec17fSDmitri Tikhonov 221b62ec17fSDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 222b62ec17fSDmitri Tikhonov} 223b62ec17fSDmitri Tikhonov 224b62ec17fSDmitri Tikhonov 225b62ec17fSDmitri Tikhonovstruct shuffle_elem { 226b62ec17fSDmitri Tikhonov unsigned packno; 227b62ec17fSDmitri Tikhonov int rand; 228b62ec17fSDmitri Tikhonov}; 229b62ec17fSDmitri Tikhonov 230b62ec17fSDmitri Tikhonov 231b62ec17fSDmitri Tikhonovstatic int 232b62ec17fSDmitri Tikhonovcomp_els (const void *a_p, const void *b_p) 233b62ec17fSDmitri Tikhonov{ 234b62ec17fSDmitri Tikhonov const struct shuffle_elem *a = a_p, *b = b_p; 235b62ec17fSDmitri Tikhonov if (a->rand < b->rand) 236b62ec17fSDmitri Tikhonov return -1; 237b62ec17fSDmitri Tikhonov if (a->rand > b->rand) 238b62ec17fSDmitri Tikhonov return 1; 239b62ec17fSDmitri Tikhonov return (a->packno > b->packno) - (b->packno > a->packno); 240b62ec17fSDmitri Tikhonov} 241b62ec17fSDmitri Tikhonov 242b62ec17fSDmitri Tikhonov 243b62ec17fSDmitri Tikhonovstatic void 244b62ec17fSDmitri Tikhonovtest_shuffle_1000 (unsigned seed) 245b62ec17fSDmitri Tikhonov{ 246b62ec17fSDmitri Tikhonov struct lsquic_rechist rechist; 247b62ec17fSDmitri Tikhonov const struct lsquic_packno_range *range; 248b62ec17fSDmitri Tikhonov enum received_st st; 249b62ec17fSDmitri Tikhonov unsigned i; 250b62ec17fSDmitri Tikhonov struct shuffle_elem *els; 251b62ec17fSDmitri Tikhonov 252b62ec17fSDmitri Tikhonov els = malloc(sizeof(els[0]) * 10000); 253f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 1, 0); 254b62ec17fSDmitri Tikhonov srand(seed); 255b62ec17fSDmitri Tikhonov 256b62ec17fSDmitri Tikhonov for (i = 0; i < 10000; ++i) 257b62ec17fSDmitri Tikhonov { 258b62ec17fSDmitri Tikhonov els[i].packno = i; 259b62ec17fSDmitri Tikhonov els[i].rand = rand(); 260b62ec17fSDmitri Tikhonov } 261b62ec17fSDmitri Tikhonov 262b62ec17fSDmitri Tikhonov qsort(els, 10000, sizeof(els[0]), comp_els); 263b62ec17fSDmitri Tikhonov 264b62ec17fSDmitri Tikhonov for (i = 0; i < 10000; ++i) 265b62ec17fSDmitri Tikhonov { 266b62ec17fSDmitri Tikhonov st = lsquic_rechist_received(&rechist, els[i].packno, 0); 267b62ec17fSDmitri Tikhonov assert(st == REC_ST_OK || st == REC_ST_DUP); 268b62ec17fSDmitri Tikhonov } 2691a0003e3SDmitri Tikhonov test_range_copy(&rechist, 1); 270b62ec17fSDmitri Tikhonov 271b62ec17fSDmitri Tikhonov range = lsquic_rechist_first(&rechist); 272b62ec17fSDmitri Tikhonov assert(range); 273b62ec17fSDmitri Tikhonov assert(range->high == 9999); 274b62ec17fSDmitri Tikhonov assert(range->low == 0); 275b62ec17fSDmitri Tikhonov range = lsquic_rechist_next(&rechist); 276b62ec17fSDmitri Tikhonov assert(!range); 277b62ec17fSDmitri Tikhonov 278b62ec17fSDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 279b62ec17fSDmitri Tikhonov free(els); 280b62ec17fSDmitri Tikhonov} 281b62ec17fSDmitri Tikhonov 282b62ec17fSDmitri Tikhonov 28350aadb33SDmitri Tikhonovint 28450aadb33SDmitri Tikhonovmain (void) 28550aadb33SDmitri Tikhonov{ 28650aadb33SDmitri Tikhonov enum received_st st; 28750aadb33SDmitri Tikhonov lsquic_rechist_t rechist; 28850aadb33SDmitri Tikhonov unsigned i; 28950aadb33SDmitri Tikhonov const struct lsquic_packno_range *range; 29050aadb33SDmitri Tikhonov 291f38b395aSDmitri Tikhonov lsquic_rechist_init(&rechist, 0, 0); 29250aadb33SDmitri Tikhonov 293b62ec17fSDmitri Tikhonov lsquic_time_t now = 1234; 29450aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, 0, now); 29550aadb33SDmitri Tikhonov assert(("inserting packet number zero results in error", st == REC_ST_ERR)); 29650aadb33SDmitri Tikhonov 29750aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, 1, now); 29850aadb33SDmitri Tikhonov assert(("inserting packet number one is successful", st == REC_ST_OK)); 29950aadb33SDmitri Tikhonov 30050aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, 1, now); 30150aadb33SDmitri Tikhonov assert(("inserting packet number one again results in duplicate error", 30250aadb33SDmitri Tikhonov st == REC_ST_DUP)); 30350aadb33SDmitri Tikhonov 30450aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 30550aadb33SDmitri Tikhonov assert(("first range returned correctly", range)); 30650aadb33SDmitri Tikhonov assert(("first range low value checks out", range->low == 1)); 30750aadb33SDmitri Tikhonov assert(("first range high value checks out", range->high == 1)); 30850aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 30950aadb33SDmitri Tikhonov assert(("second range does not exist", !range)); 31050aadb33SDmitri Tikhonov 31150aadb33SDmitri Tikhonov for (i = 3; i <= 5; ++i) 31250aadb33SDmitri Tikhonov { 31350aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, i, now); 31450aadb33SDmitri Tikhonov assert(("inserting packet", st == REC_ST_OK)); 31550aadb33SDmitri Tikhonov } 31650aadb33SDmitri Tikhonov 31750aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 31850aadb33SDmitri Tikhonov assert(("first range returned correctly", range)); 31950aadb33SDmitri Tikhonov assert(("first range low value checks out", range->low == 3)); 32050aadb33SDmitri Tikhonov assert(("first range high value checks out", range->high == 5)); 32150aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 32250aadb33SDmitri Tikhonov assert(("second range returned correctly", range)); 32350aadb33SDmitri Tikhonov assert(("second range low value checks out", range->low == 1)); 32450aadb33SDmitri Tikhonov assert(("second range high value checks out", range->high == 1)); 32550aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 32650aadb33SDmitri Tikhonov assert(("third range does not exist", !range)); 32750aadb33SDmitri Tikhonov 32850aadb33SDmitri Tikhonov lsquic_rechist_stop_wait(&rechist, 3); 32950aadb33SDmitri Tikhonov 33050aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, 1, now); 33150aadb33SDmitri Tikhonov assert(("inserting packet number one is unsuccessful after cutoff 3", 33250aadb33SDmitri Tikhonov st == REC_ST_DUP)); 33350aadb33SDmitri Tikhonov 33450aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 33550aadb33SDmitri Tikhonov assert(("first range returned correctly", range)); 33650aadb33SDmitri Tikhonov assert(("first range low value checks out", range->low == 3)); 33750aadb33SDmitri Tikhonov assert(("first range high value checks out", range->high == 5)); 33850aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 33950aadb33SDmitri Tikhonov assert(("second range does not exist", !range)); 34050aadb33SDmitri Tikhonov 34150aadb33SDmitri Tikhonov for (i = 9; i >= 7; --i) 34250aadb33SDmitri Tikhonov { 34350aadb33SDmitri Tikhonov st = lsquic_rechist_received(&rechist, i, now); 34450aadb33SDmitri Tikhonov assert(("inserting packet", st == REC_ST_OK)); 34550aadb33SDmitri Tikhonov } 34650aadb33SDmitri Tikhonov 34750aadb33SDmitri Tikhonov range = lsquic_rechist_first(&rechist); 34850aadb33SDmitri Tikhonov assert(("first range returned correctly", range)); 34950aadb33SDmitri Tikhonov assert(("first range low value checks out", range->low == 7)); 35050aadb33SDmitri Tikhonov assert(("first range high value checks out", range->high == 9)); 35150aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 35250aadb33SDmitri Tikhonov assert(("second range returned correctly", range)); 35350aadb33SDmitri Tikhonov assert(("second range low value checks out", range->low == 3)); 35450aadb33SDmitri Tikhonov assert(("second range high value checks out", range->high == 5)); 35550aadb33SDmitri Tikhonov range = lsquic_rechist_next(&rechist); 35650aadb33SDmitri Tikhonov assert(("third range does not exist", !range)); 35750aadb33SDmitri Tikhonov 358b62ec17fSDmitri Tikhonov lsquic_rechist_stop_wait(&rechist, 5); 359b62ec17fSDmitri Tikhonov 360b62ec17fSDmitri Tikhonov range = lsquic_rechist_first(&rechist); 361b62ec17fSDmitri Tikhonov range = lsquic_rechist_next(&rechist); 362b62ec17fSDmitri Tikhonov assert(("second range returned correctly", range)); 363b62ec17fSDmitri Tikhonov assert(("second range low value checks out", range->low == 5)); 364b62ec17fSDmitri Tikhonov assert(("second range high value checks out", range->high == 5)); 365b62ec17fSDmitri Tikhonov range = lsquic_rechist_next(&rechist); 366b62ec17fSDmitri Tikhonov assert(("third range does not exist", !range)); 367b62ec17fSDmitri Tikhonov 368b62ec17fSDmitri Tikhonov lsquic_rechist_stop_wait(&rechist, 8); 369b62ec17fSDmitri Tikhonov 370b62ec17fSDmitri Tikhonov range = lsquic_rechist_first(&rechist); 371b62ec17fSDmitri Tikhonov assert(("first range returned correctly", range)); 372b62ec17fSDmitri Tikhonov assert(("first range low value checks out", range->low == 8)); 373b62ec17fSDmitri Tikhonov assert(("first range high value checks out", range->high == 9)); 374b62ec17fSDmitri Tikhonov range = lsquic_rechist_next(&rechist); 375b62ec17fSDmitri Tikhonov assert(("second range does not exist", !range)); 376b62ec17fSDmitri Tikhonov 37750aadb33SDmitri Tikhonov lsquic_rechist_cleanup(&rechist); 37850aadb33SDmitri Tikhonov 37950aadb33SDmitri Tikhonov test4(); 38050aadb33SDmitri Tikhonov 38150aadb33SDmitri Tikhonov test5(); 38250aadb33SDmitri Tikhonov 383b62ec17fSDmitri Tikhonov for (i = 0; i < 10; ++i) 384f38b395aSDmitri Tikhonov test_rand_sequence(i, 0); 385f38b395aSDmitri Tikhonov 386f38b395aSDmitri Tikhonov for (i = 0; i < 10; ++i) 387f38b395aSDmitri Tikhonov test_rand_sequence(i, 111 + i * 3 /* Just something arbitrary */); 388b62ec17fSDmitri Tikhonov 389b62ec17fSDmitri Tikhonov for (i = 0; i < 10; ++i) 390b62ec17fSDmitri Tikhonov test_shuffle_1000(i); 391b62ec17fSDmitri Tikhonov 39250aadb33SDmitri Tikhonov return 0; 39350aadb33SDmitri Tikhonov} 394