Updated km4 to write to, and check, each page allocated in the multi-page allocation.

This should find cases where students ignore npages and just allocate one page, which
would previously work.
This commit is contained in:
Scott Haseley 2016-03-28 15:43:39 -04:00
parent afcb45766e
commit 7f3f686b1a

View File

@ -324,7 +324,7 @@ kmalloctest4thread(void *sm, unsigned long num)
struct semaphore *sem = sm; struct semaphore *sem = sm;
void *ptrs[NUM_KM4_SIZES]; void *ptrs[NUM_KM4_SIZES];
unsigned p, q; unsigned p, q;
unsigned i, j; unsigned i, j, k;
uint32_t magic; uint32_t magic;
for (i=0; i<NUM_KM4_SIZES; i++) { for (i=0; i<NUM_KM4_SIZES; i++) {
@ -347,15 +347,21 @@ kmalloctest4thread(void *sm, unsigned long num)
num, sizes[p]); num, sizes[p]);
} }
// Write to the allocated memory and make sure nothing overwrites it. // Write to each page of the allocated memory and make sure nothing
*(uint32_t *)ptrs[p] = magic; // overwrites it.
for (k = 0; k < sizes[p]; k++) {
*((uint32_t *)ptrs[p] + k*PAGE_SIZE/sizeof(uint32_t)) = magic;
}
for (j = 0; j < ITERATIONS; j++) { for (j = 0; j < ITERATIONS; j++) {
random_yielder(4); random_yielder(4);
if ((*(uint32_t *)ptrs[p]) != magic) { for (k = 0; k < sizes[p]; k++) {
if (*((uint32_t *)ptrs[p] + k*PAGE_SIZE/sizeof(uint32_t)) != magic) {
panic("km4: expected %u got %u. Your VM is broken!", panic("km4: expected %u got %u. Your VM is broken!",
magic, (*(uint32_t *)ptrs[p])); magic, (*(uint32_t *)ptrs[p]));
} }
} }
}
magic++; magic++;
p = (p + 1) % NUM_KM4_SIZES; p = (p + 1) % NUM_KM4_SIZES;
q = (q + 1) % NUM_KM4_SIZES; q = (q + 1) % NUM_KM4_SIZES;