From 10457ca754b6458e5ebcf43aef63d2fd60b50843 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Thu, 16 May 2024 15:39:22 -0700 Subject: testing for reallocate --- README | 2 +- imc/checker.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README b/README index 3a7c8b1..ad827a4 100644 --- a/README +++ b/README @@ -64,7 +64,7 @@ Current status of the test harness(es): - [X] init_buddy - [X] allocate - [X] liberate - - [ ] reallocate + - [X] reallocate - [ ] reserve - [ ] grow_buddy - [ ] shrink_buddy diff --git a/imc/checker.c b/imc/checker.c index d3f09cc..2a519ef 100644 --- a/imc/checker.c +++ b/imc/checker.c @@ -52,9 +52,34 @@ void check_main() { (unsigned)(uint8_t)p->data_size); assert(p->data[i] == (uint8_t)p->data_size); } - struct ll *next = p->next; - liberate(p, p->data_size + sizeof(struct ll), &buddy); - p = next; + size_t action = choose(n_size_options + 2, 0); + if (action == n_size_options) { + // do a free! + struct ll *next = p->next; + liberate(p, p->data_size + sizeof(struct ll), &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); + assert(!p); + p = next; + } else { + // do a reallocate + struct ll *next = p->next; + 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); + 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; + p->next = time_to_dielist[t + lifetime]; + time_to_dielist[t + lifetime] = p; + verbose("Reallocated %p, which should die at time %lu\n", + ll, t + lifetime); + p = next; + } } // try allocating a region -- cgit v1.2.3