tests: Add valgrind support

Add support for running tests under valgrind and reporting
valgrind-detected errors.

Allow forcing valgrind on arbitrary tests by setting USE_VALGRIND=1.

Add new 'test_write_and_read_with_valgrind' test case, which runs
the usual 'test_write_and_read' under valgrind.