## malloctest

#### OS/161 Reference Manual

### Name

malloctest - some simple tests for userlevel malloc

### Synopsis

`/testbin/malloctest` [test...]

### Description

`malloctest` contains 7 tests, 1-7. These may be run interactively or from the command line.

Test 1 checks if all the bytes we ask for actually get allocated.

Test 2 checks if `malloc` gracefully handles failing requests. This test assumes that `malloc` will eventually fail if one keeps allocating enough memory, instead of promising memory it can't deliver and then (perhaps) killing processes when it runs out. More detail regarding this condition can be found in comments in the source code.

Test 3 also checks if `malloc` gracefully handles failing requests, and thus has the same restrictions as test 2.

Test 4 attempts to check if `malloc` coalesces the free list properly. This test is only meant for first-fit, next-fit, or best-fit allocators; anything else will most likely confuse it. Running test 4 after other tests may confuse it as well.

Tests 5-7 are a randomized stress test. Test 5 uses pseudorandom seed 0. Test 6 seeds the random generator from the random: device. Test 7 prompts you for a specific seed.

### Requirements

`malloctest` uses the following system calls:

- open
- read
- write
- close
- _exit

Your system should pass all the `malloctest` tests, subject to the conditions described above, once you have implemented sbrk.

### Bugs

Because OS/161 ships with a userlevel `malloc` implementation now, rather than making you write one, this test is not very useful.

Because the userlevel `malloc` OS/161 ships with is quite dumb, test 3 can be amazingly slow.