It is not unusual to discover new requirements that needs to be implemented in existing code base when unit testing gets retrofitted into such a code base.

One such interesting case was the behavior of uvm_page_physload(), this function was originally designed to plug in segments of memory range during boot time. Hence if any errors happened it would generally print a message and make the kernel panic. Since this was the way it was expected to work, it was fine for it to return nothing (void) after it’s execution.

Here is the original prototype

void uvm_page_physload(paddr_t, paddr_t, paddr_t, paddr_t, int);

However this was a bit of a hurdle when it came to writing unit tests. One of the biggest annoyances was getting a handle to the segment that was plugged in. Since uvm_page_physload() would not return anything, the only way to get a reference to the first inserted segment would be to do a uvm_physseg_get_first(). Most of the initial unit tests written assume that we fetch the desired handle using uvm_physseg_get_first() function, but this was only a work around, since this is not a reliable approach in this methodology.

After some discussion with cherry@ (Cherry) we decided to a return value to uvm_page_physload(), which got redefined as

uvm_physseg_t uvm_page_physload(paddr_t, paddr_t, paddr_t, paddr_t, int);

Now it returns a handle to the inserted segment. I did have to re-write a lot of tests which assumed the order of insertion for getting the handle using uvm_physseg_get_first() but it made the tests look cleaner along with the API.