testsuite: grep the output patterns only when needed