Fix mkdir failure and duplicated implemenation of test_command.