tests: Move some functions into a common module.