Add commandline options to test.py
Fix logging and error handling.