Add large smalloc requests to the sfree phase of the test. This exposes
a smalloc garbage collection issue.
#define MAGIC2 0xf0a1e9b3
#define LOOPS 32
#define MAGIC2 0xf0a1e9b3
#define LOOPS 32
+#define MAXSMALLOC 120*1024*1024UL
+#define LARGESMALLOC 128*1024U
struct elem {
unsigned int magic1;
struct flist_head list;
unsigned int magic2;
struct elem {
unsigned int magic1;
struct flist_head list;
unsigned int magic2;
};
static FLIST_HEAD(list);
};
static FLIST_HEAD(list);
unsigned int size, nr, rounds = 0;
unsigned long total;
struct elem *e;
unsigned int size, nr, rounds = 0;
unsigned long total;
struct elem *e;
while (rounds++ < LOOPS) {
#ifdef STEST_SEED
srand(MAGIC1);
#endif
while (rounds++ < LOOPS) {
#ifdef STEST_SEED
srand(MAGIC1);
#endif
- while (total < 120*1024*1024UL) {
+ while (total < MAXSMALLOC) {
size = 8 * sizeof(struct elem) + (int) (999.0 * (rand() / (RAND_MAX + 1.0)));
e = smalloc(size);
if (!e) {
size = 8 * sizeof(struct elem) + (int) (999.0 * (rand() / (RAND_MAX + 1.0)));
e = smalloc(size);
if (!e) {
}
e->magic1 = MAGIC1;
e->magic2 = MAGIC2;
}
e->magic1 = MAGIC1;
e->magic2 = MAGIC2;
total += size;
flist_add_tail(&e->list, &list);
nr++;
total += size;
flist_add_tail(&e->list, &list);
nr++;
e = flist_entry(list.next, struct elem, list);
assert(e->magic1 == MAGIC1);
assert(e->magic2 == MAGIC2);
e = flist_entry(list.next, struct elem, list);
assert(e->magic1 == MAGIC1);
assert(e->magic2 == MAGIC2);
flist_del(&e->list);
sfree(e);
flist_del(&e->list);
sfree(e);
+
+ if (!error) {
+ e = smalloc(LARGESMALLOC);
+ if (!e) {
+ error = true;
+ printf("failure allocating %u bytes at %lu allocated during sfree phase\n",
+ LARGESMALLOC, total);
+ }
+ else
+ sfree(e);
+ }
debug_init();
do_rand_allocs();
debug_init();
do_rand_allocs();
+ smalloc_debug(0); /* free and total blocks should match */