Enable unit tests and fix all the issues found thanks to them
Created by: mardy
It might be simpler to review this commit by commit, as there are many unrelated changes. The unifying point is that all these commits are either related to enabling running unit tests, or to fixing errors found thanks to them.