The basic concept is the one you are using.
I personally prefer to set a callback function for the emergency button into which to set the 'fail' flag, and use ProcessSystemEvents () throughout the testing function.
I found this easier 'cause in my testing routine I have a lot of pauses (turn on a relay and wait for it to switch, start a motor engine and wait for it to rotate at the right speed...): I implemented these pauses in while loops with the code to test alarm conditions (daq errors, fuses broken, air pressure fault, carter opened...) and a ProcessSystemEvents inside, so every emergency condition stops my routine.
Hope this elps
Roberto