tests: Add function to utils to calculate CONFIG_DIR

Based on pull request #809, which doesn't change all tests.

This PR adds a common function to be used by tests to figure out the configdir and adapts the tests to use it.