You try to figure out why it failed the test, get the problem fixed and then try to pass the test again. This may or may not be an ordeal depending on what's wrong with your engine, how easily the problem is to diagnose and repair, and whether or not you flunk a retest.
The worst case scenario is spending a lot of money on repairs only to find that they didn't solve your emissions problem. You bounce back and forth between the repair facility and test station, wasting time and money all the while cursing the incompetent mechanics who tried to fix your car and the bureaucrats who created the clean air emissions testing program.
But in states or municipalities where periodic emissions testing is required, you cannot get your vehicle registration or emissions compliance sticker unless you either pass the test or meet the "waiver" requirements.
A "waiver" is a kind of loophole that allows some vehicles to get past an emissions test even when they can't meet the applicable emission requirements. Some would argue this isn't fair to those whose vehicles meet the requirements and pass the test, but nobody said emissions testing was fair.
Waivers were created by politicians who recognized the fact that many people (voters) can't afford to pay for all the repairs that might be required to pass an emissions test. So credit is given for a good faith effort and for spending a fixed dollar amount on repairs. Once you've spent up to the limit, you get an automatic pass.
Waiver limits vary from one state to another, and some vary by the model year of vehicle. Waiver limits typically range from $75 up to $150, but may be as much as $450 on new vehicles in some states). So if you don't know what the applicable waiver limit is on your vehicle, ask. Unless you're a real zealot about clean air, there's no legal reason to spend a dime more than the waiver limit on emission repairs.
The best way to improve the odds of passing an emissions test is to maintain your vehicle. A well-maintained engine is usually a clean engine as far as emissions are concerned.
Changing the spark plugs, air filter, fuel filter, PCV valve and oil regularly (or just before an emissions test), checking ignition timing and adjusting the carburetor (if you have an older vehicle) can reduce emissions and greatly improve your chance of passing.
Also, filling up your fuel tank with gasoline that contains 10% ethanol alcohol (many premium grade fuels use alcohol as an octane booster) may help lower your emissions even more. Many areas now have "reformulated" gasoline that contains alcohol or MBTE that adds oxygen to the fuel to reduce carbon monoxide and hydrocarbon emissions.
Just before the test, make sure your vehicle is at normal operating temperature. Take it out for a short spin down the expressway. This will heat up the oxygen sensor and catalytic converter to minimize emissions.