From cb605a619b96b9261994f28f4af0f3c7e77f0892 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Thu, 16 May 2024 15:46:02 -0700 Subject: test harness includes move_buddy --- imc/checker.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'imc/checker.c') diff --git a/imc/checker.c b/imc/checker.c index 2a519ef..2bde59f 100644 --- a/imc/checker.c +++ b/imc/checker.c @@ -35,15 +35,26 @@ void check_main() { if (choose(2, 0)) pool_size += 11; if (choose(2, 0)) pool = (void*)((uint8_t*)pool + 11); - struct buddy buddy; + struct buddy buddy1; + struct buddy buddy2; + struct buddy *curr_buddy = &buddy1; uint8_t magic[MAGIC_COOKIE_BYTES]; get_random(magic, MAGIC_COOKIE_BYTES); - init_buddy(pool, pool_size, magic, &buddy); + init_buddy(pool, pool_size, magic, curr_buddy); size_t size_options[] = {1, 128, 1024, 5, 167, 10500}; const size_t n_size_options = sizeof(size_options) / sizeof(size_options[0]); for (int t = 0; t < n_timesteps; t++) { + int which_buddy = choose(3, 0); + if (which_buddy == 1) { + move_buddy(&buddy1, curr_buddy); + curr_buddy = &buddy1; + } else if (which_buddy == 2) { + move_buddy(&buddy2, curr_buddy); + curr_buddy = &buddy2; + } + // free the regions at this timestep, and ensure its contents are good for (struct ll *p = time_to_dielist[t]; p;) { for (size_t i = 0; i < p->data_size; i++) { @@ -56,12 +67,12 @@ void check_main() { if (action == n_size_options) { // do a free! struct ll *next = p->next; - liberate(p, p->data_size + sizeof(struct ll), &buddy); + liberate(p, p->data_size + sizeof(struct ll), curr_buddy); p = next; } else if (action == n_size_options + 1) { // do a free, but with reallocate struct ll *next = p->next; - p = reallocate(p, p->data_size + sizeof(struct ll), 0, &buddy); + p = reallocate(p, 0, p->data_size + sizeof(struct ll), curr_buddy); assert(!p); p = next; } else { @@ -70,7 +81,7 @@ void check_main() { size_t old_size = p->data_size + sizeof(struct ll); p->data_size = size_options[action]; size_t new_size = p->data_size + sizeof(struct ll); - p = reallocate(p, old_size, new_size, &buddy); + p = reallocate(p, new_size, old_size, curr_buddy); for (size_t i = 0; i < p->data_size; i++) p->data[i] = (uint8_t)p->data_size; int lifetime = choose(n_timesteps - t, 0) + 1; @@ -84,7 +95,7 @@ void check_main() { // try allocating a region size_t size = size_options[choose(n_size_options, 0)]; - struct ll *ll = allocate(size + sizeof(struct ll), &buddy); + struct ll *ll = allocate(size + sizeof(struct ll), curr_buddy); if (!ll) continue; assert((void*)ll >= pool); assert((uint8_t*)ll + size + sizeof(struct ll) -- cgit v1.2.3