1) Moved tprintf and related functions to their own file in common/libc/printf/tprintf.c.
This file is included by both libc and hostcompat. 2) Changed printf -> tprintf in all testbin programs
This commit is contained in:
@@ -77,7 +77,7 @@ geti(void)
|
||||
break;
|
||||
}
|
||||
else if ((ch=='\b' || ch==127) && digits>0) {
|
||||
printf("\b \b");
|
||||
tprintf("\b \b");
|
||||
val = val/10;
|
||||
digits--;
|
||||
}
|
||||
@@ -117,11 +117,11 @@ markblock(volatile void *ptr, size_t size, unsigned bias, int doprint)
|
||||
val = ((unsigned long)i ^ (unsigned long)bias);
|
||||
pl[i] = val;
|
||||
if (doprint && (i%64==63)) {
|
||||
printf(".");
|
||||
tprintf(".");
|
||||
}
|
||||
}
|
||||
if (doprint) {
|
||||
printf("\n");
|
||||
tprintf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +143,9 @@ checkblock(volatile void *ptr, size_t size, unsigned bias, int doprint)
|
||||
val = ((unsigned long)i ^ (unsigned long)bias);
|
||||
if (pl[i] != val) {
|
||||
if (doprint) {
|
||||
printf("\n");
|
||||
tprintf("\n");
|
||||
}
|
||||
printf("FAILED: data mismatch at offset %lu of block "
|
||||
tprintf("FAILED: data mismatch at offset %lu of block "
|
||||
"at 0x%lx: %lu vs. %lu\n",
|
||||
(unsigned long) (i*sizeof(unsigned long)),
|
||||
(unsigned long)(uintptr_t)pl,
|
||||
@@ -153,11 +153,11 @@ checkblock(volatile void *ptr, size_t size, unsigned bias, int doprint)
|
||||
return -1;
|
||||
}
|
||||
if (doprint && (i%64==63)) {
|
||||
printf(".");
|
||||
tprintf(".");
|
||||
}
|
||||
}
|
||||
if (doprint) {
|
||||
printf("\n");
|
||||
tprintf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -178,23 +178,23 @@ test1(void)
|
||||
{
|
||||
volatile unsigned *x;
|
||||
|
||||
printf("*** Malloc test 1 ***\n");
|
||||
printf("Allocating %u bytes\n", BIGSIZE);
|
||||
tprintf("*** Malloc test 1 ***\n");
|
||||
tprintf("Allocating %u bytes\n", BIGSIZE);
|
||||
x = malloc(BIGSIZE);
|
||||
if (x==NULL) {
|
||||
printf("FAILED: malloc failed\n");
|
||||
tprintf("FAILED: malloc failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
markblock(x, BIGSIZE, 0, 0);
|
||||
if (checkblock(x, BIGSIZE, 0, 0)) {
|
||||
printf("FAILED: data corrupt\n");
|
||||
tprintf("FAILED: data corrupt\n");
|
||||
return;
|
||||
}
|
||||
|
||||
free((void *)x);
|
||||
|
||||
printf("Passed malloc test 1.\n");
|
||||
tprintf("Passed malloc test 1.\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -237,43 +237,43 @@ test2(void)
|
||||
volatile unsigned *x;
|
||||
size_t size;
|
||||
|
||||
printf("Entering malloc test 2.\n");
|
||||
printf("Make sure you read and understand the comment in malloctest.c "
|
||||
tprintf("Entering malloc test 2.\n");
|
||||
tprintf("Make sure you read and understand the comment in malloctest.c "
|
||||
"that\nexplains the conditions this test assumes.\n\n");
|
||||
|
||||
printf("Testing how much memory we can allocate:\n");
|
||||
tprintf("Testing how much memory we can allocate:\n");
|
||||
|
||||
for (size = HUGESIZE; (x = malloc(size))==NULL; size = size/2) {
|
||||
printf(" %9lu bytes: failed\n", (unsigned long) size);
|
||||
tprintf(" %9lu bytes: failed\n", (unsigned long) size);
|
||||
}
|
||||
printf(" %9lu bytes: succeeded\n", (unsigned long) size);
|
||||
tprintf(" %9lu bytes: succeeded\n", (unsigned long) size);
|
||||
|
||||
printf("Passed part 1\n");
|
||||
tprintf("Passed part 1\n");
|
||||
|
||||
printf("Touching all the words in the block.\n");
|
||||
tprintf("Touching all the words in the block.\n");
|
||||
markblock(x, size, 0, 1);
|
||||
|
||||
printf("Validating the words in the block.\n");
|
||||
tprintf("Validating the words in the block.\n");
|
||||
if (checkblock(x, size, 0, 1)) {
|
||||
printf("FAILED: data corrupt\n");
|
||||
tprintf("FAILED: data corrupt\n");
|
||||
return;
|
||||
}
|
||||
printf("Passed part 2\n");
|
||||
tprintf("Passed part 2\n");
|
||||
|
||||
|
||||
printf("Freeing the block\n");
|
||||
tprintf("Freeing the block\n");
|
||||
free((void *)x);
|
||||
printf("Passed part 3\n");
|
||||
printf("Allocating another block\n");
|
||||
tprintf("Passed part 3\n");
|
||||
tprintf("Allocating another block\n");
|
||||
|
||||
x = malloc(size);
|
||||
if (x==NULL) {
|
||||
printf("FAILED: free didn't return the memory?\n");
|
||||
tprintf("FAILED: free didn't return the memory?\n");
|
||||
return;
|
||||
}
|
||||
free((void *)x);
|
||||
|
||||
printf("Passed malloc test 2.\n");
|
||||
tprintf("Passed malloc test 2.\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -304,11 +304,11 @@ test3(void)
|
||||
int ct=0, failed=0;
|
||||
void *x;
|
||||
|
||||
printf("Entering malloc test 3.\n");
|
||||
printf("Make sure you read and understand the comment in malloctest.c "
|
||||
tprintf("Entering malloc test 3.\n");
|
||||
tprintf("Make sure you read and understand the comment in malloctest.c "
|
||||
"that\nexplains the conditions this test assumes.\n\n");
|
||||
|
||||
printf("Testing how much memory we can allocate:\n");
|
||||
tprintf("Testing how much memory we can allocate:\n");
|
||||
|
||||
while ((tmp = malloc(sizeof(struct test3))) != NULL) {
|
||||
|
||||
@@ -322,33 +322,33 @@ test3(void)
|
||||
|
||||
ct++;
|
||||
if (ct%128==0) {
|
||||
printf(".");
|
||||
tprintf(".");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Allocated %lu bytes\n", (unsigned long) tot);
|
||||
tprintf("Allocated %lu bytes\n", (unsigned long) tot);
|
||||
|
||||
printf("Trying some more allocations which I expect to fail...\n");
|
||||
tprintf("Trying some more allocations which I expect to fail...\n");
|
||||
|
||||
x = malloc(SMALLSIZE);
|
||||
if (x != NULL) {
|
||||
printf("FAILED: malloc(%u) succeeded\n", SMALLSIZE);
|
||||
tprintf("FAILED: malloc(%u) succeeded\n", SMALLSIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
x = malloc(MEDIUMSIZE);
|
||||
if (x != NULL) {
|
||||
printf("FAILED: malloc(%u) succeeded\n", MEDIUMSIZE);
|
||||
tprintf("FAILED: malloc(%u) succeeded\n", MEDIUMSIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
x = malloc(BIGSIZE);
|
||||
if (x != NULL) {
|
||||
printf("FAILED: malloc(%u) succeeded\n", BIGSIZE);
|
||||
tprintf("FAILED: malloc(%u) succeeded\n", BIGSIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Ok, now I'm going to free everything...\n");
|
||||
tprintf("Ok, now I'm going to free everything...\n");
|
||||
|
||||
while (list != NULL) {
|
||||
tmp = list->next;
|
||||
@@ -363,20 +363,20 @@ test3(void)
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
printf("FAILED: data corruption\n");
|
||||
tprintf("FAILED: data corruption\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Let me see if I can allocate some more now...\n");
|
||||
tprintf("Let me see if I can allocate some more now...\n");
|
||||
|
||||
x = malloc(MEDIUMSIZE);
|
||||
if (x == NULL) {
|
||||
printf("FAIL: Nope, I couldn't.\n");
|
||||
tprintf("FAIL: Nope, I couldn't.\n");
|
||||
return;
|
||||
}
|
||||
free(x);
|
||||
|
||||
printf("Passed malloc test 3\n");
|
||||
tprintf("Passed malloc test 3\n");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -397,34 +397,34 @@ test4(void)
|
||||
void *x, *y, *z;
|
||||
unsigned long lx, ly, lz, overhead, zsize;
|
||||
|
||||
printf("Entering malloc test 4.\n");
|
||||
printf("This test is intended for first/best-fit based mallocs.\n");
|
||||
printf("This test may not work correctly if run after other tests.\n");
|
||||
tprintf("Entering malloc test 4.\n");
|
||||
tprintf("This test is intended for first/best-fit based mallocs.\n");
|
||||
tprintf("This test may not work correctly if run after other tests.\n");
|
||||
|
||||
printf("Testing free list coalescing:\n");
|
||||
tprintf("Testing free list coalescing:\n");
|
||||
|
||||
x = malloc(SMALLSIZE);
|
||||
if (x==NULL) {
|
||||
printf("FAILED: malloc(%u) failed\n", SMALLSIZE);
|
||||
tprintf("FAILED: malloc(%u) failed\n", SMALLSIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
y = malloc(MEDIUMSIZE);
|
||||
if (y==NULL) {
|
||||
printf("FAILED: malloc(%u) failed\n", MEDIUMSIZE);
|
||||
tprintf("FAILED: malloc(%u) failed\n", MEDIUMSIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sizeof(unsigned long) < sizeof(void *)) {
|
||||
printf("Buh? I can't fit a void * in an unsigned long\n");
|
||||
printf("ENVIRONMENT FAILED...\n");
|
||||
tprintf("Buh? I can't fit a void * in an unsigned long\n");
|
||||
tprintf("ENVIRONMENT FAILED...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
lx = (unsigned long)x;
|
||||
ly = (unsigned long)y;
|
||||
|
||||
printf("x is 0x%lx; y is 0x%lx\n", lx, ly);
|
||||
tprintf("x is 0x%lx; y is 0x%lx\n", lx, ly);
|
||||
|
||||
/*
|
||||
* The memory should look something like this:
|
||||
@@ -436,7 +436,7 @@ test4(void)
|
||||
|
||||
/* This is obviously wrong. */
|
||||
if (lx == ly) {
|
||||
printf("FAIL: x == y\n");
|
||||
tprintf("FAIL: x == y\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -447,11 +447,11 @@ test4(void)
|
||||
* or the other block's start is within the first block.)
|
||||
*/
|
||||
if (lx < ly && lx + SMALLSIZE > ly) {
|
||||
printf("FAIL: y starts within x\n");
|
||||
tprintf("FAIL: y starts within x\n");
|
||||
return;
|
||||
}
|
||||
if (ly < lx && ly + MEDIUMSIZE > lx) {
|
||||
printf("FAIL: x starts within y\n");
|
||||
tprintf("FAIL: x starts within y\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ test4(void)
|
||||
* free list.
|
||||
*/
|
||||
if (ly < lx) {
|
||||
printf("TEST UNSUITABLE: y is below x\n");
|
||||
tprintf("TEST UNSUITABLE: y is below x\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -469,39 +469,39 @@ test4(void)
|
||||
* Compute the space used by index structures.
|
||||
*/
|
||||
overhead = ly - (lx + SMALLSIZE);
|
||||
printf("Apparent block overhead: %lu\n", overhead);
|
||||
tprintf("Apparent block overhead: %lu\n", overhead);
|
||||
|
||||
if (overhead > ABSURD_OVERHEAD) {
|
||||
printf("TEST UNSUITABLE: block overhead absurdly large.\n");
|
||||
tprintf("TEST UNSUITABLE: block overhead absurdly large.\n");
|
||||
return;
|
||||
}
|
||||
if (overhead > OVERHEAD) {
|
||||
printf("FAIL: block overhead is too large.\n");
|
||||
tprintf("FAIL: block overhead is too large.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Freeing blocks...\n");
|
||||
tprintf("Freeing blocks...\n");
|
||||
free(x);
|
||||
free(y);
|
||||
|
||||
zsize = SMALLSIZE + MEDIUMSIZE + overhead;
|
||||
|
||||
printf("Now allocating %lu bytes... should reuse the space.\n", zsize);
|
||||
tprintf("Now allocating %lu bytes... should reuse the space.\n", zsize);
|
||||
z = malloc(zsize);
|
||||
if (z == NULL) {
|
||||
printf("FAIL: Allocation failed...\n");
|
||||
tprintf("FAIL: Allocation failed...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
lz = (unsigned long) z;
|
||||
|
||||
printf("z is 0x%lx (x was 0x%lx, y 0x%lx)\n", lz, lx, ly);
|
||||
tprintf("z is 0x%lx (x was 0x%lx, y 0x%lx)\n", lz, lx, ly);
|
||||
|
||||
if (lz==lx) {
|
||||
printf("Passed.\n");
|
||||
tprintf("Passed.\n");
|
||||
}
|
||||
else {
|
||||
printf("Failed.\n");
|
||||
tprintf("Failed.\n");
|
||||
}
|
||||
|
||||
free(z);
|
||||
@@ -530,7 +530,7 @@ test567(int testno, unsigned long seed)
|
||||
int i, n, size, failed=0;
|
||||
|
||||
srandom(seed);
|
||||
printf("Seeded random number generator with %lu.\n", seed);
|
||||
tprintf("Seeded random number generator with %lu.\n", seed);
|
||||
|
||||
for (i=0; i<32; i++) {
|
||||
ptrs[i] = NULL;
|
||||
@@ -544,7 +544,7 @@ test567(int testno, unsigned long seed)
|
||||
ptrs[n] = malloc(size);
|
||||
psizes[n] = size;
|
||||
if (ptrs[n] == NULL) {
|
||||
printf("\nmalloc %u failed\n", size);
|
||||
tprintf("\nmalloc %u failed\n", size);
|
||||
failed = 1;
|
||||
break;
|
||||
}
|
||||
@@ -561,10 +561,10 @@ test567(int testno, unsigned long seed)
|
||||
psizes[n] = 0;
|
||||
}
|
||||
if (i%256==0) {
|
||||
printf(".");
|
||||
tprintf(".");
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
tprintf("\n");
|
||||
|
||||
for (i=0; i<32; i++) {
|
||||
if (ptrs[i] != NULL) {
|
||||
@@ -573,10 +573,10 @@ test567(int testno, unsigned long seed)
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
printf("FAILED malloc test %d\n", testno);
|
||||
tprintf("FAILED malloc test %d\n", testno);
|
||||
}
|
||||
else {
|
||||
printf("Passed malloc test %d\n", testno);
|
||||
tprintf("Passed malloc test %d\n", testno);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,7 +584,7 @@ static
|
||||
void
|
||||
test5(void)
|
||||
{
|
||||
printf("Beginning malloc test 5\n");
|
||||
tprintf("Beginning malloc test 5\n");
|
||||
test567(5, 0);
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ test6(void)
|
||||
int fd, len;
|
||||
unsigned long seed;
|
||||
|
||||
printf("Beginning malloc test 6\n");
|
||||
tprintf("Beginning malloc test 6\n");
|
||||
|
||||
fd = open(_PATH_RANDOM, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
@@ -619,9 +619,9 @@ test7(void)
|
||||
{
|
||||
unsigned long seed;
|
||||
|
||||
printf("Beginning malloc test 7\n");
|
||||
tprintf("Beginning malloc test 7\n");
|
||||
|
||||
printf("Enter random seed: ");
|
||||
tprintf("Enter random seed: ");
|
||||
seed = geti();
|
||||
|
||||
test567(7, seed);
|
||||
@@ -673,12 +673,12 @@ main(int argc, char *argv[])
|
||||
while (1) {
|
||||
if (menu) {
|
||||
for (i=0; tests[i].num>=0; i++) {
|
||||
printf(" %2d %s\n", tests[i].num,
|
||||
tprintf(" %2d %s\n", tests[i].num,
|
||||
tests[i].desc);
|
||||
}
|
||||
menu = 0;
|
||||
}
|
||||
printf("malloctest: ");
|
||||
tprintf("malloctest: ");
|
||||
tn = geti();
|
||||
if (tn < 0) {
|
||||
break;
|
||||
|
Reference in New Issue
Block a user