Lecture 19 introduced racket dialects plai/gc2/collector and plai/gc2/mutator. We also looked at the API required to be provided by a collector. Somewhat suprisingly, that does not include actual garbage collection. In this tutorial we'll get a bit more familiar with the API by writing tests for the null collector discussed in Lecture 19.
1 Error cases
Start by writing tests to exercise each of the error calls in null-gc.rkt.txt Use with-heap and test/exn.
Hints
- It should only take 5 new tests (each wrapped in its own
with-heap
). - You'll likely want to use
let
to locations returned by allocation routines. - Don't forget to call
init-allocator
, or things will fail mysteriously.
2 Atomic / flat data
Add any tests needed for the flat data part of the API.
Hints
- Here it might make sense to wrap multiple tests inside a single
with-heap
. - Two tests did it for me.
3 Cons / Pairs
Add tests to cover the cons
related code.
Hints
- Testing the
set-
functions is a bit trickier; you need several steps per test. - Don't forget you need to create roots when calling cons.
with-roots
can save some hassle creating roots, and you can use it insidewith-heap
.- You may also want to use
gc:deref
on the location returned by e.g.gc:first
.
4 Closures
Add tests to cover the remaining closure related code.
Hints
keep in mind that the code pointer is opaque, so you can pass whatever you want, a symbol, the number 42, your favourite colour.
There are a lot of similarities between the management of closures and the already tested management of
cons
pairs. In particular you need to use roots for both.two tests in one
with-heap
did it for me.
5 Reflection, test design
Unlike the tests we looked at in Lecture 19,
none of my tests for this tutorial used current-heap
to look at the
exact state of the heap, but rather just API calls to look at at
single elements of the heap. Can you think of arguments in favour of
both approaches?