Fix some bugs in test framework