adding scale tests
This commit is contained in:
parent
6d2e355e19
commit
5e83f660ea
2 changed files with 112 additions and 10 deletions
|
@ -149,16 +149,22 @@ ensure_sequential_set(int a[], int l, int r)
|
|||
int
|
||||
create_sequential_set_in_empty_map(sparsemap_t *map, int s, int r)
|
||||
{
|
||||
int placed_at;
|
||||
if (s >= r + 1) {
|
||||
placed_at = 0;
|
||||
} else {
|
||||
placed_at = random_uint32() % (s - r - 1);
|
||||
}
|
||||
for (int i = placed_at; i < placed_at + r; i++) {
|
||||
sparsemap_set(map, i, true);
|
||||
}
|
||||
return placed_at;
|
||||
do {
|
||||
int placed_at;
|
||||
if (s >= r + 1) {
|
||||
placed_at = 0;
|
||||
} else {
|
||||
placed_at = random_uint32() % (s - r - 1);
|
||||
}
|
||||
for (int i = placed_at; i < placed_at + r; i++) {
|
||||
sparsemap_is_set(map, i);
|
||||
continue;
|
||||
}
|
||||
for (int i = placed_at; i < placed_at + r; i++) {
|
||||
sparsemap_set(map, i, true);
|
||||
}
|
||||
return placed_at;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
96
tests/test.c
96
tests/test.c
|
@ -690,6 +690,100 @@ static MunitTest api_test_suite[] = {
|
|||
|
||||
/* -------------------------- Scale Tests */
|
||||
|
||||
static void *
|
||||
test_scale_lots_o_spans_setup(const MunitParameter params[], void *user_data)
|
||||
{
|
||||
uint8_t *buf = munit_calloc(1024, sizeof(uint8_t));
|
||||
sparsemap_t *map = (sparsemap_t *)test_api_setup(params, user_data);
|
||||
|
||||
sparsemap_init(map, buf, 1024);
|
||||
|
||||
return (void *)map;
|
||||
}
|
||||
static void
|
||||
test_scale_lots_o_spans_tear_down(void *fixture)
|
||||
{
|
||||
sparsemap_t *map = (sparsemap_t *)fixture;
|
||||
free(map->m_data);
|
||||
test_api_tear_down(fixture);
|
||||
}
|
||||
static MunitResult
|
||||
test_scale_lots_o_spans(const MunitParameter params[], void *data)
|
||||
{
|
||||
sparsemap_t *map = (sparsemap_t *)data;
|
||||
(void)params;
|
||||
|
||||
assert_ptr_not_null(map);
|
||||
|
||||
for (int i = 0; i < 268435456;) {
|
||||
int l = i % 31 + 16;
|
||||
create_sequential_set_in_empty_map(map, 268435456, l);
|
||||
i += l;
|
||||
/* ANSI esc code to clear line, carrage return, then print on the same line */
|
||||
//printf("\033[2K\r%d", i);
|
||||
//printf("%d\t%d\n", l, i);
|
||||
//fflush(stdout);
|
||||
}
|
||||
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
static void *
|
||||
test_scale_spans_come_spans_go_setup(const MunitParameter params[], void *user_data)
|
||||
{
|
||||
uint8_t *buf = munit_calloc(1024, sizeof(uint8_t));
|
||||
sparsemap_t *map = (sparsemap_t *)test_api_setup(params, user_data);
|
||||
|
||||
sparsemap_init(map, buf, 1024);
|
||||
|
||||
return (void *)map;
|
||||
}
|
||||
static void
|
||||
test_scale_spans_come_spans_go_tear_down(void *fixture)
|
||||
{
|
||||
sparsemap_t *map = (sparsemap_t *)fixture;
|
||||
free(map->m_data);
|
||||
test_api_tear_down(fixture);
|
||||
}
|
||||
static MunitResult
|
||||
test_scale_spans_come_spans_go(const MunitParameter params[], void *data)
|
||||
{
|
||||
sparsemap_t *map = (sparsemap_t *)data;
|
||||
(void)params;
|
||||
|
||||
assert_ptr_not_null(map);
|
||||
|
||||
for (int i = 0; i < 268435456;) {
|
||||
int l = i % 31 + 16;
|
||||
create_sequential_set_in_empty_map(map, 268435456, l);
|
||||
i += l;
|
||||
|
||||
/* After 10,000 spans are in there we consume a span every iteration. */
|
||||
if (l > 10000) {
|
||||
do {
|
||||
int s = munit_rand_int_range(1, 30);
|
||||
int o = munit_rand_int_range(1, 268435456 - s - 1);
|
||||
size_t b = sparsemap_span(map, o, s, true);
|
||||
if (b == SM_LOC_MAX) {
|
||||
continue;
|
||||
}
|
||||
for (int j = b; j < s; j++) {
|
||||
assert_true(sparsemap_is_set(map, j) == true);
|
||||
}
|
||||
for (int j = b; j < s; j++) {
|
||||
sparsemap_set(map, j, false);
|
||||
}
|
||||
for (int j = b; j < s; j++) {
|
||||
assert_true(sparsemap_is_set(map, j) == false);
|
||||
}
|
||||
break;
|
||||
} while (true);
|
||||
}
|
||||
}
|
||||
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
static void *
|
||||
test_scale_best_case_setup(const MunitParameter params[], void *user_data)
|
||||
{
|
||||
|
@ -876,6 +970,8 @@ test_perf_span_tainted(const MunitParameter params[], void *data)
|
|||
|
||||
// clang-format off
|
||||
static MunitTest scale_test_suite[] = {
|
||||
{ (char *)"/lots-o-spans", test_scale_lots_o_spans, test_scale_lots_o_spans_setup, test_scale_lots_o_spans_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
|
||||
{ (char *)"/spans_come_spans_go", test_scale_spans_come_spans_go, test_scale_spans_come_spans_go_setup, test_scale_spans_come_spans_go_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
|
||||
{ (char *)"/best-case", test_scale_best_case, test_scale_best_case_setup, test_scale_best_case_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
|
||||
{ (char *)"/worst-case", test_scale_worst_case, test_scale_worst_case_setup, test_scale_worst_case_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
|
||||
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } };
|
||||
|
|
Loading…
Reference in a new issue