[qfcc] Add failing test case for defspace_alloc_aligned_loc

qfcc is putting two temps in the same location due to
defspace_alloc_aligned_loc returning the same address when there was a
hole caused by an earlier aligned alloc: specifically, a size-3 hole and
a size-2 allocation with alignment-2.
This commit is contained in:
Bill Currie 2022-05-01 14:07:32 +09:00
parent cdd8739577
commit 7518ba0a27
1 changed files with 34 additions and 0 deletions

View File

@ -104,6 +104,39 @@ test_init (void)
return pass;
}
static int
test_aligned_alloc (void)
{
defspace_t *space = defspace_new (ds_virtual);
struct {
int size, align;
} allocations[6] = {
{ 2, 2 },
{ 2, 2 },
{ 1, 1 },
{ 4, 4 },
{ 2, 2 },
{ 2, 2 },
};
int offsets[6];
for (int i = 0; i < 6; i++) {
offsets[i] = defspace_alloc_aligned_loc (space, allocations[i].size,
allocations[i].align);
}
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 6; j++) {
if (offsets[i] == offsets[j]) {
printf ("duplicate offset in allocations");
printf ("%d %d %d %d %d %d\n",
offsets[0], offsets[1], offsets[2],
offsets[3], offsets[4], offsets[5]);
return 0;
}
}
}
return 1;
}
int
main (int argc, const char **argv)
{
@ -112,6 +145,7 @@ main (int argc, const char **argv)
int pass = 1;
pass &= test_init ();
pass &= test_aligned_alloc ();
return !pass;
}