[test] adjust tests for make test VALGRIND=valgrind

result should not interleave with post-exit valgrind ==pid== output
e.g. => "42==16469== Memcheck, a memory error detector"
We need to add "42\n" because ==... is only filtered at new lines.

Some of the filtered valgrind lines are darwin specific:
--$pid:0:syswrap- WARNING: Ignoring sigreturn( ..., UC_RESET_ALT_STACK );
on longjmp, darwin only.
or UNKNOWN task message [id 3403, to mach_task_self(), reply 0x813]

Closes GH #1150
[test] refactor, new valgrind_filter function

also print LEAK SUMMARY: definitely lost: $1 bytes in $2 blocks
if so. GH #1150