MT#5757 bin/check.sh: add -g option to generate graph only if test fails