tests: Workaround a bug in terminating valgrind

Valgrind detects SIGSEGVs when stopped with SIGTERM soon after being
started. To workaround this improve the mechanism of stopping valgrind in
our tests to wait a bit before killing any memcheck process.

Change-Id: I51c565ce2b5b86c8c6b612f756ff9df63c424f25