Automatic test pattern generation