Commit 60fb6bfc authored by Rusty Russell's avatar Rusty Russell

sub-page allocations work, still some FIXMEs to go.

parent 3d34b48f
This diff is collapsed.
......@@ -24,13 +24,32 @@ static bool unique(void *p[], unsigned int num)
return true;
}
static bool free_every_second_one(void *mem, unsigned int num, void *p[])
{
unsigned int i;
/* Free every second one. */
for (i = 0; i < num; i += 2) {
alloc_free(mem, POOL_SIZE, p[i]);
if (!alloc_check(mem, POOL_SIZE))
return false;
}
for (i = 1; i < num; i += 2) {
alloc_free(mem, POOL_SIZE, p[i]);
if (!alloc_check(mem, POOL_SIZE))
return false;
}
return true;
}
int main(int argc, char *argv[])
{
void *mem;
unsigned int i, num, max_size;
void *p[POOL_SIZE];
plan_tests(141);
plan_tests(133);
/* FIXME: Needs to be page aligned for now. */
posix_memalign(&mem, getpagesize(), POOL_SIZE);
......@@ -85,15 +104,7 @@ int main(int argc, char *argv[])
/* Uniqueness check */
ok1(unique(p, num));
/* Free every second one. */
for (i = 0; i < num; i += 2) {
alloc_free(mem, POOL_SIZE, p[i]);
ok1(alloc_check(mem, POOL_SIZE));
}
for (i = 1; i < num; i += 2) {
alloc_free(mem, POOL_SIZE, p[i]);
ok1(alloc_check(mem, POOL_SIZE));
}
ok1(free_every_second_one(mem, num, p));
ok1(alloc_check(mem, POOL_SIZE));
/* Should be able to reallocate max size. */
......@@ -111,14 +122,14 @@ int main(int argc, char *argv[])
ok1(alloc_check(mem, POOL_SIZE));
/* Alignment constraints should be met, as long as powers of two */
for (i = 0; i < POOL_ORD-2 /* FIXME: Should be -1 */; i++) {
for (i = 0; i < POOL_ORD-1; i++) {
p[i] = alloc_get(mem, POOL_SIZE, i, 1 << i);
ok1(p[i]);
ok1(((unsigned long)p[i] % (1 << i)) == 0);
ok1(alloc_check(mem, POOL_SIZE));
}
for (i = 0; i < POOL_ORD-2 /* FIXME: Should be -1 */; i++) {
for (i = 0; i < POOL_ORD-1; i++) {
alloc_free(mem, POOL_SIZE, p[i]);
ok1(alloc_check(mem, POOL_SIZE));
}
......@@ -132,5 +143,11 @@ int main(int argc, char *argv[])
ok1(alloc_check(mem, POOL_SIZE));
}
/* Alignment check for a 0-byte allocation. Corner case. */
p[0] = alloc_get(mem, POOL_SIZE, 0, 1 << (POOL_ORD - 1));
ok1(alloc_check(mem, POOL_SIZE));
alloc_free(mem, POOL_SIZE, p[0]);
ok1(alloc_check(mem, POOL_SIZE));
return exit_status();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment